See also

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

Single transmon qubit spectroscopy#

Here we will carry out qubit spectroscopy on a single transmon in order to find the \(|0\rangle \rightarrow |1\rangle\) drive frequency.

[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.spectroscopy_analysis import QubitSpectroscopyAnalysis
from quantify_scheduler import ClockResource, QuantumDevice, Schedule, ScheduleGettable
from quantify_scheduler.device_under_test.device_element import DeviceElement
from quantify_scheduler.operations import (
    IdlePulse,
    Measure,
    Reset,
    SetClockFrequency,
    VoltageOffset,
)
from quantify_scheduler.operations.control_flow_library import LoopOperation

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)

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.

Qubit spectroscopy#

[5]:
def two_tone_spec(
    qubit: DeviceElement,
    spec_pulse_frequencies: np.array,
    spec_pulse_amp: float = 0.05,
    repetitions: int = 1,
) -> Schedule:
    """
    Generate a schedule for performing fast two-tone spectroscopy.

    To avoid the qubit reset time, the schedule uses sequential averaging.

    Parameters
    ----------
    qubit
        qubit that should be used.
    spec_pulse_frequencies
        Sample frequencies for the spectroscopy pulse in Hertz.
    spec_pulse_amp
        Amplitude of the continuous spectroscopy tone.
    repetitions
        The amount of times the Schedule will be repeated.

    """
    sched = Schedule("two-tone", repetitions=1)
    sched.add_resource(ClockResource(name=qubit.name + ".01", freq=spec_pulse_frequencies.flat[0]))

    # Turn on the drive
    sched.add(
        VoltageOffset(
            offset_path_I=spec_pulse_amp,
            offset_path_Q=0,
            port=f"{qubit.name}:mw",
            clock=f"{qubit.name}.01",
        )
    )
    for acq_idx, spec_pulse_freq in enumerate(spec_pulse_frequencies):
        sched.add(Reset(qubit.name))

        # Setting the probing frequency to a new value
        sched.add(SetClockFrequency(clock=f"{qubit.name}.01", clock_freq_new=spec_pulse_freq))

        # Create a subschedule that measures the qubit.
        subsched = Schedule("meas")
        subsched.add(Measure(qubit.name, acq_index=acq_idx))
        # Add required time between certain operations
        subsched.add(IdlePulse(8e-9))
        # measure `repetitions` times at every frequency point
        sched.add(LoopOperation(subsched, repetitions=repetitions))

    # Turn off the drive at the end of the experiment
    sched.add(
        VoltageOffset(
            offset_path_I=0.0, offset_path_Q=0, port=f"{qubit.name}:mw", clock=f"{qubit.name}.01"
        )
    )
    # Add required time at the end
    sched.add(IdlePulse(8e-9))
    return sched


freqs = ManualParameter(name="freq", unit="Hz", label="Frequency")
freqs.batched = True

qubit_spec_sched_kwargs = dict(qubit=qubit, spec_pulse_frequencies=freqs, spec_pulse_amp=0.05)

gettable = ScheduleGettable(
    quantum_device,
    schedule_function=two_tone_spec,
    schedule_kwargs=qubit_spec_sched_kwargs,
    real_imag=False,
    batched=True,
)

meas_ctrl.gettables(gettable)
[6]:
quantum_device.cfg_sched_repetitions(300)
center = 5.1e9
frequency_setpoints = np.linspace(center - 20e6, center + 20e6, 300)
meas_ctrl.settables(freqs)
meas_ctrl.setpoints(frequency_setpoints)

qs_ds = meas_ctrl.run("Two-tone")
qs_ds
Starting batched measurement...
Iterative settable(s) [outer loop(s)]:
         --- (None) ---
Batched settable(s):
         freq
Batch size limit: 300

/builds/qblox/packages/software/qblox_instruments_docs/.venv/lib/python3.9/site-packages/quantify_scheduler/backends/circuit_to_device.py:433: RuntimeWarning: Clock 'q0.01' has conflicting frequency definitions: 5080000000.0 Hz in the schedule and 5100000000.0 Hz in the device config. The clock is set to '5080000000.0'. Ensure the schedule clock resource matches the device config clock frequency or set the clock frequency in the device config to np.NaN to omit this warning.
  warnings.warn(
[6]:
<xarray.Dataset> Size: 7kB
Dimensions:  (dim_0: 300)
Coordinates:
    x0       (dim_0) float64 2kB 5.08e+09 5.08e+09 ... 5.12e+09 5.12e+09
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-091007-356-4c97a9
    name:                             Two-tone
    grid_2d:                          False
    grid_2d_uniformly_spaced:         False
    1d_2_settables_uniformly_spaced:  False
[7]:
if cluster_ip is None:
    notebook_dir = Path.cwd()
    dh.set_datadir(notebook_dir / "data")
    qs_ds = dh.load_dataset("20250204-234600-751-7ad233")
qs_analysis = QubitSpectroscopyAnalysis(dataset=qs_ds)
qs_analysis.run().display_figs_mpl()
../../../_images/applications_quantify_transmon_qubit_spec_10_0.png
[8]:
qubit.clock_freqs.f01(5.1e9)
[9]:
inst_coord.last_schedule.compiled_instructions
[10]:
display_dict(quantum_device.hardware_config())
[10]:
[11]:
quantum_device.to_json_file("devices/")
[11]:
'devices/device_2q_2025-06-23_09-10-10_UTC.json'