Tutorial: Compiling to Hardware#

See also

The complete source code of this tutorial can be found in

Compiling to Hardware.ipynb

Compilation allows converting the schedules introduced in Tutorial: Schedules and Pulses into a set of instructions that can be executed on the control hardware.

In this notebook, we will define an example schedule, demonstrate how to compile it, and run it on a virtual hardware setup.

Schedule definition#

We start by defining an example schedule.

from quantify_scheduler import Schedule
from quantify_scheduler.operations.pulse_library import SquarePulse
from quantify_scheduler.resources import ClockResource

sched = Schedule("Simple schedule")
sched.add(SquarePulse(amp=0.2, duration=8e-9, port="q0:res", clock="q0.ro"))
sched.add(SquarePulse(amp=0.1, duration=12e-9, port="q0:res", clock="q0.ro"))

readout_clock = ClockResource(name="q0.ro", freq=7e9)

Schedule "Simple schedule" containing (2) 2  (unique) operations.

Hardware compilation configuration#

In our example setup, we will use a Qblox Cluster containing an RF control module (QCM-RF). To compile the schedule, we will need to provide the compiler with a dictionary detailing the hardware compilation configuration.

Please check the documentation on how to properly create such a configuration for the supported backends:

Hide code cell content
hardware_comp_cfg = {
    "config_type": "quantify_scheduler.backends.qblox_backend.QbloxHardwareCompilationConfig",
    "hardware_description": {
        "cluster0": {
            "instrument_type": "Cluster",
            "ref": "internal",
            "modules": {
                "2": {
                    "instrument_type": "QCM_RF"
    "hardware_options": {
        "modulation_frequencies": {
            "q0:res-q0.ro": {"interm_freq": 50e6},
        "mixer_corrections": {
            "q0:res-q0.ro": {
                "dc_offset_i": -0.00552,
                "dc_offset_q": -0.00556,
                "amp_ratio": 0.9998,
                "phase_error": -4.1
    "connectivity": {
        "graph": [
            ("cluster0.module2.complex_output_0", "q0:res"),


Now we are ready to proceed to the compilation stage. For each of the control stack’s instruments, the compilation generates:

  • The schedule’s absolute timing. During the schedule’s definition, we didn’t assign absolute times to the operations. Instead, only the duration was defined. For the instruments to know how to execute the schedule, the absolute timing of the operations is calculated.

  • A set of parameters that are used to properly configure each instrument for the execution of the schedule. These parameters typically don’t change during the execution of the schedule.

  • A compiled program that contains instructions on what the instrument must do in order for the schedule to be executed.

We perform the compilation via compile().

We start by setting the directory where the compiled schedule files will be stored, via set_datadir.

from quantify_core.data import handling as dh

Data will be saved in:

Next, we create a device configuration that contains all knowledge of the physical device under test (DUT). To generate it we use the QuantumDevice class.

The schedule defined at the beginning of this tutorial consists of 2 pulse operations. As such, the hardware compilation configuration must contain the necessary information to execute the schedule. We add the hardware compilation configuration to the QuantumDevice object and compile the schedule using this information. We visualize the compiled schedule in a pulse diagram.

from quantify_scheduler.backends.graph_compilation import SerialCompiler
from quantify_scheduler.device_under_test.quantum_device import QuantumDevice

quantum_device = QuantumDevice("DUT")

compiler = SerialCompiler(name="compiler")
compiled_sched = compiler.compile(
    schedule=sched, config=quantum_device.generate_compilation_config()