7.2.6.17. DispatchPipe

class DispatchPipe(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, updating its workflow.
Return type:callable

Note

This wrapper is not thread safe, because it overwrite the solution.

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 316 [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] 317 [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] 318 [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] 319 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-72f47f0e8479961c82074f0876f5209a63bc2af9/max.html">max</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="max(iterable, *[, default=obj, key=func]) -> value"] 320 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-72f47f0e8479961c82074f0876f5209a63bc2af9/func.html">x - 1</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="x - 1"] 318 -> 320 317 -> 319 319 -> 318 320 -> 316 316 -> 319 }

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

>>> fun = DispatchPipe(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 326 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-fcac2f3a7fbdde7616b7b68316b2dc3f05499825/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] 327 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-fcac2f3a7fbdde7616b7b68316b2dc3f05499825/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] 328 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-fcac2f3a7fbdde7616b7b68316b2dc3f05499825/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] 329 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-fcac2f3a7fbdde7616b7b68316b2dc3f05499825/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:21.642821</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"] 330 [label=start fillcolor=red shape=egg] 331 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-fcac2f3a7fbdde7616b7b68316b2dc3f05499825/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:21.642901</TD></TR><TR><TD align="RIGHT" border="1">duration</TD><TD align="LEFT" border="1">0:00:00.000019</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="x - 1"] 329 -> 328 331 -> 326 330 -> 327 328 -> 331 327 -> 329 330 -> 326 326 -> 329 }

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 339 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-2e9246eee65416227cf14a82df5bd0339fe6d192/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] 340 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-2e9246eee65416227cf14a82df5bd0339fe6d192/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] 341 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-2e9246eee65416227cf14a82df5bd0339fe6d192/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] 342 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-2e9246eee65416227cf14a82df5bd0339fe6d192/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:21.707340</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="max(iterable, *[, default=obj, key=func]) -> value"] 343 [label=start fillcolor=red shape=egg] 344 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-2e9246eee65416227cf14a82df5bd0339fe6d192/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:21.707401</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"] 342 -> 341 344 -> 339 343 -> 340 341 -> 344 340 -> 342 343 -> 339 339 -> 342 }

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)

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.