6.4.2.4. add_from_listsΒΆ

Dispatcher.add_from_lists(data_list=None, fun_list=None, dsp_list=None)[source]

Add multiple function and data nodes to dispatcher.

Parameters:
  • data_list (list[dict], optional) – It is a list of data node kwargs to be loaded.
  • fun_list (list[dict], optional) – It is a list of function node kwargs to be loaded.
  • dsp_list (list[dict], optional) – It is a list of sub-dispatcher node kwargs to be loaded.
Returns:

  • Data node ids.
  • Function node ids.
  • Sub-dispatcher node ids.

Return type:

(list[str], list[str], list[str])

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

Example:

Define a data list:

>>> data_list = [
...     {'data_id': 'a'},
...     {'data_id': 'b'},
...     {'data_id': 'c'},
... ]

Define a functions list:

>>> def f(a, b):
...     return a + b
...
>>> fun_list = [
...     {'function': f, 'inputs': ['a', 'b'], 'outputs': ['c']}
... ]

Define a functions list:

>>> sub_dsp = Dispatcher(name='Sub-dispatcher')
>>> sub_dsp.add_function(function=f, inputs=['e', 'f'],
...                      outputs=['g'])
'...:f'
>>>
>>> dsp_list = [
...     {'dsp_id': 'Sub', 'dsp': sub_dsp,
...      'inputs': {'a': 'e', 'b': 'f'}, 'outputs': {'g': 'c'}},
... ]

Add function and data nodes to dispatcher:

>>> dsp.add_from_lists(data_list, fun_list, dsp_list)
(['a', 'b', 'c'], ['...dispatcher:f'], ['Sub'])