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 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 configuration.

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


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 configuration must contain the necessary information to execute the schedule. We add the hardware configuration to the QuantumDevice object and compile the schedule using this information.

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()