8.1.1.2. add_data

Dispatcher.add_data(data_id=None, default_value=empty, initial_dist=0.0, wait_inputs=False, wildcard=None, function=None, callback=None, description=None, filters=None, await_result=None, **kwargs)[source]

Add a single data node to the dispatcher.

Parameters:
  • data_id (str, optional) – Data node id. If None will be assigned automatically (‘unknown<%d>’) not in dmap.
  • default_value (T, optional) – Data node default value. This will be used as input if it is not specified as inputs in the ArciDispatch algorithm.
  • initial_dist (float, int, optional) – Initial distance in the ArciDispatch algorithm when the data node default value is used.
  • wait_inputs (bool, optional) – If True ArciDispatch algorithm stops on the node until it gets all input estimations.
  • wildcard (bool, optional) – If True, when the data node is used as input and target in the ArciDispatch algorithm, the input value will be used as input for the connected functions, but not as output.
  • function (callable, optional) – Data node estimation function. This can be any function that takes only one dictionary (key=function node id, value=estimation of data node) as input and return one value that is the estimation of the data node.
  • callback (callable, optional) – Callback function to be called after node estimation. This can be any function that takes only one argument that is the data node estimation output. It does not return anything.
  • description (str, optional) – Data node’s description.
  • filters (list[function], optional) – A list of functions that are invoked after the invocation of the main function.
  • await_result (bool|int|float, optional) – If True the Dispatcher waits data results before assigning them to the solution. If a number is defined this is used as timeout for Future.result method [default: False]. Note this is used when asynchronous or parallel execution is enable.
  • kwargs (keyword arguments, optional) – Set additional node attributes using key=value.
Returns:

Data node id.

Return type:

str

——————————————————————–

Example:

Add a data to be estimated or a possible input data node:

>>> dsp.add_data(data_id='a')
'a'

Add a data with a default value (i.e., input data node):

>>> dsp.add_data(data_id='b', default_value=1)
'b'

Create a data node with function estimation and a default value.

  • function estimation: estimate one unique output from multiple estimations.
  • default value: is a default estimation.
>>> def min_fun(kwargs):
...     '''
...     Returns the minimum value of node estimations.
...
...     :param kwargs:
...         Node estimations.
...     :type kwargs: dict
...
...     :return:
...         The minimum value of node estimations.
...     :rtype: float
...     '''
...
...     return min(kwargs.values())
...
>>> dsp.add_data(data_id='c', default_value=2, wait_inputs=True,
...              function=min_fun)
'c'

Create a data with an unknown id and return the generated id:

>>> dsp.add_data()
'unknown'