7.2.1.4. get_sub_node

get_sub_node(dsp, path, node_attr='auto', solution=none, _level=0, _dsp_name=none)[source]

Returns a sub node of a dispatcher.

Parameters:
  • dsp (schedula.Dispatcher | SubDispatch) – A dispatcher object or a sub dispatch function.
  • path (tuple, str) – A sequence of node ids or a single node id. Each id identifies a sub-level node.
  • node_attr (str | None) –

    Output node attr.

    If the searched node does not have this attribute, all its attributes are returned.

    When ‘auto’, returns the “default” attributes of the searched node, which are:

    • for data node: its output, and if not exists, all its attributes.
    • for function and sub-dispatcher nodes: the ‘function’ attribute.
  • solution (schedula.utils.Solution) – Parent Solution.
  • _level (int) – Path level.
  • _dsp_name (str) – dsp name to show when the function raise a value error.
Returns:

A sub node of a dispatcher and its path.

Return type:

dict | object, tuple[str]

Example:

>>> from schedula import Dispatcher
>>> s_dsp = Dispatcher(name='Sub-dispatcher')
>>> def fun(a, b):
...     return a + b
...
>>> s_dsp.add_function('a + b', fun, ['a', 'b'], ['c'])
'a + b'
>>> dispatch = SubDispatch(s_dsp, ['c'], output_type='dict')
>>> dsp = Dispatcher(name='Dispatcher')
>>> dsp.add_function('Sub-dispatcher', dispatch, ['a'], ['b'])
'Sub-dispatcher'
>>> o = dsp.dispatch(inputs={'a': {'a': 3, 'b': 1}})
...

Get the sub node ‘c’ output or type:

>>> get_sub_node(dsp, ('Sub-dispatcher', 'c'))
(4, ('Sub-dispatcher', 'c'))
>>> get_sub_node(dsp, ('Sub-dispatcher', 'c'), node_attr='type')
('data', ('Sub-dispatcher', 'c'))

Get the sub-dispatcher output:

>>> sol, p = get_sub_node(dsp, ('Sub-dispatcher',), node_attr='output')
>>> sol, p
(Solution([('a', 3), ('b', 1), ('c', 4)]), ('Sub-dispatcher',))