Skip to content

Compute Steps

ropt.plugins.compute_step.base.ComputeStepPlugin

Bases: Plugin

Abstract base class for plugins that create ComputeStep instances.

This class defines the interface for plugins that act as factories for ComputeStep objects.

create abstractmethod classmethod

create(name: str, **kwargs: Any) -> ComputeStep

Create a ComputeStep instance.

This abstract class method serves as a factory for creating concrete ComputeStep objects. Plugin implementations must override this method to return an instance of their specific ComputeStep subclass.

The name argument specifies the requested compute step, potentially in the format "plugin-name/method-name" or just "method-name". Implementations can use this name to vary the created compute step if the plugin supports multiple compute step types.

Parameters:

Name Type Description Default
name str

The requested compute step name (potentially plugin-specific).

required
kwargs Any

Additional arguments for custom configuration.

{}

Returns:

Type Description
ComputeStep

An initialized instance of a ComputeStep subclass.

ropt.plugins.compute_step.base.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.

ComputeStep instances are typically created using the create_compute_step function.

event_handlers property

event_handlers: list[EventHandler]

Get the event handlers attached to this compute step.

Returns:

Type Description
list[EventHandler]

A list of handlers.

__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

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.