{ "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.242865843377725\n", " 1.3900765589279664\n", " 1.364983808638016\n", " 1.3472944816189392\n", " 0.04224890328547742\n", " 0.030139799998574583\n", " \n", " Singular values of target I_tilde (truncating to first 4 of 6) = \n", " 4.242640687119286\n", " 1.414213562373096\n", " 1.414213562373096\n", " 1.4142135623730954\n", " 2.484037189058858e-16\n", " 1.506337939585075e-16\n", " \n", " --- Iterative MLGST: Iter 1 of 6 92 operation sequences ---: \n", " --- Minimum Chi^2 GST ---\n", " Sum of Chi^2 = 82.6143 (92 data params - 31 model params = expected mean of 61; p-value = 0.0341509)\n", " Completed in 0.4s\n", " 2*Delta(log(L)) = 83.985\n", " Iteration 1 took 0.4s\n", " \n", " --- Iterative MLGST: Iter 2 of 6 168 operation sequences ---: \n", " --- Minimum Chi^2 GST ---\n", " Sum of Chi^2 = 146.374 (168 data params - 31 model params = expected mean of 137; p-value = 0.276283)\n", " Completed in 0.4s\n", " 2*Delta(log(L)) = 148.841\n", " Iteration 2 took 0.4s\n", " \n", " --- Iterative MLGST: Iter 3 of 6 450 operation sequences ---: \n", " --- Minimum Chi^2 GST ---\n", " Sum of Chi^2 = 440.256 (450 data params - 31 model params = expected mean of 419; p-value = 0.228089)\n", " Completed in 0.9s\n", " 2*Delta(log(L)) = 445.65\n", " Iteration 3 took 1.0s\n", " \n", " --- Iterative MLGST: Iter 4 of 6 862 operation sequences ---: \n", " --- Minimum Chi^2 GST ---\n", " Sum of Chi^2 = 891.038 (862 data params - 31 model params = expected mean of 831; p-value = 0.0728483)\n", " Completed in 1.5s\n", " 2*Delta(log(L)) = 899.156\n", " Iteration 4 took 1.7s\n", " \n", " --- Iterative MLGST: Iter 5 of 6 1282 operation sequences ---: \n", " --- Minimum Chi^2 GST ---\n", " Sum of Chi^2 = 1308.88 (1282 data params - 31 model params = expected mean of 1251; p-value = 0.124451)\n", " Completed in 2.2s\n", " 2*Delta(log(L)) = 1316.62\n", " Iteration 5 took 2.6s\n", " \n", " --- Iterative MLGST: Iter 6 of 6 1702 operation sequences ---: \n", " --- Minimum Chi^2 GST ---\n", " Sum of Chi^2 = 1715.06 (1702 data params - 31 model params = expected mean of 1671; p-value = 0.221499)\n", " Completed in 3.3s\n", " 2*Delta(log(L)) = 1723.13\n", " Iteration 6 took 4.0s\n", " \n", " Switching to ML objective (last iteration)\n", " --- MLGST ---\n", " Maximum log(L) = 860.643 below upper bound of -2.63408e+06\n", " 2*Delta(log(L)) = 1721.29 (1702 data params - 31 model params = expected mean of 1671; p-value = 0.19139)\n", " Completed in 2.3s\n", " 2*Delta(log(L)) = 1721.29\n", " Final MLGST took 2.3s\n", " \n", " Iterative MLGST Total Time: 12.4s\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 = 87.9269 (92 data params - 31 model params = expected mean of 61; p-value = 0.0135996)\n", " Completed in 3.9s\n", " 2*Delta(log(L)) = 89.2954\n", " Iteration 1 took 3.9s\n", " \n", " --- Iterative MLGST: Iter 2 of 6 168 operation sequences ---: \n", " --- Minimum Chi^2 GST ---\n", " Sum of Chi^2 = 146.627 (168 data params - 31 model params = expected mean of 137; p-value = 0.271414)\n", " Completed in 2.5s\n", " 2*Delta(log(L)) = 149.118\n", " Iteration 2 took 2.6s\n", " \n", " --- Iterative MLGST: Iter 3 of 6 450 operation sequences ---: \n", " --- Minimum Chi^2 GST ---\n", " Sum of Chi^2 = 440.27 (450 data params - 31 model params = expected mean of 419; p-value = 0.227944)\n", " Completed in 5.9s\n", " 2*Delta(log(L)) = 445.679\n", " Iteration 3 took 6.0s\n", " \n", " --- Iterative MLGST: Iter 4 of 6 862 operation sequences ---: \n", " --- Minimum Chi^2 GST ---\n", " Sum of Chi^2 = 891.047 (862 data params - 31 model params = expected mean of 831; p-value = 0.0728203)\n", " Completed in 2.5s\n", " 2*Delta(log(L)) = 899.219\n", " Iteration 4 took 2.7s\n", " \n", " --- Iterative MLGST: Iter 5 of 6 1282 operation sequences ---: \n", " --- Minimum Chi^2 GST ---\n", " Sum of Chi^2 = 1308.88 (1282 data params - 31 model params = expected mean of 1251; p-value = 0.124448)\n", " Completed in 4.0s\n", " 2*Delta(log(L)) = 1316.68\n", " Iteration 5 took 4.3s\n", " \n", " --- Iterative MLGST: Iter 6 of 6 1702 operation sequences ---: \n", " --- Minimum Chi^2 GST ---\n", " Sum of Chi^2 = 1715.06 (1702 data params - 31 model params = expected mean of 1671; p-value = 0.221499)\n", " Completed in 4.0s\n", " 2*Delta(log(L)) = 1723.13\n", " Iteration 6 took 4.5s\n", " \n", " Switching to ML objective (last iteration)\n", " --- MLGST ---\n", " Maximum log(L) = 860.675 below upper bound of -2.63408e+06\n", " 2*Delta(log(L)) = 1721.35 (1702 data params - 31 model params = expected mean of 1671; p-value = 0.191095)\n", " Completed in 2.6s\n", " 2*Delta(log(L)) = 1721.35\n", " Final MLGST took 2.6s\n", " \n", " Iterative MLGST Total Time: 26.6s\n", " -- Performing 'single' gauge optimization on CPTP 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", " targetSpamBriefTable took 0.580262 seconds\n", " targetGatesBoxTable took 0.615566 seconds\n", " datasetOverviewTable took 0.073659 seconds\n", " bestGatesetSpamParametersTable took 0.001084 seconds\n", " bestGatesetSpamBriefTable took 0.613317 seconds\n", " bestGatesetSpamVsTargetTable took 0.149132 seconds\n", " bestGatesetGaugeOptParamsTable took 0.001171 seconds\n", " bestGatesetGatesBoxTable took 0.657926 seconds\n", " bestGatesetChoiEvalTable took 1.789662 seconds\n", " bestGatesetDecompTable took 0.999271 seconds\n", " bestGatesetEvalTable took 0.007466 seconds\n", " bestGermsEvalTable took 0.09859 seconds\n", " bestGatesetVsTargetTable took 0.34271 seconds\n", " bestGatesVsTargetTable_gv took 0.467919 seconds\n", " bestGatesVsTargetTable_gvgerms took 0.474705 seconds\n", " bestGatesVsTargetTable_gi took 0.02236 seconds\n", " bestGatesVsTargetTable_gigerms took 0.171316 seconds\n", " bestGatesVsTargetTable_sum took 0.391675 seconds\n", " bestGatesetErrGenBoxTable took 3.387571 seconds\n", " metadataTable took 0.001155 seconds\n", " stdoutBlock took 0.00065 seconds\n", " profilerTable took 0.00143 seconds\n", " softwareEnvTable took 0.042716 seconds\n", " exampleTable took 0.093538 seconds\n", " singleMetricTable_gv took 0.404434 seconds\n", " singleMetricTable_gi took 0.023687 seconds\n", " fiducialListTable took 0.000457 seconds\n", " prepStrListTable took 0.000166 seconds\n", " effectStrListTable took 0.000308 seconds\n", " colorBoxPlotKeyPlot took 0.100806 seconds\n", " germList2ColTable took 0.000279 seconds\n", " progressTable took 7.075741 seconds\n", "*** Generating plots ***\n", " gramBarPlot took 0.526319 seconds\n", " progressBarPlot took 3.211627 seconds\n", " progressBarPlot_sum took 0.000978 seconds\n", " finalFitComparePlot took 0.10372 seconds\n", " bestEstimateColorBoxPlot took 24.774211 seconds\n", " bestEstimateTVDColorBoxPlot took 10.215594 seconds\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ " bestEstimateColorScatterPlot took 12.058885 seconds\n", " bestEstimateColorHistogram took 4.539033 seconds\n", " progressTable_scl took 0.000109 seconds\n", " progressBarPlot_scl took 7.9e-05 seconds\n", " bestEstimateColorBoxPlot_scl took 0.000244 seconds\n", " bestEstimateColorScatterPlot_scl took 0.000233 seconds\n", " bestEstimateColorHistogram_scl took 0.000232 seconds\n", " progressTable_ume took 0.000121 seconds\n", " progressBarPlot_ume took 0.000144 seconds\n", " bestEstimateColorBoxPlot_ume took 0.000305 seconds\n", " bestEstimateColorScatterPlot_ume took 0.000314 seconds\n", " bestEstimateColorHistogram_ume took 0.000308 seconds\n", " dataScalingColorBoxPlot took 0.000117 seconds\n", " unmodeledErrorBudgetTable took 7.8e-05 seconds\n", "*** Merging into template file ***\n", " Rendering topSwitchboard took 0.000122 seconds\n", " Rendering maxLSwitchboard1 took 9.3e-05 seconds\n", " Rendering targetSpamBriefTable took 0.499264 seconds\n", " Rendering targetGatesBoxTable took 0.543943 seconds\n", " Rendering datasetOverviewTable took 0.000742 seconds\n", " Rendering bestGatesetSpamParametersTable took 0.003709 seconds\n", " Rendering bestGatesetSpamBriefTable took 1.073395 seconds\n", " Rendering bestGatesetSpamVsTargetTable took 0.003761 seconds\n", " Rendering bestGatesetGaugeOptParamsTable took 0.002381 seconds\n", " Rendering bestGatesetGatesBoxTable took 1.595731 seconds\n", " Rendering bestGatesetChoiEvalTable took 1.026165 seconds\n", " Rendering bestGatesetDecompTable took 0.53177 seconds\n", " Rendering bestGatesetEvalTable took 0.032985 seconds\n", " Rendering bestGermsEvalTable took 0.130801 seconds\n", " Rendering bestGatesetVsTargetTable took 0.002113 seconds\n", " Rendering bestGatesVsTargetTable_gv took 0.006232 seconds\n", " Rendering bestGatesVsTargetTable_gvgerms took 0.009567 seconds\n", " Rendering bestGatesVsTargetTable_gi took 0.006184 seconds\n", " Rendering bestGatesVsTargetTable_gigerms took 0.007106 seconds\n", " Rendering bestGatesVsTargetTable_sum took 0.005732 seconds\n", " Rendering bestGatesetErrGenBoxTable took 2.591958 seconds\n", " Rendering metadataTable took 0.005712 seconds\n", " Rendering stdoutBlock took 0.002161 seconds\n", " Rendering profilerTable took 0.005056 seconds\n", " Rendering softwareEnvTable took 0.002612 seconds\n", " Rendering exampleTable took 0.058347 seconds\n", " Rendering metricSwitchboard_gv took 4.1e-05 seconds\n", " Rendering metricSwitchboard_gi took 2.8e-05 seconds\n", " Rendering singleMetricTable_gv took 0.008675 seconds\n", " Rendering singleMetricTable_gi took 0.008158 seconds\n", " Rendering fiducialListTable took 0.00338 seconds\n", " Rendering prepStrListTable took 0.002688 seconds\n", " Rendering effectStrListTable took 0.002236 seconds\n", " Rendering colorBoxPlotKeyPlot took 0.06652 seconds\n", " Rendering germList2ColTable took 0.00412 seconds\n", " Rendering progressTable took 0.013123 seconds\n", " Rendering gramBarPlot took 0.179864 seconds\n", " Rendering progressBarPlot took 0.165632 seconds\n", " Rendering progressBarPlot_sum took 0.182284 seconds\n", " Rendering finalFitComparePlot took 0.057412 seconds\n", " Rendering bestEstimateColorBoxPlot took 2.25944 seconds\n", " Rendering bestEstimateTVDColorBoxPlot took 2.223713 seconds\n", " Rendering bestEstimateColorScatterPlot took 4.238531 seconds\n", " Rendering bestEstimateColorHistogram took 1.706827 seconds\n", " Rendering progressTable_scl took 0.000936 seconds\n", " Rendering progressBarPlot_scl took 0.000623 seconds\n", " Rendering bestEstimateColorBoxPlot_scl took 0.001427 seconds\n", " Rendering bestEstimateColorScatterPlot_scl took 0.001313 seconds\n", " Rendering bestEstimateColorHistogram_scl took 0.001065 seconds\n", " Rendering progressTable_ume took 0.000713 seconds\n", " Rendering progressBarPlot_ume took 0.001078 seconds\n", " Rendering bestEstimateColorBoxPlot_ume took 0.000733 seconds\n", " Rendering bestEstimateColorScatterPlot_ume took 0.000985 seconds\n", " Rendering bestEstimateColorHistogram_ume took 0.001069 seconds\n", " Rendering dataScalingColorBoxPlot took 0.001034 seconds\n", " Rendering unmodeledErrorBudgetTable took 0.000896 seconds\n", "Output written to ../tutorial_files/gettingStartedReport directory\n", "*** Report Generation Complete! Total time 93.6646s ***\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 }