xdl.execution.abstract_executor module
- class xdl.execution.abstract_executor.AbstractXDLExecutor(xdl: XDL = None)[source]
Bases:
abc.ABC
Abstract class for XDL executor. The main functionality of this class is to perform compilation and execution of a given XDL object.
- Parameters
xdl (XDL) – XDL object to compile / execute.
- _prepared_for_execution
Flag to specify whether self._xdl is ready for execution or not. Should be set to True at the end of
prepare_for_execution()
.- Type
bool
- _xdl
XDL object passed to
__init__
. This object will be altered duringprepare_for_execution()
.- Type
- _graph
Graph passed to
prepare_for_execution()
.self._xdl
will be altered to execute on this graph during :py:meth`prepare_for_execution`.- Type
MultiDiGraph
- logger
Logger object for executor to use when logging.
- Type
logging.Logger
- _abc_impl = <_abc_data object>
- _graph: networkx.classes.multidigraph.MultiDiGraph = None
- _graph_hash(graph: Optional[networkx.classes.multidigraph.MultiDiGraph] = None) str [source]
Get SHA 256 hash of graph. Used to determine whether graph used for execution is the same as the one used for compilation.
Recommended to override this basic implementation, as this will give you a different hash if the position of nodes change, even if the properties and connectivity stays the same.
- Parameters
graph (MultiDiGraph) – Graph to get hash of.
- Returns
Hash of graph.
- Return type
str
- _prepared_for_execution: bool = False
- add_internal_properties(graph: Optional[networkx.classes.multidigraph.MultiDiGraph] = None, steps: Optional[List[xdl.steps.core.step.Step]] = None) None [source]
Recursively add internal properties to all steps, child steps and substeps in given list of steps. If graph and steps not given use self._graph and
self._xdl.steps
. This method recursively calls theon_prepare_for_execution
method of every step, child step and substep in the step list.- Parameters
graph (MultiDiGraph) – Graph to pass to step
on_prepare_for_execution
method.steps (List[Step]) – List of steps to add internal properties to. This steps in this list are altered in place, hence no return value.
- add_internal_properties_to_step(graph: networkx.classes.multidigraph.MultiDiGraph, step: xdl.steps.core.step.Step) None [source]
Add internal properties to given step and all its substeps and child steps.
- Parameters
graph (MultiDiGraph) – Graph to pass to step
on_prepare_for_execution
method.step (Step) – Step to add internal properties to. The step is altered in place, hence no return value.
- async execute(platform_controller: Any, interactive: Optional[bool] = True, tracer: Optional[List[Tuple[type, Dict]]] = None) None [source]
Execute XDL procedure with given platform controller. The same graph must be passed to the platform controller and to prepare_for_execution.
Schedules each Step as a task. Once all Step’s are scheduled, they will be executed once their requirements are met (appropriate locks acquired and Step’s they are dependent on are completed).
If execution is aborted (a Step returns False), all pending tasks will be cancelled.
- Parameters
platform_controller (Any) – Platform controller object to execute XDL with.
interactive (bool, optional) – Prompt user to confirm certain steps. Defaults to True.
tracer (List[(str, Dict)]) – Tracer with all steps that have been executed and their properties at execution time.
- Raises
XDLExecutionOnDifferentGraphError – If trying to execute XDLEXE on different graph to the one which was used to compile it.
XDLExecutionBeforeCompilationError – Trying to execute XDL object before it has been compiled.
- logger: logging.Logger = None
- perform_sanity_checks(steps: Optional[List[xdl.steps.core.step.Step]] = None, graph: Optional[networkx.classes.multidigraph.MultiDiGraph] = None) None [source]
Recursively perform sanity checks on every step in steps list. If steps list not given defaults to
self._xdl.steps
.
- prepare_dynamic_steps_for_execution(step: xdl.steps.core.step.Step, graph: networkx.classes.multidigraph.MultiDiGraph) None [source]
Prepare any dynamic steps’ start blocks for execution. This is used during
add_internal_properties()
and during execution. The reason for using during execution is that when loaded from XDLEXE dynamic steps do not have a start block. In the future the start block of dynamic steps could potentially be saved in the XDLEXE.- Parameters
step (Step) – Step to recursively prepare any dynamic steps for execution.
graph (MultiDiGraph) – Graph to use when preparing for execution.
- prepare_for_execution(graph: networkx.classes.multidigraph.MultiDiGraph, **kwargs) None [source]
Abstract compile method. Should convert
_xdl
into an executable form.At the moment, the implementation of this method is completely open. When it becomes clear what overlap there is between implementation on different platforms, it could make sense to move some code from platform specific implementations into the abstract class. At the moment pretty much everything has to be done in the platform specific implementation.
- Tasks this method must generally complete:
Map all vessels in
self._xdl.vessel_specs
to vessels in graph. This involves choosing a graph vessel to use for every vessel inself._xdl.vessel_specs
, and updating every occurrence of the xdl vessel inself._xdl.steps
with the appropriate graph vessel.Add internal properties to all steps, child steps and substeps. This can typically be done by calling
add_internal_properties()
. This may need to be done more than once, depending on the way in which new steps are added and step properties are updated during this method.Do sanity checks to make sure that the procedure is indeed executable. As a bare minimum
perform_sanity_checks()
should be called at the end of this method.Once
_xdl
has been successfully prepared for execution, setself._prepared_for_execution
to True.
Additionally, if for any reason
_xdl
cannot be prepared for execution with the given graph, helpful, informative errors should be raised.- Parameters
graph_file (Union[str, MultiDiGraph]) – Path to graph file, or loaded graph to compile procedure with.