8.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}})
...

digraph workflow { graph [ratio=1] node [style=filled] label = <workflow> splines = ortho style = filled 273 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-0dbf79a801555859f0a7640e1bf1bb8598555be0/Sub-dispatcher.html">Sub-dispatcher</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">1.0</TD></TR><TR><TD align="RIGHT" border="1">started</TD><TD align="LEFT" border="1">2019-12-06T17:54:55.565993</TD></TR><TR><TD align="RIGHT" border="1">duration</TD><TD align="LEFT" border="1">0:00:00.000580</TD></TR></TABLE>> fillcolor=yellow id=0 shape=note style=filled tooltip="\"Sub-dispatcher\""] 274 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-0dbf79a801555859f0a7640e1bf1bb8598555be0/a-output.html">a</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">0.0</TD></TR></TABLE>> fillcolor=cyan id=1 shape=box style="rounded,filled" tooltip="\"a\""] 275 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-0dbf79a801555859f0a7640e1bf1bb8598555be0/b-output.html">b</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">2.0</TD></TR></TABLE>> fillcolor=cyan id=2 shape=box style="rounded,filled" tooltip="\"b\""] 276 [label=start fillcolor=red id=start shape=egg] 276 -> 274 274 -> 273 273 -> 275 }

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',))

digraph workflow { graph [ratio=1] node [style=filled] label = <workflow> splines = ortho style = filled 290 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-5c50ce9a7a2ba78b46973a5ed47fa43ffe94a65b/a-output.html">a</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">0.0</TD></TR></TABLE>> fillcolor=cyan id=1 shape=box style="rounded,filled" tooltip="\"a\""] 291 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-5c50ce9a7a2ba78b46973a5ed47fa43ffe94a65b/fun.html">a + b</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">1.0</TD></TR><TR><TD align="RIGHT" border="1">started</TD><TD align="LEFT" border="1">2019-12-06T17:54:55.631717</TD></TR><TR><TD align="RIGHT" border="1">duration</TD><TD align="LEFT" border="1">0:00:00.000022</TD></TR></TABLE>> fillcolor=springgreen id=0 shape=box tooltip="\"a + b\""] 292 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-5c50ce9a7a2ba78b46973a5ed47fa43ffe94a65b/b-output.html">b</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">0.0</TD></TR></TABLE>> fillcolor=cyan id=2 shape=box style="rounded,filled" tooltip="\"b\""] 293 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-5c50ce9a7a2ba78b46973a5ed47fa43ffe94a65b/c-output.html">c</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">2.0</TD></TR></TABLE>> fillcolor=cyan id=3 shape=box style="rounded,filled" tooltip="\"c\""] 294 [label=start fillcolor=red id=start shape=egg] 294 -> 290 294 -> 292 290 -> 291 292 -> 291 291 -> 293 }