quantify_scheduler.backends.graph_compilation

Module Contents

Classes

SimpleNodeConfig

Datastructure specifying the structure of a simple compiler pass config

CompilationConfig

Base class for a CompilationConfig.

SerialCompilationConfig

A compilation config for a simple serial compiler.

CompilationNode

A node representing a compiler pass.

SimpleNode

A node representing a simple compiler pass consisting of calling a single

QuantifyCompiler

A compiler for quantify Schedule s.

SerialCompiler

A compiler that dynamically generates a graph of serial compilation

exception CompilationError[source]

Bases: RuntimeError

Custom exception class for failures in compilation of quantify schedules.

class SimpleNodeConfig[source]

Bases: quantify_scheduler.structure.model.DataStructure

Datastructure specifying the structure of a simple compiler pass config (also see SimpleNode).

Parameters
  • name – the name of the compilation pass

  • compilation_func – the function to perform the compilation pass as an importable string (e.g., “package_name.my_module.function_name”).

  • compilation_options – the options passed to the compilation function along with the intermediate representation.

name :str[source]
compilation_func :str[source]
compilation_options :Optional[Dict][source]
class CompilationConfig[source]

Bases: quantify_scheduler.structure.model.DataStructure

Base class for a CompilationConfig. Subclassing is generally required to create useful configs, here extra fields can be defined.

name :str[source]
backend :str[source]
class SerialCompilationConfig[source]

Bases: CompilationConfig

A compilation config for a simple serial compiler. Specifies compilation as a list of compilation passes.

backend :str = quantify_scheduler.backends.graph_compilation.SerialCompiler[source]
compilation_passes :List[SimpleNodeConfig][source]
class CompilationNode(name: str)[source]

A node representing a compiler pass.

__repr__()[source]

Return repr(self).

__str__()[source]

Return str(self).

abstract _compilation_func(schedule: Union[quantify_scheduler.Schedule, quantify_scheduler.structure.model.DataStructure], config: quantify_scheduler.structure.model.DataStructure) Union[quantify_scheduler.Schedule, quantify_scheduler.structure.model.DataStructure][source]

This is the private compilation method. It should be completely stateless whenever inheriting from the CompilationNode, this is the object that should be modified.

compile(schedule: Union[quantify_scheduler.Schedule, quantify_scheduler.structure.model.DataStructure], config: quantify_scheduler.structure.model.DataStructure) Union[quantify_scheduler.Schedule, quantify_scheduler.structure.model.DataStructure][source]

Execute a compilation pass, taking a Schedule and using the information provided in the config to return a new (updated) Schedule.

class SimpleNode(name: str, compilation_func: Callable)[source]

Bases: CompilationNode

A node representing a simple compiler pass consisting of calling a single compilation function.

_compilation_func(schedule: quantify_scheduler.Schedule, config: Union[quantify_scheduler.structure.model.DataStructure, dict]) quantify_scheduler.Schedule[source]

This is the private compilation method. It should be completely stateless whenever inheriting from the CompilationNode, this is the object that should be modified.

class QuantifyCompiler(name)[source]

Bases: CompilationNode

A compiler for quantify Schedule s. The compiler defines a directed acyclic graph containing CompilationNode s. In this graph, nodes represent modular compilation passes.

property input_node[source]

Node designated as the default input for compilation. If not specified will return None.

property output_node[source]

Node designated as the default output for compilation. If not specified will return None.

compile(schedule: quantify_scheduler.Schedule, config: CompilationConfig) quantify_scheduler.CompiledSchedule[source]

Compile a Schedule using the information provided in the config.

Parameters
  • schedule – the schedule to compile.

  • config – describing the information required to compile the schedule.

Returns

a compiled schedule containing the compiled instructions suitable for execution on a (hardware) backend.

Return type

CompiledSchedule

abstract construct_graph(config: CompilationConfig)[source]

Construct the compilation graph based on a provided config.

draw(ax: matplotlib.axes.Axes = None, figsize: Tuple[float, float] = (20, 10), **options) matplotlib.axes.Axes[source]

Draws the graph defined by this backend using matplotlib.

Will attempt to position the nodes using the “dot” algorithm for directed acyclic graphs from graphviz if available. See https://pygraphviz.github.io/documentation/stable/install.html for installation instructions of pygraphviz and graphviz.

If not available will use the Kamada Kawai positioning algorithm.

Parameters
  • ax – Matplotlib axis to plot the figure on

  • figsize – Optional figure size, defaults to something slightly larger that fits the size of the nodes.

  • options – optional keyword arguments that are passed to networkx.draw_networkx.

class SerialCompiler(name)[source]

Bases: QuantifyCompiler

A compiler that dynamically generates a graph of serial compilation passes upon calling the compile method.

construct_graph(config: SerialCompilationConfig)[source]

Construct the compilation graph based on a provided config.

For a serial backend, it is just a list of compilation passes.

_compilation_func(schedule: quantify_scheduler.Schedule, config: SerialCompilationConfig) quantify_scheduler.CompiledSchedule[source]

Compile a schedule using the backend and the information provided in the config.

Parameters
  • schedule – The schedule to compile.

  • config – A dictionary containing the information needed to compile the schedule. Nodes in this compiler specify what key they need information from in this dictionary.