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

digraph workflow { graph [ratio=1] node [style=filled] label = <workflow> splines = ortho style = filled 228 [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">2018-10-08T22:02:37.537575</TD></TR><TR><TD align="RIGHT" border="1">duration</TD><TD align="LEFT" border="1">0:00:00.000403</TD></TR></TABLE>> fillcolor=yellow shape=note style=filled tooltip="Sub-dispatcher"] 229 [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 shape=box style="rounded,filled" tooltip=a] 230 [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 shape=box style="rounded,filled" tooltip=b] 231 [label=start fillcolor=red shape=egg] 228 -> 230 231 -> 229 229 -> 228 }

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 245 [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 shape=box style="rounded,filled" tooltip=a] 246 [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">2018-10-08T22:02:37.616503</TD></TR><TR><TD align="RIGHT" border="1">duration</TD><TD align="LEFT" border="1">0:00:00.000006</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="a + b"] 247 [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 shape=box style="rounded,filled" tooltip=b] 248 [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 shape=box style="rounded,filled" tooltip=c] 249 [label=start fillcolor=red shape=egg] 245 -> 246 246 -> 248 249 -> 245 249 -> 247 247 -> 246 }