8.2.8.1. add_function

add_function(dsp, inputs_kwargs=False, inputs_defaults=False, **kw)[source]

Decorator to add a function to a dispatcher.

Parameters:
  • dsp (schedula.Dispatcher) – A dispatcher.
  • inputs_kwargs (bool) – Do you want to include kwargs as inputs?
  • inputs_defaults (bool) – Do you want to set default values?
  • kw (dict) – See :func:~`schedula.dispatcher.Dispatcher.add_function`.
Returns:

Decorator.

Return type:

callable

————————————————————————

Example:

>>> import schedula as sh
>>> dsp = sh.Dispatcher(name='Dispatcher')
>>> @sh.add_function(dsp, outputs=['e'])
... @sh.add_function(dsp, False, True, outputs=['i'], inputs='ecah')
... @sh.add_function(dsp, True, outputs=['l'])
... def f(a, b, c, d=1):
...     return (a + b) - c + d
>>> @sh.add_function(dsp, True, outputs=['d'])
... def g(e, i, *args, d=0):
...     return e + i + d
>>> sol = dsp({'a': 1, 'b': 2, 'c': 3}); sol
Solution([('a', 1), ('b', 2), ('c', 3), ('h', 1), ('e', 1), ('i', 4),
          ('d', 5), ('l', 5)])

digraph workflow { graph [ratio=1] node [style=filled] label = <workflow> splines = ortho style = filled 546 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-f9a512d943e35ce05228eb43a2e348231ebcaea5/a-output.html">a</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">0.0</TD></TR></TABLE>> fillcolor=cyan id=1 shape=box style="rounded,filled" tooltip="\"a\""] 547 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-f9a512d943e35ce05228eb43a2e348231ebcaea5/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\""] 548 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-f9a512d943e35ce05228eb43a2e348231ebcaea5/c-output.html">c</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">0.0</TD></TR></TABLE>> fillcolor=cyan id=3 shape=box style="rounded,filled" tooltip="\"c\""] 549 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-f9a512d943e35ce05228eb43a2e348231ebcaea5/d-output.html">d</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">6.0</TD></TR></TABLE>> fillcolor=cyan id=4 shape=box style="rounded,filled" tooltip="\"d\""] 550 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-f9a512d943e35ce05228eb43a2e348231ebcaea5/e-output.html">e</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">2.0</TD></TR></TABLE>> fillcolor=cyan id=7 shape=box style="rounded,filled" tooltip="\"e\""] 551 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-f9a512d943e35ce05228eb43a2e348231ebcaea5/f.html">f</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">7.0</TD></TR><TR><TD align="RIGHT" border="1">started</TD><TD align="LEFT" border="1">2019-12-06T17:54:59.877355</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=0 shape=box tooltip="\"f\""] 552 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-f9a512d943e35ce05228eb43a2e348231ebcaea5/f-0.html">f&lt;0&gt;</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.877224</TD></TR><TR><TD align="RIGHT" border="1">duration</TD><TD align="LEFT" border="1">0:00:00.000014</TD></TR></TABLE>> fillcolor=springgreen id=6 shape=box tooltip="\"f<0>\""] 553 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-f9a512d943e35ce05228eb43a2e348231ebcaea5/f-1.html">f&lt;1&gt;</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.877144</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=10 shape=box tooltip="\"f<1>\""] 554 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-f9a512d943e35ce05228eb43a2e348231ebcaea5/g.html">g</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">5.0</TD></TR><TR><TD align="RIGHT" border="1">started</TD><TD align="LEFT" border="1">2019-12-06T17:54:59.877291</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=11 shape=box tooltip="\"g\""] 555 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-f9a512d943e35ce05228eb43a2e348231ebcaea5/h-output.html">h</TD></TR><TR><TD align="RIGHT" border="1">default</TD><TD align="LEFT" border="1">1</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">0.0</TD></TR></TABLE>> fillcolor=cyan id=8 shape=box style="rounded,filled" tooltip="\"h\""] 556 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-f9a512d943e35ce05228eb43a2e348231ebcaea5/i-output.html">i</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">4.0</TD></TR></TABLE>> fillcolor=cyan id=9 shape=box style="rounded,filled" tooltip="\"i\""] 557 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-f9a512d943e35ce05228eb43a2e348231ebcaea5/l-output.html">l</TD></TR><TR><TD align="RIGHT" border="1">distance</TD><TD align="LEFT" border="1">8.0</TD></TR></TABLE>> fillcolor=cyan id=5 shape=box style="rounded,filled" tooltip="\"l\""] 558 [label=start fillcolor=red id=start shape=egg] 558 -> 546 558 -> 547 558 -> 548 558 -> 555 546 -> 551 546 -> 552 546 -> 553 547 -> 551 547 -> 553 548 -> 551 548 -> 552 548 -> 553 555 -> 552 551 -> 557 552 -> 556 553 -> 550 550 -> 552 550 -> 554 554 -> 549 556 -> 554 549 -> 551 }