quantify_scheduler.backends.graph_compilation
Module Contents
Classes
Datastructure specifying the structure of a simple compiler pass config |
|
Base class for hardware options, such as |
|
Describes how the instruments are connected to port-clock combinations on the |
|
Base class for a compilation config. Subclassing is generally required to create |
|
A node representing a compiler pass. |
|
A node representing a simple compiler pass consisting of calling a single |
|
A compiler for quantify |
|
A compiler that dynamically generates a graph of serial compilation |
|
A compilation config for a simple serial compiler. |
- exception CompilationError[source]
Bases:
RuntimeError
Custom exception class for failures in compilation of quantify schedules.
Initialize self. See help(type(self)) for accurate signature.
- 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.
- compilation_func: Callable[[quantify_scheduler.schedules.schedule.Schedule, Any], quantify_scheduler.schedules.schedule.Schedule][source]
- classmethod 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 HardwareOption[source]
Bases:
quantify_scheduler.structure.model.DataStructure
Base class for hardware options, such as
LatencyCorrections
.
- class Connectivity[source]
Bases:
quantify_scheduler.structure.model.DataStructure
Describes how the instruments are connected to port-clock combinations on the quantum device.
- class CompilationConfig[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.
- Parameters:
name – The name of the compiler.
version – The version of the CompilationConfig to facilitate backwards compatibility.
backend – A reference string to the QuantifyCompiler class used in the compilation.
device_compilation_config – The DeviceCompilationConfig used in the compilation from the quantum-circuit layer to the quantum-device layer.
hardware_options – A list of `HardwareOption`s used in the compilation from the quantum-device layer to the control-hardware layer.
connectivity – Datastructure representing how the port-clocks on the quantum device are connected to the control hardware.
- backend: Type[QuantifyCompiler][source]
- device_compilation_config: Optional[Union[quantify_scheduler.backends.circuit_to_device.DeviceCompilationConfig, Dict]][source]
- hardware_options: Optional[List[HardwareOption]][source]
- connectivity: Optional[Union[Connectivity, Dict]][source]
- classmethod import_backend_if_str(class_: Union[Type[QuantifyCompiler], str]) Type[QuantifyCompiler] [source]
- class CompilationNode(name: str)[source]
A node representing a compiler pass.
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.
- abstract _compilation_func(schedule: Union[quantify_scheduler.schedules.schedule.Schedule, quantify_scheduler.structure.model.DataStructure], config: quantify_scheduler.structure.model.DataStructure) Union[quantify_scheduler.schedules.schedule.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.schedules.schedule.Schedule, quantify_scheduler.structure.model.DataStructure], config: quantify_scheduler.structure.model.DataStructure) Union[quantify_scheduler.schedules.schedule.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.
A node representing a simple compiler pass consisting of calling a single compilation function.
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(schedule: quantify_scheduler.schedules.schedule.Schedule, config: Union[quantify_scheduler.structure.model.DataStructure, dict]) quantify_scheduler.schedules.schedule.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, quantum_device: Optional[quantify_scheduler.device_under_test.quantum_device.QuantumDevice] = None)[source]
Bases:
CompilationNode
A compiler for quantify
Schedule
s. The compiler defines a directed acyclic graph containingCompilationNode
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
- 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.schedules.schedule.Schedule, config: Optional[CompilationConfig] = 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:
- 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, quantum_device: Optional[quantify_scheduler.device_under_test.quantum_device.QuantumDevice] = None)[source]
Bases:
QuantifyCompiler
A compiler that dynamically generates a graph of serial compilation passes upon calling the compile method.
- 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
- 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.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[source]
Bases:
CompilationConfig
A compilation config for a simple serial compiler. Specifies compilation as a list of compilation passes.
- backend: Type[SerialCompiler][source]
- compilation_passes: List[SimpleNodeConfig][source]
- classmethod import_backend_if_str(class_: Union[Type[SerialCompiler], str]) Type[SerialCompiler] [source]