{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Example for qutrit GST\n", "This notebook demonstrates how to construct the operation sequences and perform the analysis for qutrit GST when the model 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": {}, "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": {}, "source": [ "First, we construct the target model. 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": {}, "outputs": [], "source": [ "target_model = qutrit.make_qutrit_model(errorScale=0, Xangle=pi/2, Yangle=pi/2, MSglobal=pi/2, MSlocal=0, basis=\"qt\")\n", "#print(target_model)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now construct the operation sequences needed by GST. These fiducials and germs have been computed ahead of time and the results are used to construct the operation sequence 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": {}, "outputs": [], "source": [ "fiducialPrep = pc.circuit_list(\n", " [(),('Gy',),('Gx',),('Gm',),\n", " ('Gx','Gx'), ('Gm','Gy'),('Gm','Gx'),\n", " ('Gy','Gy','Gy'),('Gx','Gx','Gx')])\n", "\n", "fiducialMeasure = pc.circuit_list(\n", " [(),('Gy',),('Gx',),('Gm',),\n", " ('Gy','Gm'),('Gx','Gm')])\n", "\n", "maxLengths = [1,2,4]\n", "\n", "germs = pygsti.construction.circuit_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": {}, "outputs": [], "source": [ "#Note above construction is now a \"standard\" qutrit model\n", "from pygsti.construction import stdQT_XYIMS\n", "target_model = stdQT_XYIMS.target_model()\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": {}, "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": {}, "outputs": [], "source": [ "#generate data template\n", "expList = pygsti.construction.make_lsgst_experiment_list(target_model.operations.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 }, "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": {}, "outputs": [], "source": [ "mdl_datagen = target_model.depolarize(op_noise=0.05)\n", "DS = pygsti.construction.generate_fake_data(mdl_datagen, expList, 500, sampleError='multinomial', seed=2018)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "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": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-- Std Practice: Iter 1 of 2 (TP) --: \n", " --- Circuit Creation ---\n", " --- LGST ---\n", " --- Iterative MLGST: [##################################################] 100.0% 2017 operation sequences ---\n", " Iterative MLGST Total Time: 33.1s\n", " -- Performing 'single' gauge optimization on TP estimate --\n", "-- Std Practice: Iter 2 of 2 (CPTP) --: \n", " --- Circuit Creation ---\n", " --- Iterative MLGST: [##################################################] 100.0% 2017 operation sequences ---\n", " Iterative MLGST Total Time: 586.1s\n", " --- Re-optimizing logl after robust data scaling ---\n", " -- Performing 'single' gauge optimization on CPTP estimate --\n", " -- Conveying 'single' gauge optimization to CPTP.Robust+ 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,target_model,fiducialPrep,fiducialMeasure,germs,maxLengths,\n", " verbosity=2, comm=None, memLimit=3*(1024)**3, modes=\"TP,CPTP\")" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "*** Creating workspace ***\n", "*** Generating switchboard ***\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/Users/enielse/research/pyGSTi/packages/pygsti/report/factory.py:785: UserWarning:\n", "\n", "Idle tomography failed:\n", "Label{layers}\n", "\n", "/Users/enielse/research/pyGSTi/packages/pygsti/objects/operation.py:967: ComplexWarning:\n", "\n", "Casting complex values to real discards the imaginary part\n", "\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "*** Generating tables ***\n", " targetSpamBriefTable took 0.948642 seconds\n", " targetGatesBoxTable took 0.408834 seconds\n", " datasetOverviewTable took 0.12006 seconds\n", " bestGatesetSpamParametersTable took 0.001933 seconds\n", " bestGatesetSpamBriefTable took 1.165074 seconds\n", " bestGatesetSpamVsTargetTable took 0.67162 seconds\n", " bestGatesetGaugeOptParamsTable took 0.001592 seconds\n", " bestGatesetGatesBoxTable took 0.960349 seconds\n", " bestGatesetChoiEvalTable took 1.359139 seconds\n", " bestGatesetDecompTable took 32.569516 seconds\n", " bestGatesetEvalTable took 0.028175 seconds\n", " bestGermsEvalTable took 0.680471 seconds\n", " bestGatesetVsTargetTable took 0.011108 seconds\n", " bestGatesVsTargetTable_gv took 2.653336 seconds\n", " bestGatesVsTargetTable_gvgerms took 3.52283 seconds\n", " bestGatesVsTargetTable_gi took 0.083563 seconds\n", " bestGatesVsTargetTable_gigerms took 1.005465 seconds\n", " bestGatesVsTargetTable_sum took 2.513654 seconds\n", " bestGatesetErrGenBoxTable took 2.718083 seconds\n", " metadataTable took 0.002088 seconds\n", " stdoutBlock took 0.000354 seconds\n", " profilerTable took 0.002132 seconds\n", " softwareEnvTable took 0.059882 seconds\n", " exampleTable took 0.073524 seconds\n", " singleMetricTable_gv took 1.809641 seconds\n", " singleMetricTable_gi took 0.061872 seconds\n", " fiducialListTable took 0.000658 seconds\n", " prepStrListTable took 0.00024 seconds\n", " effectStrListTable took 0.000194 seconds\n", " colorBoxPlotKeyPlot took 0.251883 seconds\n", " germList2ColTable took 0.000432 seconds\n", " progressTable took 3.431832 seconds\n", "*** Generating plots ***\n", " gramBarPlot took 0.109183 seconds\n", " progressBarPlot took 0.375818 seconds\n", " progressBarPlot_sum took 0.000835 seconds\n", " finalFitComparePlot took 0.144866 seconds\n", " bestEstimateColorBoxPlot took 12.789732 seconds\n", " bestEstimateTVDColorBoxPlot took 11.530546 seconds\n", " bestEstimateColorScatterPlot took 13.806537 seconds\n", " bestEstimateColorHistogram took 11.955992 seconds\n", " progressTable_scl took 1.511275 seconds\n", " progressBarPlot_scl took 0.232363 seconds\n", " bestEstimateColorBoxPlot_scl took 6.033762 seconds\n", " bestEstimateColorScatterPlot_scl took 6.666415 seconds\n", " bestEstimateColorHistogram_scl took 5.965612 seconds\n", " dataScalingColorBoxPlot took 0.137673 seconds\n", "*** Merging into template file ***\n", " Rendering topSwitchboard took 0.000134 seconds\n", " Rendering maxLSwitchboard1 took 7.6e-05 seconds\n", " Rendering targetSpamBriefTable took 0.098134 seconds\n", " Rendering targetGatesBoxTable took 0.085305 seconds\n", " Rendering datasetOverviewTable took 0.001947 seconds\n", " Rendering bestGatesetSpamParametersTable took 0.00314 seconds\n", " Rendering bestGatesetSpamBriefTable took 0.379709 seconds\n", " Rendering bestGatesetSpamVsTargetTable took 0.002969 seconds\n", " Rendering bestGatesetGaugeOptParamsTable took 0.002197 seconds\n", " Rendering bestGatesetGatesBoxTable took 0.38997 seconds\n", " Rendering bestGatesetChoiEvalTable took 0.318637 seconds\n", " Rendering bestGatesetDecompTable took 0.213322 seconds\n", " Rendering bestGatesetEvalTable took 0.042549 seconds\n", " Rendering bestGermsEvalTable took 0.320558 seconds\n", " Rendering bestGatesetVsTargetTable took 0.00131 seconds\n", " Rendering bestGatesVsTargetTable_gv took 0.005009 seconds\n", " Rendering bestGatesVsTargetTable_gvgerms took 0.014515 seconds\n", " Rendering bestGatesVsTargetTable_gi took 0.005062 seconds\n", " Rendering bestGatesVsTargetTable_gigerms took 0.010149 seconds\n", " Rendering bestGatesVsTargetTable_sum took 0.004553 seconds\n", " Rendering bestGatesetErrGenBoxTable took 1.01326 seconds\n", " Rendering metadataTable took 0.004815 seconds\n", " Rendering stdoutBlock took 0.001379 seconds\n", " Rendering profilerTable took 0.002674 seconds\n", " Rendering softwareEnvTable took 0.002272 seconds\n", " Rendering exampleTable took 0.021317 seconds\n", " Rendering metricSwitchboard_gv took 7e-05 seconds\n", " Rendering metricSwitchboard_gi took 4.4e-05 seconds\n", " Rendering singleMetricTable_gv took 0.008173 seconds\n", " Rendering singleMetricTable_gi took 0.007073 seconds\n", " Rendering fiducialListTable took 0.003428 seconds\n", " Rendering prepStrListTable took 0.002495 seconds\n", " Rendering effectStrListTable took 0.002131 seconds\n", " Rendering colorBoxPlotKeyPlot took 0.024398 seconds\n", " Rendering germList2ColTable took 0.010392 seconds\n", " Rendering progressTable took 0.005172 seconds\n", " Rendering gramBarPlot took 0.020919 seconds\n", " Rendering progressBarPlot took 0.037914 seconds\n", " Rendering progressBarPlot_sum took 0.038827 seconds\n", " Rendering finalFitComparePlot took 0.016507 seconds\n", " Rendering bestEstimateColorBoxPlot took 0.217022 seconds\n", " Rendering bestEstimateTVDColorBoxPlot took 0.210556 seconds\n", " Rendering bestEstimateColorScatterPlot took 0.358414 seconds\n", " Rendering bestEstimateColorHistogram took 0.203399 seconds\n", " Rendering progressTable_scl took 0.002996 seconds\n", " Rendering progressBarPlot_scl took 0.020068 seconds\n", " Rendering bestEstimateColorBoxPlot_scl took 0.113779 seconds\n", " Rendering bestEstimateColorScatterPlot_scl took 0.18969 seconds\n", " Rendering bestEstimateColorHistogram_scl took 0.102361 seconds\n", " Rendering dataScalingColorBoxPlot took 0.056695 seconds\n", "Output written to example_files/sampleQutritReport directory\n", "Opening example_files/sampleQutritReport/main.html...\n", "*** Report Generation Complete! Total time 134.806s ***\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": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Qutrit Basis : (no labels computed yet)\n" ] } ], "source": [ "print(target_model.basis)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "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.7.0" } }, "nbformat": 4, "nbformat_minor": 1 }