Skip to main content

OptimizationContext

class OptimizationContext(BaseModel)

Domain-agnostic description of an optimization job, returned by BaseExecutor.build_optimization_context(). Use this when implementing a custom executor to read parameters, step the simulator, and report results without going through RL env/agent types.

Import

from adk.models.optimization_context import OptimizationContext

Fields

FieldDescription
static_parametersFixed design parameters for this run (DesignParamSpec).
optimized_parametersParameters your algorithm may change.
randomized_parametersParameters sampled stochastically each step/episode.
default_*_parametersDefault values for each parameter group.
targetsTarget specs keyed by name (runtime TargetSpec).
default_observationsObservation values at default parameters.
internal_structure_graphOptional NetworkX graph of the system (when instrumented).
default_world_featuresOptional internal feature values at defaults.
optimization_dataInference flag and loaded GenieModel.
step_worldCallable (design_params, is_reset, extract_features) → (raw_obs, obs, features).
update_displayCallable to push stats to the platform.
send_errorCallable (code, message) for errors.
finish_optimizationCallable (OptimizationCompleteCode, message) to end the run.
is_stop_requestedCallable returning True when the user or platform requested stop.

Example

def run(self) -> None:
ctx = self.build_optimization_context()

params = dict(ctx.default_optimized_parameters)
while not ctx.is_stop_requested():
_, observations, _ = ctx.step_world(params, is_reset=False, extract_features=False)
# ... update params based on your algorithm ...
ctx.update_display(self._optimization_stats)

ctx.finish_optimization(OptimizationCompleteCode.Limit, "Finished.")

When using RLExecutor, your agent receives EnvData and AgentData instead — RLExecutor builds those from the same underlying context. See RL Agents and RL Run Data.