Component#

class maize.core.component.Component(parent: Graph | None = None, name: str | None = None, description: str | None = None, fail_ok: bool = False, n_attempts: int = 1, level: int | str | None = None, cleanup_temp: bool = True, resume: bool = False, logfile: Path | None = None, max_cpus: int | None = None, max_gpus: int | None = None, loop: bool | None = None)[source]#

Bases: object

Base class for all components. Should not be used directly.

Parameters:
  • parent – Parent component, typically the graph in context

  • name – The name of the component

  • description – An optional additional description

  • fail_ok – If True, the failure in the component will not trigger the whole network to shutdown

  • n_attempts – Number of attempts at executing the run() method

  • level – Logging level, if not given or None will use the parent logging level

  • cleanup_temp – Whether to remove any temporary directories after completion

  • resume – Whether to resume from a previous checkpoint

  • logfile – File to output all log messages to, defaults to STDOUT

  • max_cpus – Maximum number of CPUs to use, defaults to the number of available cores in the system

  • max_gpus – Maximum number of GPUs to use, defaults to the number of available GPUs in the system

  • loop – Whether to run the run method in a loop, as opposed to a single time

See also

node.Node

Node class for implementing custom tasks

graph.Graph

Graph class to group nodes together to form a subgraph

workflow.Workflow

Workflow class to group nodes and graphs together to an executable workflow

__init__(parent: Graph | None = None, name: str | None = None, description: str | None = None, fail_ok: bool = False, n_attempts: int = 1, level: int | str | None = None, cleanup_temp: bool = True, resume: bool = False, logfile: Path | None = None, max_cpus: int | None = None, max_gpus: int | None = None, loop: bool | None = None) None[source]#

Methods

__init__([parent, name, description, ...])

as_dict()

Provides a non-recursive dictionary view of the component.

get_available_nodes()

Returns all available and registered nodes.

get_inputs()

Returns all inputs available to the node.

get_interfaces([kind])

Returns all interfaces available to the node.

get_node_class(name)

Returns the node class corresponding to the given name.

get_outputs()

Returns all outputs available to the node.

get_parameters()

Returns all parameters available to the node.

get_summary_line()

Provides a one-line summary of the node.

ports_active()

Check if all required ports are active.

send_update()

Send a status update to the main process.

serialized_summary()

Provides a serialized representation of the component type.

setup_directories([parent_path])

Sets up the required directories.

update_parameters(**kwargs)

Update component parameters.

Attributes

all_parameters

Returns all settable parameters and unconnected inputs

component_path

Provides the full path to the component as a tuple of names.

datatype

The component datatype if it's generic.

n_inbound

Returns the number of items waiting to be received

n_outbound

Returns the number of items waiting to be sent

node_config

Provides the configuration of the current node

parents

Provides all parent components.

ports

Provides a convenience iterator for all inputs and outputs.

required_callables

List of external commandline programs that are required for running the component.

required_packages

List of required python packages

root

Provides the root workflow or graph instance.

status

Current status of the component.

logger

Python logger for both the build and run procedures.

run_timer

Timer for the run duration, without waiting for resources or other nodes.

full_timer

Timer for the full duration, including waiting for resources or other nodes.

work_dir

Working directory for the component.

property all_parameters: dict[str, Input[Any] | MultiInput[Any] | Parameter[Any]]#

Returns all settable parameters and unconnected inputs

as_dict() dict[str, Any][source]#

Provides a non-recursive dictionary view of the component.

property component_path: tuple[str, ...]#

Provides the full path to the component as a tuple of names.

datatype: Any#

The component datatype if it’s generic.

full_timer: Timer#

Timer for the full duration, including waiting for resources or other nodes.

static get_available_nodes() set[type[Component]][source]#

Returns all available and registered nodes.

Returns:

All available node names

Return type:

set[str]

classmethod get_inputs() set[str][source]#

Returns all inputs available to the node.

classmethod get_interfaces(kind: Literal['input', 'output', 'parameter'] | None = None) set[str][source]#

Returns all interfaces available to the node.

Parameters:

kind – Kind of interface to retrieve

Returns:

Interface names

Return type:

set[str]

static get_node_class(name: str) type[Component][source]#

Returns the node class corresponding to the given name.

Parameters:

name – Name of the component class to retrieve

Returns:

The retrieved component class, can be passed to add_node

Return type:

Type[Component]

classmethod get_outputs() set[str][source]#

Returns all outputs available to the node.

classmethod get_parameters() set[str][source]#

Returns all parameters available to the node.

classmethod get_summary_line() str[source]#

Provides a one-line summary of the node.

logger: Logger#

Python logger for both the build and run procedures.

property n_inbound: int#

Returns the number of items waiting to be received

property n_outbound: int#

Returns the number of items waiting to be sent

property node_config: NodeConfig#

Provides the configuration of the current node

property parents: tuple[Component, ...] | None#

Provides all parent components.

property ports: dict[str, Port[Any]]#

Provides a convenience iterator for all inputs and outputs.

ports_active() bool[source]#

Check if all required ports are active.

Can be overridden by the user to allow custom shutdown scenarios, for example in the case of complex inter-port dependencies. By default only checks if any mandatory ports are inactive.

Returns:

True if all required ports are active, False otherwise.

Return type:

bool

required_callables: ClassVar[list[str]] = []#

List of external commandline programs that are required for running the component.

required_packages: ClassVar[list[str]] = []#

List of required python packages

property root: Graph#

Provides the root workflow or graph instance.

run_timer: Timer#

Timer for the run duration, without waiting for resources or other nodes.

send_update() None[source]#

Send a status update to the main process.

classmethod serialized_summary() _SerialType[source]#

Provides a serialized representation of the component type.

Returns:

Nested dictionary of the component type structure, including I/O and parameters.

Return type:

dict[str, Any]

Examples

>>> Merge.serialized_summary()
{"name": "Merge", "inputs": [{"name": "inp", ...}]}
setup_directories(parent_path: Path | None = None) None[source]#

Sets up the required directories.

status#

Current status of the component.

update_parameters(**kwargs: dict[str, Any]) None[source]#

Update component parameters.

Parameters:

**kwargs – Name - value pairs supplied as keyword arguments

work_dir: Path#

Working directory for the component.