7.2.8.16. DispatchPipe¶
- class DispatchPipe(dsp=None, *args, **kwargs)[source]¶
It converts a
Dispatcher
into a function.This function takes a sequence of arguments as input of the dispatch.
- Returns:
A function that executes the pipe of the given dsp, updating its workflow.
- Return type:
callable
Note
This wrapper is not thread safe, because it overwrite the solution.
See also
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 = DispatchPipe(dsp, 'myF', ['a', 'b'], ['a']) >>> fun.__name__ 'myF' >>> fun(2, 1) 1
The created function raises a ValueError if un-valid inputs are provided:
>>> fun(1, 0) 0
Methods
Initializes the Sub-dispatch Function.
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.
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, no_domain=True, wildcard=True, shrink=True, output_type=None, output_type_kw=None, first_arg_as_kw=False)¶
Initializes the Sub-dispatch Function.
- Parameters:
dsp (schedula.Dispatcher | schedula.utils.blue.BlueDispatcher) – A dispatcher that identifies the model adopted.
function_id (str) – Function name.
outputs (list[str], iterable, optional) – Ending data nodes.
inputs_dist (dict[str, int | float], optional) – Initial distances of input data nodes.
no_domain (bool, optional) – Skip the domain check.
shrink (bool, optional) – If True the dispatcher is shrink before the dispatch.
wildcard (bool, 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.
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 – Converts first argument of the __call__ method as kwargs.
Attributes
var_keyword
- plot(workflow=None, *args, **kwargs)[source]¶
Plots the Dispatcher with a graph in the DOT language with Graphviz.
- Parameters:
workflow (bool, optional) – If True the latest solution will be plotted, otherwise the dmap.
view (bool, optional) – Open the rendered directed graph in the DOT language with the sys default opener.
node_data (tuple[str], optional) – Data node attributes to view.
node_function (tuple[str], optional) – Function node attributes to view.
node_styles (dict[str|Token, dict[str, str]]) – Default node styles according to graphviz node attributes.
depth (int, optional) – Depth of sub-dispatch plots. If negative all levels are plotted.
name (str) – Graph name used in the source code.
comment (str) – Comment added to the first line of the source.
directory (str, optional) – (Sub)directory for source saving and rendering.
format (str, optional) – Rendering output format (‘pdf’, ‘png’, …).
engine (str, optional) – Layout command used (‘dot’, ‘neato’, …).
encoding (str, optional) – Encoding for saving the source.
graph_attr (dict, optional) – Dict of (attribute, value) pairs for the graph.
node_attr (dict, optional) – Dict of (attribute, value) pairs set for all nodes.
edge_attr (dict, optional) – Dict of (attribute, value) pairs set for all edges.
body (dict, optional) – Dict of (attribute, value) pairs to add to the graph body.
raw_body (list, optional) – List of command to add to the graph body.
directory – Where is the generated Flask app root located?
sites (set[Site], optional) – A set of
Site
to maintain alive the backend server.index (bool, optional) – Add the site index as first page?
max_lines (int, optional) – Maximum number of lines for rendering node attributes.
max_width (int, optional) – Maximum number of characters in a line to render node attributes.
view – Open the main page of the site?
render (bool, optional) – Render all pages statically?
viz (bool, optional) – Use viz.js as back-end?
short_name (int, optional) – Maximum length of the filename, if set name is hashed and reduced.
executor (str, optional) – Pool executor to render object.
run (bool, optional) – Run the backend server?
- Returns:
A SiteMap or a Site if .
- Return type:
Example:
>>> from schedula import Dispatcher >>> dsp = Dispatcher(name='Dispatcher') >>> def fun(a): ... return a + 1, a - 1 >>> dsp.add_function('fun', fun, ['a'], ['b', 'c']) 'fun' >>> dsp.plot(view=False, graph_attr={'ratio': '1'}) SiteMap([(Dispatcher, SiteMap())])