7.2.6.20. SubDispatchFunction

class SubDispatchFunction(dsp, function_id, inputs, 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

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 393 [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] 394 [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] 395 [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] 396 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-a9c3a489c4321dcb823f6c6211b5ba345e434238/my_log.html">log(x - 1)</TD></TR><TR><TD align="RIGHT" border="1">input_domain</TD><TD align="LEFT" border="1" href="./dispatcher-a9c3a489c4321dcb823f6c6211b5ba345e434238/lambda.html">&lt;lambda&gt;</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="log(x - 1)"] 397 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-a9c3a489c4321dcb823f6c6211b5ba345e434238/max.html">max</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="max(iterable, *[, default=obj, key=func]) -> value"] 396 -> 393 394 -> 397 393 -> 397 395 -> 396 397 -> 395 }

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(2, 1)
0.0

digraph workflow { graph [ratio=1] node [style=filled] label = <workflow> splines = ortho style = filled 403 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-51ebe53dc9510a28bb182b55cf4646a31a086143/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] 404 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-51ebe53dc9510a28bb182b55cf4646a31a086143/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] 405 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-51ebe53dc9510a28bb182b55cf4646a31a086143/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] 406 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-51ebe53dc9510a28bb182b55cf4646a31a086143/my_log.html">log(x - 1)</TD></TR><TR><TD align="RIGHT" border="1">solution_domain</TD><TD align="LEFT" border="1" href="./dispatcher-51ebe53dc9510a28bb182b55cf4646a31a086143/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">2018-10-08T22:02:40.939341</TD></TR><TR><TD align="RIGHT" border="1">duration</TD><TD align="LEFT" border="1">0:00:00.000007</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="log(x - 1)"] 407 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-51ebe53dc9510a28bb182b55cf4646a31a086143/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-10-08T22:02:40.939270</TD></TR><TR><TD align="RIGHT" border="1">duration</TD><TD align="LEFT" border="1">0:00:00.000006</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="max(iterable, *[, default=obj, key=func]) -> value"] 408 [label=start fillcolor=red shape=egg] 406 -> 403 408 -> 404 408 -> 403 404 -> 407 403 -> 407 405 -> 406 407 -> 405 }

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

>>> fun(1, 0)  
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 416 [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] 417 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-015c19170e1beb7f7ebebf12fc6469f4593a40a1/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] 418 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-015c19170e1beb7f7ebebf12fc6469f4593a40a1/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] 419 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-015c19170e1beb7f7ebebf12fc6469f4593a40a1/my_log.html">log(x - 1)</TD></TR><TR><TD align="RIGHT" border="1">input_domain</TD><TD align="LEFT" border="1" href="./dispatcher-015c19170e1beb7f7ebebf12fc6469f4593a40a1/lambda.html">&lt;lambda&gt;</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 shape=box tooltip="log(x - 1)"] 420 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-015c19170e1beb7f7ebebf12fc6469f4593a40a1/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-10-08T22:02:40.969048</TD></TR><TR><TD align="RIGHT" border="1">duration</TD><TD align="LEFT" border="1">0:00:00.000005</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip="max(iterable, *[, default=obj, key=func]) -> value"] 421 [label=start fillcolor=red shape=egg] 421 -> 417 421 -> 416 417 -> 420 416 -> 420 420 -> 418 418 -> 419 }

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, shrink=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.