7.1.1.3. add_dispatcherΒΆ

Dispatcher.add_dispatcher(dsp, inputs, outputs, dsp_id=None, input_domain=None, weight=None, inp_weight=None, description=None, include_defaults=False, **kwargs)[source]

Add a single sub-dispatcher node to dispatcher.

Parameters:
  • dsp (Dispatcher | dict[str, list]) – Child dispatcher that is added as sub-dispatcher node to the parent dispatcher.
  • inputs (dict[str, str | list[str]] | tuple[str] | (str, ..., dict[str, str | list[str]])) – Inputs mapping. Data node ids from parent dispatcher to child sub-dispatcher.
  • outputs (dict[str, str | list[str]] | tuple[str] | (str, ..., dict[str, str | list[str]])) – Outputs mapping. Data node ids from child sub-dispatcher to parent dispatcher.
  • dsp_id (str, optional) – Sub-dispatcher node id. If None will be assigned as <dsp.name>.
  • input_domain ((dict) -> bool, optional) –

    A function that checks if input values satisfy the function domain. This can be any function that takes the a dictionary with the inputs of the sub-dispatcher node and returns True if input values satisfy the domain, otherwise False.

    Note

    This function is invoked every time that a data node reach the sub-dispatcher node.

  • weight (float, int, optional) – Node weight. It is a weight coefficient that is used by the dispatch algorithm to estimate the minimum workflow.
  • inp_weight (dict[str, int | float], optional) – Edge weights from data nodes to the sub-dispatcher node. It is a dictionary (key=data node id) with the weight coefficients used by the dispatch algorithm to estimate the minimum workflow.
  • description (str, optional) – Sub-dispatcher node’s description.
  • include_defaults (bool, optional) – If True the default values of the sub-dispatcher are added to the current dispatcher.
  • kwargs (keyword arguments, optional) – Set additional node attributes using key=value.
Returns:

Sub-dispatcher node id.

Return type:

str

***********************************************************************

Example:

Create a sub-dispatcher:

>>> sub_dsp = Dispatcher()
>>> sub_dsp.add_function('max', max, ['a', 'b'], ['c'])
'max'

Add the sub-dispatcher to the parent dispatcher:

>>> dsp.add_dispatcher(dsp_id='Sub-Dispatcher', dsp=sub_dsp,
...                    inputs={'A': 'a', 'B': 'b'},
...                    outputs={'c': 'C'})
'Sub-Dispatcher'

Add a sub-dispatcher node with domain:

>>> def my_domain(kwargs):
...     return kwargs['C'] > 3
...
>>> dsp.add_dispatcher(dsp_id='Sub-Dispatcher with domain',
...                    dsp=sub_dsp, inputs={'C': 'a', 'D': 'b'},
...                    outputs={'c': 'E'}, input_domain=my_domain)
'Sub-Dispatcher with domain'