bout_runners.runner.bout_runner¶
Contains the BOUT runner class.
Classes
|
Class for executing a run and store its metadata. |
-
class
bout_runners.runner.bout_runner.
BoutRunner
(run_graph: Optional[bout_runners.runner.run_graph.RunGraph] = None, wait_time: int = 5)[source]¶ Class for executing a run and store its metadata.
Examples
The easiest way to use BoutRunner is to run a script from the root directory of the project (i.e. where the Makefile and data directory are normally situated. The script can simply call
>>> BoutRunner().run()
and BoutRunner takes care of the rest.
A more elaborate example where all the dependency objects are built manually:
Import dependencies
>>> from pathlib import Path >>> from bout_runners.executor.bout_paths import BoutPaths >>> from bout_runners.executor.executor import BoutRunExecutor >>> from bout_runners.database.database_connector import DatabaseConnector >>> from bout_runners.parameters.default_parameters import DefaultParameters >>> from bout_runners.parameters.run_parameters import RunParameters >>> from bout_runners.parameters.final_parameters import FinalParameters >>> from bout_runners.submitter.local_submitter import LocalSubmitter >>> from bout_runners.runner.bout_run_setup import BoutRunSetup >>> from bout_runners.runner.run_graph import RunGraph >>> from bout_runners.runner.run_group import RunGroup
Create the bout_paths object
>>> project_path = Path().joinpath('path', 'to', 'project') >>> bout_inp_src_dir = Path().joinpath('path', 'to', 'source', 'BOUT.inp') >>> bout_inp_dst_dir = Path().joinpath('path', 'to', 'destination', 'BOUT.inp') >>> bout_paths = BoutPaths(project_path=project_path, ... bout_inp_src_dir=bout_inp_src_dir, ... bout_inp_dst_dir=bout_inp_dst_dir)
Create the input objects
>>> default_parameters = DefaultParameters(bout_paths) >>> run_parameters = RunParameters({'global': {'nout': 0}}) >>> final_parameters = FinalParameters(default_parameters, ... run_parameters) >>> executor = BoutRunExecutor( ... bout_paths=bout_paths, ... submitter=LocalSubmitter(bout_paths.project_path), ... run_parameters=run_parameters) >>> db_connector = DatabaseConnector('name_of_database', db_root_path=Path()) >>> bout_run_setup = BoutRunSetup(executor, db_connector, final_parameters) >>> run_graph = RunGraph() >>> # The RunGroup can attach pre and post-processors to the run >>> # See the user manual for more info >>> _ = RunGroup(run_graph, bout_run_setup, name='my_test_run')
Run the project
>>> runner = BoutRunner(run_graph) >>> runner.run()
- Attributes
- __run_graphRunGraph
Getter variable for executor the run graph
run_graph
GraphGet the properties of self.run_graph.
- wait_timeint
Time to wait before checking if a job has completed
Methods
__add_waiting_for(node_name)
Add the job_ids to wait for in the submission script
__prepare_run(force, restart_all)
Prepare the run sequence
__updates_when_restart_all_is_true()
Update paths and nodes when restart_all is True
__inject_copy_restart_files_node(node_with_restart)
Inject a node which copy restart files
__make_restart_files_node(to_node_name, copy_restart_from, copy_restart_to)
Make nodes which copies restart files
__next_order_has_local(submitter_dict)
Check if the current order of nodes has any local submitters
__monitor_runs(submitter_dict, raise_errors)
Monitor the runs belonging to the same order
__run_status_checker(node_name)
Run the StatusChecker
__this_order_has_local(submitter_dict)
Check if the current order of nodes has any local submitters
__update_submitter_dict_after_run_bout_run(node_name, submitted, submitter_dict)
Update the submitter dict after calling run_bout_run
find_matching_order_number(node_names, node_orders)
Return the order matching the node names
run_bout_run(bout_run_setup, restart_from_bout_inp_dst, force)
Perform the BOUT++ run and capture the related metadata
run_function(path, function, args, kwargs, submitter)
Submit a function for execution
reset()
Reset the run_graph
release_nodes(nodes_to_release)
Release nodes to a submission queue if applicable
cluster_node_exist(node_names)
Check if any of the nodes have a submitter of type AbstractClusterSubmitter
wait_until_completed(self)
Wait until all submitted nodes are completed
run(restart_all, force, raise_errors)
Execute the run
Set the member data.
- Parameters
- run_graphNone or RunGraph
The run graph to be executed If None the run graph will be constructed and added parameters from the default BoutRunSetup
- wait_timeint
Time to wait before checking if a job has completed
- Attributes
run_graph
Get the properties of self.run_graph.
Methods
cluster_node_exist
(node_names)Check if any of the nodes have a submitter of type AbstractClusterSubmitter.
find_matching_order_number
(node_names, …)Return the order matching the node names.
release_nodes
(nodes_to_release)Release nodes to a submission queue if applicable.
reset
()Reset the run_graph.
run
([restart_all, force, raise_errors])Execute all the nodes in the run_graph.
run_bout_run
(bout_run_setup[, force])Perform the BOUT++ run and capture the related metadata.
run_function
(path, submitter, function[, …])Submit a function for execution.
Wait until all submitted nodes are completed.
-
cluster_node_exist
(node_names: Iterable[str]) → bool[source]¶ Check if any of the nodes have a submitter of type AbstractClusterSubmitter.
- Parameters
- node_namesiterable of str
Iterable containing node names
- Returns
- bool
Whether the iterable contains any cluster nodes
-
static
find_matching_order_number
(node_names: Tuple[str, …], node_orders: Tuple[Tuple[str, …], …]) → Optional[int][source]¶ Return the order matching the node names.
- Parameters
- node_namestuple of str
Node names
- node_orderstuple of tuple of str
Ordered tuple of orders
- Returns
- order_numberint or None
The first order where a match was found If no match was found 0 is returned
-
release_nodes
(nodes_to_release: Tuple[Tuple[str, …], …]) → None[source]¶ Release nodes to a submission queue if applicable.
- Parameters
- nodes_to_releaseiterable
Name of nodes to release
-
run
(restart_all: bool = False, force: bool = False, raise_errors: bool = True) → None[source]¶ Execute all the nodes in the run_graph.
- Parameters
- restart_allbool
All the BOUT++ runs in the run graph will be restarted
- forcebool
Execute the run even if has been performed with the same parameters
- raise_errorsbool
If True the program will raise any error caught when during the running of the nodes If False the program will continue execution, but all nodes depending on the errored node will be marked as errored and not submitted
-
static
run_bout_run
(bout_run_setup: bout_runners.parameters.bout_run_setup.BoutRunSetup, force: bool = False) → bool[source]¶ Perform the BOUT++ run and capture the related metadata.
- Parameters
- bout_run_setupBoutRunSetup
The setup for the BOUT++ run
- forcebool
Execute the run even if has been performed with the same parameters
- Returns
- bool
Whether or not the run was submitted
-
static
run_function
(path: pathlib.Path, submitter: bout_runners.submitter.abstract_submitter.AbstractSubmitter, function: Callable, args: Optional[Tuple[Any, …]] = None, kwargs: Optional[Dict[str, Any]] = None) → bout_runners.submitter.abstract_submitter.AbstractSubmitter[source]¶ Submit a function for execution.
- Parameters
- pathPath
Absolute path to store the python file which holds the function and its arguments
- submitterAbstractSubmitter
The submitter to submit the function with Uses the default LocalSubmitter if None
- functionfunction
The function to call
- argsNone or tuple
The positional arguments
- kwargsNone or dict
The keyword arguments
- Returns
- submitterAbstractSubmitter
The submitter used
-
property
run_graph
¶ Get the properties of self.run_graph.
- Returns
- self.__run_graphRunGraph
The RunGraph object