{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# An overview of Gate Set Tomography" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `pygsti` package provides multiple levels of abstraction over the core Gate Set Tomography (GST) algorithms. This tutorial will show you how to run Gate Set Tomography on some simulated (generated) data, hopefully giving you an overall sense of what it takes (and how easy it is!) to run GST. For more details and options for running GST, see the [GST circuits tutorial](../objects/advanced/GSTCircuitConstruction.ipynb) and the [tutorial covering the different pyGSTi functions for running GST](GST-Drivers.ipynb).\n", "\n", "To run GST, we need three inputs:\n", "1. a \"**target model**\" which describes the desired, or ideal, operations we want our experimental hardware to perform. In the example below, we use one of pyGSTi's \"standard\" models (see the [tutorial on standard modules](objects/advanced/StandardModules.ipynb)) - which acts on a single qubit with the following operations:\n", " - three gates: the identity, and $\\pi/2$ rotations around the $x$- and $y$-axes.\n", " - a single state preparation in the $|0\\rangle$ state.\n", " - a 2-outcome measurement with the label \"0\" associated with measuring $|0\\rangle$ and \"1\" with measuring $|1\\rangle$.\n", " \n", "2. a list of circuits tailored to the target model; essentially a list of what experiments we need to run. Using a standard model makes things especially straightforward here, since the building blocks, called *germ* and *fiducial* circuits, needed to make good GST circuits have already been computed (see the [tutorial on GST circuits](../objects/advanced/GSTCircuitConstruction.ipynb)).\n", "\n", "3. data, in the form of experimental outcome counts, for each of the required sequences. In this example we'll generate \"fake\" or \"simulated\" data from a depolarized version of our ideal model. For more information about `DataSet` objects, see the [tutorial on DataSets](../objects/DataSet.ipynb).\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "#Make print statements compatible with Python 2 and 3\n", "from __future__ import print_function\n", "\n", "#Import the pygsti module (always do this) and the standard XYI model\n", "import pygsti\n", "from pygsti.construction import std1Q_XYI\n", "\n", "# 1) get the target Model\n", "target_model = std1Q_XYI.target_model()\n", "\n", "# 2) get the building blocks needed to specify which operation sequences are needed\n", "prep_fiducials, meas_fiducials = std1Q_XYI.prepStrs, std1Q_XYI.effectStrs\n", "germs = std1Q_XYI.germs\n", "maxLengths = [1,2,4,8,16,32] # roughly gives the length of the sequences used by GST\n", "\n", "# 3) generate \"fake\" data from a depolarized version of target_model\n", "mdl_datagen = target_model.depolarize(op_noise=0.01, spam_noise=0.001)\n", "listOfExperiments = pygsti.construction.make_lsgst_experiment_list(\n", " target_model, prep_fiducials, meas_fiducials, germs, maxLengths)\n", "ds = pygsti.construction.generate_fake_data(mdl_datagen, listOfExperiments, nSamples=1000,\n", " sampleError=\"binomial\", seed=1234)\n", "\n", "#Note: from listOfExperiments we can also create an empty dataset file\n", "# which has columns of zeros where actual data should go. \n", "pygsti.io.write_empty_dataset(\"../tutorial_files/GettingStartedDataTemplate.txt\", listOfExperiments,\n", " \"## Columns = 0 count, 1 count\")\n", "# After replacing the zeros with actual data, the data set can be \n", "# loaded back into pyGSTi using the line below and used in the rest\n", "# of this tutorial. \n", "#ds = pygsti.io.load_dataset(\"tutorial_files/GettingStartedDataTemplate.txt\")\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now that we have all of the inputs, we can run GST in a standard way using the `do_stdpractice_gst` function. For more information about this and related functions, see the [GST methods tutorial](GST-Drivers.ipynb). This returns a `pygsti.report.Results` object (see the [Results tutorial](../objects/advanced/Results.ipynb)), from which we can generate a report giving us a summary of the analysis. " ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-- Std Practice: Iter 1 of 3 (TP) --: \n", " --- Circuit Creation ---\n", " 1702 sequences created\n", " Dataset has 1702 entries: 1702 utilized, 0 requested sequences were missing\n", " --- LGST ---\n", " Singular values of I_tilde (truncating to first 4 of 6) = \n", " 4.243095501422058\n", " 1.3901808798412303\n", " 1.366465649836718\n", " 1.345711384664332\n", " 0.024975111125949443\n", " 0.006813806654669674\n", " \n", " Singular values of target I_tilde (truncating to first 4 of 6) = \n", " 4.242640687119286\n", " 1.414213562373096\n", " 1.4142135623730956\n", " 1.4142135623730954\n", " 2.5038933168948026e-16\n", " 2.023452063009528e-16\n", " \n", " --- Iterative MLGST: Iter 1 of 6 92 operation sequences ---: \n", " --- Minimum Chi^2 GST ---\n", " Sum of Chi^2 = 81.6754 (92 data params - 31 model params = expected mean of 61; p-value = 0.0397842)\n", " Completed in 0.2s\n", " 2*Delta(log(L)) = 82.4971\n", " Iteration 1 took 0.2s\n", " \n", " --- Iterative MLGST: Iter 2 of 6 168 operation sequences ---: \n", " --- Minimum Chi^2 GST ---\n", " Sum of Chi^2 = 145.571 (168 data params - 31 model params = expected mean of 137; p-value = 0.292027)\n", " Completed in 0.1s\n", " 2*Delta(log(L)) = 147.471\n", " Iteration 2 took 0.1s\n", " \n", " --- Iterative MLGST: Iter 3 of 6 450 operation sequences ---: \n", " --- Minimum Chi^2 GST ---\n", " Sum of Chi^2 = 440.19 (450 data params - 31 model params = expected mean of 419; p-value = 0.228755)\n", " Completed in 0.3s\n", " 2*Delta(log(L)) = 445.072\n", " Iteration 3 took 0.4s\n", " \n", " --- Iterative MLGST: Iter 4 of 6 862 operation sequences ---: \n", " --- Minimum Chi^2 GST ---\n", " Sum of Chi^2 = 883.073 (862 data params - 31 model params = expected mean of 831; p-value = 0.102429)\n", " Completed in 0.5s\n", " 2*Delta(log(L)) = 890.914\n", " Iteration 4 took 0.5s\n", " \n", " --- Iterative MLGST: Iter 5 of 6 1282 operation sequences ---: \n", " --- Minimum Chi^2 GST ---\n", " Sum of Chi^2 = 1310.35 (1282 data params - 31 model params = expected mean of 1251; p-value = 0.118708)\n", " Completed in 0.8s\n", " 2*Delta(log(L)) = 1318.52\n", " Iteration 5 took 0.9s\n", " \n", " --- Iterative MLGST: Iter 6 of 6 1702 operation sequences ---: \n", " --- Minimum Chi^2 GST ---\n", " Sum of Chi^2 = 1719.42 (1702 data params - 31 model params = expected mean of 1671; p-value = 0.200152)\n", " Completed in 1.2s\n", " 2*Delta(log(L)) = 1727.85\n", " Iteration 6 took 1.2s\n", " \n", " Switching to ML objective (last iteration)\n", " --- MLGST ---\n", " Maximum log(L) = 862.67 below upper bound of -2.63408e+06\n", " 2*Delta(log(L)) = 1725.34 (1702 data params - 31 model params = expected mean of 1671; p-value = 0.173228)\n", " Completed in 0.5s\n", " 2*Delta(log(L)) = 1725.34\n", " Final MLGST took 0.5s\n", " \n", " Iterative MLGST Total Time: 3.8s\n", " -- Performing 'single' gauge optimization on TP estimate --\n", "-- Std Practice: Iter 2 of 3 (CPTP) --: \n", " --- Circuit Creation ---\n", " 1702 sequences created\n", " Dataset has 1702 entries: 1702 utilized, 0 requested sequences were missing\n", " --- Iterative MLGST: Iter 1 of 6 92 operation sequences ---: \n", " --- Minimum Chi^2 GST ---\n", " Sum of Chi^2 = 86.2545 (92 data params - 31 model params = expected mean of 61; p-value = 0.0183576)\n", " Completed in 98.0s\n", " 2*Delta(log(L)) = 87.4462\n", " Iteration 1 took 98.1s\n", " \n", " --- Iterative MLGST: Iter 2 of 6 168 operation sequences ---: \n", " --- Minimum Chi^2 GST ---\n", " Sum of Chi^2 = 146.49 (168 data params - 31 model params = expected mean of 137; p-value = 0.274036)\n", " Completed in 3.0s\n", " 2*Delta(log(L)) = 148.699\n", " Iteration 2 took 3.0s\n", " \n", " --- Iterative MLGST: Iter 3 of 6 450 operation sequences ---: \n", " --- Minimum Chi^2 GST ---\n", " Sum of Chi^2 = 440.728 (450 data params - 31 model params = expected mean of 419; p-value = 0.223352)\n", " Completed in 2.6s\n", " 2*Delta(log(L)) = 445.969\n", " Iteration 3 took 2.6s\n", " \n", " --- Iterative MLGST: Iter 4 of 6 862 operation sequences ---: \n", " --- Minimum Chi^2 GST ---\n", " Sum of Chi^2 = 883.111 (862 data params - 31 model params = expected mean of 831; p-value = 0.102268)\n", " Completed in 3.3s\n", " 2*Delta(log(L)) = 890.996\n", " Iteration 4 took 3.3s\n", " \n", " --- Iterative MLGST: Iter 5 of 6 1282 operation sequences ---: \n", " --- Minimum Chi^2 GST ---\n", " Sum of Chi^2 = 1325.24 (1282 data params - 31 model params = expected mean of 1251; p-value = 0.0709149)\n", " Completed in 2.7s\n", " 2*Delta(log(L)) = 1333.63\n", " Iteration 5 took 2.7s\n", " \n", " --- Iterative MLGST: Iter 6 of 6 1702 operation sequences ---: \n", " --- Minimum Chi^2 GST ---\n", " Sum of Chi^2 = 1837.81 (1702 data params - 31 model params = expected mean of 1671; p-value = 0.00250633)\n", " Completed in 5.5s\n", " 2*Delta(log(L)) = 1846.55\n", " Iteration 6 took 5.5s\n", " \n", " Switching to ML objective (last iteration)\n", " --- MLGST ---\n", " Maximum log(L) = 921.987 below upper bound of -2.63408e+06\n", " 2*Delta(log(L)) = 1843.97 (1702 data params - 31 model params = expected mean of 1671; p-value = 0.0018297)\n", " Completed in 1.9s\n", " 2*Delta(log(L)) = 1843.97\n", " Final MLGST took 1.9s\n", " \n", " Iterative MLGST Total Time: 117.1s\n", " --- Re-optimizing logl after robust data scaling ---\n", " --- MLGST ---\n", " Maximum log(L) = 921.987 below upper bound of -2.63408e+06\n", " 2*Delta(log(L)) = 1843.97 (1702 data params - 31 model params = expected mean of 1671; p-value = 0.0018297)\n", " Completed in 0.4s\n", " -- Performing 'single' gauge optimization on CPTP estimate --\n", " -- Conveying 'single' gauge optimization to CPTP.Robust+ estimate --\n", "-- Std Practice: Iter 3 of 3 (Target) --: \n", " --- Circuit Creation ---\n", " 1702 sequences created\n", " Dataset has 1702 entries: 1702 utilized, 0 requested sequences were missing\n", " -- Performing 'single' gauge optimization on Target estimate --\n", "*** Creating workspace ***\n", "*** Generating switchboard ***\n", "Found standard clifford compilation from std1Q_XYI\n", "Found standard clifford compilation from std1Q_XYI\n", "Found standard clifford compilation from std1Q_XYI\n", "*** Generating tables ***\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" ] }, { "name": "stdout", "output_type": "stream", "text": [ " targetSpamBriefTable took 0.456289 seconds\n", " targetGatesBoxTable took 0.103372 seconds\n", " datasetOverviewTable took 0.071497 seconds\n", " bestGatesetSpamParametersTable took 0.001049 seconds\n", " bestGatesetSpamBriefTable took 0.379651 seconds\n", " bestGatesetSpamVsTargetTable took 0.112113 seconds\n", " bestGatesetGaugeOptParamsTable took 0.00072 seconds\n", " bestGatesetGatesBoxTable took 0.316536 seconds\n", " bestGatesetChoiEvalTable took 0.564329 seconds\n", " bestGatesetDecompTable took 0.384811 seconds\n", " bestGatesetEvalTable took 0.006007 seconds\n", " bestGermsEvalTable took 0.086904 seconds\n", " bestGatesetVsTargetTable took 0.331994 seconds\n", " bestGatesVsTargetTable_gv took 0.358619 seconds\n", " bestGatesVsTargetTable_gvgerms took 0.462676 seconds\n", " bestGatesVsTargetTable_gi took 0.018499 seconds\n", " bestGatesVsTargetTable_gigerms took 0.151713 seconds\n", " bestGatesVsTargetTable_sum took 0.312634 seconds\n", " bestGatesetErrGenBoxTable took 1.079022 seconds\n", " metadataTable took 0.001188 seconds\n", " stdoutBlock took 0.000593 seconds\n", " profilerTable took 0.001878 seconds\n", " softwareEnvTable took 0.026952 seconds\n", " exampleTable took 0.045064 seconds\n", " singleMetricTable_gv took 0.452879 seconds\n", " singleMetricTable_gi took 0.024732 seconds\n", " fiducialListTable took 0.000496 seconds\n", " prepStrListTable took 0.000221 seconds\n", " effectStrListTable took 0.000293 seconds\n", " colorBoxPlotKeyPlot took 0.051723 seconds\n", " germList2ColTable took 0.000277 seconds\n", " progressTable took 5.41824 seconds\n", "*** Generating plots ***\n", " gramBarPlot took 0.0701 seconds\n", " progressBarPlot took 0.197948 seconds\n", " progressBarPlot_sum took 0.000816 seconds\n", " finalFitComparePlot took 0.058429 seconds\n", " bestEstimateColorBoxPlot took 19.434083 seconds\n", " bestEstimateTVDColorBoxPlot took 19.108907 seconds\n", " bestEstimateColorScatterPlot took 22.517147 seconds\n", " bestEstimateColorHistogram took 19.467219 seconds\n", " progressTable_scl took 2.817503 seconds\n", " progressBarPlot_scl took 0.151075 seconds\n", " bestEstimateColorBoxPlot_scl took 9.869324 seconds\n", " bestEstimateColorScatterPlot_scl took 11.671722 seconds\n", " bestEstimateColorHistogram_scl took 9.346774 seconds\n", " dataScalingColorBoxPlot took 0.119282 seconds\n", "*** Merging into template file ***\n", " Rendering topSwitchboard took 0.00011 seconds\n", " Rendering maxLSwitchboard1 took 8.1e-05 seconds\n", " Rendering targetSpamBriefTable took 0.067154 seconds\n", " Rendering targetGatesBoxTable took 0.060814 seconds\n", " Rendering datasetOverviewTable took 0.001027 seconds\n", " Rendering bestGatesetSpamParametersTable took 0.00212 seconds\n", " Rendering bestGatesetSpamBriefTable took 0.293808 seconds\n", " Rendering bestGatesetSpamVsTargetTable took 0.002717 seconds\n", " Rendering bestGatesetGaugeOptParamsTable took 0.001973 seconds\n", " Rendering bestGatesetGatesBoxTable took 0.556903 seconds\n", " Rendering bestGatesetChoiEvalTable took 0.278714 seconds\n", " Rendering bestGatesetDecompTable took 0.149818 seconds\n", " Rendering bestGatesetEvalTable took 0.026117 seconds\n", " Rendering bestGermsEvalTable took 0.087169 seconds\n", " Rendering bestGatesetVsTargetTable took 0.001762 seconds\n", " Rendering bestGatesVsTargetTable_gv took 0.004305 seconds\n", " Rendering bestGatesVsTargetTable_gvgerms took 0.007829 seconds\n", " Rendering bestGatesVsTargetTable_gi took 0.004855 seconds\n", " Rendering bestGatesVsTargetTable_gigerms took 0.004935 seconds\n", " Rendering bestGatesVsTargetTable_sum took 0.004524 seconds\n", " Rendering bestGatesetErrGenBoxTable took 0.577129 seconds\n", " Rendering metadataTable took 0.005254 seconds\n", " Rendering stdoutBlock took 0.001616 seconds\n", " Rendering profilerTable took 0.003169 seconds\n", " Rendering softwareEnvTable took 0.002233 seconds\n", " Rendering exampleTable took 0.020732 seconds\n", " Rendering metricSwitchboard_gv took 3.9e-05 seconds\n", " Rendering metricSwitchboard_gi took 3.9e-05 seconds\n", " Rendering singleMetricTable_gv took 0.008638 seconds\n", " Rendering singleMetricTable_gi took 0.006742 seconds\n", " Rendering fiducialListTable took 0.003064 seconds\n", " Rendering prepStrListTable took 0.002028 seconds\n", " Rendering effectStrListTable took 0.00199 seconds\n", " Rendering colorBoxPlotKeyPlot took 0.0257 seconds\n", " Rendering germList2ColTable took 0.004417 seconds\n", " Rendering progressTable took 0.012155 seconds\n", " Rendering gramBarPlot took 0.021662 seconds\n", " Rendering progressBarPlot took 0.041203 seconds\n", " Rendering progressBarPlot_sum took 0.052368 seconds\n", " Rendering finalFitComparePlot took 0.02458 seconds\n", " Rendering bestEstimateColorBoxPlot took 0.415696 seconds\n", " Rendering bestEstimateTVDColorBoxPlot took 0.466314 seconds\n", " Rendering bestEstimateColorScatterPlot took 0.740952 seconds\n", " Rendering bestEstimateColorHistogram took 0.445746 seconds\n", " Rendering progressTable_scl took 0.005789 seconds\n", " Rendering progressBarPlot_scl took 0.022603 seconds\n", " Rendering bestEstimateColorBoxPlot_scl took 0.201241 seconds\n", " Rendering bestEstimateColorScatterPlot_scl took 0.353307 seconds\n", " Rendering bestEstimateColorHistogram_scl took 0.231134 seconds\n", " Rendering dataScalingColorBoxPlot took 0.047566 seconds\n", "Output written to ../tutorial_files/gettingStartedReport directory\n", "*** Report Generation Complete! Total time 131.707s ***\n" ] }, { "data": { "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#Run GST and create a report\n", "results = pygsti.do_stdpractice_gst(ds, target_model, prep_fiducials, meas_fiducials, \n", " germs, maxLengths, verbosity=3)\n", "\n", "pygsti.report.create_standard_report(results, filename=\"../tutorial_files/gettingStartedReport\",\n", " title=\"GST Overview Tutorial Example Report\", verbosity=2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can now open the file [../tutorial_files/gettingStartedReport/main.html](../tutorial_files/gettingStartedReport/main.html) in your browser (Firefox works best) to view the report. **That's it! You've just run GST!** \n", "\n", "In the cell above, `results` is a `Results` object, which is used to generate a HTML report. For more information see the [Results object tutorial](../objects/advanced/Results.ipynb) and [report generation tutorial](../reporting/ReportGeneration.ipynb)." ] }, { "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 }