8.2.8.20. SubDispatchPipe

class SubDispatchPipe(dsp, function_id=None, inputs=None, 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

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 510 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">a</TD></TR></TABLE>> fillcolor=cyan id=1 shape=box style="rounded,filled" tooltip="\"a\""] 511 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">b</TD></TR></TABLE>> fillcolor=cyan id=2 shape=box style="rounded,filled" tooltip="\"b\""] 512 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">c</TD></TR></TABLE>> fillcolor=cyan id=3 shape=box style="rounded,filled" tooltip="\"c\""] 513 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-fdda43260757ab0452396a453eefac1e5c124faa/max.html">max</TD></TR></TABLE>> fillcolor=springgreen id=0 shape=box tooltip="\"max(iterable, *[, default=obj, key=func]) -> value\""] 514 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-fdda43260757ab0452396a453eefac1e5c124faa/func.html">x - 1</TD></TR></TABLE>> fillcolor=springgreen id=4 shape=box tooltip="\"x - 1\""] 513 -> 512 510 -> 513 511 -> 513 512 -> 514 514 -> 510 }

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 520 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-1206f8458f54afbfbb4678b1d08a384712a542eb/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 id=1 shape=box style="rounded,filled" tooltip="\"a\""] 521 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-1206f8458f54afbfbb4678b1d08a384712a542eb/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\""] 522 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-1206f8458f54afbfbb4678b1d08a384712a542eb/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\""] 523 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-1206f8458f54afbfbb4678b1d08a384712a542eb/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">2019-12-06T17:54:59.738519</TD></TR><TR><TD align="RIGHT" border="1">duration</TD><TD align="LEFT" border="1">0:00:00.000019</TD></TR></TABLE>> fillcolor=springgreen id=0 shape=box tooltip="\"max(iterable, *[, default=obj, key=func]) -> value\""] 524 [label=start fillcolor=red id=start shape=egg] 525 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-1206f8458f54afbfbb4678b1d08a384712a542eb/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">2019-12-06T17:54:59.738570</TD></TR><TR><TD align="RIGHT" border="1">duration</TD><TD align="LEFT" border="1">0:00:00.000012</TD></TR></TABLE>> fillcolor=springgreen id=4 shape=box tooltip="\"x - 1\""] 524 -> 520 524 -> 521 520 -> 523 523 -> 522 521 -> 523 522 -> 525 525 -> 520 }

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 533 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-bcc0a46ffebf9286733ce7bb72fa6b59da64d8be/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 id=1 shape=box style="rounded,filled" tooltip="\"a\""] 534 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-bcc0a46ffebf9286733ce7bb72fa6b59da64d8be/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\""] 535 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-bcc0a46ffebf9286733ce7bb72fa6b59da64d8be/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\""] 536 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-bcc0a46ffebf9286733ce7bb72fa6b59da64d8be/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">2019-12-06T17:54:59.768353</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="\"max(iterable, *[, default=obj, key=func]) -> value\""] 537 [label=start fillcolor=red id=start shape=egg] 538 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-bcc0a46ffebf9286733ce7bb72fa6b59da64d8be/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">2019-12-06T17:54:59.768442</TD></TR><TR><TD align="RIGHT" border="1">duration</TD><TD align="LEFT" border="1">0:00:00.000013</TD></TR></TABLE>> fillcolor=springgreen id=4 shape=box tooltip="\"x - 1\""] 537 -> 533 537 -> 534 533 -> 536 536 -> 535 534 -> 536 535 -> 538 538 -> 533 }

Methods

__init__ Initializes the Sub-dispatch Function.
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, function_id=None, inputs=None, 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.

Attributes

var_keyword