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 defaultconstant_inputs – The names of all inputs with constant loop/batch-invariant data
outputs – The names of all outputs to parallelize, will use
'out'
as defaultkwargs – Additional arguments to be passed to the
add
method
- Returns:
A subgraph containing multiple parallel branches of the node
- Return type:
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), ... )