Context Class
ropt.context
The validated configuration of a single optimization run.
EnOptContext is the frozen container holding
every setting a run needs, normally built from a plain dictionary with
EnOptContext.model_validate(config). See
Configuration for the fields,
broadcasting rules and defaults.
EnOptContext
Bases: BaseModel
The validated configuration of a single optimization run.
Holds the variables, objectives, constraints, realizations, gradient settings, samplers, filters, optimizer and backend that a run needs. It is built from plain dictionaries or configuration objects and validated on creation.
See Configuration.
Warning
Construction scales several settings in a way that cannot be undone. Treat a context as read-only afterwards, and do not rebuild one from serialized field values; persist the raw input dictionaries instead.
Attributes:
| Name | Type | Description |
|---|---|---|
variables |
VariablesConfig
|
Variable settings. |
objectives |
ObjectiveFunctionsConfig
|
Objective function settings. |
linear_constraints |
LinearConstraintsConfig | None
|
Optional linear constraint settings. |
nonlinear_constraints |
NonlinearConstraintsConfig | None
|
Optional nonlinear constraint settings. |
realizations |
RealizationsConfig
|
Ensemble realization settings. |
optimizer |
OptimizerConfig
|
Optimizer settings. |
backend |
BackendInstance
|
Backend plugin instance used for function evaluations. |
gradient |
GradientConfig
|
Gradient estimation settings. |
realization_filters |
RealizationFilterInstances
|
Realization filter instances, by key. |
function_estimators |
FunctionEstimatorInstances
|
Function estimator instances, by key. |
samplers |
SamplerInstances
|
Sampler instances, by key. |
names |
dict[str, tuple[str | int, ...]]
|
Optional mapping of axis names to label sequences. |
get_objective_scales
Return the scale applied to each objective.
Objectives are divided by their scale before they reach the optimizer,
and multiplied by it again before they are reported. The scales are the
configured scales, multiplied by an estimated factor if auto-scaling
is enabled and has run.
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
The objective scales. |
get_constraint_scales
Return the scale applied to each nonlinear constraint.
Returns:
| Type | Description |
|---|---|
NDArray[float64] | None
|
The constraint scales, or |
get_objective_offsets
Return the offset applied to each objective.
Objectives have their offset subtracted before they are divided by their scale, and it is added back before they are reported.
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
The objective offsets. |
get_nonlinear_constraint_bounds
Return the scaled nonlinear constraint bounds.
The bounds are transformed together with the constraint values, so that the configured constraint is the constraint that is solved. Scales are positive, so the bounds keep their order.
Returns:
| Type | Description |
|---|---|
tuple[NDArray[float64], NDArray[float64]] | None
|
The lower and upper bounds, or |
lock
Lock the object to prevent sharing and re-use.
Raises:
| Type | Description |
|---|---|
WorkflowError
|
If the object is already locked. |