Tutorial: Compiling to Hardware#
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)
sched.add_resource(readout_clock)
sched
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:
Creating an example Qblox hardware compilation configuration
Below we create an example hardware configuration dictionary, for the Qblox backend. In this configuration, we include:
The
"config_type"
, which points to the specificHardwareCompilationConfig
datastructure for the backend we want to use (the Qblox backend, in this case).The description of the setup, including:
A Cluster containing a QCM-RF module (in the 2nd slot).
The hardware options we want to use in the compilation.
The connectivity between the control hardware and the quantum device.
Example hardware configuration
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"),
]
},
}
Compilation#
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
dh.set_datadir(dh.default_datadir())
Data will be saved in:
/root/quantify-data
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")
quantum_device.hardware_config(hardware_comp_cfg)
compiler = SerialCompiler(name="compiler")
compiled_sched = compiler.compile(
schedule=sched, config=quantum_device.generate_compilation_config()
)
compiled_sched.plot_pulse_diagram(plot_backend='plotly')