8.2.8.18. SubDispatch

class SubDispatch(dsp, outputs=None, cutoff=None, inputs_dist=None, wildcard=False, no_call=False, shrink=False, rm_unused_nds=False, output_type='all')[source]

It dispatches a given Dispatcher like a function.

This function takes a sequence of dictionaries as input that will be combined before the dispatching.

Returns:A function that executes the dispatch of the given Dispatcher.
Return type:callable

Example:

>>> from schedula import Dispatcher
>>> sub_dsp = Dispatcher(name='Sub-dispatcher')
...
>>> def fun(a):
...     return a + 1, a - 1
...
>>> sub_dsp.add_function('fun', fun, ['a'], ['b', 'c'])
'fun'
>>> dispatch = SubDispatch(sub_dsp, ['a', 'b', 'c'], output_type='dict')
>>> dsp = Dispatcher(name='Dispatcher')
>>> dsp.add_function('Sub-dispatch', dispatch, ['d'], ['e'])
'Sub-dispatch'

digraph dmap { graph [ratio=1] node [style=filled] label = <dmap> splines = ortho style = filled 434 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-727e98ce3f074ff99f4c0998e2263fc0388eac18/Sub-dispatch.html">Sub-dispatch</TD></TR></TABLE>> fillcolor=yellow id=0 shape=note style=filled tooltip="\"Sub-dispatcher\""] 435 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">d</TD></TR></TABLE>> fillcolor=cyan id=1 shape=box style="rounded,filled" tooltip="\"d\""] 436 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">e</TD></TR></TABLE>> fillcolor=cyan id=2 shape=box style="rounded,filled" tooltip="\"e\""] 434 -> 436 435 -> 434 }

The Dispatcher output is:

>>> o = dsp.dispatch(inputs={'d': {'a': 3}})

digraph workflow { graph [ratio=1] node [style=filled] label = <workflow> splines = ortho style = filled 450 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-43e515825c63389e366b6687fbea881de3c747d8/Sub-dispatch.html">Sub-dispatch</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:59.418713</TD></TR><TR><TD align="RIGHT" border="1">duration</TD><TD align="LEFT" border="1">0:00:00.000628</TD></TR></TABLE>> fillcolor=yellow id=0 shape=note style=filled tooltip="\"Sub-dispatcher\""] 451 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-43e515825c63389e366b6687fbea881de3c747d8/d-output.html">d</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="\"d\""] 452 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-43e515825c63389e366b6687fbea881de3c747d8/e-output.html">e</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="\"e\""] 453 [label=start fillcolor=red id=start shape=egg] 453 -> 451 451 -> 450 450 -> 452 }

while, the Sub-dispatch is:

>>> sol = o.workflow.nodes['Sub-dispatch']['solution']
>>> sol
Solution([('a', 3), ('b', 4), ('c', 2)])
>>> sol == o['e']
True

digraph workflow { graph [ratio=1] node [style=filled] label = <workflow> splines = ortho style = filled 466 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-e16503d54faa9ff79f6e3b15905d7d583c03e018/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\""] 467 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-e16503d54faa9ff79f6e3b15905d7d583c03e018/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\""] 468 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-e16503d54faa9ff79f6e3b15905d7d583c03e018/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\""] 469 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-e16503d54faa9ff79f6e3b15905d7d583c03e018/fun.html">fun</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:59.484458</TD></TR><TR><TD align="RIGHT" border="1">duration</TD><TD align="LEFT" border="1">0:00:00.000021</TD></TR></TABLE>> fillcolor=springgreen id=0 shape=box tooltip="\"fun\""] 470 [label=start fillcolor=red id=start shape=egg] 470 -> 466 466 -> 469 469 -> 467 469 -> 468 }

Methods

__init__ Initializes the Sub-dispatch.
blue Constructs a Blueprint out of the current object.
copy
get_node Returns a sub node of a dispatcher.
plot Plots the Dispatcher with a graph in the DOT language with Graphviz.
search_node_description
web Creates a dispatcher Flask app.
__init__(dsp, outputs=None, cutoff=None, inputs_dist=None, wildcard=False, no_call=False, shrink=False, rm_unused_nds=False, output_type='all')[source]

Initializes the Sub-dispatch.

Parameters:
  • dsp (schedula.Dispatcher) – A dispatcher that identifies the model adopted.
  • outputs (list[str], iterable) – Ending data nodes.
  • cutoff (float, int, optional) – Depth to stop the search.
  • inputs_dist (dict[str, int | float], optional) – Initial distances of input data nodes.
  • wildcard (bool, optional) – If True, when the data node is used as input and target in the ArciDispatch algorithm, the input value will be used as input for the connected functions, but not as output.
  • no_call (bool, optional) – If True data node estimation function is not used.
  • shrink (bool, optional) – If True the dispatcher is shrink before the dispatch.
  • rm_unused_nds (bool, optional) – If True unused function and sub-dispatcher nodes are removed from workflow.
  • output_type (str, optional) –

    Type of function output:

    • ’all’: a dictionary with all dispatch outputs.
    • ’list’: a list with all outputs listed in outputs.
    • ’dict’: a dictionary with any outputs listed in outputs.
blue(memo=None)[source]

Constructs a Blueprint out of the current object.

Parameters:memo (dict[T,schedula.utils.blue.Blueprint]) – A dictionary to cache Blueprints.
Returns:A Blueprint of the current object.
Return type:schedula.utils.blue.Blueprint