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 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_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().
Attributes
list of weak references to the object
- __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