{ "cells": [ { "cell_type": "markdown", "id": "b4889d6f", "metadata": {}, "source": [ "(sec-tutorial-experiment)=\n", "\n", "# Tutorial: Running an Experiment\n", "\n", "```{seealso}\n", "The complete source code of this tutorial can be found in\n", "\n", "{nb-download}`Running an Experiment.ipynb`\n", "\n", "The example dataset can be downloaded {download}`here <../examples/dataset.hdf5>`.\n", "```\n", "\n", "This notebook presents a structure for setting up experiments using a\n", "combination of `quantify-scheduler` and `quantify-core`. `quantify-scheduler`\n", "provides a high-level interface with the hardware, allowing users to abstract\n", "hardware-specific nuances. `quantify-core`, on the other hand, serves as an\n", "experiment management tool, using `quantify-scheduler` as its hardware\n", "interface. This allows users to manage, execute, and analyze experiments easily.\n", "\n", "The following is a general workflow for using Quantify\n", "\n", "- **{ref}`initial_setup`**\n", " - Set the directory for data storage for the experiment\n", " - Initialize the {class}`~quantify_core.measurement.control.MeasurementControl` and {class}`~quantify_scheduler.instrument_coordinator.instrument_coordinator.InstrumentCoordinator` objects\n", "\n", "- **{ref}`device_setup`**\n", " - Set up a *device compilation configuration* for the *device under test*\n", "\n", "- **{ref}`hardware_setup`**\n", " - Connect to the *control hardware*\n", " - Set up the *hardware compilation configuration*\n", "\n", "- **{ref}`create_schedule`**\n", " - Create a *schedule* containing the timeline of operations for the experiment\n", " - *Compile* the schedule to control-hardware code\n", " - *Visualize* the schedule\n", "\n", "- **{ref}`run_experiment`**\n", " - Setup {class}`~quantify_core.measurement.control.MeasurementControl` to run the experiment\n", " - *Run* the experiment\n", " - *Analyze* the results\n", "\n", "\n", "(initial_setup)=\n", "## 1. Initial Setup\n", "We first set up the directory in which all experimental data will be stored and managed." ] }, { "cell_type": "code", "execution_count": 1, "id": "fb153de2", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Data will be saved in:\n", "/root/quantify-data\n" ] } ], "source": [ "from quantify_core.data import handling as dh\n", "dh.set_datadir()" ] }, { "cell_type": "markdown", "id": "deca6e5a", "metadata": {}, "source": [ "Next, we need to initialize two classes:\n", "{class}`~quantify_core.measurement.control.MeasurementControl` for managing the\n", "experiment and {class}`~quantify_scheduler.instrument_coordinator.instrument_coordinator.InstrumentCoordinator` for managing the control hardware." ] }, { "cell_type": "code", "execution_count": 2, "id": "429762e2", "metadata": {}, "outputs": [], "source": [ "from quantify_core.measurement.control import MeasurementControl\n", "from quantify_scheduler import InstrumentCoordinator\n", "\n", "measurement_control = MeasurementControl(\"measurement_control\")\n", "instrument_coordinator = InstrumentCoordinator(\"instrument_coordinator\")" ] }, { "cell_type": "markdown", "id": "468baec1", "metadata": {}, "source": [ "(device_setup)=\n", "## 2. Device Setup\n", "\n", "We set up the quantum device on which we perform the actual experiments.\n", "This one-qubit chip is represented by {class}`~quantify_scheduler.device_under_test.quantum_device.QuantumDevice` where we add a single\n", "transmon qubit (represented by {class}`~quantify_scheduler.device_under_test.transmon_element.BasicTransmonElement`) `q0` to it." ] }, { "cell_type": "code", "execution_count": 3, "id": "57070e6b", "metadata": {}, "outputs": [], "source": [ "# Device parameters\n", "ACQ_DELAY = 100e-9\n", "FREQ_01 = 4e9\n", "READOUT_AMP = 0.1\n", "READOUT_FREQ = 4.3e9\n", "PI_PULSE_AMP = 0.15\n", "LO_FREQ_QUBIT = 3.9e9\n", "LO_FREQ_READOUT = 4.5e9" ] }, { "cell_type": "code", "execution_count": 4, "id": "2ad5c7dc", "metadata": {}, "outputs": [], "source": [ "from quantify_scheduler import BasicTransmonElement, QuantumDevice\n", "\n", "single_qubit_device = QuantumDevice(\"single_qubit_device\")\n", "single_qubit_device.instr_instrument_coordinator(instrument_coordinator.name)\n", "\n", "q0 = BasicTransmonElement(\"q0\")\n", "single_qubit_device.add_element(q0)\n", "\n", "# Assign device parameters to transmon element\n", "q0.measure.pulse_amp(READOUT_AMP)\n", "q0.clock_freqs.readout(READOUT_FREQ)\n", "q0.clock_freqs.f01(FREQ_01)\n", "q0.measure.acq_delay(ACQ_DELAY)\n", "q0.rxy.amp180(PI_PULSE_AMP)" ] }, { "cell_type": "markdown", "id": "66936fe8", "metadata": {}, "source": [ "```{admonition} Quantum Devices and Elements\n", "More information on quantum devices and elements can be found in\n", "{ref}`sec-tutorial-ops-qubits`.\n", "```\n", "\n", "(hardware_setup)=\n", "## 3. Hardware Setup\n", "\n", "Let us now set up the connections to the control hardware. In this example, we\n", "use a dummy Qblox device that is created via an instance of the\n", "{class}`~qblox_instruments.Cluster` class, and is initialized with a dummy\n", "configuration consisting of a readout module in slot `1` and a control module in\n", "slot `2`." ] }, { "cell_type": "code", "execution_count": 5, "id": "973ac46e", "metadata": {}, "outputs": [], "source": [ "from qblox_instruments import Cluster, ClusterType\n", "from quantify_scheduler.qblox import ClusterComponent\n", "cluster = Cluster(\n", " \"cluster\",\n", " dummy_cfg={\n", " 1: ClusterType.CLUSTER_QRM_RF,\n", " 2: ClusterType.CLUSTER_QCM_RF,\n", " },\n", ")\n", "\n", "ic_cluster = ClusterComponent(cluster)\n", "instrument_coordinator.add_component(ic_cluster)" ] }, { "cell_type": "markdown", "id": "976d027e", "metadata": {}, "source": [ "The last part of setting up the hardware is to define the {class}`~.backends.types.common.HardwareCompilationConfig`\n", "and attach it to our `single_qubit_device`. The hardware compilation configuration is a\n", "pydantic datastructure, parsed either from a file or from a Python\n", "dictionary. It contains all of the information about the instruments used to run\n", "the experiment and is used to compile the schedule to hardware.\n", "For more information on this datastructure, please refer to the explanation in the {ref}`User Guide `." ] }, { "cell_type": "code", "execution_count": 6, "id": "afd534ea", "metadata": {}, "outputs": [], "source": [ "hardware_comp_cfg = {\n", " \"version\": \"0.2\",\n", " \"config_type\": \"quantify_scheduler.backends.qblox_backend.QbloxHardwareCompilationConfig\",\n", " \"hardware_description\": {\n", " f\"{cluster.name}\": {\n", " \"instrument_type\": \"Cluster\",\n", " \"ref\": \"internal\",\n", " \"modules\": {\n", " \"1\": {\n", " \"instrument_type\": \"QRM_RF\"\n", " },\n", " \"2\": {\n", " \"instrument_type\": \"QCM_RF\"\n", " },\n", " },\n", " },\n", " },\n", " \"hardware_options\": {\n", " \"modulation_frequencies\": {\n", " \"q0:res-q0.ro\": {\"lo_freq\": LO_FREQ_READOUT},\n", " \"q0:mw-q0.01\": {\"lo_freq\": LO_FREQ_QUBIT},\n", " },\n", " },\n", " \"connectivity\": {\n", " \"graph\": [\n", " (f\"{cluster.name}.{cluster.module1.name.split('_')[-1]}.complex_output_0\", \"q0:res\"),\n", " (f\"{cluster.name}.{cluster.module1.name.split('_')[-1]}.complex_input_0\", \"q0:res\"),\n", " (f\"{cluster.name}.{cluster.module2.name.split('_')[-1]}.complex_output_0\", \"q0:mw\")\n", " ]\n", " },\n", "}" ] }, { "cell_type": "code", "execution_count": 7, "id": "428ab020", "metadata": {}, "outputs": [], "source": [ "# Tie hardware config to device\n", "single_qubit_device.hardware_config(hardware_comp_cfg)" ] }, { "cell_type": "markdown", "id": "cdd4599a", "metadata": {}, "source": [ "(create_schedule)=\n", "## 4. Schedule Definition and Compilation\n", "Now we must create a schedule, where we define the set of operations that we\n", "wish to perform on the device under test. We define the schedule independent of\n", "the hardware configuration and rely on Quantify's ability to compile a schedule\n", "to hardware for converting it to hardware-level commands. For this tutorial, we\n", "will define a simple schedule that will run a *T1 experiment* to determine the\n", "relaxation time of our qubit. For various delay times `tau`, we repeatedly\n", "excite the qubit, wait `tau` seconds and then measure the qubit." ] }, { "cell_type": "code", "execution_count": 8, "id": "769e8fb4", "metadata": {}, "outputs": [], "source": [ "from quantify_scheduler import Schedule\n", "from quantify_scheduler.operations import Measure, Reset, X\n", "\n", "def t1_sched(times, repetitions=1):\n", " schedule = Schedule(\"T1\", repetitions)\n", " for i, tau in enumerate(times):\n", " schedule.add(Reset(\"q0\"), label=f\"Reset {i}\")\n", " schedule.add(X(\"q0\"), label=f\"pi {i}\")\n", " schedule.add(\n", " Measure(\"q0\", acq_index=i),\n", " ref_pt=\"start\",\n", " rel_time=tau,\n", " label=f\"Measurement {i}\",\n", " )\n", " return schedule" ] }, { "cell_type": "markdown", "id": "206b8686", "metadata": {}, "source": [ "```{admonition} Pre-defined Schedules\n", ":class: tip\n", "\n", "The T1 schedule can be imported with `from quantify_scheduler.schedules import t1_sched`.\n", "\n", "For more pre-defined schedules, see {mod}`quantify_scheduler.schedules`.\n", "```\n", "\n", "We can inspect the details of the schedule in three different ways: via (1)\n", "*circuit* and (2) *pulse diagrams*, or through (3) a *timing table* containing the\n", "timing and other information of each operation.\n", "\n", "The\n", "{meth}`~quantify_scheduler.schedules.schedule.ScheduleBase.plot_circuit_diagram`\n", "method can directly be used to display the quantum circuit that corresponds to\n", "the schedule that we defined above." ] }, { "cell_type": "code", "execution_count": 9, "id": "abc41d73", "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWMAAAB3CAYAAADW8iHYAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAMuklEQVR4nO3df3BVZX7H8fdzbxIgETYoQ2BdMa5LtAk/Cw2srSFdoiCphIhUlkExwzBTLOzQdKKUIpUfZR1cBWSRhHGhLp2uDAMmF+igElCXVcNMVKik/BCjYVOJ0q3QpBHCvU//SMgmkEB+3Mt5knxeM3cy9znnnvPNzc3nPvc5zznXWGsRERFv+bwuQEREFMYiIk5QGIuIOEBhLCLiAIWxiIgDFMYiIg5QGIuIOEBhLCLiAIWxiIgDFMYiIg5QGEu3Y4yxbbylN6w/3xizwxhT0dD+L57+AtIjRXldgEgEPH7V/SeAB1po/8+Gn88AfYHDwODIlibSMoWxdDvW2n9tet8YMx544Or2JiYAFdZaa4ypjniBIi1QGEuPZ6390usaRDRmLCLiAIWxiIgDFMYiIg5QGIuIOEBhLCLiAIWxiIgDFMYiIg7QPGPp8YwxDwMjG+5GAyOMMUsb7gestUe9qUx6EoWxCEwH5jS5P7rhBvB7QGEsEWestV7XICLS42nMWETEAQpjEREHKIxFRBygMBYRc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WIYrWJCcnh6mq7qFnz37vYhITE1m0aJHXZUgPVlRU1HgxoMGDBzN69GiPK+o+wtIzttamh2M7cn0KY/HShQsXKC4uJhgM4vP5GucWS3ioZywibfLmm282XqEtFArpwFuYacxYRNrkjTfeaOwJDxs2rN1fdCDXp56xiNzQ119/zccff0z9ZCnIzs72uKLuR2EsIjd02223kZqaCtR/o0dPO4noZtAwhYjckN/v57XXXuPMmTNERUVd9/Rn6RiFsYi0WXe/PoSXNEwhIuIAhbGIiAMUxiIiDlAYi4g4wFyZN+gYJ4sSEemANp0zrp6xiIgDFMYiIg5QGIuIOEBhLCLiAIWxiIgDFMYiIg5QGIuIOEBhLCLiAIWxiIgDFMYiIg5QGIuIOEBhLCLiAIWxiIgDFMYiIg5QGIuIOEBhLCLiAIWxiIgDFMYiIg6I8rqAVrTpa0pERLoL9YxFRBygMBYRcYDCWETEAQpjEREHKIxFRBygMBYRcYDCWETEAQpjEREHKIxFRBzw/45ef9yYhh7NAAAAAElFTkSuQmCC", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "t1_schedule = t1_sched(times=[1e-6])\n", "t1_schedule.plot_circuit_diagram();" ] }, { "cell_type": "markdown", "id": "f81c9f45", "metadata": {}, "source": [ "For displaying the pulse diagram and timing table, the schedule first needs to get timing information for each operation in the schedule. This is achieved by compiling the schedule using {class}`~quantify_scheduler.backends.graph_compilation.SerialCompiler`. Please note that below in section {ref}`run_experiment`, the compilation is handled by {class}`~quantify_core.measurement.control.MeasurementControl` internally; it is done here only to enable displaying the timing table and pulse diagram.\n", "\n", "```{admonition} Compiling to Hardware\n", "More information on compilation can be found in {ref}`sec-tutorial-compiling`.\n", "```" ] }, { "cell_type": "code", "execution_count": 10, "id": "c31feae9", "metadata": {}, "outputs": [], "source": [ "from quantify_scheduler import SerialCompiler\n", "\n", "compiler = SerialCompiler(name=\"compiler\", quantum_device=single_qubit_device)\n", "compiled_schedule = compiler.compile(schedule=t1_schedule)" ] }, { "cell_type": "markdown", "id": "ad2d681a", "metadata": {}, "source": [ "Each operation is compiled into pulses that can be viewed and inspected via the {meth}`~quantify_scheduler.schedules.schedule.ScheduleBase.plot_pulse_diagram` method." ] }, { "cell_type": "code", "execution_count": 11, "id": "713096dd", "metadata": {}, "outputs": [ { "data": { "text/html": [ "