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 during prepare_for_execution().

Type

XDL

_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
_xdl: XDL = None
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 the on_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
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.

Parameters
  • steps (List[Step]) – List of steps to perform sanity checks recursively for every step / substep. Defaults to self._xdl.steps

  • graph (MultiDiGraph) – Graph to use when running sanity checks. If not given will use _graph.

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:
  1. Map all vessels in self._xdl.vessel_specs to vessels in graph. This involves choosing a graph vessel to use for every vessel in self._xdl.vessel_specs, and updating every occurrence of the xdl vessel in self._xdl.steps with the appropriate graph vessel.

  2. 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.

  3. 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.

  4. Once _xdl has been successfully prepared for execution, set self._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.