8.2.8.21. SubDispatch¶
- class SubDispatch(dsp=None, *args, **kwargs)[source]¶
It dispatches a given
Dispatcherlike a function.This function takes a sequence of dictionaries as input that will be combined before the dispatching.
- Returns:
A function that executes the dispatch of the given
Dispatcher.- Return type:
callable
See also
Example:
>>> from schedula import Dispatcher >>> sub_dsp = Dispatcher(name='Sub-dispatcher') ... >>> def fun(a): ... return a + 1, a - 1 ... >>> sub_dsp.add_function('fun', fun, ['a'], ['b', 'c']) 'fun' >>> dispatch = SubDispatch(sub_dsp, ['a', 'b', 'c'], output_type='dict') >>> dsp = Dispatcher(name='Dispatcher') >>> dsp.add_function('Sub-dispatch', dispatch, ['d'], ['e']) 'Sub-dispatch'
The Dispatcher output is:
>>> o = dsp.dispatch(inputs={'d': {'a': 3}})
while, the Sub-dispatch is:
>>> sol = o.workflow.nodes['Sub-dispatch']['solution'] >>> sol Solution({'a': 3, 'b': 4, 'c': 2}) >>> sol == o['e'] True
Methods
Call self as a function.
__deepcopy____delattr__Implement delattr(self, name).
__dir__Default dir() implementation.
__eq__Return self==value.
__format__Default object formatter.
__ge__Return self>=value.
__getattribute__Return getattr(self, name).
Helper for pickle.
__gt__Return self>value.
__hash__Return hash(self).
Initializes the Sub-dispatch.
__init_subclass__This method is called when a class is subclassed.
__le__Return self<=value.
__lt__Return self<value.
__ne__Return self!=value.
__reduce__Helper for pickle.
__reduce_ex__Helper for pickle.
__repr__Return repr(self).
__setattr__Implement setattr(self, name, value).
__sizeof__Size of object in memory, in bytes.
__str__Return str(self).
__subclasshook__Abstract classes can override this to customize issubclass().
Constructs a Blueprint out of the current object.
formCreates a dispatcher Form Flask app.
get_nodeReturns a sub node of a dispatcher.
plotPlots the Dispatcher with a graph in the DOT language with Graphviz.
webCreates a dispatcher Flask app.
- __init__(dsp, outputs=None, inputs_dist=None, wildcard=False, no_call=False, shrink=False, rm_unused_nds=False, output_type='all', function_id=None, output_type_kw=None)[source]¶
Initializes the Sub-dispatch.
- Parameters:
dsp (schedula.Dispatcher | schedula.utils.blue.BlueDispatcher) – A dispatcher that identifies the model adopted.
inputs_dist (dict[str, int | float], optional) – Initial distances of input data nodes.
wildcard (bool, int, 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. If it is equal to 2, the the data node that cannot be calculated are excluded by the wildcard condition.
no_call (bool, optional) – If True data node estimation function is not used.
shrink (bool, optional) – If True the dispatcher is shrink before the dispatch.
rm_unused_nds (bool, optional) – If True unused function and sub-dispatcher nodes are removed from workflow.
output_type (str, optional) –
Type of function output:
’all’: a dictionary with all dispatch outputs.
’list’: a list with all outputs listed in outputs.
’dict’: a dictionary with any outputs listed in outputs.
output_type_kw (dict, optional) – Extra kwargs to pass to the selector function.
function_id (str, optional) – Function name.
Attributes
__dict____weakref__list of weak references to the object
- __init__(dsp, outputs=None, inputs_dist=None, wildcard=False, no_call=False, shrink=False, rm_unused_nds=False, output_type='all', function_id=None, output_type_kw=None)[source]¶
Initializes the Sub-dispatch.
- Parameters:
dsp (schedula.Dispatcher | schedula.utils.blue.BlueDispatcher) – A dispatcher that identifies the model adopted.
inputs_dist (dict[str, int | float], optional) – Initial distances of input data nodes.
wildcard (bool, int, 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. If it is equal to 2, the the data node that cannot be calculated are excluded by the wildcard condition.
no_call (bool, optional) – If True data node estimation function is not used.
shrink (bool, optional) – If True the dispatcher is shrink before the dispatch.
rm_unused_nds (bool, optional) – If True unused function and sub-dispatcher nodes are removed from workflow.
output_type (str, optional) –
Type of function output:
’all’: a dictionary with all dispatch outputs.
’list’: a list with all outputs listed in outputs.
’dict’: a dictionary with any outputs listed in outputs.
output_type_kw (dict, optional) – Extra kwargs to pass to the selector function.
function_id (str, optional) – Function name.
- __doc__ = "\n It dispatches a given :class:`~schedula.dispatcher.Dispatcher` like a\n function.\n\n This function takes a sequence of dictionaries as input that will be\n combined before the dispatching.\n\n :return:\n A function that executes the dispatch of the given\n :class:`~schedula.dispatcher.Dispatcher`.\n :rtype: callable\n\n .. seealso:: :func:`~schedula.dispatcher.Dispatcher.dispatch`,\n :func:`combine_dicts`\n\n Example:\n\n .. dispatcher:: dsp\n :opt: graph_attr={'ratio': '1'}, depth=-1\n :code:\n\n >>> from schedula import Dispatcher\n >>> sub_dsp = Dispatcher(name='Sub-dispatcher')\n ...\n >>> def fun(a):\n ... return a + 1, a - 1\n ...\n >>> sub_dsp.add_function('fun', fun, ['a'], ['b', 'c'])\n 'fun'\n >>> dispatch = SubDispatch(sub_dsp, ['a', 'b', 'c'], output_type='dict')\n >>> dsp = Dispatcher(name='Dispatcher')\n >>> dsp.add_function('Sub-dispatch', dispatch, ['d'], ['e'])\n 'Sub-dispatch'\n\n The Dispatcher output is:\n\n .. dispatcher:: o\n :opt: graph_attr={'ratio': '1'}, depth=-1\n :code:\n\n >>> o = dsp.dispatch(inputs={'d': {'a': 3}})\n\n while, the Sub-dispatch is:\n\n .. dispatcher:: sol\n :opt: graph_attr={'ratio': '1'}, depth=-1\n :code:\n\n >>> sol = o.workflow.nodes['Sub-dispatch']['solution']\n >>> sol\n Solution({'a': 3, 'b': 4, 'c': 2})\n >>> sol == o['e']\n True\n\n "¶
- blue(memo=None, depth=-1)[source]¶
Constructs a Blueprint out of the current object.
- Parameters:
memo (dict[T,schedula.utils.blue.Blueprint]) – A dictionary to cache Blueprints.
depth (int, optional) – Depth of sub-dispatch blue. If negative all levels are bluprinted.
- Returns:
A Blueprint of the current object.
- Return type:
- __call__(*input_dicts, copy_input_dicts=False, _stopper=None, _executor=False, _sol_name=(), _verbose=False)[source]¶
Call self as a function.
- __annotations__ = {}¶
- __module__ = 'schedula.utils.dsp'¶