See also
A Jupyter notebook version of this tutorial can be downloaded here
.
[1]:
from __future__ import annotations
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.single_qubit_timedomain import RamseyAnalysis
from quantify_core.data.handling import load_dataset
from quantify_scheduler import QuantumDevice, Schedule, ScheduleGettable
from quantify_scheduler.operations import X90, Measure, Reset, Rxy
from utils import display_dict, initialize_hardware, run_schedule, show_connectivity # noqa:F401
[2]:
hw_config_path = "configs/tuning_spin_coupled_pair_hardware_config.json"
device_path = "devices/spin_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)
Ramsey Spectroscopy#
Here we demonstrate Ramsey Spectroscopy, which is used to tune the \(|0\rangle \rightarrow |1\rangle\) drive frequency more precisely. Ramsey spectroscopy is also used to find \(T_2^*\).
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.
Ramsey oscillations#
[5]:
# This schedule can also be imported from from quantify_scheduler.schedules
def ramsey_sched(
times: np.ndarray | float,
qubit: str,
artificial_detuning: float = 0,
repetitions: int = 1,
) -> Schedule:
r"""
Generate a schedule for performing a Ramsey experiment.
This measures the dephasing time :math:`T_2^{\star}`.
Schedule sequence
.. centered:: Reset -- pi/2 -- Idle(tau) -- pi/2 -- Measure
See section III.B.2. of :cite:t:`krantz_quantum_2019` for an explanation of the Bloch-Redfield
model of decoherence and the Ramsey experiment.
Parameters
----------
times
an array of wait times tau between the start of the first pi/2 pulse and
the start of the second pi/2 pulse.
artificial_detuning
frequency in Hz of the software emulated, or ``artificial`` qubit detuning, which is
implemented by changing the phase of the second pi/2 (recovery) pulse. The
artificial detuning changes the observed frequency of the Ramsey oscillation,
which can be useful to distinguish a slow oscillation due to a small physical
detuning from the decay of the dephasing noise.
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.
"""
device_element = qubit
# ensure times is an iterable when passing floats.
times = np.asarray(times)
times = times.reshape(times.shape or (1,))
schedule = Schedule("Ramsey", repetitions)
if isinstance(times, float):
times = [times]
for i, tau in enumerate(times):
schedule.add(Reset(device_element), label=f"Reset {i}")
schedule.add(X90(device_element))
# the phase of the second pi/2 phase progresses to propagate
recovery_phase = np.rad2deg(2 * np.pi * artificial_detuning * tau)
schedule.add(
Rxy(theta=90, phi=recovery_phase, qubit=device_element), ref_pt="start", rel_time=tau
)
schedule.add(Measure(device_element, acq_index=i), label=f"Measurement {i}")
return schedule
[6]:
tau = ManualParameter(name="tau", unit="s", label="Time")
tau.batched = True
ramsey_sched_kwargs = {
"qubit": qubit.name,
"times": tau,
"artificial_detuning": 0.0,
}
gettable = ScheduleGettable(
quantum_device,
schedule_function=ramsey_sched,
schedule_kwargs=ramsey_sched_kwargs,
real_imag=False,
batched=True,
)
meas_ctrl.gettables(gettable)
[7]:
tau_setpoints = np.arange(20e-9, 4e-6, 32e-9)
meas_ctrl.settables(tau)
meas_ctrl.setpoints(tau_setpoints)
quantum_device.cfg_sched_repetitions(500)
ramsey_ds = meas_ctrl.run("ramsey")
ramsey_ds
Starting batched measurement...
Iterative settable(s) [outer loop(s)]:
--- (None) ---
Batched settable(s):
tau
Batch size limit: 125
[7]:
<xarray.Dataset> Size: 3kB Dimensions: (dim_0: 125) Coordinates: x0 (dim_0) float64 1kB 2e-08 5.2e-08 8.4e-08 ... 3.956e-06 3.988e-06 Dimensions without coordinates: dim_0 Data variables: y0 (dim_0) float64 1kB nan nan nan nan nan nan ... nan nan nan nan nan y1 (dim_0) float64 1kB nan nan nan nan nan nan ... nan nan nan nan nan Attributes: tuid: 20250312-180023-622-5bf946 name: ramsey 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")
ramsey_ds = load_dataset("20250206-230423-264-3c48f3")
ramsey_analysis = RamseyAnalysis(ramsey_ds)
ramsey_analysis.run(
artificial_detuning=ramsey_sched_kwargs["artificial_detuning"]
).display_figs_mpl()

[9]:
detuning = ramsey_analysis.quantities_of_interest["detuning"].nominal_value
"qubit.clock_freqs.f_larmor(qubit.clock_freqs.f_larmor() - detuning)"
print(f"New qubit frequency is {qubit.clock_freqs.f_larmor} Hz")
New qubit frequency is q0_clock_freqs_f_larmor Hz
[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-03-12_18-00-27_UTC.json'