{ "cells": [ { "cell_type": "markdown", "id": "f903ab3a", "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": "f95bfb6b", "metadata": { "execution": { "iopub.execute_input": "2024-09-02T01:45:44.851500Z", "iopub.status.busy": "2024-09-02T01:45:44.851192Z", "iopub.status.idle": "2024-09-02T01:45:46.508364Z", "shell.execute_reply": "2024-09-02T01:45:46.507493Z" } }, "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": "6b4a17a0", "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": "5dee92e8", "metadata": { "execution": { "iopub.execute_input": "2024-09-02T01:45:46.511590Z", "iopub.status.busy": "2024-09-02T01:45:46.511014Z", "iopub.status.idle": "2024-09-02T01:45:46.515680Z", "shell.execute_reply": "2024-09-02T01:45:46.515046Z" } }, "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": "9b2a9aa5", "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": "649397d5", "metadata": { "execution": { "iopub.execute_input": "2024-09-02T01:45:46.517954Z", "iopub.status.busy": "2024-09-02T01:45:46.517746Z", "iopub.status.idle": "2024-09-02T01:45:48.504543Z", "shell.execute_reply": "2024-09-02T01:45:48.500631Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "No devices found\r\n" ] } ], "source": [ "!qblox-pnp list" ] }, { "cell_type": "code", "execution_count": 4, "id": "851f7469", "metadata": { "execution": { "iopub.execute_input": "2024-09-02T01:45:48.512547Z", "iopub.status.busy": "2024-09-02T01:45:48.512341Z", "iopub.status.idle": "2024-09-02T01:45:48.515615Z", "shell.execute_reply": "2024-09-02T01:45:48.514932Z" } }, "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": "f64ae81a", "metadata": {}, "source": [ "### Connect to Cluster\n", "\n", "We now make a connection with the Cluster." ] }, { "cell_type": "code", "execution_count": 5, "id": "03aee47c", "metadata": { "execution": { "iopub.execute_input": "2024-09-02T01:45:48.517931Z", "iopub.status.busy": "2024-09-02T01:45:48.517734Z", "iopub.status.idle": "2024-09-02T01:45:49.146976Z", "shell.execute_reply": "2024-09-02T01:45:49.146207Z" }, "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": "6524430c", "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": "1083fcf6", "metadata": { "execution": { "iopub.execute_input": "2024-09-02T01:45:49.149732Z", "iopub.status.busy": "2024-09-02T01:45:49.149510Z", "iopub.status.idle": "2024-09-02T01:45:49.161101Z", "shell.execute_reply": "2024-09-02T01:45:49.160434Z" } }, "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": "05183721", "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": "fd2ea276", "metadata": { "execution": { "iopub.execute_input": "2024-09-02T01:45:49.163571Z", "iopub.status.busy": "2024-09-02T01:45:49.163296Z", "iopub.status.idle": "2024-09-02T01:45:49.170514Z", "shell.execute_reply": "2024-09-02T01:45:49.169870Z" } }, "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": "c651eb20", "metadata": { "lines_to_next_cell": 0 }, "source": [ "## Schedule definition" ] }, { "cell_type": "code", "execution_count": 8, "id": "1c157695", "metadata": { "execution": { "iopub.execute_input": "2024-09-02T01:45:49.172840Z", "iopub.status.busy": "2024-09-02T01:45:49.172655Z", "iopub.status.idle": "2024-09-02T01:45:49.176111Z", "shell.execute_reply": "2024-09-02T01:45:49.175443Z" } }, "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": "c391237e", "metadata": { "lines_to_next_cell": 0 }, "source": [ "## Measuring time of flight with trace acquisition" ] }, { "cell_type": "code", "execution_count": 9, "id": "29bcb8ab", "metadata": { "execution": { "iopub.execute_input": "2024-09-02T01:45:49.178423Z", "iopub.status.busy": "2024-09-02T01:45:49.178188Z", "iopub.status.idle": "2024-09-02T01:45:49.182197Z", "shell.execute_reply": "2024-09-02T01:45:49.181585Z" }, "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": "905493e0", "metadata": { "execution": { "iopub.execute_input": "2024-09-02T01:45:49.184446Z", "iopub.status.busy": "2024-09-02T01:45:49.184238Z", "iopub.status.idle": "2024-09-02T01:45:49.188615Z", "shell.execute_reply": "2024-09-02T01:45:49.187888Z" }, "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": "12ca8055", "metadata": { "execution": { "iopub.execute_input": "2024-09-02T01:45:49.190909Z", "iopub.status.busy": "2024-09-02T01:45:49.190687Z", "iopub.status.idle": "2024-09-02T01:45:49.358087Z", "shell.execute_reply": "2024-09-02T01:45:49.357470Z" } }, "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": "5cd62a157c734cf991fa34bc294978de", "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 0.0004166 -0.002275 ... -0.0004985 -0.0005552\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: 20240902-014549-194-f0e128\n", " name: Time of flight measurement q0\n", " grid_2d: False\n", " grid_2d_uniformly_spaced: False\n", " 1d_2_settables_uniformly_spaced: False