{ "cells": [ { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "# Example for qutrit GST\n", "This notebook demonstrates how to construct the gate sequences and perform the analysis for qutrit GST when the gate set consists of symmetric $\\pi/2$-rotations on each single qubit separately, `X`, `Y` and a 2-qubit Molmer-Sorenson gate which rotates around the `XX` axis by $\\pi/2$." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [ "import pygsti\n", "import pygsti.construction as pc\n", "from pygsti.construction import qutrit\n", "\n", "from numpy import pi, array\n", "import pickle\n", "\n", "import numpy as np" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "First, we construct the target gate set. This functionality is built into pyGSTi, so we just need to specify the single-qubit and M-S angles." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [ "gs_target = qutrit.make_qutrit_gateset(errorScale=0, Xangle=pi/2, Yangle=pi/2, MSglobal=pi/2, MSlocal=0, basis=\"qt\")\n", "#print(gs_target)" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "Now construct the gate sequences needed by GST. These fiducials and germs have been computed ahead of time and the results are used to construct the gate string lists below. Then we construct an empty dataset containing all of the necessary experimental sequences which can serve as a template for the actual experimental results." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [ "fiducialPrep = pc.gatestring_list(\n", " [(),('Gy',),('Gx',),('Gm',),\n", " ('Gx','Gx'), ('Gm','Gy'),('Gm','Gx'),\n", " ('Gy','Gy','Gy'),('Gx','Gx','Gx')])\n", "\n", "fiducialMeasure = pc.gatestring_list(\n", " [(),('Gy',),('Gx',),('Gm',),\n", " ('Gy','Gm'),('Gx','Gm')])\n", "\n", "maxLengths = [1,2,4]\n", "\n", "germs = pygsti.construction.gatestring_list(\n", "[('Gi',),\n", " ('Gy',),\n", " ('Gx',),\n", " ('Gm',),\n", " ('Gi', 'Gy'),\n", " ('Gi', 'Gx'),\n", " ('Gi', 'Gm'),\n", " ('Gy', 'Gx'),\n", " ('Gy', 'Gm'),\n", " ('Gx', 'Gm'),\n", " ('Gi', 'Gi', 'Gy'),\n", " ('Gi', 'Gi', 'Gx'),\n", " ('Gi', 'Gi', 'Gm'),\n", " ('Gi', 'Gy', 'Gy'),\n", " ('Gi', 'Gy', 'Gx'),\n", " ('Gi', 'Gy', 'Gm'),\n", " ('Gi', 'Gx', 'Gy'),\n", " ('Gi', 'Gx', 'Gx'),\n", " ('Gi', 'Gx', 'Gm'),\n", " ('Gi', 'Gm', 'Gy'),\n", " ('Gi', 'Gm', 'Gx'),\n", " ('Gi', 'Gm', 'Gm'),\n", " ('Gy', 'Gy', 'Gx'),\n", " ('Gy', 'Gy', 'Gm'),\n", " ('Gy', 'Gx', 'Gx'),\n", " ('Gy', 'Gx', 'Gm'),\n", " ('Gy', 'Gm', 'Gx'),\n", " ('Gy', 'Gm', 'Gm'),\n", " ('Gx', 'Gx', 'Gm'),\n", " ('Gx', 'Gm', 'Gm')])" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [ "#Note above construction is now a \"standard\" qutrit gateset\n", "from pygsti.construction import stdQT_XYIMS\n", "gs_target = stdQT_XYIMS.gs_target\n", "fiducialPrep = stdQT_XYIMS.prepStrs\n", "fiducialMeasure = stdQT_XYIMS.effectStrs\n", "germs = stdQT_XYIMS.germs_lite\n", "maxLengths = [1,2,4]" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "9 prep fiducials\n", "7 meas fiducials\n", "31 germs\n" ] } ], "source": [ "print(\"%d prep fiducials\" % len(fiducialPrep))\n", "print(\"%d meas fiducials\" % len(fiducialMeasure))\n", "print(\"%d germs\" % len(germs))" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [ "#generate data template\n", "expList = pygsti.construction.make_lsgst_experiment_list(gs_target.gates.keys(), fiducialPrep, fiducialMeasure, germs, maxLengths)\n", "pygsti.io.write_empty_dataset(\"example_files/dataTemplate_qutrit_maxL=4.txt\", expList, \"## Columns = 0bright count, 1bright count, 2bright count\")" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true, "deletable": true, "editable": true }, "source": [ "At this point **STOP** and create/fill a dataset file using the template written in the above cell. Then proceed with the lines below to run GST on the data and create (hopefully useful) reports telling you about your gates." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [ "gs_datagen = gs_target.depolarize(gate_noise=0.05)\n", "DS = pygsti.construction.generate_fake_data(gs_datagen, expList, 500, sampleError='multinomial', seed=2018)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [ "#DS = pygsti.io.load_dataset('PATH_TO_YOUR_DATASET',cache=True) # (cache=True speeds up future loads)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false, "deletable": true, "editable": true, "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-- Std Practice: Iter 1 of 2 (TP) --: \n", " --- Gate Sequence Creation ---\n", " --- LGST ---\n", " --- Iterative MLGST: [##################################################] 100.0% 2017 gate strings ---\n", " Iterative MLGST Total Time: 113.0s\n", " -- Performing 'single' gauge optimization on TP estimate --\n", "-- Std Practice: Iter 2 of 2 (CPTP) --: \n", " --- Gate Sequence Creation ---\n", " --- Iterative MLGST: [##################################################] 100.0% 2017 gate strings ---\n", " Iterative MLGST Total Time: 911.3s\n", " -- Performing 'single' gauge optimization on CPTP estimate --\n" ] } ], "source": [ "#Run qutrit GST... which could take a while on a single CPU. Please adjust memLimit to machine specs \n", "# (now 3GB; usually set to slightly less than the total machine memory)\n", "result = pygsti.do_stdpractice_gst(DS,gs_target,fiducialPrep,fiducialMeasure,germs,maxLengths,\n", " verbosity=2, comm=None, memLimit=3*(1024)**3, modes=\"TP,CPTP\")" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "*** Creating workspace ***\n", "*** Generating switchboard ***\n", "*** Generating tables ***\n", " targetSpamBriefTable took 1.130184 seconds\n", " targetGatesBoxTable took 0.768596 seconds\n", " datasetOverviewTable took 0.15751 seconds\n", " bestGatesetSpamParametersTable took 0.00211 seconds\n", " bestGatesetSpamBriefTable took 1.348534 seconds\n", " bestGatesetSpamVsTargetTable took 0.976345 seconds\n", " bestGatesetGaugeOptParamsTable took 0.001051 seconds\n", " bestGatesetGatesBoxTable took 1.661451 seconds\n", " bestGatesetChoiEvalTable took 1.922052 seconds\n", " bestGatesetDecompTable took 37.690038 seconds\n", " bestGatesetEvalTable took 0.030987 seconds\n", " bestGermsEvalTable took 0.191243 seconds\n", " bestGatesetVsTargetTable took 0.230642 seconds\n", " bestGatesVsTargetTable_gv took 4.512879 seconds\n", " bestGatesVsTargetTable_gvgerms took 1.414876 seconds\n", " bestGatesVsTargetTable_gi took 0.116063 seconds\n", " bestGatesVsTargetTable_gigerms took 0.228211 seconds\n", " bestGatesVsTargetTable_sum took 3.921726 seconds\n", " bestGatesetErrGenBoxTable took 3.824554 seconds\n", " metadataTable took 0.00292 seconds\n", " stdoutBlock took 0.000265 seconds\n", " profilerTable took 0.001611 seconds\n", " softwareEnvTable took 0.047045 seconds\n", " exampleTable took 0.103485 seconds\n", " singleMetricTable_gv took 4.093062 seconds\n", " singleMetricTable_gi took 0.181159 seconds\n", " fiducialListTable took 0.001412 seconds\n", " prepStrListTable took 0.000414 seconds\n", " effectStrListTable took 0.00038 seconds\n", " colorBoxPlotKeyPlot took 0.154182 seconds\n", " germList2ColTable took 0.00132 seconds\n", " progressTable took 4.296712 seconds\n", "*** Generating plots ***\n", " gramBarPlot took 0.400508 seconds\n", " progressBarPlot took 5.252052 seconds\n", " progressBarPlot_sum took 0.000994 seconds\n", " finalFitComparePlot took 3.52889 seconds\n", " bestEstimateColorBoxPlot took 19.502516 seconds\n", " bestEstimateTVDColorBoxPlot took 18.337428 seconds\n", " bestEstimateColorScatterPlot took 16.526874 seconds\n", " bestEstimateColorHistogram took 9.821597 seconds\n", " progressTable_scl took 9.8e-05 seconds\n", " progressBarPlot_scl took 8.4e-05 seconds\n", " bestEstimateColorBoxPlot_scl took 0.000144 seconds\n", " bestEstimateColorScatterPlot_scl took 0.000239 seconds\n", " bestEstimateColorHistogram_scl took 0.00025 seconds\n", " dataScalingColorBoxPlot took 0.000119 seconds\n", "*** Merging into template file ***\n", " Rendering topSwitchboard took 0.000114 seconds\n", " Rendering maxLSwitchboard1 took 9.5e-05 seconds\n", " Rendering targetSpamBriefTable took 0.023726 seconds\n", " Rendering targetGatesBoxTable took 0.021159 seconds\n", " Rendering datasetOverviewTable took 0.000592 seconds\n", " Rendering bestGatesetSpamParametersTable took 0.003677 seconds\n", " Rendering bestGatesetSpamBriefTable took 0.042857 seconds\n", " Rendering bestGatesetSpamVsTargetTable took 0.003735 seconds\n", " Rendering bestGatesetGaugeOptParamsTable took 0.00167 seconds\n", " Rendering bestGatesetGatesBoxTable took 0.041176 seconds\n", " Rendering bestGatesetChoiEvalTable took 0.032225 seconds\n", " Rendering bestGatesetDecompTable took 0.03117 seconds\n", " Rendering bestGatesetEvalTable took 0.051789 seconds\n", " Rendering bestGermsEvalTable took 0.378753 seconds\n", " Rendering bestGatesetVsTargetTable took 0.001501 seconds\n", " Rendering bestGatesVsTargetTable_gv took 0.010799 seconds\n", " Rendering bestGatesVsTargetTable_gvgerms took 0.03754 seconds\n", " Rendering bestGatesVsTargetTable_gi took 0.00664 seconds\n", " Rendering bestGatesVsTargetTable_gigerms took 0.015202 seconds\n", " Rendering bestGatesVsTargetTable_sum took 0.008159 seconds\n", " Rendering bestGatesetErrGenBoxTable took 0.07702 seconds\n", " Rendering metadataTable took 0.006746 seconds\n", " Rendering stdoutBlock took 0.001322 seconds\n", " Rendering profilerTable took 0.002831 seconds\n", " Rendering softwareEnvTable took 0.002716 seconds\n", " Rendering exampleTable took 0.004072 seconds\n", " Rendering metricSwitchboard_gv took 4.2e-05 seconds\n", " Rendering metricSwitchboard_gi took 5.8e-05 seconds\n", " Rendering singleMetricTable_gv took 0.014893 seconds\n", " Rendering singleMetricTable_gi took 0.010027 seconds\n", " Rendering fiducialListTable took 0.004187 seconds\n", " Rendering prepStrListTable took 0.002783 seconds\n", " Rendering effectStrListTable took 0.002927 seconds\n", " Rendering colorBoxPlotKeyPlot took 0.003678 seconds\n", " Rendering germList2ColTable took 0.006353 seconds\n", " Rendering progressTable took 0.006161 seconds\n", " Rendering gramBarPlot took 0.004022 seconds\n", " Rendering progressBarPlot took 0.0052 seconds\n", " Rendering progressBarPlot_sum took 0.004971 seconds\n", " Rendering finalFitComparePlot took 0.003096 seconds\n", " Rendering bestEstimateColorBoxPlot took 0.111234 seconds\n", " Rendering bestEstimateTVDColorBoxPlot took 0.111954 seconds\n", " Rendering bestEstimateColorScatterPlot took 0.106989 seconds\n", " Rendering bestEstimateColorHistogram took 0.062671 seconds\n", " Rendering progressTable_scl took 0.00085 seconds\n", " Rendering progressBarPlot_scl took 0.000946 seconds\n", " Rendering bestEstimateColorBoxPlot_scl took 0.000865 seconds\n", " Rendering bestEstimateColorScatterPlot_scl took 0.000801 seconds\n", " Rendering bestEstimateColorHistogram_scl took 0.001342 seconds\n", " Rendering dataScalingColorBoxPlot took 0.001253 seconds\n", "Output written to example_files/sampleQutritReport directory\n", "Opening example_files/sampleQutritReport/main.html...\n", "*** Report Generation Complete! Total time 145.062s ***\n" ] } ], "source": [ "#Create a report\n", "ws = pygsti.report.create_standard_report(result, \"example_files/sampleQutritReport\",\n", " \"Example Qutrit Report\", verbosity=3, auto_open=True)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Qutrit Basis : II, X+Y, X-Y, YZ, IX, IY, IZ, XY, XZ\n" ] } ], "source": [ "print(gs_target.basis)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "deletable": true, "editable": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.4" } }, "nbformat": 4, "nbformat_minor": 0 }