{ "cells": [ { "cell_type": "markdown", "id": "2c60202a", "metadata": {}, "source": [ "(sec-tutorial-compiling)=\n", "\n", "# Tutorial: Compiling to Hardware\n", "\n", "```{seealso}\n", "The complete source code of this tutorial can be found in\n", "\n", "{nb-download}`Compiling to Hardware.ipynb`\n", "```\n", "\n", "Compilation allows converting the schedules introduced in {ref}`sec-tutorial-sched-pulse` into a set of instructions that can be executed on the control hardware.\n", "\n", "In this notebook, we will define an example schedule, demonstrate how to compile it, and run it on a virtual hardware setup.\n", "\n", "## Schedule definition\n", "\n", "We start by defining an example schedule." ] }, { "cell_type": "code", "execution_count": 1, "id": "730e7731", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Schedule \"Simple schedule\" containing (2) 2 (unique) operations." ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from quantify_scheduler import Schedule\n", "from quantify_scheduler.operations.pulse_library import SquarePulse\n", "from quantify_scheduler.resources import ClockResource\n", "\n", "sched = Schedule(\"Simple schedule\")\n", "sched.add(SquarePulse(amp=0.2, duration=8e-9, port=\"q0:res\", clock=\"q0.ro\"))\n", "sched.add(SquarePulse(amp=0.1, duration=12e-9, port=\"q0:res\", clock=\"q0.ro\"))\n", "\n", "readout_clock = ClockResource(name=\"q0.ro\", freq=7e9)\n", "sched.add_resource(readout_clock)\n", "\n", "sched\n", "\n" ] }, { "cell_type": "markdown", "id": "fe0e483e", "metadata": {}, "source": [ "## Hardware configuration\n", "\n", "In our example setup, we will use a Qblox Cluster containing an RF control module (QCM-RF). To compile the schedule, we will need to provide the compiler with a dictionary detailing the hardware configuration.\n", "\n", "Please check the documentation on how to properly create such a configuration for the supported backends:\n", "\n", "- {ref}`sec-backend-qblox`\n", "- {ref}`sec-backend-zhinst`\n", "\n", "``````{admonition} Creating an example Qblox hardware configuration dictionary\n", ":class: dropdown\n", "\n", "Below we create an example hardware configuration dictionary, for the Qblox backend.\n", "In this configuration, we include:\n", "\n", "- The backend that we want to use (the Qblox backend, in this case).\n", "- A Cluster containing a QCM-RF module (in the 2nd slot).\n", "- A Local Oscillator.\n", "\n", "In the QCM-RF output's settings, {code}`interm_freq` (which stands for Intermediate Frequency or IF) is the frequency with which the device modulates the pulses.\n", "In this case, the internal LO frequency is not specified but is automatically calculated by the backend, such that the relation {math}`\\text{clock} = \\text{LO} + \\text{IF}` is respected.\n", "\n", "```{code-block} python\n", "\n", "hardware_cfg = {\n", " \"backend\": \"quantify_scheduler.backends.qblox_backend.hardware_compile\",\n", " \"cluster0\": {\n", " \"ref\": \"internal\",\n", " \"instrument_type\": \"Cluster\",\n", " \"cluster0_module2\": {\n", " \"instrument_type\": \"QCM_RF\",\n", " \"complex_output_0\": {\n", " \"lo_freq\": None,\n", " \"dc_mixer_offset_I\": -0.00552,\n", " \"dc_mixer_offset_Q\": -0.00556,\n", " \"portclock_configs\": [\n", " {\n", " \"mixer_amp_ratio\": 0.9998,\n", " \"mixer_phase_error_deg\": -4.1,\n", " \"port\": \"q0:res\",\n", " \"clock\": \"q0.ro\",\n", " \"interm_freq\": 50e6,\n", " }\n", " ],\n", " },\n", " },\n", " },\n", "}\n", "```\n", "\n", "Note that, for any experiment, all the required instruments need to be present in the hardware configuration.\n", "``````\n", "\n", "## Compilation\n", "\n", "Now we are ready to proceed to the compilation stage. For each of the control stack's instruments, the compilation generates:\n", "\n", "- The schedule's absolute timing. During the schedule's definition, we didn't assign absolute times to the operations. Instead, only the duration was defined. For the instruments to know how to execute the schedule, the absolute timing of the operations is calculated.\n", "- A set of parameters that are used to properly configure each instrument for the execution of the schedule. These parameters typically don't change during the execution of the schedule.\n", "- A compiled program that contains instructions on what the instrument must do in order for the schedule to be executed.\n", "\n", "We perform the compilation via {func}`~quantify_scheduler.backends.graph_compilation.QuantifyCompiler.compile`.\n", "\n", "We start by setting the directory where the compiled schedule files will be stored, via [set_datadir](https://quantify-quantify-core.readthedocs-hosted.com/en/latest/usage.html#data-directory)." ] }, { "cell_type": "code", "execution_count": 2, "id": "a8d486ba", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Data will be saved in:\n", "/home/rsoko/quantify-data\n" ] } ], "source": [ "from quantify_core.data import handling as dh\n", "\n", "dh.set_datadir(dh.default_datadir()) \n", "\n" ] }, { "cell_type": "code", "execution_count": 3, "id": "8361f63e", "metadata": { "mystnb": { "remove_code_outputs": true, "remove_code_source": true } }, "outputs": [], "source": [ "hardware_cfg = {\n", " \"backend\": \"quantify_scheduler.backends.qblox_backend.hardware_compile\",\n", " \"cluster0\": {\n", " \"ref\": \"internal\",\n", " \"instrument_type\": \"Cluster\",\n", " \"cluster0_module2\": {\n", " \"instrument_type\": \"QCM_RF\",\n", " \"complex_output_0\": {\n", " \"lo_freq\": None,\n", " \"dc_mixer_offset_I\": -0.00552,\n", " \"dc_mixer_offset_Q\": -0.00556,\n", " \"portclock_configs\": [\n", " {\n", " \"mixer_amp_ratio\": 0.9998,\n", " \"mixer_phase_error_deg\": -4.1,\n", " \"port\": \"q0:res\",\n", " \"clock\": \"q0.ro\",\n", " \"interm_freq\": 50e6,\n", " }\n", " ],\n", " },\n", " },\n", " },\n", "}" ] }, { "cell_type": "markdown", "id": "ad2b8070", "metadata": {}, "source": [ "Next, we create a device configuration that contains all knowledge of the physical device under test (DUT). To generate it we use the {class}`~quantify_scheduler.device_under_test.quantum_device.QuantumDevice` class.\n", "\n", "The schedule defined at the beginning of this tutorial consists of 2 pulse operations. As such, the hardware configuration must contain the necessary information to execute the schedule. We add the hardware configuration to the `QuantumDevice` object and compile the schedule using this information." ] }, { "cell_type": "code", "execution_count": 4, "id": "dd9f8012", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "hoverinfo": "x+y+name", "hoverlabel": { "namelength": -1 }, "legendgroup": "0", "line": { "color": "#EF553B" }, "mode": "lines", "name": "ModSquarePulse, clock: q0.ro", "showlegend": true, "type": "scatter", "x": [ 0.0, 1e-09, 2e-09, 3.0000000000000004e-09, 4e-09, 5e-09, 6.000000000000001e-09, 7.000000000000001e-09 ], "xaxis": "x", "y": [ 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2 ], "yaxis": "y" }, { "hoverinfo": "x+y+name", "hoverlabel": { "namelength": -1 }, "legendgroup": "1", "line": { "color": "#00CC96" }, "mode": "lines", "name": "ModSquarePulse, clock: q0.ro", "showlegend": true, "type": "scatter", "x": [ 8e-09, 9.000000000000001e-09, 1.0000000000000002e-08, 1.1000000000000003e-08, 1.2000000000000003e-08, 1.3000000000000004e-08, 1.4000000000000005e-08, 1.5000000000000005e-08, 1.6000000000000004e-08, 1.7000000000000007e-08, 1.800000000000001e-08, 1.9000000000000008e-08 ], "xaxis": "x", "y": [ 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 ], "yaxis": "y" } ], "layout": { "height": 300, "showlegend": false, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "sequentialminus": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } }, "title": { "text": "Simple schedule" }, "width": 1000, "xaxis": { "anchor": "y", "domain": [ 0.0, 1.0 ], "hoverformat": ".3s", "rangeslider": { "visible": true }, "showgrid": true, "tickformat": ".2s", "tickformatstops": [ { "dtickrange": [ null, 1e-09 ], "value": ".10s" }, { "dtickrange": [ 1e-09, 1e-06 ], "value": ".7s" }, { "dtickrange": [ 1e-06, 0.001 ], "value": ".4s" } ], "ticksuffix": "s", "title": { "text": "Time" } }, "yaxis": { "anchor": "x", "domain": [ 0.0, 1.0 ], "hoverformat": ".3s", "range": [ -1.1, 1.1 ], "tickformat": ".2s", "ticksuffix": "V", "title": { "text": "q0:res" } } } }, "text/html": [ "