Basic Optimization Workflow
BasicOptimizer is the high-level driver for
running a single optimization. See Basic Optimization for
a walkthrough.
ropt.workflow._basic_optimizer
This module defines a basic optimization object.
ropt.workflow.BasicOptimizer
A simple interface for single optimization runs.
Wraps the workflow framework into a run-once interface with built-in result tracking.
See Basic Optimization for a walkthrough and full example.
__init__
__init__(
config: dict[str, Any],
evaluator: EvaluationBatchCallback | Evaluator,
*,
constraint_tolerance: float = 1e-10,
) -> None
Initialize a BasicOptimizer object.
This constructor sets up the necessary components for a single optimization run. It requires an optimization configuration, an evaluator, and optional domain transform, which together define the optimization problem.
The constraint_tolerance is used to check any constraints, if a
constraint value is within this tolerance, it is considered satisfied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any]
|
The configuration for the optimization. |
required |
evaluator
|
EvaluationBatchCallback | Evaluator
|
The evaluator object. |
required |
constraint_tolerance
|
float
|
The constraint violation tolerance. |
1e-10
|
results
property
The optimal result found during the optimization.
This property provides access to the best
FunctionResults object discovered
during the optimization process. It encapsulates the objective function
value, constraint values, and other relevant information about the
optimal solution.
Returns:
| Type | Description |
|---|---|
FunctionResults | None
|
The optimal result. |
run
Run the optimization process.
This method initiates and executes the optimization workflow defined by
the BasicOptimizer object. It manages the optimization, result
handling, and event processing. After the optimization is complete, the
optimal results, variables, and exit code can be accessed via the
corresponding properties.
Returns:
| Type | Description |
|---|---|
ExitCode
|
The exit code returned by the optimization workflow. |
set_abort_callback
Set a callback to check for abort conditions.
The provided callback function will be invoked repeatedly during the
optimization process. If the callback returns True, the optimization
will be aborted, and the BasicOptimizer will exit with an
ExitCode.USER_ABORT.
The callback function should have no arguments and return a boolean value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback
|
Callable[[], bool]
|
The callable to check for abort conditions. |
required |
set_results_callback
Set a callback to report new results.
The provided callback function will be invoked whenever new results become available during the optimization process. This allows for real-time monitoring and analysis of the optimization's progress.
The required signature of the callback function should be:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback
|
Callable[..., None]
|
The callable that will be invoked to report new results. |
required |