WorkflowGraph#
- class scikitplot.agent.WorkflowGraph(start, nodes, edges=(), *, channels=None, initial=None)[source]#
A checked, immutable workflow: nodes, edges and channels.
- Parameters:
- startstr
The first node.
- nodessequence of Task, FanOut or Finish
Every node, with unique names.
- edgessequence of Edge
Transitions; a source’s edges are tried in order. At most one edge of a source is unconditional, and it is the last.
- channelsmapping of str to str or callable, default=None
Channel name to reducer: a name in
REDUCERSor a callable(old, new) -> value.- initialmapping, default=None
Initial channel values (JSON); a channel not given starts at its reducer’s empty value (
Nonefor a custom reducer).
- Raises:
- WorkflowError
If the graph is malformed, has a node unreachable from
startor one from which noFinishis reachable, has a cycle through no node withmax_visits, or anon_exhaustedtarget that leads back to its node.
- Parameters:
See also
WorkflowGraph.sequenceA graph that runs its nodes in order.
Examples
>>> from scikitplot.agent import Edge, Finish, Task, Tool, WorkflowGraph >>> count = Tool("count", lambda: 1) >>> graph = WorkflowGraph( ... "tick", ... [ ... Task("tick", count, into="n", max_visits=3, on_exhausted="done"), ... Finish("done", answer=lambda view: view.channels["n"]), ... ], ... [Edge("tick", "tick")], ... channels={"n": "add"}, ... ) >>> [tool.name for tool in graph.tools()] ['count']
- property fingerprint: str#
Digest of the graph’s structure.
Notes
Developer. Names, kinds, tools, modes, bounds and edge order are covered; callbacks are not (a function has no stable digest), so two graphs that differ only in a callback share a fingerprint.
- replay(state, *, artifacts=None)[source]#
Rebuild where
statestands in this graph.- Parameters:
- stateRunState
A run’s state.
- artifactsArtifactStore or None, default=None
As for
planner.
- Returns:
- WorkflowView
- Raises:
- WorkflowError
If a recorded step is not the one this graph would have taken.
- Parameters:
- Return type:
- classmethod sequence(*nodes, channels=None, initial=None)[source]#
Return a graph that runs
nodesin order and ends at the last one.- Parameters:
- *nodesTask, FanOut or Finish
At least one; the last must be a
Finish.- channels, initial
As for
WorkflowGraph.
- Returns:
- WorkflowGraph
- Raises:
- WorkflowError
If no node is given or the last is not a
Finish.
- Parameters:
- Return type: