8.2.8.16. DispatchPipe

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

Note

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

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 394 [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\""] 395 [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\""] 396 [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\""] 397 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-93240e623dc600cf7405cd2e9620ad8c0fb3d41d/max.html">max</TD></TR></TABLE>> fillcolor=springgreen id=0 shape=box tooltip="\"max(iterable, *[, default=obj, key=func]) -> value\""] 398 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-93240e623dc600cf7405cd2e9620ad8c0fb3d41d/func.html">x - 1</TD></TR></TABLE>> fillcolor=springgreen id=4 shape=box tooltip="\"x - 1\""] 397 -> 396 394 -> 397 395 -> 397 396 -> 398 398 -> 394 }

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 dmap { graph [ratio=1] node [style=filled] label = <dmap> splines = ortho style = filled 404 [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\""] 405 [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\""] 406 [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\""] 407 [label=end fillcolor=blue fontcolor=white id=end shape=egg] 408 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-f7fe2eaf04f972de65e9a05d8aa9e55d1bfc452a/max.html">max</TD></TR></TABLE>> fillcolor=springgreen id=0 shape=box tooltip="\"max(iterable, *[, default=obj, key=func]) -> value\""] 409 [label=start fillcolor=red id=start shape=egg] 410 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-f7fe2eaf04f972de65e9a05d8aa9e55d1bfc452a/func.html">x - 1</TD></TR></TABLE>> fillcolor=springgreen id=4 shape=box tooltip="\"x - 1\""] 404 -> 408 410 -> 404 406 -> 410 408 -> 406 405 -> 408 409 -> 404 [xlabel=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">start --&gt; a</TD></TR><TR><TD align="RIGHT" border="1">inp_id</TD><TD align="LEFT" border="1">0</TD></TR></TABLE>>] 409 -> 405 [xlabel=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">start --&gt; b</TD></TR><TR><TD align="RIGHT" border="1">inp_id</TD><TD align="LEFT" border="1">1</TD></TR></TABLE>>] 404 -> 407 [xlabel=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">a --&gt; end</TD></TR><TR><TD align="RIGHT" border="1">out_id</TD><TD align="LEFT" border="1">0</TD></TR></TABLE>>] }

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

>>> fun(1, 0)
0

digraph dmap { graph [ratio=1] node [style=filled] label = <dmap> splines = ortho style = filled 419 [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\""] 420 [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\""] 421 [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\""] 422 [label=end fillcolor=blue fontcolor=white id=end shape=egg] 423 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-1bd25ac416e6c6d0df3a0cd68d7bef90019a651c/max.html">max</TD></TR></TABLE>> fillcolor=springgreen id=0 shape=box tooltip="\"max(iterable, *[, default=obj, key=func]) -> value\""] 424 [label=start fillcolor=red id=start shape=egg] 425 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-1bd25ac416e6c6d0df3a0cd68d7bef90019a651c/func.html">x - 1</TD></TR></TABLE>> fillcolor=springgreen id=4 shape=box tooltip="\"x - 1\""] 419 -> 423 425 -> 419 421 -> 425 423 -> 421 420 -> 423 424 -> 419 [xlabel=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">start --&gt; a</TD></TR><TR><TD align="RIGHT" border="1">inp_id</TD><TD align="LEFT" border="1">0</TD></TR></TABLE>>] 424 -> 420 [xlabel=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">start --&gt; b</TD></TR><TR><TD align="RIGHT" border="1">inp_id</TD><TD align="LEFT" border="1">1</TD></TR></TABLE>>] 419 -> 422 [xlabel=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">a --&gt; end</TD></TR><TR><TD align="RIGHT" border="1">out_id</TD><TD align="LEFT" border="1">0</TD></TR></TABLE>>] }

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)

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