Context Class
EnOptContext is the validated, frozen container
that holds every setting needed to execute a single optimization run. It is
typically built from a plain dict (EnOptContext.model_validate(CONFIG)).
For a narrative overview of all fields — including broadcasting rules, index-based sharing of plugin instances, defaults, and worked examples — see the Configuration user-manual page.
ropt.context
The ropt.context module provides the context class used by optimization workflows.
EnOptContext
Bases: BaseModel
The primary context object for a single optimization run.
EnOptContext holds all information needed to run an ensemble-based
optimization: variables, objectives, constraints, realizations, gradient
settings, samplers, filters, and the optimizer/backend. It is constructed
from plain Python dicts or config objects and validated on creation.
See the Configuration guide for an in-depth
description of broadcasting rules, index-based sharing of plugin
instances, the names attribute, and how dicts are resolved into plugin
instances.
Warning
EnOptContext objects are immutable after construction. Do not attempt
to serialize and round-trip them (e.g., to/from JSON): numpy arrays
and plugin instances cannot survive a round-trip faithfully. Persist the
raw input dicts 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 |
tuple[RealizationFilterInstance, ...]
|
Tuple of realization filter plugin instances. |
function_estimators |
tuple[FunctionEstimatorInstance, ...]
|
Tuple of function estimator plugin instances. |
samplers |
tuple[SamplerInstance, ...]
|
Tuple of sampler plugin instances. |
variable_transforms |
tuple[VariableTransformInstance, ...]
|
Tuple of variable transform plugin instances. |
objective_transforms |
tuple[ObjectiveTransformInstance, ...]
|
Tuple of objective transform plugin instances. |
nonlinear_constraint_transforms |
tuple[NonlinearConstraintTransformInstance, ...]
|
Tuple of nonlinear constraint transform plugin instances. |
names |
dict[str, tuple[str | int, ...]]
|
Optional mapping of axis names to label sequences. |
lock
Lock the object to prevent sharing and re-use.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the object is already locked. |