bout_runners.runner.run_graph¶
Contains the RunGraph class.
Classes
|
A directed acyclic graph where the nodes contains instructions for execution. |
-
class
bout_runners.runner.run_graph.
RunGraph
[source]¶ A directed acyclic graph where the nodes contains instructions for execution.
See also
RunGroup
Class for building a run group
Examples
The RunGraph contains the graph executed by BoutRunners
>>> bout_run_setup = BoutRunSetup(executor, db_connector, final_parameters) >>> run_graph = RunGraph() >>> # Attach a RunGroup to the run_graph >>> _ = RunGroup(run_graph, bout_run_setup) >>> runner = BoutRunner(run_graph) >>> runner.run()
- Attributes
- __graphnx.DiGraph
The run graph
- __node_setset
The set of nodes belonging to the graph
nodes
nx.classes.reportviews.NodeViewReturn the nodes.
Methods
__iter__()
Make the class iterable
__next__()
Return the next order nodes from graph (ordered by the breadth)
__len__()
Return the number of nodes with status ready
__getitem__(nodename)
Return the content of a node
get_node_orders(reverse)
Return nodes sorted after order
predecessors(node_name)
Return the predecessors of the node
successors(node_name)
Return the successors of the node
reset()
Reset the nodes by setting the status to ‘ready’
add_bout_run_node(name, bout_run_setup)
Add a node where the setup of a BOUT++ run is attached
add_function_node(name, function_dict=None, path=None, submitter=None)
Add a node with an optionally attached callable to the graph
add_edge(start_node, end_node)
Connect two nodes through an directed edge
remove_edge(start_node, end_node)
Remove edge between two nodes
add_waiting_for(nodes_to_wait_for, name_of_waiting_node)
Make a node wait for the completion of one or more nodes
get_waiting_for_tuple(start_node_name)
Return the list of nodes waiting for a given node
change_status_node_and_dependencies(start_node_name, status=”errored”)
Remove node and all nodes waiting for the specified node
get_dot_string()
Return the graph as a string i the dot format
Instantiate the graph.
- Attributes
nodes
Return the nodes.
Methods
add_bout_run_node
(name, bout_run_setup)Add a node where the setup of a BOUT++ run is attached.
add_edge
(start_node, end_node)Connect two nodes through an directed edge.
add_function_node
(name[, function_dict, …])Add a node with an optionally attached callable to the graph.
add_waiting_for
(name_of_waiting_node, …)Make a node wait for the completion of one or more nodes.
Remove node and all nodes waiting for the specified node.
Return the graph as a string i the dot format.
get_node_orders
([reverse])Return nodes sorted after order.
get_waiting_for_tuple
(start_node_name)Return the list of nodes waiting for a given node.
predecessors
(node_name)Return the predecessors of the node.
remove_edge
(start_node, end_node)Remove edge between two nodes.
reset
()Reset the nodes by setting status to ‘ready’ and calling node.reset().
successors
(node_name)Return the successors of the node.
-
add_bout_run_node
(name: str, bout_run_setup: bout_runners.parameters.bout_run_setup.BoutRunSetup) → None[source]¶ Add a node where the setup of a BOUT++ run is attached.
- Parameters
- namestr
Name of the node
- bout_run_setupBoutRunSetup
The setup of the BOUT++ run
- Raises
- ValueError
If the node is already present in the graph
-
add_edge
(start_node: str, end_node: str) → None[source]¶ Connect two nodes through an directed edge.
- Parameters
- start_nodestr
Name of the start node
- end_nodestr
Name of the end node
- Raises
- ValueError
If the graph after adding the nodes becomes cyclic
-
add_function_node
(name: str, function_dict: Optional[Dict[str, Optional[Union[Callable, Tuple[Any, …], Dict[str, Any]]]]] = None, path: Optional[pathlib.Path] = None, submitter: Optional[bout_runners.submitter.abstract_submitter.AbstractSubmitter] = None) → None[source]¶ Add a node with an optionally attached callable to the graph.
- Parameters
- namestr
Name of the node
- function_dictNone or dict
Dict with the function to call On the form >>> {‘function’: None or callable, … ‘args’: None or tuple, … ‘kwargs’: None or dict}
- pathNone or Path
Absolute path to store the python file which holds the function and its arguments
- submitterAbstractSubmitter
Submitter to submit the function with If None, the default LocalSubmitter will be used
- Raises
- ValueError
If the node is already present in the graph
-
add_waiting_for
(name_of_waiting_node: str, nodes_to_wait_for: Optional[Union[str, Iterable[str]]]) → None[source]¶ Make a node wait for the completion of one or more nodes.
In other words we will let one or more nodes point to name_of_waiting_node.
- Parameters
- name_of_waiting_nodestr
Name of the node which will wait for the node(s) in waiting_for to finish
- nodes_to_wait_forstr or iterable
Name of nodes the name_of_waiting_node will wait for
-
change_status_node_and_dependencies
(start_node_name, status: str = 'errored') → None[source]¶ Remove node and all nodes waiting for the specified node.
- Parameters
- start_node_namestr
Name of the node to remove All nodes waiting for start_node_name will be removed
- statusstr
Status to set on start_node_name and all its dependencies
-
get_dot_string
() → str[source]¶ Return the graph as a string i the dot format.
This can be visualized through GraphViz or online at http://www.webgraphviz.com/
- Returns
- str
The graph written in the dot format
-
get_node_orders
(reverse: bool = False) → Tuple[Tuple[str, …], …][source]¶ Return nodes sorted after order.
One order is considered as the nodes without any in edges To find the next order remove the first order from the graph and repeat the first step
- Parameters
- reversebool
Whether or not to reverse the graph before finding the orders
- Returns
- orderstuple of tuple of str
A tuple of tuple where the innermost tuple constitutes an order
Warning
As we are counting an order from the nodes with no in edges the result of >>> self.get_node_orders(reverse=True) != self.get_node_orders()[::-1]
-
get_waiting_for_tuple
(start_node_name) → Tuple[str, …][source]¶ Return the list of nodes waiting for a given node.
- Parameters
- start_node_namestr
Name of the node other nodes are waiting for
- Returns
- tuple
Tuple of the nodes which are waiting for the given node
-
property
nodes
¶ Return the nodes.
-
predecessors
(node_name: str) → Tuple[str, …][source]¶ Return the predecessors of the node.
- Parameters
- node_namestr
Name of the node to get the predecessors from
- Returns
- predecessor_namestuple of str
Names of predecessors