8.2.8.26. run_model

class run_model(func, *args, _init=None, **kwargs)[source]

It is an utility function to execute dynamically generated function/models and - if Dispatcher based - add their workflows to the parent solution.

Returns:

A function that executes the dispatch of the given dsp.

Return type:

callable

Example:

Follows a simple example on how to use the run_model():

Moreover, it can be used also with all SubDispatcher() like objects:

>>> sub_dsp = SubDispatch(dsp_model, outputs=['c'], output_type='list')
>>> sol = dsp({'dsp_model': sub_dsp, 'inputs': {'b': 1, 'a': 2}})
>>> sol['outputs']
[2]
>>> sol.workflow.nodes['execute_dsp']['solution']
Solution({'a': 2, 'b': 1, 'c': 2})

Methods

__call__

Call self as a function.

__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__

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

__sizeof__

Size of object in memory, in bytes.

__str__

Return str(self).

__subclasshook__

Abstract classes can override this to customize issubclass().

__init__(func, *args, _init=None, **kwargs)[source]

Attributes

__annotations__

__dict__

__doc__

__module__

__weakref__

list of weak references to the object

__init__(func, *args, _init=None, **kwargs)[source]
__call__(**kwargs)[source]

Call self as a function.

__annotations__ = {}
__dict__ = mappingproxy({'__module__': 'schedula.utils.dsp', '__doc__': "\n    It is an utility function to execute dynamically generated function/models\n    and - if Dispatcher based - add their workflows to the parent solution.\n\n    :return:\n        A function that executes the dispatch of the given `dsp`.\n    :rtype: callable\n\n    **Example**:\n\n    Follows a simple example on how to use the\n    :func:`~schedula.utils.dsp.run_model`:\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(\n        ...     function_id='execute_dsp', function=run_model,\n        ...     inputs=['dsp_model', 'inputs'], outputs=['outputs']\n        ... )\n        'execute_dsp'\n        >>> dsp_model = Dispatcher(name='Model')\n        >>> dsp_model.add_function('max', max, inputs=['a', 'b'], outputs=['c'])\n        'max'\n        >>> sol = dsp({'dsp_model': dsp_model, 'inputs': {'b': 1, 'a': 2}})\n        >>> sol['outputs']\n        Solution({'a': 2, 'b': 1, 'c': 2})\n        >>> sol.workflow.nodes['execute_dsp']['solution']\n        Solution({'a': 2, 'b': 1, 'c': 2})\n\n    Moreover, it can be used also with all\n    :func:`~schedula.utils.dsp.SubDispatcher` like objects::\n\n        >>> sub_dsp = SubDispatch(dsp_model, outputs=['c'], output_type='list')\n        >>> sol = dsp({'dsp_model': sub_dsp, 'inputs': {'b': 1, 'a': 2}})\n        >>> sol['outputs']\n        [2]\n        >>> sol.workflow.nodes['execute_dsp']['solution']\n        Solution({'a': 2, 'b': 1, 'c': 2})\n    ", '__init__': <function run_model.__init__>, '__call__': <function run_model.__call__>, '__dict__': <attribute '__dict__' of 'run_model' objects>, '__weakref__': <attribute '__weakref__' of 'run_model' objects>, '__annotations__': {}})
__doc__ = "\n    It is an utility function to execute dynamically generated function/models\n    and - if Dispatcher based - add their workflows to the parent solution.\n\n    :return:\n        A function that executes the dispatch of the given `dsp`.\n    :rtype: callable\n\n    **Example**:\n\n    Follows a simple example on how to use the\n    :func:`~schedula.utils.dsp.run_model`:\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(\n        ...     function_id='execute_dsp', function=run_model,\n        ...     inputs=['dsp_model', 'inputs'], outputs=['outputs']\n        ... )\n        'execute_dsp'\n        >>> dsp_model = Dispatcher(name='Model')\n        >>> dsp_model.add_function('max', max, inputs=['a', 'b'], outputs=['c'])\n        'max'\n        >>> sol = dsp({'dsp_model': dsp_model, 'inputs': {'b': 1, 'a': 2}})\n        >>> sol['outputs']\n        Solution({'a': 2, 'b': 1, 'c': 2})\n        >>> sol.workflow.nodes['execute_dsp']['solution']\n        Solution({'a': 2, 'b': 1, 'c': 2})\n\n    Moreover, it can be used also with all\n    :func:`~schedula.utils.dsp.SubDispatcher` like objects::\n\n        >>> sub_dsp = SubDispatch(dsp_model, outputs=['c'], output_type='list')\n        >>> sol = dsp({'dsp_model': sub_dsp, 'inputs': {'b': 1, 'a': 2}})\n        >>> sol['outputs']\n        [2]\n        >>> sol.workflow.nodes['execute_dsp']['solution']\n        Solution({'a': 2, 'b': 1, 'c': 2})\n    "
__module__ = 'schedula.utils.dsp'
__weakref__

list of weak references to the object