graph_compilation#

Graph compilation backend of quantify-scheduler.

Module Contents#

Classes#

SimpleNodeConfig

Datastructure specifying the structure of a simple compiler pass config.

OperationCompilationConfig

Information required to compile an individual operation to the quantum-device layer.

DeviceCompilationConfig

Information required to compile a schedule to the quantum-device layer.

CompilationConfig

Base class for a compilation config.

CompilationNode

A node representing a compiler pass.

SimpleNode

A node representing a single compilation pass.

QuantifyCompiler

A compiler for quantify Schedule s.

SerialCompiler

A compiler that executes compilation passes sequentially.

SerialCompilationConfig

A compilation config for a simple serial compiler.

exception CompilationError[source]#

Bases: RuntimeError

Custom exception class for failures in compilation of quantify schedules.

class SimpleNodeConfig(/, **data: Any)[source]#

Bases: quantify_scheduler.structure.model.DataStructure

Datastructure specifying the structure of a simple compiler pass config.

See also SimpleNode.

name: str[source]#

The name of the compilation pass.

compilation_func: Callable[[quantify_scheduler.schedules.schedule.Schedule, quantify_scheduler.structure.model.DataStructure | dict], quantify_scheduler.schedules.schedule.ScheduleBase][source]#

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

_serialize_compilation_func(v: object) str[source]#
_import_compilation_func_if_str(fun: Callable[[quantify_scheduler.schedules.schedule.Schedule, Any], quantify_scheduler.schedules.schedule.Schedule]) Callable[[quantify_scheduler.schedules.schedule.Schedule, Any], quantify_scheduler.schedules.schedule.Schedule][source]#
class OperationCompilationConfig(/, **data: Any)[source]#

Bases: quantify_scheduler.structure.model.DataStructure

Information required to compile an individual operation to the quantum-device layer.

From a point of view of Compilation this information is needed to convert an operation defined on a quantum-circuit layer to an operation defined on a quantum-device layer.

factory_func: Callable[Ellipsis, quantify_scheduler.operations.operation.Operation | quantify_scheduler.schedules.schedule.Schedule] | None[source]#

A callable designating a factory function used to create the representation of the operation at the quantum-device level.

factory_kwargs: dict[str, Any][source]#

A dictionary containing the keyword arguments and corresponding values to use when creating the operation by evaluating the factory function.

gate_info_factory_kwargs: list[str] | None = None[source]#

A list of keyword arguments of the factory function for which the value must be retrieved from the gate_info of the operation.

_serialize_factory_func(v: object) str | None[source]#
_import_factory_func_if_str(fun: str | Callable[Ellipsis, quantify_scheduler.operations.operation.Operation]) Callable[Ellipsis, quantify_scheduler.operations.operation.Operation][source]#
class DeviceCompilationConfig(/, **data: Any)[source]#

Bases: quantify_scheduler.structure.model.DataStructure

Information required to compile a schedule to the quantum-device layer.

From a point of view of Compilation this information is needed to convert a schedule defined on a quantum-circuit layer to a schedule defined on a quantum-device layer.

clocks: dict[str, float][source]#

A dictionary specifying the clock frequencies available on the device e.g., {"q0.01": 6.123e9}.

elements: dict[str, dict[str, OperationCompilationConfig]][source]#

A dictionary specifying the elements on the device, what operations can be applied to them and how to compile these.

edges: dict[str, dict[str, OperationCompilationConfig]][source]#

A dictionary specifying the edges, links between elements on the device to which operations can be applied, and the operations that can be applied to them and how to compile these.

scheduling_strategy: Literal['asap', 'alap'] = 'asap'[source]#

The scheduling strategy used when determining the absolute timing of each operation of the schedule.

compilation_passes: list[SimpleNodeConfig][source]#

The list of compilation nodes that should be called in succession to compile a schedule to the quantum-device layer.

class CompilationConfig(/, **data: Any)[source]#

Bases: quantify_scheduler.structure.model.DataStructure

Base class for a compilation config.

Subclassing is generally required to create useful compilation configs, here extra fields can be defined.

name: str[source]#

The name of the compiler.

version: str = 'v0.6'[source]#

The version of the CompilationConfig to facilitate backwards compatibility.

keep_original_schedule: bool = True[source]#

If True, the compiler will not modify the schedule argument. If False, the compilation modifies the schedule, thereby making the original schedule unusable for further usage; this improves compilation time. Warning: if False, the returned schedule references objects from the original schedule, please refrain from modifying the original schedule after compilation in this case!

backend: type[QuantifyCompiler][source]#

A reference string to the QuantifyCompiler class used in the compilation.

device_compilation_config: DeviceCompilationConfig | None = None[source]#

The DeviceCompilationConfig used in the compilation from the quantum-circuit layer to the quantum-device layer.

hardware_compilation_config: quantify_scheduler.backends.types.common.HardwareCompilationConfig | None = None[source]#

The HardwareCompilationConfig used in the compilation from the quantum-device layer to the control-hardware layer.

debug_mode: bool = False[source]#

Debug mode can modify the compilation process, so that debugging of the compilation process is easier.

_serialize_backend_func(v: object) str[source]#
_import_backend_if_str(class_: type[QuantifyCompiler] | str) type[QuantifyCompiler][source]#
class CompilationNode(name: str)[source]#

A node representing a compiler pass.

Note

To compile, the compile() method should be used.

Parameters:

name – The name of the node. Should be unique if it is added to a (larger) compilation graph.

name[source]#
abstract _compilation_func(schedule: quantify_scheduler.schedules.schedule.Schedule | quantify_scheduler.structure.model.DataStructure, config: quantify_scheduler.structure.model.DataStructure) quantify_scheduler.schedules.schedule.Schedule | quantify_scheduler.structure.model.DataStructure[source]#

Private compilation method of this CompilationNode.

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

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

Execute a compilation pass.

This method takes a Schedule and returns a new (updated) Schedule using the information provided in the config.

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

Bases: CompilationNode

A node representing a single compilation pass.

Note

To compile, the compile() method should be used.

Parameters:
  • name – The name of the node. Should be unique if it is added to a (larger) compilation graph.

  • compilation_func – A Callable that will be wrapped in this object. A compilation function should take the intermediate representation (commonly Schedule) and a config as inputs and returns a new (modified) intermediate representation.

compilation_func[source]#
_compilation_func(schedule: quantify_scheduler.schedules.schedule.Schedule, config: quantify_scheduler.structure.model.DataStructure | dict) quantify_scheduler.schedules.schedule.Schedule[source]#

Private compilation method of this CompilationNode.

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

class QuantifyCompiler(name: str, quantum_device: quantify_scheduler.device_under_test.quantum_device.QuantumDevice | None = None)[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.

Parameters:
  • name – name of the compiler instance

  • quantum_device – quantum_device from which a CompilationConfig will be generated if None is provided for the compile step

_task_graph: networkx.DiGraph = None[source]#
_input_node = None[source]#
_output_node = None[source]#
quantum_device[source]#
compile(schedule: quantify_scheduler.schedules.schedule.Schedule, config: CompilationConfig | None = None) quantify_scheduler.schedules.schedule.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. If not specified, self.quantum_device will be used to generate the config.

Returns:

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

Return type:

CompiledSchedule

property input_node: SimpleNode[source]#

Node designated as the default input for compilation.

If not specified will return None.

property output_node: SimpleNode | None[source]#

Node designated as the default output for compilation.

If not specified will return None.

abstract construct_graph(config: CompilationConfig) NoReturn[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: str, quantum_device: quantify_scheduler.device_under_test.quantum_device.QuantumDevice | None = None)[source]#

Bases: QuantifyCompiler

A compiler that executes compilation passes sequentially.

construct_graph(config: SerialCompilationConfig) None[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.schedules.schedule.Schedule, config: SerialCompilationConfig) quantify_scheduler.schedules.schedule.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.

class SerialCompilationConfig(/, **data: Any)[source]#

Bases: CompilationConfig

A compilation config for a simple serial compiler.

Specifies compilation as a list of compilation passes.

backend: type[SerialCompiler][source]#

A reference string to the QuantifyCompiler class used in the compilation.

_serialize_backend_func(v: object) str[source]#
_import_backend_if_str(class_: type[SerialCompiler] | str) type[SerialCompiler][source]#