Skip to content

Commit

Permalink
Issue #38: update the sample notebooks to work with this code
Browse files Browse the repository at this point in the history
  • Loading branch information
ahelsing committed Sep 26, 2019
1 parent c912ee3 commit 2fafcfa
Show file tree
Hide file tree
Showing 10 changed files with 688 additions and 569 deletions.
152 changes: 89 additions & 63 deletions notebooks/QGL2 AllXY.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
]
},
{
Expand All @@ -77,9 +121,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"#from pyqgl2.ast_util import NodeError\n",
Expand All @@ -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,))"
]
},
{
Expand All @@ -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()"
]
},
{
Expand All @@ -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": []
}
Expand All @@ -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
}
Loading

0 comments on commit 2fafcfa

Please sign in to comment.