Skip to content

component

Component submodule providing functionality related to components and their execution.

Component

Component(
    *,
    name: str,
    initial_values: Optional[dict[str, Iterable]] = None,
    parameters: Optional[dict[str, Any]] = None,
    state: Optional[StateBackend] = None,
    constraints: Optional[dict] = None,
)

Bases: ABC, ExportMixin

Component base class for all components in a process model.

Attributes:

Name Type Description
name

The name of the component.

io IOController

The IOController for the component, specifying inputs, outputs, and events.

exports Optional[list[str]]

Optional; The exportable fields from the component during distributed runs in addition to input and output fields.

id property

id: str

Unique ID for Component.

parameters property

parameters: dict[str, Any]

Gets the parameters of the component.

state property

state: Optional[StateBackend]

State backend for the process.

status property

status: Status

Gets the status of the component.

__setattr__

__setattr__(key: str, value: Any) -> None

Sets attributes on the component.

If the attribute is an input field, it is set in the field input buffer for the current step. This data is consumed by the step method when it is called and must be reset for subsequent steps.

cancel async

cancel() -> None

Called from the Process to set correct status.

connect_state async

connect_state(state: Optional[StateBackend] = None) -> None

Connects the Component to the StateBackend.

destroy async

destroy() -> None

Performs tear-down actions for Component.

init async

init() -> None

Performs component initialisation actions.

run async

run() -> None

Executes component logic for all steps to completion.

step async

step() -> None

Executes component logic for a single step.

IOController

IOController(
    inputs: Optional[Any] = None,
    outputs: Optional[Any] = None,
    initial_values: Optional[dict[str, Iterable]] = None,
    input_events: Optional[list[Type[Event]]] = None,
    output_events: Optional[list[Type[Event]]] = None,
    namespace: str = IO_NS_UNSET,
    component: Optional[Component] = None,
)

IOController manages input/output to/from components.

is_closed property

is_closed: bool

Returns True if the IOController is closed, False otherwise.

close async

close() -> None

Closes all input/output channels.

connect async

connect(connectors: list[Connector]) -> None

Connects the input/output fields to input/output channels.

queue_event

queue_event(event: Event) -> None

Queues an event for output.

read async

read(timeout: float | None = None) -> None

Reads data and/or events from input channels.

Read behaviour is dependent on the specific combination of input fields, output fields, and input events. In general, all components will have at a minimum the system defined input events, such as StopEvent. Logic for the various cases is as follows:

  • At least one input field: the method waits until either all input fields have received data or an input event is received, and returns after whichever occurs first.
  • No input fields but at least one output field: the method waits for a short amount of time to give chance for input events to be received before returning so that the control flow can continue on to processing output events.
  • No input fields or output fields: this is the pure event driven case where the method waits until an input event is received, and returns after the first received event.

write async

write() -> None

Writes data to output channels.

component.utils

Provides utility functions for working with Plugboard components.

ComponentDecoratorHelper

ComponentDecoratorHelper(
    func: _FuncT, component_cls: Type[Component]
)

Stores wrapped function and dynamically created component class.

__call__

__call__(*args: Any, **kwargs: Any) -> _t.Any

Calls the wrapped function directly.

component

component(
    name: Optional[str] = None, **kwargs: Any
) -> Component

Creates an instance of the component class for the wrapped function.

component

component(
    inputs: Optional[Any] = None,
    outputs: Optional[Any] = None,
) -> _t.Callable[[_FuncT], "ComponentDecoratorHelper"]

A decorator to auto generate a Plugboard component from a function.

The wrapped function will be added to a dynamically created component class as the step method. The returned helper class can either be called directly, retaining the original behaviour of the wrapped function; or can be used to create a component instance.

Parameters:

Name Type Description Default
inputs Optional[Any]

The input schema or schema factory for the component.

None
outputs Optional[Any]

The output schema or schema factory for the component.

None

Returns:

Type Description
Callable[[_FuncT], 'ComponentDecoratorHelper']

A helper class which can be used to both call the original function and create

Callable[[_FuncT], 'ComponentDecoratorHelper']

an instance of the component class.