From 9613445c7a209af57287a75c11167ac5556bfc78 Mon Sep 17 00:00:00 2001 From: "Richard B. Lazarus" Date: Tue, 24 Sep 2019 09:29:27 -0400 Subject: [PATCH] updating example to work with current code --- doc/QGL-demo.ipynb | 152 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 128 insertions(+), 24 deletions(-) diff --git a/doc/QGL-demo.ipynb b/doc/QGL-demo.ipynb index 0b30ad69..f1728a1e 100644 --- a/doc/QGL-demo.ipynb +++ b/doc/QGL-demo.ipynb @@ -5,7 +5,10 @@ "metadata": {}, "source": [ "# Setup\n", - "Load the necessary modules from QGL. This will also import ``numpy`` into the namespace as ``np``." + "\n", + "Load the necessary modules from QGL. This will also import ``numpy`` into the namespace as ``np``. \n", + "\n", + "The AWGDir environment variable is used to indicate where QGL will store it's output sequence files. First we load the QGL module. It defaults to a temporary directory as provided by Python's tempfile module.\n" ] }, { @@ -17,31 +20,43 @@ "from QGL import *" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Next we instantiate the channel library. By default bbndb will use an sqlite database at the location specified by the BBN_DB environment variabe, but we override this behavior below in order to use a temporary in memory database for testing purposes.\n" + ] + }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "output_notebook()" + "cl = ChannelLibrary(db_resource_name=\":memory:\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The channel library has a number of convenience functions defined to create instruments and qubits, as well as functions to define the relationships between them. Let us create a qubit first:\n" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ - "# create a channel library object, which loads qubit configurations from file.\n", - "# By default, we look for the BBN_MEAS_FILE environment variable for the location of the\n", - "# YAML configuration. Calling ChannelLibrary with no arguments will load the file from\n", - "# that location.\n", - "#cl = ChannelLibrary()\n", - "\n", - "# Altneratively you can specify the desired configuration file location.\n", - "cl = ChannelLibrary(library_file=\"./config/measure.yml\")" + "q1 = cl.new_qubit(\"q1\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In order to compile the QGL program into pulse sequences, we need to define a minimal hardware configuration. Basically, we need to specify AWG resources for output pulse compilation and digitizer resources for signal measurement. " ] }, { @@ -50,47 +65,136 @@ "metadata": {}, "outputs": [], "source": [ - "# create a Qubit object (holds onto pulse parameters like shape, duration, channel, etc)\n", - "q1 = QubitFactory('q1')" + "# Most calls required label and address. Let's define \n", + "# an AWG for control pulse generation \n", + "aps2_1 = cl.new_APS2(\"BBNAPS1\", address=\"192.168.5.101\") \n", + "# an AWG for measurement pulse generation\n", + "aps2_2 = cl.new_APS2(\"BBNAPS2\", address=\"192.168.5.102\")\n", + "# and digitizer for measurement collection\n", + "dig_1 = cl.new_X6(\"X6_1\", address=0)\n", + "\n", + "# Qubit q1 is controlled by AWG aps2_1, and uses microwave source h1\n", + "cl.set_control(q1, aps2_1)\n", + "# Qubit q1 is measured by AWG aps2_2 and digitizer dig_1, and uses microwave source h2\n", + "cl.set_measure(q1, aps2_2, dig_1.ch(1))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Basic sequence construction" + "# Basic sequence construction and plotting" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "You can construct sequences by creating lists of `Pulse` objects. These can be constructed by calling various primitives defined for qubits. For example, 90 and 180 degree rotations about X and Y:" + "You can construct simple gate sequences by creating `Lists` of `Pulse` objects. These can be constructed by calling various primitives defined for qubits, for example, 90 and 180 degree rotations about X and Y:" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ - "seq = [X90(q1),Y90(q1),X(q1),Id(q1),Y(q1)]" + "seq1 = [[X(q1), Y(q1)]]\n", + "seq2 = [[X90(q1),Y90(q1),X(q1),Id(q1),Y(q1)]]\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Display these in the \"logical\" space with the `show` command. Since our `Qubit` object is a quadrature channel, you see two colors corresponding to I and Q control." + "This sequence of pulses can be plotted for visual review. First, you must compile the QGL into pulses based on the hardware defined above. Since our `Qubit` object is a quadrature channel, you see two colors corresponding to the I and Q control signals." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Compiled 1 sequences.\n" + ] + } + ], "source": [ - "show(seq)" + "mf = compile_to_hardware(seq1, 'Test1')" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "1cbc56fea1b8497b9d03453ec8266d8d", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "VBox(children=(IntSlider(value=1, description='Segment', max=1, min=1), Figure(animation_duration=50, axes=[Ax…" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "plot_pulse_files(mf)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now, let's visualize the second sequence. " + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Compiled 1 sequences.\n" + ] + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "bd9aaa48fbec45dabd46bf8320cf8ad1", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "VBox(children=(IntSlider(value=1, description='Segment', max=1, min=1), Figure(animation_duration=50, axes=[Ax…" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "mf = compile_to_hardware(seq2, 'Test2')\n", + "plot_pulse_files(mf)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Constructing more sophisticated sequences (stopped here)" ] }, { @@ -401,7 +505,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.0" + "version": "3.7.3" } }, "nbformat": 4,