8.2.8.22. SubDispatchFunction

class SubDispatchFunction(dsp=None, *args, **kwargs)[source]

It converts a Dispatcher into a function.

This function takes a sequence of arguments or a key values as input of the dispatch.

Returns:

A function that executes the dispatch of the given dsp.

Return type:

callable

Example:

A dispatcher with two functions max and min and an unresolved cycle (i.e., a –> max –> c –> min –> a):

Extract a static function node, i.e. the inputs a and b and the output a are fixed:

>>> fun = SubDispatchFunction(dsp, 'myF', ['a', 'b'], ['a'])
>>> fun.__name__
'myF'
>>> fun(b=1, a=2)
0.0

The created function raises a ValueError if un-valid inputs are provided:

>>> fun(1, 0)
Traceback (most recent call last):
...
DispatcherError:
  Unreachable output-targets: ...
  Available outputs: ...

Methods

__call__

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).

__getstate__

Helper for pickle.

__gt__

Return self>value.

__hash__

Return hash(self).

__init__

Initializes the Sub-dispatch Function.

__init_subclass__

This method is called when a class is subclassed.

__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__

__reduce__

Helper for pickle.

__reduce_ex__

Helper for pickle.

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__setstate__

__sizeof__

Size of object in memory, in bytes.

__str__

Return str(self).

__subclasshook__

Abstract classes can override this to customize issubclass().

_parse_inputs

_return

blue

Constructs a Blueprint out of the current object.

copy

form

Creates a dispatcher Form Flask app.

get_node

Returns a sub node of a dispatcher.

plot

Plots the Dispatcher with a graph in the DOT language with Graphviz.

web

Creates a dispatcher Flask app.

__init__(dsp, function_id=None, inputs=None, outputs=None, inputs_dist=None, shrink=True, wildcard=True, output_type=None, output_type_kw=None, first_arg_as_kw=False)[source]

Initializes the Sub-dispatch Function.

Parameters:
  • dsp (schedula.Dispatcher | schedula.utils.blue.BlueDispatcher) – A dispatcher that identifies the model adopted.

  • function_id (str, optional) – Function name.

  • inputs (list[str], iterable, optional) – Input data nodes.

  • outputs (list[str], iterable, optional) – Ending data nodes.

  • inputs_dist (dict[str, int | float], optional) – Initial distances of input data nodes.

  • shrink (bool, optional) – If True the dispatcher is shrink before the dispatch.

  • 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.

  • 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 (bool) – Extra kwargs to pass to the selector function.

  • first_arg_as_kw – Uses the first argument of the __call__ method as kwargs.

Attributes

__annotations__

__dict__

__doc__

__module__

__signature__

__weakref__

list of weak references to the object

var_keyword

var_keyword = 'kw'
__init__(dsp, function_id=None, inputs=None, outputs=None, inputs_dist=None, shrink=True, wildcard=True, output_type=None, output_type_kw=None, first_arg_as_kw=False)[source]

Initializes the Sub-dispatch Function.

Parameters:
  • dsp (schedula.Dispatcher | schedula.utils.blue.BlueDispatcher) – A dispatcher that identifies the model adopted.

  • function_id (str, optional) – Function name.

  • inputs (list[str], iterable, optional) – Input data nodes.

  • outputs (list[str], iterable, optional) – Ending data nodes.

  • inputs_dist (dict[str, int | float], optional) – Initial distances of input data nodes.

  • shrink (bool, optional) – If True the dispatcher is shrink before the dispatch.

  • 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.

  • 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 (bool) – Extra kwargs to pass to the selector function.

  • first_arg_as_kw – Uses the first argument of the __call__ method as kwargs.

property __signature__
_parse_inputs(*args, **kw)[source]
__call__(*args, _stopper=None, _executor=False, _sol_name=(), _verbose=False, **kw)[source]

Call self as a function.

__annotations__ = {}
__doc__ = "\n    It converts a :class:`~schedula.dispatcher.Dispatcher` into a function.\n\n    This function takes a sequence of arguments or a key values as input of the\n    dispatch.\n\n    :return:\n        A function that executes the dispatch of the given `dsp`.\n    :rtype: callable\n\n    .. seealso:: :func:`~schedula.dispatcher.Dispatcher.dispatch`,\n       :func:`~schedula.dispatcher.Dispatcher.shrink_dsp`\n\n    **Example**:\n\n    A dispatcher with two functions `max` and `min` and an unresolved cycle\n    (i.e., `a` --> `max` --> `c` --> `min` --> `a`):\n\n    .. dispatcher:: dsp\n       :opt: graph_attr={'ratio': '1'}\n\n        >>> from schedula import Dispatcher\n        >>> dsp = Dispatcher(name='Dispatcher')\n        >>> dsp.add_function('max', max, inputs=['a', 'b'], outputs=['c'])\n        'max'\n        >>> from math import log\n        >>> def my_log(x):\n        ...     return log(x - 1)\n        >>> dsp.add_function('log(x - 1)', my_log, inputs=['c'],\n        ...                  outputs=['a'], input_domain=lambda c: c > 1)\n        'log(x - 1)'\n\n    Extract a static function node, i.e. the inputs `a` and `b` and the\n    output `a` are fixed::\n\n        >>> fun = SubDispatchFunction(dsp, 'myF', ['a', 'b'], ['a'])\n        >>> fun.__name__\n        'myF'\n        >>> fun(b=1, a=2)\n        0.0\n\n    .. dispatcher:: fun\n       :opt: workflow=True, graph_attr={'ratio': '1'}\n\n        >>> fun.dsp.name = 'Created function internal'\n\n    The created function raises a ValueError if un-valid inputs are\n    provided:\n\n    .. dispatcher:: fun\n       :opt: workflow=True, graph_attr={'ratio': '1'}\n       :code:\n\n        >>> fun(1, 0)  # doctest: +IGNORE_EXCEPTION_DETAIL\n        Traceback (most recent call last):\n        ...\n        DispatcherError:\n          Unreachable output-targets: ...\n          Available outputs: ...\n    "
__module__ = 'schedula.utils.dsp'