parallel#

maize.utilities.macros.parallel(node_type: type[Component], n_branches: int, inputs: Sequence[str] | None = None, constant_inputs: Sequence[str] | None = None, outputs: Sequence[str] | None = None, **kwargs: Any) type[Graph][source]#

Workflow macro to parallelize a node. The created subgraph will have the exact same interface as the wrapped node.

Parameters:
  • node_type – The node class to parallelize

  • n_branches – The number of parallel branches to create

  • inputs – The names of all inputs to parallelize, will use 'inp' as default

  • constant_inputs – The names of all inputs with constant loop/batch-invariant data

  • outputs – The names of all outputs to parallelize, will use 'out' as default

  • kwargs – Additional arguments to be passed to the add method

Returns:

A subgraph containing multiple parallel branches of the node

Return type:

type[Graph]

Examples

>>> parallel_node = flow.add(parallel(
...     ExampleNode,
...     n_branches=3,
...     inputs=('inp', 'inp_other'),
...     constant_inputs=('inp_const',),
...     outputs=('out',)
... ))
>>> flow.connect_all(
...     (input_node.out, parallel_node.inp),
...     (other_input_node.out, parallel_node.inp_other),
...     (const_input.out, parallel_node.inp_const),
...     (parallel_node.out, output_node.inp),
... )