In order to execute a Schedule on physical hardware or a simulator one needs to compile the schedule. This is done using a QuantifyCompiler. The compile() method requires both the Schedule to compile and a CompilationConfig describing the information required to perform the compilation.

Upon the start of the compilation, the QuantifyCompiler defines a directed acyclic graph in which individual nodes represent compilation steps. A Schedule can be compiled by traversing the graph. The Schedule class serves as the intermediate representation which is modified by the compiler passes. For most practical purposes, a user does not need to be aware of the internal structure of the compilation backends.

Compiling a schedule

To compile a schedule, one needs to instantiate a QuantifyCompiler and call the compile() method. This method requires both the Schedule to compile as well as a generate_compilation_config(). This config can conveniently be generated from a QuantumDevice object which describes the knowledge required for compilation.


Here we focus on using a QuantifyCompiler to compile a Schedule in isolation. When executing schedules, one needs to interact with and manage the parameters of an experimental setup. For this we refer to the section on execution in the user guide.

First we set up a mock setup and create a simple schedule that we want to compile.

    import numpy as np
    from quantify_scheduler.device_under_test.mock_setup import set_up_mock_transmon_setup, set_standard_params_transmon
    from quantify_scheduler.schedules.timedomain_schedules import echo_sched

    # instantiate the instruments of the mock setup
    mock_setup = set_up_mock_transmon_setup()

    # provide some sensible values to allow compilation without errors

    echo_schedule = echo_sched(times=np.arange(0, 60e-6, 1.5e-6), qubit="q0", repetitions=1024)

Next, we retrieve the CompilationConfig from the quantum device and see for which compilation backend this is suitable. In the current example we have a simple SerialCompiler that is used to do different compilation passes as a linear chain.

    quantum_device = mock_setup["quantum_device"]
    config = quantum_device.generate_compilation_config()


We can then instantiate the compiler and compile the program.

from quantify_scheduler.backends.graph_compilation import SerialCompiler

compiler = SerialCompiler(name="Device compile")
comp_sched = compiler.compile(schedule=echo_schedule, config=config)

CompiledSchedule "Echo" containing (43) 200  (unique) operations.

Understanding the structure of compilation

A compilation backend defines a graph of compilation steps. This makes it really easy to visualize the different steps in the compilation process by drawing the graph.

Here we show the compilation structure for several commonly used compilers. To do this, we will use the example configuration files of the different compilers and then use the quantum device to generate the relevant CompilationConfig s. Note that in the future we want to improve how the hardware config is managed so one does not need to set a custom dictionary to the hardware config parameter of the quantum_device object.

from quantify_scheduler.schemas.examples import utils

QBLOX_HARDWARE_MAPPING = utils.load_json_example_scheme("qblox_test_mapping.json")
ZHINST_HARDWARE_MAPPING = utils.load_json_example_scheme("zhinst_test_mapping.json")

dev_cfg = quantum_device.generate_compilation_config()

qblox_cfg = quantum_device.generate_compilation_config()

zhinst_cfg = quantum_device.generate_compilation_config()
from quantify_scheduler.backends import SerialCompiler

# constructing graph is normally done when at compile time as it
# requires information from the compilation config.

dev_compiler = SerialCompiler(name="Device compiler")

qblox_compiler = SerialCompiler(name="Qblox compiler")

zhinst_compiler = SerialCompiler(name="Zhinst compiler")

import matplotlib.pyplot as plt
f, axs = plt.subplots(1,3, figsize=(16,7))

# Show the graph of the currently included compilers
axs[0].set_title("Device Backend")
axs[1].set_title("Qblox Backend")
axs[2].set_title("Zhinst Backend")
_images/3b1b009e7e73b620eed4952ca34a8127a3ad8c63d221234aaaff3e11d24d51f6.png _images/3b1b009e7e73b620eed4952ca34a8127a3ad8c63d221234aaaff3e11d24d51f6.png