An overview of Gate Set Tomography

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 and the tutorial covering the different pyGSTi functions for running GST.

To run GST, we need three inputs:

  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) - which acts on a single qubit with the following operations:

    • three gates: the identity, and $\pi/2$ rotations around the $x$- and $y$-axes.
    • a single state preparation in the $|0\rangle$ state.
    • a 2-outcome measurement with the label "0" associated with measuring $|0\rangle$ and "1" with measuring $|1\rangle$.
  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).

  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.

In [1]:
#Make print statements compatible with Python 2 and 3
from __future__ import print_function

#Import the pygsti module (always do this) and the standard XYI model
import pygsti
from pygsti.construction import std1Q_XYI

# 1) get the target Model
target_model = std1Q_XYI.target_model()

# 2) get the building blocks needed to specify which operation sequences are needed
prep_fiducials, meas_fiducials = std1Q_XYI.prepStrs, std1Q_XYI.effectStrs
germs = std1Q_XYI.germs
maxLengths = [1,2,4,8,16,32] # roughly gives the length of the sequences used by GST

# 3) generate "fake" data from a depolarized version of target_model
mdl_datagen = target_model.depolarize(op_noise=0.01, spam_noise=0.001)
listOfExperiments = pygsti.construction.make_lsgst_experiment_list(
    target_model, prep_fiducials, meas_fiducials, germs, maxLengths)
ds = pygsti.construction.generate_fake_data(mdl_datagen, listOfExperiments, nSamples=1000,
                                            sampleError="binomial", seed=1234)

#Note: from listOfExperiments we can also create an empty dataset file
# which has columns of zeros where actual data should go. 
pygsti.io.write_empty_dataset("../tutorial_files/GettingStartedDataTemplate.txt", listOfExperiments,
                              "## Columns = 0 count, 1 count")
# After replacing the zeros with actual data, the data set can be 
# loaded back into pyGSTi using the line below and used in the rest
# of this tutorial. 
#ds = pygsti.io.load_dataset("tutorial_files/GettingStartedDataTemplate.txt")

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. This returns a pygsti.report.Results object (see the Results tutorial), from which we can generate a report giving us a summary of the analysis.

In [2]:
#Run GST and create a report
results = pygsti.do_stdpractice_gst(ds, target_model, prep_fiducials, meas_fiducials, 
                                    germs, maxLengths, verbosity=3)

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

You can now open the file ../tutorial_files/gettingStartedReport/main.html in your browser (Firefox works best) to view the report. That's it! You've just run GST!

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 and report generation tutorial.

In [ ]: