{ "cells": [ { "cell_type": "markdown", "id": "7812247d", "metadata": {}, "source": [ "# Time of flight measurement\n", "The notebook will show how to measure time of flight for your system." ] }, { "cell_type": "code", "execution_count": 1, "id": "60195c03", "metadata": { "execution": { "iopub.execute_input": "2024-09-18T14:59:06.146395Z", "iopub.status.busy": "2024-09-18T14:59:06.146222Z", "iopub.status.idle": "2024-09-18T14:59:07.758908Z", "shell.execute_reply": "2024-09-18T14:59:07.758134Z" } }, "outputs": [], "source": [ "from __future__ import annotations\n", "\n", "import json\n", "\n", "import numpy as np\n", "import rich # noqa:F401\n", "from qcodes.instrument import find_or_create_instrument\n", "from qcodes.parameters import ManualParameter\n", "\n", "import quantify_core.data.handling as dh\n", "from qblox_instruments import Cluster, ClusterType\n", "from quantify_core.analysis.time_of_flight_analysis import TimeOfFlightAnalysis\n", "from quantify_core.measurement.control import MeasurementControl\n", "from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt as PlotMonitor\n", "from quantify_scheduler import Schedule\n", "from quantify_scheduler.backends.qblox import constants\n", "from quantify_scheduler.device_under_test.quantum_device import QuantumDevice\n", "from quantify_scheduler.gettables import ScheduleGettable\n", "from quantify_scheduler.instrument_coordinator import InstrumentCoordinator\n", "from quantify_scheduler.instrument_coordinator.components.qblox import (\n", " ClusterComponent,\n", ")\n", "from quantify_scheduler.math import closest_number_ceil\n", "from quantify_scheduler.operations.gate_library import Measure" ] }, { "cell_type": "markdown", "id": "05f96e35", "metadata": {}, "source": [ "## Setup\n", "In this section we configure the hardware configuration which specifies the connectivity of our system.\n", "\n", "The experiments of this tutorial are meant to be executed with a Qblox Cluster controlling a transmon system.\n", "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.\n", "When using a dummy device, the analysis will not work because the experiments will return `np.nan` values.\n", "\n", "### Configuration file\n", "\n", "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.\n", "\n", "The hardware setup is as follows, by cluster slot:\n", "- **QCM** (Slot 2)\n", " - Flux line for `q0`.\n", "- **QCM-RF** (Slot 6)\n", " - Drive line for `q0` using fixed 80 MHz IF.\n", "- **QRM-RF** (Slot 8)\n", " - Readout line for `q0` using a fixed LO set at 7.5 GHz.\n", "\n", "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." ] }, { "cell_type": "code", "execution_count": 2, "id": "e105d514", "metadata": { "execution": { "iopub.execute_input": "2024-09-18T14:59:07.761672Z", "iopub.status.busy": "2024-09-18T14:59:07.761115Z", "iopub.status.idle": "2024-09-18T14:59:07.765714Z", "shell.execute_reply": "2024-09-18T14:59:07.765069Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Data will be saved in:\n", "/root/quantify-data\n" ] } ], "source": [ "with open(\"configs/tuning_transmon_coupled_pair_hardware_config.json\") as hw_cfg_json_file:\n", " hardware_cfg = json.load(hw_cfg_json_file)\n", "\n", "# Enter your own dataset directory here!\n", "dh.set_datadir(dh.default_datadir())" ] }, { "cell_type": "markdown", "id": "814050b8", "metadata": {}, "source": [ "### Scan For Clusters\n", "\n", "We scan for the available devices connected via ethernet using the Plug & Play functionality of the Qblox Instruments package (see [Plug & Play](https://qblox-qblox-instruments.readthedocs-hosted.com/en/main/api_reference/tools.html#api-pnp) for more info)." ] }, { "cell_type": "code", "execution_count": 3, "id": "d326cd3d", "metadata": { "execution": { "iopub.execute_input": "2024-09-18T14:59:07.767545Z", "iopub.status.busy": "2024-09-18T14:59:07.767370Z", "iopub.status.idle": "2024-09-18T14:59:09.761860Z", "shell.execute_reply": "2024-09-18T14:59:09.757970Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "No devices found\r\n" ] } ], "source": [ "!qblox-pnp list" ] }, { "cell_type": "code", "execution_count": 4, "id": "9aad5056", "metadata": { "execution": { "iopub.execute_input": "2024-09-18T14:59:09.771728Z", "iopub.status.busy": "2024-09-18T14:59:09.770727Z", "iopub.status.idle": "2024-09-18T14:59:09.783938Z", "shell.execute_reply": "2024-09-18T14:59:09.780897Z" } }, "outputs": [], "source": [ "cluster_ip = None # To run this tutorial on hardware, fill in the IP address of the cluster here\n", "cluster_name = \"cluster0\"" ] }, { "cell_type": "markdown", "id": "406dcd59", "metadata": {}, "source": [ "### Connect to Cluster\n", "\n", "We now make a connection with the Cluster." ] }, { "cell_type": "code", "execution_count": 5, "id": "0fc4700d", "metadata": { "execution": { "iopub.execute_input": "2024-09-18T14:59:09.790668Z", "iopub.status.busy": "2024-09-18T14:59:09.790463Z", "iopub.status.idle": "2024-09-18T14:59:10.414139Z", "shell.execute_reply": "2024-09-18T14:59:10.413342Z" }, "lines_to_next_cell": 0 }, "outputs": [], "source": [ "cluster = find_or_create_instrument(\n", " Cluster,\n", " recreate=True,\n", " name=cluster_name,\n", " identifier=cluster_ip,\n", " dummy_cfg=(\n", " {\n", " 2: ClusterType.CLUSTER_QCM,\n", " 4: ClusterType.CLUSTER_QRM,\n", " 6: ClusterType.CLUSTER_QCM_RF,\n", " 8: ClusterType.CLUSTER_QRM_RF,\n", " }\n", " if cluster_ip is None\n", " else None\n", " ),\n", ")" ] }, { "cell_type": "markdown", "id": "0078aa35", "metadata": {}, "source": [ "### Quantum device settings\n", "Here we initialize our `QuantumDevice` and our qubit parameters, checkout this [tutorial](https://quantify-os.org/docs/quantify-scheduler/tutorials/Operations%20and%20Qubits.html) for further details.\n", "\n", "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." ] }, { "cell_type": "code", "execution_count": 6, "id": "802994ec", "metadata": { "execution": { "iopub.execute_input": "2024-09-18T14:59:10.416415Z", "iopub.status.busy": "2024-09-18T14:59:10.416211Z", "iopub.status.idle": "2024-09-18T14:59:10.427926Z", "shell.execute_reply": "2024-09-18T14:59:10.427203Z" } }, "outputs": [], "source": [ "quantum_device = QuantumDevice.from_json_file(\"devices/transmon_device_2q.json\")\n", "qubit = quantum_device.get_element(\"q0\")\n", "quantum_device.hardware_config(hardware_cfg)" ] }, { "cell_type": "markdown", "id": "909ae524", "metadata": { "lines_to_next_cell": 2 }, "source": [ "### Configure measurement control loop\n", "We will use a `MeasurementControl` object for data acquisition as well as an `InstrumentCoordinator` for controlling the instruments in our setup.\n", "\n", "The `PlotMonitor` is used for live plotting.\n", "\n", "All of these are then associated with the `QuantumDevice`." ] }, { "cell_type": "code", "execution_count": 7, "id": "02016f12", "metadata": { "execution": { "iopub.execute_input": "2024-09-18T14:59:10.429860Z", "iopub.status.busy": "2024-09-18T14:59:10.429669Z", "iopub.status.idle": "2024-09-18T14:59:10.436926Z", "shell.execute_reply": "2024-09-18T14:59:10.436295Z" } }, "outputs": [], "source": [ "def configure_measurement_control_loop(\n", " device: QuantumDevice, cluster: Cluster, live_plotting: bool = False\n", ") -> tuple[MeasurementControl, InstrumentCoordinator]:\n", " meas_ctrl = find_or_create_instrument(MeasurementControl, recreate=True, name=\"meas_ctrl\")\n", " ic = find_or_create_instrument(InstrumentCoordinator, recreate=True, name=\"ic\")\n", "\n", " # Add cluster to instrument coordinator\n", " ic_cluster = ClusterComponent(cluster)\n", " ic.add_component(ic_cluster)\n", "\n", " if live_plotting:\n", " # Associate plot monitor with measurement controller\n", " plotmon = find_or_create_instrument(PlotMonitor, recreate=False, name=\"PlotMonitor\")\n", " meas_ctrl.instr_plotmon(plotmon.name)\n", "\n", " # Associate measurement controller and instrument coordinator with the quantum device\n", " device.instr_measurement_control(meas_ctrl.name)\n", " device.instr_instrument_coordinator(ic.name)\n", "\n", " return (meas_ctrl, ic)\n", "\n", "\n", "meas_ctrl, instrument_coordinator = configure_measurement_control_loop(quantum_device, cluster)" ] }, { "cell_type": "markdown", "id": "4fae8db4", "metadata": { "lines_to_next_cell": 0 }, "source": [ "## Schedule definition" ] }, { "cell_type": "code", "execution_count": 8, "id": "20a9e71c", "metadata": { "execution": { "iopub.execute_input": "2024-09-18T14:59:10.438827Z", "iopub.status.busy": "2024-09-18T14:59:10.438648Z", "iopub.status.idle": "2024-09-18T14:59:10.442045Z", "shell.execute_reply": "2024-09-18T14:59:10.441415Z" } }, "outputs": [], "source": [ "def tof_trace_schedule(\n", " qubit_name: str,\n", " repetitions: int = 1,\n", ") -> Schedule:\n", " schedule = Schedule(\"Trace measurement schedule\", repetitions=repetitions)\n", " schedule.add(Measure(qubit_name, acq_protocol=\"Trace\"))\n", " return schedule" ] }, { "cell_type": "markdown", "id": "b335aebf", "metadata": { "lines_to_next_cell": 0 }, "source": [ "## Measuring time of flight with trace acquisition" ] }, { "cell_type": "code", "execution_count": 9, "id": "8ed9d9e1", "metadata": { "execution": { "iopub.execute_input": "2024-09-18T14:59:10.444048Z", "iopub.status.busy": "2024-09-18T14:59:10.443858Z", "iopub.status.idle": "2024-09-18T14:59:10.447808Z", "shell.execute_reply": "2024-09-18T14:59:10.447195Z" }, "lines_to_next_cell": 0 }, "outputs": [], "source": [ "def set_readout_attenuation_hardware_config(attenuation_dB: int):\n", " hwcfg = quantum_device.hardware_config()\n", " output_att = hwcfg[\"hardware_options\"][\"output_att\"]\n", " output_att[f\"{qubit.ports.readout()}-{qubit.name}.ro\"] = attenuation_dB\n", " quantum_device.hardware_config(hwcfg)\n", "\n", "\n", "set_readout_attenuation_hardware_config(0)\n", "qubit.measure.pulse_duration(300e-9)\n", "qubit.measure.integration_time(1e-6)\n", "qubit.measure.pulse_amp(0.1)\n", "qubit.measure.acq_delay(4e-9)" ] }, { "cell_type": "code", "execution_count": 10, "id": "8957b861", "metadata": { "execution": { "iopub.execute_input": "2024-09-18T14:59:10.449599Z", "iopub.status.busy": "2024-09-18T14:59:10.449412Z", "iopub.status.idle": "2024-09-18T14:59:10.453831Z", "shell.execute_reply": "2024-09-18T14:59:10.453121Z" }, "lines_to_next_cell": 0 }, "outputs": [], "source": [ "tof_t = ManualParameter(name=\"tof_t\", unit=\"ns\", label=\"Trace acquisition sample\")\n", "tof_t.batched = True\n", "tof_t.batch_size = round(qubit.measure.integration_time() * constants.SAMPLING_RATE)\n", "\n", "tof_sched_kwargs = dict(\n", " qubit_name=qubit.name,\n", ")\n", "\n", "# set gettable\n", "gettable = ScheduleGettable(\n", " quantum_device,\n", " schedule_function=tof_trace_schedule,\n", " schedule_kwargs=tof_sched_kwargs,\n", " real_imag=False,\n", " batched=True,\n", ")\n", "\n", "# set measurement control\n", "meas_ctrl.gettables(gettable)" ] }, { "cell_type": "code", "execution_count": 11, "id": "4b873568", "metadata": { "execution": { "iopub.execute_input": "2024-09-18T14:59:10.455732Z", "iopub.status.busy": "2024-09-18T14:59:10.455531Z", "iopub.status.idle": "2024-09-18T14:59:10.624504Z", "shell.execute_reply": "2024-09-18T14:59:10.623940Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Starting batched measurement...\n", "Iterative settable(s) [outer loop(s)]:\n", "\t --- (None) --- \n", "Batched settable(s):\n", "\t tof_t \n", "Batch size limit: 1000\n", "\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "1aaf493e7c2e4ed584f50c2857332d2c", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Completed: 0%| [ elapsed time: 00:00 | time left: ? ] it" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
<xarray.Dataset> Size: 24kB\n", "Dimensions: (x0: 1000)\n", "Coordinates:\n", " * x0 (x0) int64 8kB 0 1 2 3 4 5 6 7 ... 992 993 994 995 996 997 998 999\n", "Data variables:\n", " y0 (x0) float64 8kB 9.913e-07 0.0007135 ... 0.0001498 -0.0003165\n", " 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\n", "Attributes:\n", " tuid: 20240918-145910-459-4d893a\n", " name: Time of flight measurement q0\n", " grid_2d: False\n", " grid_2d_uniformly_spaced: False\n", " 1d_2_settables_uniformly_spaced: False