Skip to content

Compute Steps

A ComputeStep is an executable unit of work in the workflow framework. Two implementations ship with ropt: OptimizationStep runs an optimization algorithm, and EvaluationStep runs a single ensemble evaluation.

See Optimization Workflows for usage.

ropt.workflow.compute_steps.ComputeStep

Bases: ABC

Abstract base class for optimization compute steps.

This class defines the fundamental interface for all executable compute steps within an optimization workflow. Concrete implementations, which perform specific actions like running an optimizer or evaluating functions, must inherit from this base class.

__init__

__init__() -> None

Initialize the ComputeStep.

add_event_handler

add_event_handler(handler: EventHandler) -> None

Add an event handler.

Compute steps emit events to report on the calculations they perform. These events are processed by independently created event handlers. Use the add_event_handler method to attach these handlers to the compute step.

Parameters:

Name Type Description Default
handler EventHandler

The handler to add.

required

event_handlers property

event_handlers: list[EventHandler]

The event handlers attached to this compute step.

Returns:

Type Description
list[EventHandler]

A list of handlers.

run abstractmethod

run(*args: Any, **kwargs: Any) -> Any

Execute the logic defined by this compute step.

This abstract method must be implemented by concrete ComputeStep subclasses to define the specific action the compute step performs within the optimization workflow.

The return value and type can vary depending on the specific implementation.

Parameters:

Name Type Description Default
args Any

Positional arguments.

()
kwargs Any

Keyword arguments.

{}

Returns:

Type Description
Any

The result of the execution, if any.

ropt.workflow.compute_steps.EvaluationStep

Bases: ComputeStep

The default evaluation step compute step.

Evaluates a batch of variable vectors (a single vector or a 2-D matrix where each row is a variable vector) and yields FunctionResults objects. Emits START_ENSEMBLE_EVALUATOR, START_EVALUATION, FINISHED_EVALUATION, and FINISHED_ENSEMBLE_EVALUATOR events.

See Optimization Workflows for the full event lifecycle description.

__init__

__init__(*, evaluator: Evaluator) -> None

Initialize a default evaluator.

Parameters:

Name Type Description Default
evaluator Evaluator

The evaluator object to run function evaluations.

required

run

run(
    context: EnOptContext,
    variables: ArrayLike,
    *,
    metadata: dict[str, Any] | None = None,
) -> ExitCode

Run the ensemble evaluation.

Parameters:

Name Type Description Default
context EnOptContext

Optimizer context.

required
variables ArrayLike

Variable vector(s) to evaluate.

required
metadata dict[str, Any] | None

Optional dictionary attached to emitted FunctionResults via the FINISHED_EVALUATION event.

None

Returns:

Type Description
ExitCode

An ExitCode describing the outcome.

Raises:

Type Description
ValueError

If the input variables have the wrong shape.

ropt.workflow.compute_steps.OptimizationStep

Bases: ComputeStep

The default optimizer compute step.

Executes an optimization algorithm, iteratively performing function and gradient evaluations. Emits START_OPTIMIZER, START_EVALUATION, FINISHED_EVALUATION, and FINISHED_OPTIMIZER events.

See Optimization Workflows for the full event lifecycle description.

__init__

__init__(*, evaluator: Evaluator) -> None

Initialize a default optimizer.

Parameters:

Name Type Description Default
evaluator Evaluator

The evaluator object to run function evaluations.

required

run

run(
    context: EnOptContext,
    variables: ArrayLike,
    *,
    metadata: dict[str, Any] | None = None,
) -> ExitCode

Run the optimization.

Parameters:

Name Type Description Default
context EnOptContext

The optimizer context.

required
variables ArrayLike

Initial variable vector(s).

required
metadata dict[str, Any] | None

Optional dictionary attached to emitted Results via the FINISHED_EVALUATION event.

None

Returns:

Type Description
ExitCode

An exit code describing the outcome of the optimization.

Raises:

Type Description
ValueError

If the input variables have the wrong shape.