8.2.8.19. SubDispatchFunction

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

It converts a Dispatcher into a function.

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

Returns:A function that executes the dispatch 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 475 [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\""] 476 [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\""] 477 [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\""] 478 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-3776fe987acc40339b219063896a9d2077074fd6/my_log.html">log(x - 1)</TD></TR><TR><TD align="RIGHT" border="1">input_domain</TD><TD align="LEFT" border="1" href="./dispatcher-3776fe987acc40339b219063896a9d2077074fd6/lambda.html">&lt;lambda&gt;</TD></TR></TABLE>> fillcolor=springgreen id=4 shape=box tooltip="\"log(x - 1)\""] 479 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-3776fe987acc40339b219063896a9d2077074fd6/max.html">max</TD></TR></TABLE>> fillcolor=springgreen id=0 shape=box tooltip="\"max(iterable, *[, default=obj, key=func]) -> value\""] 479 -> 477 475 -> 479 476 -> 479 477 -> 478 478 -> 475 }

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

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

digraph workflow { graph [ratio=1] node [style=filled] label = <workflow> splines = ortho style = filled 485 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-f3cc9e7067a73708c39310acc05da07eff0a4460/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\""] 486 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-f3cc9e7067a73708c39310acc05da07eff0a4460/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\""] 487 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-f3cc9e7067a73708c39310acc05da07eff0a4460/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\""] 488 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-f3cc9e7067a73708c39310acc05da07eff0a4460/my_log.html">log(x - 1)</TD></TR><TR><TD align="RIGHT" border="1">solution_domain</TD><TD align="LEFT" border="1" href="./dispatcher-f3cc9e7067a73708c39310acc05da07eff0a4460/log(x_-_1)-solution_domain.html">log(x - 1)-solution_domain</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.604706</TD></TR><TR><TD align="RIGHT" border="1">duration</TD><TD align="LEFT" border="1">0:00:00.000018</TD></TR></TABLE>> fillcolor=springgreen id=4 shape=box tooltip="\"log(x - 1)\""] 489 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-f3cc9e7067a73708c39310acc05da07eff0a4460/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.604613</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\""] 490 [label=start fillcolor=red id=start shape=egg] 490 -> 485 490 -> 486 485 -> 489 489 -> 487 486 -> 489 487 -> 488 488 -> 485 }

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

>>> fun(1, 0)  # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
DispatcherError:
  Unreachable output-targets: ...
  Available outputs: ...

digraph workflow { graph [ratio=1] node [style=filled] label = <workflow> splines = ortho style = filled 498 [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\""] 499 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-f782f196e86772fae03beea15bcdbd9dc6ed971b/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\""] 500 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-f782f196e86772fae03beea15bcdbd9dc6ed971b/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\""] 501 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-f782f196e86772fae03beea15bcdbd9dc6ed971b/my_log.html">log(x - 1)</TD></TR><TR><TD align="RIGHT" border="1">solution_domain</TD><TD align="LEFT" border="1" href="./dispatcher-f782f196e86772fae03beea15bcdbd9dc6ed971b/log(x_-_1)-solution_domain.html">log(x - 1)-solution_domain</TD></TR><TR><TD align="RIGHT" border="1">M_outputs</TD><TD align="LEFT" border="1">(&#x27;a&#x27;,)</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">3.0</TD></TR></TABLE>> fillcolor=orange id=4 shape=box tooltip="\"log(x - 1)\""] 502 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-f782f196e86772fae03beea15bcdbd9dc6ed971b/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.635565</TD></TR><TR><TD align="RIGHT" border="1">duration</TD><TD align="LEFT" border="1">0:00:00.000036</TD></TR></TABLE>> fillcolor=springgreen id=0 shape=box tooltip="\"max(iterable, *[, default=obj, key=func]) -> value\""] 503 [label=start fillcolor=red id=start shape=egg] 503 -> 498 503 -> 499 498 -> 502 502 -> 500 499 -> 502 500 -> 501 }

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, shrink=True, wildcard=True)[source]

Initializes the Sub-dispatch Function.

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