Skip to content

Commit

Permalink
RabiAmp example
Browse files Browse the repository at this point in the history
Revised example of compiling RabiAmp on a qreg
  • Loading branch information
Diego Ristè committed Jun 8, 2017
1 parent 0e7e8e8 commit a199816
Showing 1 changed file with 116 additions and 16 deletions.
132 changes: 116 additions & 16 deletions notebooks/QGL2 RabiAmp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,36 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### imports"
"## Imports"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
"collapsed": false
},
"outputs": [],
"source": [
"from pyqgl2.main import compile_function, qgl2_compile_to_hardware\n",
"from pyqgl2.main import compile_function, 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 QGL import QubitFactory\n",
"from pyqgl2.qreg import QRegister\n",
"import numpy as np\n",
"import os"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"seqpath = \"../src/python/qgl2/basic_sequences\""
]
},
{
Expand Down Expand Up @@ -67,40 +81,61 @@
"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 function\n",
"# intermediate_output option saves to the specified file"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Uncomment below for debugging"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"scrolled": true
"collapsed": true
},
"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"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"qgl1MainFunc = compile_function(\"../src/python/qgl2/basic_sequences/RabiMin.py\", \"doRabiAmp\", True)"
"qR = QRegister('q1','q2')\n",
"amps = np.linspace(0,1,11)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Generate pulse sequences"
"## Compile function from file"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": false,
"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'))"
"seqs = compile_function(os.path.join(seqpath, \"RabiMin.py\"), \"doRabiAmp\", (qR, amps, 0), intermediate_output=\"debug.txt\")()"
]
},
{
Expand All @@ -121,7 +156,72 @@
},
"outputs": [],
"source": [
"fileNames = qgl2_compile_to_hardware(seqs, \"Rabi/Rabi\")"
"fileNames = compile_to_hardware(seqs, \"Rabi/Rabi\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Alternative: Write to file and compile\n",
"Define sequences on the fly in this notebook. First, a file needs to be created with the required imports. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"if not os.path.exists('../user_seqs'):\n",
" os.mkdir('../user_seqs')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%%writefile ../user_seqs/my_seqs.py\n",
"from qgl2.qgl2 import qgl2decl, qreg, QRegister\n",
"from qgl2.qgl1 import Utheta, MEAS, X, Id\n",
"from qgl2.util import init\n",
"import qgl2.basic_sequences.pulses"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%%writefile -a ../user_seqs/my_seqs.py\n",
"\n",
"\n",
"@qgl2decl\n",
"def test(q:qreg, amps, phase):\n",
" for amp in amps:\n",
" init(q)\n",
" Id(q, amp=amp, phase=phase)\n",
" MEAS(q)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"seqs = compile_function(\"../user_seqs/my_seqs.py\", \"test\", (qR, amps, 0))()"
]
},
{
Expand Down Expand Up @@ -160,7 +260,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
"version": "3.6.0"
}
},
"nbformat": 4,
Expand Down

0 comments on commit a199816

Please sign in to comment.