7.2.6.21. SubDispatchPipe

class SubDispatchPipe(dsp, function_id, inputs, outputs=None, cutoff=None, inputs_dist=None, no_domain=True, wildcard=True)[source]

It converts a Dispatcher() into a function.

This function takes a sequence of arguments as input of the dispatch.

Returns:A function that executes the pipe of the given dsp.
Return type:callable

See also

dispatch(), shrink_dsp()

Example:

A dispatcher with two functions max and min and an unresolved cycle (i.e., a –> max –> c –> min –> a):

digraph dmap { graph [ratio=1] node [style=filled] label = <dmap> splines = ortho style = filled 428 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">a</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip=a] 429 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">b</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip=b] 430 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">c</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip=c] 431 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-352727b7a575d760cf6e18bf5259afb6d651fed5/max.html">max</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="max(iterable, *[, default=obj, key=func]) -> value"] 432 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-352727b7a575d760cf6e18bf5259afb6d651fed5/func.html">x - 1</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="x - 1"] 430 -> 432 429 -> 431 431 -> 430 432 -> 428 428 -> 431 }

Extract a static function node, i.e. the inputs a and b and the output a are fixed:

>>> fun = SubDispatchPipe(dsp, 'myF', ['a', 'b'], ['a'])
>>> fun.__name__
'myF'
>>> fun(2, 1)
1

digraph workflow { graph [ratio=1] node [style=filled] label = <workflow> splines = ortho style = filled 438 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-0be54285dd2075c5e754f6c6e53cc8036b45c528/a-output.html">a</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">4.0</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip=a] 439 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-0be54285dd2075c5e754f6c6e53cc8036b45c528/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] 440 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-0be54285dd2075c5e754f6c6e53cc8036b45c528/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] 441 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-0be54285dd2075c5e754f6c6e53cc8036b45c528/max.html">max</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-06-05T10:44:22.345477</TD></TR><TR><TD align="RIGHT" border="1">duration</TD><TD align="LEFT" border="1">0:00:00.000016</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="max(iterable, *[, default=obj, key=func]) -> value"] 442 [label=start fillcolor=red shape=egg] 443 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-0be54285dd2075c5e754f6c6e53cc8036b45c528/func.html">x - 1</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">3.0</TD></TR><TR><TD align="RIGHT" border="1">started</TD><TD align="LEFT" border="1">2018-06-05T10:44:22.345548</TD></TR><TR><TD align="RIGHT" border="1">duration</TD><TD align="LEFT" border="1">0:00:00.000014</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="x - 1"] 441 -> 440 443 -> 438 442 -> 439 440 -> 443 439 -> 441 442 -> 438 438 -> 441 }

The created function raises a ValueError if un-valid inputs are provided:

>>> fun(1, 0)
0

digraph workflow { graph [ratio=1] node [style=filled] label = <workflow> splines = ortho style = filled 451 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-abae933081626ea55940a0a584bb8e776166aa74/a-output.html">a</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">4.0</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip=a] 452 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-abae933081626ea55940a0a584bb8e776166aa74/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] 453 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-abae933081626ea55940a0a584bb8e776166aa74/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] 454 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-abae933081626ea55940a0a584bb8e776166aa74/max.html">max</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-06-05T10:44:22.380655</TD></TR><TR><TD align="RIGHT" border="1">duration</TD><TD align="LEFT" border="1">0:00:00.000015</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="max(iterable, *[, default=obj, key=func]) -> value"] 455 [label=start fillcolor=red shape=egg] 456 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-abae933081626ea55940a0a584bb8e776166aa74/func.html">x - 1</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">3.0</TD></TR><TR><TD align="RIGHT" border="1">started</TD><TD align="LEFT" border="1">2018-06-05T10:44:22.380725</TD></TR><TR><TD align="RIGHT" border="1">duration</TD><TD align="LEFT" border="1">0:00:00.000013</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="x - 1"] 454 -> 453 456 -> 451 455 -> 452 453 -> 456 452 -> 454 455 -> 451 451 -> 454 }

Methods

__init__ Initializes the Sub-dispatch Function.
copy
get_node Returns a sub node of a dispatcher.
parse_inputs
plot Plots the Dispatcher with a graph in the DOT language with Graphviz.
search_node_description
web Creates a dispatcher Flask app.
__init__(dsp, function_id, inputs, outputs=None, cutoff=None, inputs_dist=None, no_domain=True, wildcard=True)[source]

Initializes the Sub-dispatch Function.

Parameters:
  • dsp (schedula.Dispatcher) – A dispatcher that identifies the model adopted.
  • function_id (str) – Function name.
  • inputs (list[str], iterable) – Input data nodes.
  • outputs (list[str], iterable, optional) – 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.