Compute Steps
ropt.plugins.compute_step.default
This module provides the default plugin implementations for compute steps.
Supported Components:
ensemble_evaluator: Performs ensemble evaluations (DefaultEnsembleEvaluatorComputeStep).optimizer: Runs an optimization algorithm using a configured optimizer plugin (DefaultOptimizerComputeStep).
ropt.plugins.compute_step.default.DefaultComputeStepPlugin
Bases: ComputeStepPlugin
The default plugin for creating compute_steps.
This plugin acts as a factory for the standard ComputeStep implementations
provided by ropt.
Supported Compute Steps:
ensemble_evaluator: Creates aDefaultEnsembleEvaluatorComputeStepinstance, which performs ensemble evaluations.optimizer: Creates aDefaultOptimizerComputeStepinstance, which runs an optimization algorithm using a configured optimizer plugin.
ropt.plugins.compute_step.ensemble_evaluator.DefaultEnsembleEvaluatorComputeStep
Bases: ComputeStep
The default ensemble evaluator compute step for optimization workflows.
This compute step performs one or more ensemble evaluations based on the
provided variables. It yields a tuple of
FunctionResults objects, one for each
input variable vector evaluated.
The compute step emits the following events:
START_ENSEMBLE_EVALUATOR: Emitted before the evaluation process begins.START_EVALUATION: Emitted just before the underlying ensemble evaluation is called.FINISHED_EVALUATION: Emitted after the evaluation completes, carrying the generatedFunctionResultsin itsdatadictionary under the key"results". Event handlers typically listen for this event.FINISHED_ENSEMBLE_EVALUATOR: Emitted after the entire compute step, including result emission, is finished.
__init__
Initialize a default evaluator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evaluator
|
Evaluator
|
The evaluator object to run function evaluations. |
required |
run
run(
config: EnOptConfig,
variables: ArrayLike,
*,
transforms: OptModelTransforms | None = None,
metadata: dict[str, Any] | None = None,
) -> ExitCode
Run the ensemble evaluator.
This method executes the core logic of the ensemble evaluator. It
requires an optimizer configuration
(EnOptConfig) and optionally accepts
specific variable vectors to evaluate.
If metadata is provided, it is attached to the
Results objects emitted via the
FINISHED_EVALUATION event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
EnOptConfig
|
Optimizer configuration. |
required |
variables
|
ArrayLike
|
Variable vector(s) to evaluate. |
required |
transforms
|
OptModelTransforms | None
|
Optional transforms to apply to the variables, objectives, and constraints. |
None
|
metadata
|
dict[str, Any] | None
|
Optional dictionary to attach to emitted |
None
|
Returns:
| Type | Description |
|---|---|
ExitCode
|
An |
ropt.plugins.compute_step.optimizer.DefaultOptimizerComputeStep
Bases: ComputeStep
The default optimizer compute step.
This compute step executes an optimization algorithm based on a provided
configuration (EnOptConfig or a compatible
dictionary). It iteratively performs function and potentially gradient
evaluations, yielding a sequence of
FunctionResults and
GradientResults objects.
While initial variable values are typically specified in the configuration,
they can be overridden by passing them directly to the run method.
The following events are emitted during execution:
START_OPTIMIZER: Emitted just before the optimization process begins.START_EVALUATION: Emitted immediately before an ensemble evaluation (for functions or gradients) is requested from the underlying optimizer.FINISHED_EVALUATION: Emitted after an evaluation completes. This event carries the generatedResultsobject(s) in itsdatadictionary under the key"results". Event handlers typically listen for this event to process or track optimization progress.FINISHED_OPTIMIZER: Emitted after the entire optimization process concludes (successfully, or due to termination conditions or errors).
This compute step also supports nested optimization. If a
nested_optimization function is provided to the run method, the
optimizer will execute a nested optimization at as part of each function
evaluation. The nested_optimization function is expected to return a
single FunctionResults object and a flag
that indicates whether the optimization was aborted by the user.
__init__
Initialize a default optimizer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evaluator
|
Evaluator
|
The evaluator object to run function evaluations. |
required |
run
run(
config: EnOptConfig,
variables: ArrayLike,
*,
transforms: OptModelTransforms | None = None,
nested_optimization: NestedOptimizationCallable
| None = None,
metadata: dict[str, Any] | None = None,
) -> ExitCode
Run the compute step to perform an optimization.
This method executes the core logic of the optimizer compute step. It
requires an optimizer configuration
(EnOptConfig) and optionally accepts
specific initial variable vectors, and/or a nested optimization
workflow, and metadata.
If variables are not provided, the initial values specified in the
config are used. If variables are provided, they override the
config's initial values.
If metadata is provided, it is attached to the
Results objects emitted via the
FINISHED_EVALUATION event.
If a nested_optimization callable is provided, a callable will be
called passing the initial variables to use. The callable should return
a a single FunctionResults object that
should contain the results of the nested optimization, and a flag
indicating whether the optimization was aborted by the user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
EnOptConfig
|
Optimizer configuration. |
required |
transforms
|
OptModelTransforms | None
|
Optional transforms to apply to the variables, objectives, and constraints. |
None
|
variables
|
ArrayLike
|
Optional initial variable vector(s) to start from. |
required |
nested_optimization
|
NestedOptimizationCallable | None
|
Optional callable to run a nested optimization. |
None
|
metadata
|
dict[str, Any] | None
|
Optional dictionary to attach to emitted |
None
|
Returns:
| Type | Description |
|---|---|
ExitCode
|
An exit code indicating the outcome of the optimization. |