7.1.1.5. add_function

Dispatcher.add_function(function_id=None, function=None, inputs=None, outputs=None, input_domain=None, weight=None, inp_weight=None, out_weight=None, description=None, filters=None, **kwargs)[source]

Add a single function node to dispatcher.

Parameters:
  • function_id (str, optional) – Function node id. If None will be assigned as <fun.__name__>.
  • function (callable, optional) – Data node estimation function.
  • inputs (list, optional) – Ordered arguments (i.e., data node ids) needed by the function.
  • outputs (list, optional) – Ordered results (i.e., data node ids) returned by the function.
  • input_domain (callable, optional) – A function that checks if input values satisfy the function domain. This can be any function that takes the same inputs of the function and returns True if input values satisfy the domain, otherwise False. In this case the dispatch algorithm doesn’t pass on the node.
  • weight (float, int, optional) – Node weight. It is a weight coefficient that is used by the dispatch algorithm to estimate the minimum workflow.
  • inp_weight (dict[str, float | int], optional) – Edge weights from data nodes to the function node. It is a dictionary (key=data node id) with the weight coefficients used by the dispatch algorithm to estimate the minimum workflow.
  • out_weight (dict[str, float | int], optional) – Edge weights from the function node to data nodes. It is a dictionary (key=data node id) with the weight coefficients used by the dispatch algorithm to estimate the minimum workflow.
  • description (str, optional) – Function node’s description.
  • filters (list[function], optional) – A list of functions that are invoked after the invocation of the main function.
  • kwargs (keyword arguments, optional) – Set additional node attributes using key=value.
Returns:

Function node id.

Return type:

str

***********************************************************************

Example:

Add a function node:

>>> def my_function(a, b):
...     c = a + b
...     d = a - b
...     return c, d
...
>>> dsp.add_function(function=my_function, inputs=['a', 'b'],
...                  outputs=['c', 'd'])
'my_function'

Add a function node with domain:

>>> from math import log
>>> def my_log(a, b):
...     return log(b - a)
...
>>> def my_domain(a, b):
...     return a < b
...
>>> dsp.add_function(function=my_log, inputs=['a', 'b'],
...                  outputs=['e'], input_domain=my_domain)
'my_log'