See also

A Jupyter notebook version of this tutorial can be downloaded here.

image0

[1]:
from pathlib import Path

import numpy as np
import rich  # noqa:F401
from qcodes.parameters import ManualParameter

import quantify_core.data.handling as dh
from quantify_core.analysis import RabiAnalysis
from quantify_core.data.handling import load_dataset
from quantify_scheduler import QuantumDevice, Schedule, ScheduleGettable
from quantify_scheduler.operations import Measure, Reset, X

from utils import (  # noqa:F401  # noqa:F401
    display_dict,
    initialize_hardware,
    run_schedule,
    show_connectivity,
)
[2]:
hw_config_path = "configs/tuning_transmon_coupled_pair_hardware_config.json"
device_path = "devices/transmon_device_2q.json"
[3]:
# Enter your own dataset directory here!
dh.set_datadir(dh.default_datadir())
Data will be saved in:
/root/quantify-data
[4]:
quantum_device = QuantumDevice.from_json_file(device_path)
qubit = quantum_device.get_element("q0")
quantum_device.hardware_config.load_from_json_file(hw_config_path)
cluster_ip = None
meas_ctrl, inst_coord, cluster = initialize_hardware(quantum_device, ip=cluster_ip)

Rabi Oscillations#

Here we will carry out an experiment to measure the Rabi frequency that is required to excite the qubit to \(|1\rangle\).

Setup#

In this section we configure the hardware configuration which specifies the connectivity of our system.

The experiments of this tutorial are meant to be executed with a Qblox Cluster controlling a transmon system. The experiments can also be executed using a dummy Qblox device that is created via an instance of the Cluster class, and is initialized with a dummy configuration. When using a dummy device, the analysis will not work because the experiments will return np.nan values.

Configuration file#

This is a template hardware configuration file for a 2-qubit system with a flux-control line which can be used to tune the qubit frequency. We will only work with qubit 0.

The hardware connectivity is as follows, by cluster slot:

  • QCM (Slot 2)

    • \(\text{O}^{1}\): Flux line for q0.

    • \(\text{O}^{2}\): Flux line for q1.

  • QCM-RF (Slot 6)

    • \(\text{O}^{1}\): Drive line for q0 using fixed 80 MHz IF.

    • \(\text{O}^{2}\): Drive line for q1 using fixed 80 MHz IF.

  • QRM-RF (Slot 8)

    • \(\text{O}^{1}\) and \(\text{I}^{1}\): Shared readout line for q0/q1 using a fixed LO set at 7.5 GHz.

Note that in the hardware configuration below the mixers are uncorrected, but for high fidelity experiments this should also be done for all the modules.

Quantum device settings#

Here we initialize our QuantumDevice and our qubit parameters, checkout this tutorial for further details.

In short, a QuantumDevice contains device elements where we save our found parameters. Here we are loading a template for 2 qubits, but we will only use qubit 0.

Rabi Oscillations#

[5]:
def rabi_sched(
    pulse_amps: np.ndarray,
    qubit: str,
    repetitions: int = 1,
) -> Schedule:
    r"""
    Generate a schedule for performing a Rabi experiment.

    Parameters
    ----------
    pulse_amps
        an array of pulse amplitudes.
    qubit
        the name of the device element e.g., :code:`"q0"` to perform the Ramsey experiment on.
    repetitions
        The amount of times the Schedule will be repeated.

    Returns
    -------
    :
        An experiment schedule.

    """
    sched = Schedule("rabi_amplitude", repetitions=repetitions)

    for acq_idx, pulse_amp in enumerate(pulse_amps):
        sched.add(Reset(qubit))
        sched.add(X(qubit, amp180=pulse_amp))
        sched.add(Measure(qubit, acq_index=acq_idx), rel_time=20e-9)  # wait 20ns before measuring
    return sched
[6]:
amp = ManualParameter(name="amp", unit="", label="Amplitude")
amp.batched = True

rabi_sched_kwargs = {
    "qubit": qubit.name,
    "pulse_amps": amp,
}

gettable = ScheduleGettable(
    quantum_device,
    schedule_function=rabi_sched,
    schedule_kwargs=rabi_sched_kwargs,
    real_imag=False,
    batched=True,
)
meas_ctrl.gettables(gettable)
[7]:
pulse_amps = np.linspace(-0.14, 0.14, 201)

meas_ctrl.settables(amp)
meas_ctrl.setpoints(pulse_amps)

quantum_device.cfg_sched_repetitions(300)
rabi_ds = meas_ctrl.run("rabi")
rabi_ds
Starting batched measurement...
Iterative settable(s) [outer loop(s)]:
         --- (None) ---
Batched settable(s):
         amp
Batch size limit: 201

[7]:
<xarray.Dataset> Size: 5kB
Dimensions:  (dim_0: 201)
Coordinates:
    x0       (dim_0) float64 2kB -0.14 -0.1386 -0.1372 ... 0.1372 0.1386 0.14
Dimensions without coordinates: dim_0
Data variables:
    y0       (dim_0) float64 2kB nan nan nan nan nan nan ... nan nan nan nan nan
    y1       (dim_0) float64 2kB nan nan nan nan nan nan ... nan nan nan nan nan
Attributes:
    tuid:                             20250623-091006-322-1fe8b9
    name:                             rabi
    grid_2d:                          False
    grid_2d_uniformly_spaced:         False
    1d_2_settables_uniformly_spaced:  False
[8]:
if cluster_ip is None:
    notebook_dir = Path.cwd()
    dh.set_datadir(notebook_dir / "data")
    rabi_ds = load_dataset("20250205-003934-203-4f4791")

rabi_analysis = RabiAnalysis(tuid=rabi_ds.attrs["tuid"], dataset=rabi_ds)
rabi_analysis.run().display_figs_mpl()
../../../_images/applications_quantify_transmon_rabi_12_0.png
[9]:
qubit.rxy.amp180(rabi_analysis.quantities_of_interest["Pi-pulse amplitude"].nominal_value)
print(f"Pi pulse amplitude: {qubit.rxy.amp180()}")
Pi pulse amplitude: 0.5430058585105821
[10]:
inst_coord.last_schedule.compiled_instructions
[11]:
display_dict(quantum_device.hardware_config())
[11]:
[12]:
quantum_device.to_json_file("devices/")
[12]:
'devices/device_2q_2025-06-23_09-10-08_UTC.json'