From 2fafcfaab3c4c54b9c599f3b8494b15e9dd53095 Mon Sep 17 00:00:00 2001 From: Aaron Helsinger Date: Thu, 26 Sep 2019 12:06:38 -0400 Subject: [PATCH] Issue #38: update the sample notebooks to work with this code --- notebooks/QGL2 AllXY.ipynb | 152 ++++++++++++--------- notebooks/QGL2 CPMG.ipynb | 151 +++++++++++---------- notebooks/QGL2 HahnEcho.ipynb | 136 +++++++++++-------- notebooks/QGL2 InversionRecovery.ipynb | 141 +++++++++++--------- notebooks/QGL2 RabiAmp-indirect.ipynb | 143 +++++--------------- notebooks/QGL2 RabiAmp.ipynb | 174 ++++++++++++++++++------- notebooks/QGL2 RabiPulsedSpec.ipynb | 77 ++++++----- notebooks/QGL2 RabiSingleShot.ipynb | 103 +++++++-------- notebooks/QGL2 RabiWidth.ipynb | 88 ++++++++----- notebooks/QGL2 Ramsey.ipynb | 92 ++++++++----- 10 files changed, 688 insertions(+), 569 deletions(-) diff --git a/notebooks/QGL2 AllXY.ipynb b/notebooks/QGL2 AllXY.ipynb index 9614fc3..b109730 100644 --- a/notebooks/QGL2 AllXY.ipynb +++ b/notebooks/QGL2 AllXY.ipynb @@ -13,47 +13,91 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## imports" + "## Imports" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "from pyqgl2.main import compile_function, qgl2_compile_to_hardware\n", - "from QGL.ChannelLibrary import QubitFactory\n", - "from QGL.Plotting import output_notebook\n", - "from QGL.PulseSequencePlotter import plot_pulse_files\n", - "import QGL.config\n", - "import os" + "from pyqgl2.test_cl import create_default_channelLibrary\n", + "from pyqgl2.qreg import QRegister\n", + "from QGL import plot_pulse_files, ChannelLibrary" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Should sequences be compiled to hardware, or just to QGL?" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ - "output_notebook()" + "toHW = True" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Create a test ChannelLibrary; alternatively, load a library you already defined" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ - "# Ensure the AWG directory exists\n", - "if not os.path.exists(QGL.config.AWGDir):\n", - " os.makedirs(QGL.config.AWGDir)" + "create_default_channelLibrary(toHW, True)\n", + "\n", + "# Or create a new ChannelLibrary with channels\n", + "# cl = ChannelLibrary(db_resource_name=\":memory:\")\n", + "# q1 = cl.new_qubit('q1')\n", + "\n", + "# Most calls required label and address\n", + "# aps2_1 = cl.new_APS2(\"BBNAPS1\", address=\"192.168.5.101\") \n", + "# aps2_2 = cl.new_APS2(\"BBNAPS2\", address=\"192.168.5.102\")\n", + "# dig_1 = cl.new_X6(\"X6_1\", address=0)\n", + "\n", + "# Label, instrument type, address, and an additional config parameter\n", + "# h1 = cl.new_source(\"Holz1\", \"HolzworthHS9000\", \"HS9004A-009-1\", power=-30)\n", + "# h2 = cl.new_source(\"Holz2\", \"HolzworthHS9000\", \"HS9004A-009-2\", power=-30)\n", + "\n", + "# Qubit q1 is controlled by AWG aps2_1, and uses microwave source h1\n", + "# cl.set_control(q1, aps2_1, generator=h1)\n", + "\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), generator=h2)\n", + "\n", + "# The AWG aps2_1 is the master AWG, and distributes a synchronization trigger on its second marker channel\n", + "# cl.set_master(aps2_1, aps2_1.ch(\"m2\"))\n", + "# cl.commit()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create needed qubit(s)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# For QGL2, use a QRegister, not a QGL Qubit\n", + "q = QRegister(1)" ] }, { @@ -77,9 +121,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "#from pyqgl2.ast_util import NodeError\n", @@ -92,26 +134,22 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "# Insert proper path to QGL2 source and name of qgl2main if not so marked\n", - "# Here we compile the named function in the named file from QGL2 to QGL1 and return the new function\n", - "# True argument means save the QGL1 compiled function to a file" + "# Here we compile the named function in the named file from QGL2 to QGL1 and return the new function" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false, "scrolled": false }, "outputs": [], "source": [ - "qgl1MainFunc = compile_function(\"../src/python/qgl2/basic_sequences/AllXYMin.py\", \"doAllXY\", True)" + "qgl1MainFunc = compile_function(\"../src/python/qgl2/basic_sequences/AllXY.py\", \"AllXY\", (q,))" ] }, { @@ -124,14 +162,11 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "# Now run the QGL1 function, producing a list of sequences\n", - "# Supply name of qubit from channel library, or omit to use a default\n", - "seqs = qgl1MainFunc(q=QubitFactory('q1'))" + "seqs = qgl1MainFunc()" ] }, { @@ -140,47 +175,38 @@ "collapsed": true }, "source": [ - "## Compile to machine instructions" + "## Optionally compile to machine instructions" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "scrolled": true, + "slideshow": { + "slide_type": "-" + } }, "outputs": [], "source": [ - "fileNames = qgl2_compile_to_hardware(seqs, \"AllXY/AllXY\")\n", - "print(fileNames)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "collapsed": true - }, - "source": [ - "## Plot the sequences" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "plot_pulse_files(fileNames)" + "if toHW:\n", + " from IPython.display import display\n", + " metaFileName = qgl2_compile_to_hardware(seqs, \"AllXY/AllXY\")\n", + " print(f\"Generated sequence details in '{metaFileName}'\")\n", + " # Plot the sequences\n", + " p = plot_pulse_files(metaFileName)\n", + " # Explicitly display the graph which fails to auto-draw in some cases\n", + " display(p)\n", + "else:\n", + " from QGL.Scheduler import schedule\n", + " from IPython.lib.pretty import pretty\n", + " print(pretty(schedule(seqs)))" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [] } @@ -201,9 +227,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.1" + "version": "3.7.3" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/notebooks/QGL2 CPMG.ipynb b/notebooks/QGL2 CPMG.ipynb index fd0e25c..9c1d7d2 100644 --- a/notebooks/QGL2 CPMG.ipynb +++ b/notebooks/QGL2 CPMG.ipynb @@ -13,32 +13,36 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## imports" + "## Imports" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "from pyqgl2.main import compile_function, qgl2_compile_to_hardware\n", - "from QGL.Plotting import output_notebook\n", - "from QGL.PulseSequencePlotter import plot_pulse_files\n", - "from QGL.ChannelLibrary import QubitFactory" + "from pyqgl2.test_cl import create_default_channelLibrary\n", + "from pyqgl2.qreg import QRegister\n", + "from QGL import plot_pulse_files, ChannelLibrary\n", + "import numpy as np" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Should sequences be compiled to hardware, or just to QGL?" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ - "output_notebook()" + "toHW = True" ] }, { @@ -47,106 +51,107 @@ "collapsed": true }, "source": [ - "## Compile to QGL1" + "### Create a test ChannelLibrary" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "create_default_channelLibrary(toHW, True)\n", + "# Alternatively could load an existing library, or create one here; see the 'AllXY' notebook" ] }, { "cell_type": "markdown", - "metadata": { - "collapsed": true - }, + "metadata": {}, "source": [ - "### To turn on debug output, uncomment the next 4 lines" + "## Create needed qubit(s)" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ - "#from pyqgl2.ast_util import NodeError\n", - "#from pyqgl2.debugmsg import DebugMsg\n", - "\n", - "#DebugMsg.set_level(1)\n", - "#NodeError.MUTE_ERR_LEVEL = NodeError.NODE_ERROR_NONE" + "# For QGL2, use a QRegister, not a QGL Qubit\n", + "q = QRegister(1)" ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": { "collapsed": true }, - "outputs": [], - "source": [] + "source": [ + "## Compile to QGL1" + ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": { "collapsed": true }, - "outputs": [], "source": [ - "# Insert proper path to QGL2 source and name of qgl2main if not so marked\n", - "# Here we compile the named function in the named file from QGL2 to QGL1 and return the new function\n", - "# True argument means save the QGL1 compiled function to a file" + "### To turn on debug output, uncomment the next 4 lines" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false, - "scrolled": false - }, + "metadata": {}, "outputs": [], "source": [ - "qgl1MainFunc = compile_function(\"../src/python/qgl2/basic_sequences/DecouplingMin.py\", \"doCPMG\", True)" + "#from pyqgl2.ast_util import NodeError\n", + "#from pyqgl2.debugmsg import DebugMsg\n", + "\n", + "#DebugMsg.set_level(1)\n", + "#NodeError.MUTE_ERR_LEVEL = NodeError.NODE_ERROR_NONE" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ - "## Generate pulse sequences" + "# Insert proper path to QGL2 source and name of qgl2main if not so marked\n", + "# Here we compile the named function in the named file from QGL2 to QGL1 and return the new function" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "scrolled": false }, "outputs": [], "source": [ - "# Now run the QGL1 function, producing a list of sequences\n", - "# Supply name of qubit from channel library, or omit to use a default\n", - "seqs = qgl1MainFunc(q=QubitFactory('q1'))" + "tCalR = 2 # calRepeats\n", + "cpmgNumPulses = [0, 2, 4, 6]\n", + "cpmgSpacing = 500e-9\n", + "qgl1MainFunc = compile_function(\"../src/python/qgl2/basic_sequences/Decoupling.py\", \"CPMG\", \n", + " (q, cpmgNumPulses, cpmgSpacing, tCalR))" ] }, { "cell_type": "markdown", - "metadata": { - "collapsed": true - }, + "metadata": {}, "source": [ - "## Compile to machine instructions" + "## Generate pulse sequences" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ - "fileNames = qgl2_compile_to_hardware(seqs, \"CPMG/CPMG\")\n", - "print(fileNames)" + "# Now run the QGL1 function, producing a list of sequences\n", + "seqs = qgl1MainFunc()" ] }, { @@ -155,28 +160,34 @@ "collapsed": true }, "source": [ - "## Plot the sequences" + " ## Optionally compile to machine instructions" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ - "plot_pulse_files(fileNames)" + "if toHW:\n", + " from qgl2.basic_sequences.helpers import delay_descriptor, cal_descriptor\n", + " axis_desc = [\n", + " # NOTE: numPulses is not a numpy array, so cannot multiply by a float\n", + " # But thankfully, np.array(np.array) = np.array so this is always a good move here.\n", + " delay_descriptor(cpmgSpacing * np.array(cpmgNumPulses)),\n", + " cal_descriptor(('qubit',), tCalR)\n", + " ]\n", + " metaFileName = qgl2_compile_to_hardware(seqs, filename=\"CPMG/CPMG\", axis_descriptor=axis_desc)\n", + " print(f\"Generated sequence details in '{metaFileName}'\")\n", + " # Plot the sequences\n", + " p = plot_pulse_files(metaFileName)\n", + " # Explicitly display the graph which fails to auto-draw in some cases\n", + " display(p)\n", + "else:\n", + " from QGL.Scheduler import schedule\n", + " from IPython.lib.pretty import pretty\n", + " print(pretty(schedule(seqs)))" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] } ], "metadata": { @@ -195,9 +206,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.1" + "version": "3.7.3" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/notebooks/QGL2 HahnEcho.ipynb b/notebooks/QGL2 HahnEcho.ipynb index d2628b3..f09becc 100644 --- a/notebooks/QGL2 HahnEcho.ipynb +++ b/notebooks/QGL2 HahnEcho.ipynb @@ -13,32 +13,70 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## imports" + "## Imports" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "from pyqgl2.main import compile_function, qgl2_compile_to_hardware\n", - "from QGL.ChannelLibrary import QubitFactory\n", - "from QGL.Plotting import output_notebook\n", - "from QGL.PulseSequencePlotter import plot_pulse_files" + "from pyqgl2.test_cl import create_default_channelLibrary\n", + "from pyqgl2.qreg import QRegister\n", + "from QGL import plot_pulse_files, ChannelLibrary\n", + "import numpy as np" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Should sequences be compiled to hardware, or just to QGL?" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, + "outputs": [], + "source": [ + "toHW = True" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Create a test ChannelLibrary" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "create_default_channelLibrary(toHW, True)\n", + "# Alternatively could load an existing library, or create one here; see the 'AllXY' notebook" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create needed qubit(s)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], "source": [ - "output_notebook()" + "# For QGL2, use a QRegister, not a QGL Qubit\n", + "q = QRegister(1)" ] }, { @@ -62,9 +100,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "#from pyqgl2.ast_util import NodeError\n", @@ -77,26 +113,25 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "# Insert proper path to QGL2 source and name of qgl2main if not so marked\n", - "# Here we compile the named function in the named file from QGL2 to QGL1 and return the new function\n", - "# True argument means save the QGL1 compiled function to a file" + "# Here we compile the named function in the named file from QGL2 to QGL1 and return the new function" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false, "scrolled": false }, "outputs": [], "source": [ - "qgl1MainFunc = compile_function(\"../src/python/qgl2/basic_sequences/DecouplingMin.py\", \"doHahnEcho\", True)" + "tCalR = 2 # calRepeats\n", + "hahnSpacings = np.linspace(0, 5e-6, 11)\n", + "qgl1MainFunc = compile_function(\"../src/python/qgl2/basic_sequences/Decoupling.py\", \"HahnEcho\", \n", + " (q, hahnSpacings, 0, tCalR))" ] }, { @@ -109,35 +144,11 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "# Now run the QGL1 function, producing a list of sequences\n", - "# Supply name of qubit from channel library, or omit to use a default\n", - "seqs = qgl1MainFunc(q=QubitFactory('q1'))" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "collapsed": true - }, - "source": [ - "## Compile to machine instructions" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "fileNames = qgl2_compile_to_hardware(seqs, \"Echo/Echo\")\n", - "print(fileNames)" + "seqs = qgl1MainFunc()" ] }, { @@ -146,26 +157,37 @@ "collapsed": true }, "source": [ - "## Plot the sequences" + "## Optionally compile to machine instructions" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ - "plot_pulse_files(fileNames)" + "if toHW:\n", + " from qgl2.basic_sequences.helpers import delay_descriptor, cal_descriptor\n", + " axis_desc = [\n", + " delay_descriptor(2 * hahnSpacings),\n", + " cal_descriptor(('qubit',), tCalR)\n", + " ]\n", + " metaFileName = qgl2_compile_to_hardware(seqs, \"Echo/Echo\", axis_descriptor=axis_desc)\n", + " print(f\"Generated sequence details in '{metaFileName}'\")\n", + " # Plot the sequences\n", + " p = plot_pulse_files(metaFileName)\n", + " # Explicitly display the graph which fails to auto-draw in some cases\n", + " display(p)\n", + "else:\n", + " from QGL.Scheduler import schedule\n", + " from IPython.lib.pretty import pretty\n", + " print(pretty(schedule(seqs)))" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [] } @@ -186,9 +208,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.1" + "version": "3.7.3" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/notebooks/QGL2 InversionRecovery.ipynb b/notebooks/QGL2 InversionRecovery.ipynb index 8f86529..a37b49f 100644 --- a/notebooks/QGL2 InversionRecovery.ipynb +++ b/notebooks/QGL2 InversionRecovery.ipynb @@ -9,123 +9,125 @@ "# Compiling a QGL2 InversionRecovery and plotting the output" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Imports" + ] + }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ - "# Using delays=np.linspace(0, 5e-6, 11)" + "from pyqgl2.main import compile_function, qgl2_compile_to_hardware\n", + "from pyqgl2.test_cl import create_default_channelLibrary\n", + "from pyqgl2.qreg import QRegister\n", + "from QGL import plot_pulse_files, ChannelLibrary\n", + "import numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## imports" + "### Should sequences be compiled to hardware, or just to QGL?" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ - "from pyqgl2.main import compile_function, qgl2_compile_to_hardware\n", - "from QGL.ChannelLibrary import QubitFactory\n", - "from QGL.Plotting import output_notebook\n", - "from QGL.PulseSequencePlotter import plot_pulse_files" + "toHW = True\n", + "# Append suffix to filenames?\n", + "suffix = True" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Create a test ChannelLibrary" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ - "output_notebook()" + "create_default_channelLibrary(toHW, True)\n", + "# Alternatively could load an existing library, or create one here; see the 'AllXY' notebook" ] }, { "cell_type": "markdown", - "metadata": { - "collapsed": true - }, + "metadata": {}, "source": [ - "## Compile to QGL1" + "## Create needed qubit(s)" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ - "# Insert proper path to QGL2 source and name of qgl2main if not so marked\n", - "# Here we compile the named function in the named file from QGL2 to QGL1 and return the new function\n", - "# True argument means save the QGL1 compiled function to a file" + "# For QGL2, use a QRegister, not a QGL Qubit\n", + "q = QRegister(1)" ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": { - "collapsed": false, - "scrolled": true + "collapsed": true }, - "outputs": [], "source": [ - "qgl1MainFunc = compile_function(\"../src/python/qgl2/basic_sequences/T1T2Min.py\", \"doInversionRecovery\", True)" + "## Compile to QGL1" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ - "## Generate pulse sequences" + "# Insert proper path to QGL2 source and name of qgl2main if not so marked\n", + "# Here we compile the named function in the named file from QGL2 to QGL1 and return the new function" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": true + "scrolled": true }, "outputs": [], "source": [ - "# Now run the QGL1 function, producing a list of sequences\n", - "# Supply name of qubit from channel library, or omit to use a default\n", - "seqs = qgl1MainFunc(q=QubitFactory('q1'))" + "irDelays = np.linspace(0, 5e-6, 11)\n", + "tCalR = 2\n", + "qgl1MainFunc = compile_function(\"../src/python/qgl2/basic_sequences/T1T2.py\", \"InversionRecovery\", (q, irDelays, tCalR))" ] }, { "cell_type": "markdown", - "metadata": { - "collapsed": true - }, + "metadata": {}, "source": [ - "## Compile to machine instructions" + "## Generate pulse sequences" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ - "# True filename optionally is T1_q1/T1_q1 where q1 is the qubit label\n", - "fileNames = qgl2_compile_to_hardware(seqs, \"T1/T1\")\n", - "print(fileNames)" + "# Now run the QGL1 function, producing a list of sequences\n", + "seqs = qgl1MainFunc()" ] }, { @@ -134,29 +136,38 @@ "collapsed": true }, "source": [ - "## Plot the sequences" + "## Optionally compile to machine instructions" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false, - "scrolled": true - }, + "metadata": {}, "outputs": [], "source": [ - "plot_pulse_files(fileNames)" + "if toHW:\n", + " from qgl2.basic_sequences.helpers import delay_descriptor, cal_descriptor\n", + " axis_desc = [\n", + " delay_descriptor(irDelays),\n", + " cal_descriptor(('qubit',), tCalR)\n", + " ]\n", + " label = \"T1\"\n", + " # Generate proper filenames; for these, it isn't just the label T1\n", + " # T1T2 QGL functions take a suffix boolean default false. If true, then append to label \"_qubit.label\"; ie \"_q1\"\n", + " if suffix:\n", + " label = label + \"_q1\"\n", + " \n", + " metaFileName = qgl2_compile_to_hardware(seqs, filename=f\"{label}/{label}\", axis_descriptor=axis_desc)\n", + " print(f\"Generated sequence details in '{metaFileName}'\")\n", + " # Plot the sequences\n", + " p = plot_pulse_files(metaFileName)\n", + " # Explicitly display the graph which fails to auto-draw in some cases\n", + " display(p)\n", + "else:\n", + " from QGL.Scheduler import schedule\n", + " from IPython.lib.pretty import pretty\n", + " print(pretty(schedule(seqs)))" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] } ], "metadata": { @@ -175,9 +186,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.1" + "version": "3.7.3" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/notebooks/QGL2 RabiAmp-indirect.ipynb b/notebooks/QGL2 RabiAmp-indirect.ipynb index 0899bee..1dad7fb 100644 --- a/notebooks/QGL2 RabiAmp-indirect.ipynb +++ b/notebooks/QGL2 RabiAmp-indirect.ipynb @@ -1,12 +1,10 @@ { "cells": [ { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": { "collapsed": true }, - "outputs": [], "source": [ "# Sample notebook running a previously compiled QGL2 program" ] @@ -14,155 +12,82 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "import QGL" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ - "from QGL.Compiler import compile_to_hardware" + "import QGL\n", + "from QGL.Compiler import compile_to_hardware\n", + "from QGL.Scheduler import schedule\n", + "from QGL.PulseSequencePlotter import plot_pulse_files\n", + "from pyqgl2.test_cl import create_default_channelLibrary\n", + "\n", + "# This next should be a valid import of a compiled QGL2 program and its qgl2main\n", + "# EG do the compilation manually with -o and put it in the right spot\n", + "from RabiAmpqgl1 import RabiAmp" ] }, { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], + "cell_type": "markdown", + "metadata": {}, "source": [ - "from QGL.PulseSequencePlotter import plot_pulse_files" + "### Create a test ChannelLibrary" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ - "# This next should be a valid import of a compiled QGL2 program and its qgl2main" + "create_default_channelLibrary(True, True)\n", + "# Alternatively could load an existing library, or create one here; see the 'AllXY' notebook" ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": { "collapsed": true }, - "outputs": [], "source": [ - "# EG do the compilation manually with -o and put it in the right spot" + "## Generate pulse sequences" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ - "from Rabiqgl1 import doRabiAmp" + "# Now run the QGL1 function as before, producing a list of sequences\n", + "seqs = RabiAmp()" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ - "from QGL.Plotting import output_notebook" + "# Note we cannot provide the correct axis description without knowing the amplitudes used\n", + "# Note we schedule the sequences and ensure they are a list\n", + "metaFileName = compile_to_hardware([schedule(seqs)], \"Rabi/Rabi\")\n", + "print(f\"Generated sequence details in '{metaFileName}'\")" ] }, { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], + "cell_type": "markdown", + "metadata": {}, "source": [ - "output_notebook()" + "## Plot the sequences" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "channels = QGL.ChannelLibrary.channelLib" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "# Specify the name of the qubit to use" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "seqs = doRabiAmp(q=channels['q1'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "fileNames = compile_to_hardware(seqs, \"Rabi/Rabi\", qgl2=True)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "print(fileNames)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ - "plot_pulse_files(fileNames)" + "display(plot_pulse_files(metaFileName))" ] } ], @@ -182,9 +107,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.1" + "version": "3.7.3" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/notebooks/QGL2 RabiAmp.ipynb b/notebooks/QGL2 RabiAmp.ipynb index fc1b012..31649b5 100644 --- a/notebooks/QGL2 RabiAmp.ipynb +++ b/notebooks/QGL2 RabiAmp.ipynb @@ -9,10 +9,8 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 22, + "metadata": {}, "outputs": [], "source": [ "# Using phase=0, amp from 0 -> 1 stepping by 0.1" @@ -22,33 +20,54 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### imports" + "### Imports" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 23, + "metadata": {}, "outputs": [], "source": [ "from pyqgl2.main import compile_function, qgl2_compile_to_hardware\n", - "import QGL\n", - "from QGL.Plotting import output_notebook\n", - "from QGL.PulseSequencePlotter import plot_pulse_files\n", - "from QGL import QubitFactory" + "from pyqgl2.test_cl import create_default_channelLibrary\n", + "from pyqgl2.qreg import QRegister\n", + "from QGL import plot_pulse_files, ChannelLibrary\n", + "import numpy as np" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Create a test ChannelLibrary" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, + "execution_count": 24, + "metadata": {}, "outputs": [], "source": [ - "output_notebook()" + "create_default_channelLibrary(True, True)\n", + "# Alternatively could load an existing library, or create one here; see the 'AllXY' notebook" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create needed qubit(s)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [], + "source": [ + "# For QGL2, use a QRegister, not a QGL Qubit\n", + "q = QRegister(1)" ] }, { @@ -60,27 +79,51 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 26, + "metadata": {}, "outputs": [], "source": [ "# Insert proper path to QGL2 source and name of qgl2main if not so marked\n", - "# Here we compile the named function in the named file from QGL2 to QGL1 and return the new functio\n", - "# True argument means save the QGL1 compiled function to a file" + "# Here we compile the named function in the named file from QGL2 to QGL1 and return the new functio" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": { - "collapsed": false, "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "COMPILING [../src/python/qgl2/basic_sequences/Rabi.py] main RabiAmp\n", + "2019-09-26 11:50:08.300694: CALLING IMPORTER\n", + "../src/python/qgl2/basic_sequences/Rabi.py:188:4: warning: conditional/runtime import [from pyqgl2.qreg import QRegister] ignored by pyqgl2\n", + "../src/python/qgl2/basic_sequences/Rabi.py:189:4: warning: conditional/runtime import [import pyqgl2.test_cl] ignored by pyqgl2\n", + "../src/python/qgl2/basic_sequences/Rabi.py:190:4: warning: conditional/runtime import [from pyqgl2.main import compile_function\n", + "from pyqgl2.main import qgl2_compile_to_hardware] ignored by pyqgl2\n", + "../src/python/qgl2/basic_sequences/Rabi.py:191:4: warning: conditional/runtime import [import numpy as np] ignored by pyqgl2\n", + "../src/python/qgl2/basic_sequences/Rabi.py:192:4: warning: conditional/runtime import [import QGL.PulseShapes] ignored by pyqgl2\n", + "../src/python/qgl2/basic_sequences/Rabi.py:290:12: warning: conditional/runtime import [from QGL.Scheduler import schedule] ignored by pyqgl2\n", + "../src/python/qgl2/basic_sequences/Rabi.py:293:12: warning: conditional/runtime import [from IPython.lib.pretty import pretty] ignored by pyqgl2\n", + "../src/python/qgl2/basic_sequences/Rabi.py:285:16: warning: conditional/runtime import [from QGL.PulseSequencePlotter import plot_pulse_files] ignored by pyqgl2\n", + "2019-09-26 11:50:08.365738: CALLING INLINER\n", + "2019-09-26 11:50:08.365983: ITERATION 0\n", + "2019-09-26 11:50:08.367424: ITERATION 1\n", + "2019-09-26 11:50:08.368372: CALLING EVALUATOR\n", + "2019-09-26 11:50:08.373181: CALLING FLATTENER\n", + "2019-09-26 11:50:08.373489: GENERATING QGL1 SEQUENCE FUNCTION\n", + "Saved compiled code to /home/ahelsing/machome/Projects/Quantum/pyqgl2/src/python/qgl2/basic_sequences/Rabiqgl1.py\n" + ] + } + ], "source": [ - "qgl1MainFunc = compile_function(\"../src/python/qgl2/basic_sequences/RabiMin.py\", \"doRabiAmp\", True)" + "rAmpAmps = np.linspace(0, 1, 1)\n", + "qgl1MainFunc = compile_function(\"../src/python/qgl2/basic_sequences/Rabi.py\", \"RabiAmp\", (q, rAmpAmps, 0), saveOutput=True)" ] }, { @@ -92,15 +135,12 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, + "execution_count": 28, + "metadata": {}, "outputs": [], "source": [ "# Now run the QGL1 function, producing a list of sequences\n", - "# Supply name of qubit from channel library, or omit to use a default\n", - "seqs = qgl1MainFunc(q=QubitFactory('q1'))" + "seqs = qgl1MainFunc()" ] }, { @@ -114,14 +154,30 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false, - "scrolled": false - }, - "outputs": [], + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Compiled 1 sequences.\n", + "Generated sequence details in '/tmp/AWGpj4dtdnh/Rabi/Rabi-meta.json'\n" + ] + } + ], "source": [ - "fileNames = qgl2_compile_to_hardware(seqs, \"Rabi/Rabi\")" + "from qgl2.basic_sequences.helpers import delay_descriptor, cal_descriptor\n", + "axis_desc = [{\n", + " 'name': 'amplitude',\n", + " 'unit': None,\n", + " 'points': list(rAmpAmps),\n", + " 'partition': 1\n", + " }]\n", + "label = \"Rabi\"\n", + "\n", + "metaFileName = qgl2_compile_to_hardware(seqs, filename=f\"{label}/{label}\", axis_descriptor=axis_desc)\n", + "print(f\"Generated sequence details in '{metaFileName}'\")" ] }, { @@ -133,14 +189,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": { - "collapsed": false, "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Sampling rate from extract_waveforms 1200000000.0\n", + "Sampling rate from extract_waveforms 1200000000.0\n" + ] + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "21712ef20433491e82aaf7c8f7d855bc", + "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(fileNames)" + "p = plot_pulse_files(metaFileName)\n", + "# Explicitly display the graph which fails to auto-draw in some cases\n", + "display(p)" ] } ], @@ -160,9 +240,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.1" + "version": "3.7.3" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/notebooks/QGL2 RabiPulsedSpec.ipynb b/notebooks/QGL2 RabiPulsedSpec.ipynb index 4df1cdd..5fae667 100644 --- a/notebooks/QGL2 RabiPulsedSpec.ipynb +++ b/notebooks/QGL2 RabiPulsedSpec.ipynb @@ -13,32 +13,53 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## imports" + "## Imports" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "from pyqgl2.main import compile_function, qgl2_compile_to_hardware\n", - "from QGL.ChannelLibrary import QubitFactory\n", - "from QGL.Plotting import output_notebook\n", - "from QGL.PulseSequencePlotter import plot_pulse_files" + "from pyqgl2.test_cl import create_default_channelLibrary\n", + "from pyqgl2.qreg import QRegister\n", + "from QGL import plot_pulse_files, ChannelLibrary" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Create a test ChannelLibrary" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, + "outputs": [], + "source": [ + "create_default_channelLibrary(True, True)\n", + "# Alternatively could load an existing library, or create one here; see the 'AllXY' notebook" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create needed qubit(s)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], "source": [ - "output_notebook()" + "# For QGL2, use a QRegister, not a QGL Qubit\n", + "q = QRegister(1)" ] }, { @@ -62,9 +83,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "#from pyqgl2.ast_util import NodeError\n", @@ -78,16 +97,13 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false, "scrolled": false }, "outputs": [], "source": [ "# Insert proper path to QGL2 source and name of qgl2main if not so marked\n", "# Here we compile the named function in the named file from QGL2 to QGL1 and return the new function\n", - "# True argument means save the QGL1 compiled function to a file\n", - "\n", - "qgl1MainFunc = compile_function(\"../src/python/qgl2/basic_sequences/RabiMin.py\", \"doPulsedSpec\", True)" + "qgl1MainFunc = compile_function(\"../src/python/qgl2/basic_sequences/Rabi.py\", \"PulsedSpec\", (q, True))" ] }, { @@ -100,14 +116,11 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "# Now run the QGL1 function, producing a list of sequences\n", - "# Supply name of qubit from channel library, or omit to use a default\n", - "seqs = qgl1MainFunc(q=QubitFactory('q1'))" + "seqs = qgl1MainFunc()" ] }, { @@ -122,13 +135,11 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ - "fileNames = qgl2_compile_to_hardware(seqs, \"Spec/Spec\")\n", - "print(fileNames)" + "metaFileName = qgl2_compile_to_hardware(seqs, \"Spec/Spec\")\n", + "print(f\"Generated sequence details in '{metaFileName}'\")" ] }, { @@ -143,12 +154,10 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ - "plot_pulse_files(fileNames)" + "display(plot_pulse_files(metaFileName))" ] } ], @@ -168,9 +177,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.1" + "version": "3.7.3" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/notebooks/QGL2 RabiSingleShot.ipynb b/notebooks/QGL2 RabiSingleShot.ipynb index 489ed3e..bb95cd7 100644 --- a/notebooks/QGL2 RabiSingleShot.ipynb +++ b/notebooks/QGL2 RabiSingleShot.ipynb @@ -12,26 +12,25 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "from pyqgl2.main import compile_function, qgl2_compile_to_hardware\n", - "from QGL.ChannelLibrary import QubitFactory\n", - "from QGL.Plotting import output_notebook\n", - "from QGL.PulseSequencePlotter import plot_pulse_files" + "from pyqgl2.test_cl import create_default_channelLibrary\n", + "from pyqgl2.qreg import QRegister\n", + "from QGL import plot_pulse_files, ChannelLibrary" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ - "output_notebook()" + "# Compile to hardware or just to QGL pulse sequence?\n", + "toHW = False\n", + "# Create a test library (or load one)\n", + "create_default_channelLibrary(toHW, True)" ] }, { @@ -53,31 +52,45 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ - "#from pyqgl2.ast_util import NodeError\n", - "#from pyqgl2.debugmsg import DebugMsg\n", + "# from pyqgl2.ast_util import NodeError\n", + "# from pyqgl2.debugmsg import DebugMsg\n", "\n", - "#DebugMsg.set_level(1)\n", - "#NodeError.MUTE_ERR_LEVEL = NodeError.NODE_ERROR_NONE" + "# DebugMsg.set_level(1)\n", + "# NodeError.MUTE_ERR_LEVEL = NodeError.NODE_ERROR_NONE" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Generate a list of the arguments to the QGL2 function" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "qr = QRegister('q1')\n", + "args=(qr,)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "scrolled": true }, "outputs": [], "source": [ "# Insert proper path to QGL2 source and name of qgl2main if not so marked\n", "# Here we compile the named function in the named file from QGL2 to QGL1 and return the new function\n", "# True argument means save the QGL1 compiled function to a file\n", - "\n", - "qgl1MainFunc = compile_function(\"../src/python/qgl2/basic_sequences/RabiMin.py\", \"doSingleShot\", True)" + "qgl1MainFunc = compile_function(\"../src/python/qgl2/basic_sequences/Rabi.py\", \"SingleShot\", args, saveOutput=True)" ] }, { @@ -90,14 +103,12 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "# Now run the QGL1 function, producing a list of sequences\n", - "# Supply name of qubit from channel library, or omit to use a default\n", - "seqs = qgl1MainFunc(q=QubitFactory('q1'))" + "# QGL2 to QGL1 compiled functions take no arguments\n", + "seqs = qgl1MainFunc()" ] }, { @@ -110,9 +121,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "# import logging\n", @@ -127,40 +136,26 @@ "collapsed": true }, "source": [ - "## Compile to machine instructions" + "## Optionally compile to machine instructions" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false, "scrolled": false }, "outputs": [], "source": [ - "fileNames = qgl2_compile_to_hardware(seqs, \"SingleShot/SingleShot\")\n", - "print(fileNames)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "collapsed": true - }, - "source": [ - "## Plot the sequences" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "plot_pulse_files(fileNames)" + "if toHW:\n", + " metaFileName = qgl2_compile_to_hardware(seqs, \"SingleShot/SingleShot\")\n", + " print(f\"Generated sequence details in '{metaFileName}'\")\n", + " # Plot the sequences\n", + " display(plot_pulse_files(metaFileName))\n", + "else:\n", + " from QGL.Scheduler import schedule\n", + " from IPython.lib.pretty import pretty\n", + " print(pretty(schedule(seqs)))" ] } ], @@ -180,9 +175,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.1" + "version": "3.7.3" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/notebooks/QGL2 RabiWidth.ipynb b/notebooks/QGL2 RabiWidth.ipynb index 52708c4..1403a5f 100644 --- a/notebooks/QGL2 RabiWidth.ipynb +++ b/notebooks/QGL2 RabiWidth.ipynb @@ -12,9 +12,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "# Using phase=0, amp=0, shapeFun=tanh, length: 0 to 5e-6 in 11 steps" @@ -24,32 +22,55 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## imports" + "## Imports" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ - "from QGL.Plotting import output_notebook\n", - "from QGL.PulseSequencePlotter import plot_pulse_files\n", - "from QGL.ChannelLibrary import QubitFactory\n", - "from pyqgl2.main import compile_function, qgl2_compile_to_hardware" + "from pyqgl2.main import compile_function, qgl2_compile_to_hardware\n", + "from pyqgl2.test_cl import create_default_channelLibrary\n", + "from pyqgl2.qreg import QRegister\n", + "from QGL import plot_pulse_files, ChannelLibrary\n", + "import QGL.PulseShapes\n", + "import numpy as np" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Create a test ChannelLibrary" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ - "output_notebook()" + "create_default_channelLibrary(True, True)\n", + "# Alternatively could load an existing library, or create one here; see the 'AllXY' notebook" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create needed qubit(s)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# For QGL2, use a QRegister, not a QGL Qubit\n", + "q = QRegister(1)" ] }, { @@ -62,15 +83,15 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "# Insert proper path to QGL2 source and name of qgl2main if not so marked\n", "# Here we compile the named function in the named file from QGL2 to QGL1 and return the new function\n", "# True argument means save compiled QGL1 to file\n", - "qgl1MainFunc = compile_function(\"../src/python/qgl2/basic_sequences/RabiMin.py\", \"doRabiWidth\", True)" + "rWidthWidths = np.linspace(0, 5e-6, 11)\n", + "qgl1MainFunc = compile_function(\"../src/python/qgl2/basic_sequences/Rabi.py\", \"RabiWidth\", \n", + " (q, rWidthWidths, 1, 0, QGL.PulseShapes.tanh), saveOutput=True)" ] }, { @@ -83,14 +104,11 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "# Now run the QGL1 function, producing a list of sequences\n", - "# Supply name of qubit from channel library, or omit to use a default\n", - "seqs = qgl1MainFunc(q=QubitFactory('q1'))" + "seqs = qgl1MainFunc()" ] }, { @@ -103,13 +121,15 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ - "fileNames = qgl2_compile_to_hardware(seqs, \"Rabi/Rabi\")\n", - "print(fileNames)" + "from qgl2.basic_sequences.helpers import delay_descriptor\n", + "axis_desc = [delay_descriptor(rWidthWidths)]\n", + "label = \"Rabi\"\n", + "\n", + "metaFileName = qgl2_compile_to_hardware(seqs, filename=f\"{label}/{label}\", axis_descriptor=axis_desc)\n", + "print(f\"Generated sequence details in '{metaFileName}'\")" ] }, { @@ -124,12 +144,10 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ - "plot_pulse_files(fileNames)" + "display(plot_pulse_files(metaFileName))" ] } ], @@ -149,9 +167,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.1" + "version": "3.7.3" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/notebooks/QGL2 Ramsey.ipynb b/notebooks/QGL2 Ramsey.ipynb index 1592688..154545f 100644 --- a/notebooks/QGL2 Ramsey.ipynb +++ b/notebooks/QGL2 Ramsey.ipynb @@ -12,9 +12,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "# Using pulseSpacings=np.arange(100e-9, 10e-6, 100e-9); 100ns to 10us step by 100ns\n", @@ -25,32 +23,54 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## imports" + "## Imports" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ - "from QGL.Plotting import output_notebook\n", - "from QGL.PulseSequencePlotter import plot_pulse_files\n", - "from QGL.ChannelLibrary import QubitFactory\n", - "from pyqgl2.main import compile_function, qgl2_compile_to_hardware" + "from pyqgl2.main import compile_function, qgl2_compile_to_hardware\n", + "from pyqgl2.test_cl import create_default_channelLibrary\n", + "from pyqgl2.qreg import QRegister\n", + "from QGL import plot_pulse_files, ChannelLibrary\n", + "import numpy as np" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Create a test ChannelLibrary" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ - "output_notebook()" + "create_default_channelLibrary(True, True)\n", + "# Alternatively could load an existing library, or create one here; see the 'AllXY' notebook" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create needed qubit(s)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# For QGL2, use a QRegister, not a QGL Qubit\n", + "q = QRegister(1)" ] }, { @@ -65,9 +85,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "# Insert proper path to QGL2 source and name of qgl2main if not so marked\n", @@ -79,12 +97,14 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false, "scrolled": true }, "outputs": [], "source": [ - "qgl1MainFunc = compile_function(\"../src/python/qgl2/basic_sequences/T1T2Min.py\", \"doRamsey\", True)" + "rSpacings = np.linspace(0, 5e-6, 11)\n", + "tCalR = 2\n", + "qgl1MainFunc = compile_function(\"../src/python/qgl2/basic_sequences/T1T2.py\", \"Ramsey\", \n", + " (q,rSpacings, 0, tCalR), saveOutput=True)" ] }, { @@ -97,14 +117,11 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "# Now run the QGL1 function, producing a list of sequences\n", - "# Supply name of qubit from channel library, or omit to use a default\n", - "seqs = qgl1MainFunc(q=QubitFactory('q1'))" + "seqs = qgl1MainFunc()" ] }, { @@ -119,14 +136,20 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ - "# True filename optionally is Ramsey_q1/Ramsey_q1 where q1 is the qubit label\n", - "fileNames = qgl2_compile_to_hardware(seqs, \"Ramsey/Ramsey\")\n", - "print(fileNames)" + "from qgl2.basic_sequences.helpers import delay_descriptor, cal_descriptor\n", + "axis_desc = [ \n", + " delay_descriptor(rSpacings),\n", + " cal_descriptor(('qubit',), tCalR)\n", + "]\n", + "label = \"Ramsey\"\n", + "# Include the qbit name in the filename\n", + "label += \"_q1\"\n", + "\n", + "metaFileName = qgl2_compile_to_hardware(seqs, filename=f\"{label}/{label}\", axis_descriptor=axis_desc)\n", + "print(f\"Generated sequence details in '{metaFileName}'\")" ] }, { @@ -142,12 +165,11 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false, "scrolled": true }, "outputs": [], "source": [ - "plot_pulse_files(fileNames)" + "display(plot_pulse_files(metaFileName))" ] } ], @@ -167,9 +189,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.1" + "version": "3.7.3" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 }