See also

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

Time of flight measurement#

The notebook will show how to measure time of flight for your system.

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

import quantify_core.data.handling as dh
from quantify_core.analysis.time_of_flight_analysis import TimeOfFlightAnalysis
from quantify_scheduler import Schedule
from quantify_scheduler.backends.qblox import constants
from quantify_scheduler.gettables import ScheduleGettable
from quantify_scheduler.math import closest_number_ceil
from quantify_scheduler.operations.gate_library import Measure
[2]:
import json

import rich  # noqa:F401

import quantify_core.data.handling as dh
from quantify_scheduler.device_under_test.quantum_device import QuantumDevice

from utils import initialize_hardware, run  # noqa:F401

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.

[3]:
with open("configs/tuning_transmon_coupled_pair_hardware_config.json") as hw_cfg_json_file:
    hardware_cfg = json.load(hw_cfg_json_file)

# Enter your own dataset directory here!
dh.set_datadir(dh.default_datadir())
Data will be saved in:
/root/quantify-data

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.

[4]:
quantum_device = QuantumDevice.from_json_file("devices/transmon_device_2q.json")
qubit = quantum_device.get_element("q0")
quantum_device.hardware_config(hardware_cfg)
meas_ctrl, _, cluster = initialize_hardware(quantum_device, ip=None)
/usr/local/lib/python3.9/site-packages/quantify_scheduler/backends/types/qblox.py:1220: ValidationWarning: Setting `auto_lo_cal=on_lo_interm_freq_change` will overwrite settings `dc_offset_i=0.0` and `dc_offset_q=0.0`. To suppress this warning, do not set either `dc_offset_i` or `dc_offset_q` for this port-clock.
  warnings.warn(
/usr/local/lib/python3.9/site-packages/quantify_scheduler/backends/types/qblox.py:1235: ValidationWarning: Setting `auto_sideband_cal=on_interm_freq_change` will overwrite settings `amp_ratio=1.0` and `phase_error=0.0`. To suppress this warning, do not set either `amp_ratio` or `phase_error` for this port-clock.
  warnings.warn(

Schedule definition#

[5]:
def tof_trace_schedule(
    qubit_name: str,
    repetitions: int = 1,
) -> Schedule:
    schedule = Schedule("Trace measurement schedule", repetitions=repetitions)
    schedule.add(Measure(qubit_name, acq_protocol="Trace"))
    return schedule

Measuring time of flight with trace acquisition#

[6]:
def set_readout_attenuation_hardware_config(attenuation_dB: int):
    hwcfg = quantum_device.hardware_config()
    output_att = hwcfg["hardware_options"]["output_att"]
    output_att[f"{qubit.ports.readout()}-{qubit.name}.ro"] = attenuation_dB
    quantum_device.hardware_config(hwcfg)


set_readout_attenuation_hardware_config(0)
qubit.measure.pulse_duration(300e-9)
qubit.measure.integration_time(1e-6)
qubit.measure.pulse_amp(0.1)
qubit.measure.acq_delay(4e-9)
[7]:
tof_t = ManualParameter(name="tof_t", unit="ns", label="Trace acquisition sample")
tof_t.batched = True
tof_t.batch_size = round(qubit.measure.integration_time() * constants.SAMPLING_RATE)

tof_sched_kwargs = dict(
    qubit_name=qubit.name,
)

# set gettable
gettable = ScheduleGettable(
    quantum_device,
    schedule_function=tof_trace_schedule,
    schedule_kwargs=tof_sched_kwargs,
    real_imag=False,
    batched=True,
)

# set measurement control
meas_ctrl.gettables(gettable)
[8]:
tof_t_setpoints = np.arange(tof_t.batch_size)

meas_ctrl.settables(tof_t)
meas_ctrl.setpoints(tof_t_setpoints)

# replace the get method for the gettable in case the cluster is a dummy
if "dummy" in str(cluster._transport):

    def get_fake_tof_data():
        """Generate mock data for a time of flight measurement."""
        y = (
            np.heaviside(tof_t_setpoints - 200, 0.5)
            - np.heaviside(tof_t_setpoints - tof_t_setpoints.size * 0.7, 0.5)
        ) * 30e-3
        y += np.random.normal(loc=0.0, scale=1e-3, size=y.size)
        return [y, np.zeros_like(y)]

    gettable.get = get_fake_tof_data

tof_ds = dh.to_gridded_dataset(meas_ctrl.run("Time of flight measurement " + qubit.name))
tof_ds
Starting batched measurement...
Iterative settable(s) [outer loop(s)]:
         --- (None) ---
Batched settable(s):
         tof_t
Batch size limit: 1000

[8]:
<xarray.Dataset> Size: 24kB
Dimensions:  (x0: 1000)
Coordinates:
  * x0       (x0) int64 8kB 0 1 2 3 4 5 6 7 ... 992 993 994 995 996 997 998 999
Data variables:
    y0       (x0) float64 8kB 0.0009902 -0.0002468 ... -0.0007712 1.271e-05
    y1       (x0) float64 8kB 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0
Attributes:
    tuid:                             20241028-023702-958-1d00b6
    name:                             Time of flight measurement q0
    grid_2d:                          False
    grid_2d_uniformly_spaced:         False
    1d_2_settables_uniformly_spaced:  False

Analysis#

[9]:
tof_analysis = TimeOfFlightAnalysis(tuid=dh.get_latest_tuid())
tof_analysis.run(playback_delay=149e-9).display_figs_mpl()
../../_images/applications_quantify_time_of_flight_14_0.png
[10]:
fit_results = tof_analysis.quantities_of_interest
nco_prop_delay = fit_results["nco_prop_delay"]
measured_tof = fit_results["tof"]

qubit.measure.acq_delay(
    closest_number_ceil(
        measured_tof * constants.SAMPLING_RATE, constants.MIN_TIME_BETWEEN_OPERATIONS
    )
    / constants.SAMPLING_RATE
)
[11]:
rich.print(quantum_device.hardware_config())
{
    'config_type': 'quantify_scheduler.backends.qblox_backend.QbloxHardwareCompilationConfig',
    'hardware_description': {
        'cluster0': {
            'instrument_type': 'Cluster',
            'modules': {
                '6': {'instrument_type': 'QCM_RF'},
                '2': {'instrument_type': 'QCM'},
                '8': {'instrument_type': 'QRM_RF'}
            },
            'sequence_to_file': False,
            'ref': 'internal'
        }
    },
    'hardware_options': {
        'output_att': {'q0:mw-q0.01': 10, 'q1:mw-q1.01': 10, 'q0:res-q0.ro': 0, 'q1:res-q1.ro': 60},
        'mixer_corrections': {
            'q0:mw-q0.01': {
                'auto_lo_cal': 'on_lo_interm_freq_change',
                'auto_sideband_cal': 'on_interm_freq_change',
                'dc_offset_i': None,
                'dc_offset_q': None,
                'amp_ratio': 1.0,
                'phase_error': 0.0
            },
            'q1:mw-q1.01': {
                'auto_lo_cal': 'on_lo_interm_freq_change',
                'auto_sideband_cal': 'on_interm_freq_change',
                'dc_offset_i': None,
                'dc_offset_q': None,
                'amp_ratio': 1.0,
                'phase_error': 0.0
            },
            'q0:res-q0.ro': {
                'auto_lo_cal': 'on_lo_interm_freq_change',
                'auto_sideband_cal': 'on_interm_freq_change',
                'dc_offset_i': None,
                'dc_offset_q': None,
                'amp_ratio': 1.0,
                'phase_error': 0.0
            },
            'q1:res-q1.ro': {
                'auto_lo_cal': 'on_lo_interm_freq_change',
                'auto_sideband_cal': 'on_interm_freq_change',
                'dc_offset_i': None,
                'dc_offset_q': None,
                'amp_ratio': 1.0,
                'phase_error': 0.0
            }
        },
        'modulation_frequencies': {
            'q0:mw-q0.01': {'interm_freq': 80000000.0},
            'q1:mw-q1.01': {'interm_freq': 80000000.0},
            'q0:res-q0.ro': {'lo_freq': 7500000000.0},
            'q1:res-q1.ro': {'lo_freq': 7500000000.0}
        }
    },
    'connectivity': {
        'graph': [
            ['cluster0.module6.complex_output_0', 'q0:mw'],
            ['cluster0.module6.complex_output_1', 'q1:mw'],
            ['cluster0.module2.real_output_0', 'q0:fl'],
            ['cluster0.module2.real_output_1', 'q1:fl'],
            ['cluster0.module8.complex_output_0', 'q0:res'],
            ['cluster0.module8.complex_output_0', 'q1:res']
        ]
    }
}
[12]:
quantum_device.to_json_file("devices/")
[12]:
'devices/device_2q_2024-10-28_02-37-04_UTC.json'