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.243095501422058
    1.3901808798412303
    1.366465649836718
    1.345711384664332
    0.024975111125949443
    0.006813806654669674
    
    Singular values of target I_tilde (truncating to first 4 of 6) = 
    4.242640687119286
    1.414213562373096
    1.4142135623730956
    1.4142135623730954
    2.5038933168948026e-16
    2.023452063009528e-16
    
  --- Iterative MLGST: Iter 1 of 6  92 operation sequences ---: 
    --- Minimum Chi^2 GST ---
    Sum of Chi^2 = 81.6754 (92 data params - 31 model params = expected mean of 61; p-value = 0.0397842)
    Completed in 0.2s
    2*Delta(log(L)) = 82.4971
    Iteration 1 took 0.2s
    
  --- Iterative MLGST: Iter 2 of 6  168 operation sequences ---: 
    --- Minimum Chi^2 GST ---
    Sum of Chi^2 = 145.571 (168 data params - 31 model params = expected mean of 137; p-value = 0.292027)
    Completed in 0.1s
    2*Delta(log(L)) = 147.471
    Iteration 2 took 0.1s
    
  --- Iterative MLGST: Iter 3 of 6  450 operation sequences ---: 
    --- Minimum Chi^2 GST ---
    Sum of Chi^2 = 440.19 (450 data params - 31 model params = expected mean of 419; p-value = 0.228755)
    Completed in 0.3s
    2*Delta(log(L)) = 445.072
    Iteration 3 took 0.4s
    
  --- Iterative MLGST: Iter 4 of 6  862 operation sequences ---: 
    --- Minimum Chi^2 GST ---
    Sum of Chi^2 = 883.073 (862 data params - 31 model params = expected mean of 831; p-value = 0.102429)
    Completed in 0.5s
    2*Delta(log(L)) = 890.914
    Iteration 4 took 0.5s
    
  --- Iterative MLGST: Iter 5 of 6  1282 operation sequences ---: 
    --- Minimum Chi^2 GST ---
    Sum of Chi^2 = 1310.35 (1282 data params - 31 model params = expected mean of 1251; p-value = 0.118708)
    Completed in 0.8s
    2*Delta(log(L)) = 1318.52
    Iteration 5 took 0.9s
    
  --- Iterative MLGST: Iter 6 of 6  1702 operation sequences ---: 
    --- Minimum Chi^2 GST ---
    Sum of Chi^2 = 1719.42 (1702 data params - 31 model params = expected mean of 1671; p-value = 0.200152)
    Completed in 1.2s
    2*Delta(log(L)) = 1727.85
    Iteration 6 took 1.2s
    
    Switching to ML objective (last iteration)
    --- MLGST ---
      Maximum log(L) = 862.67 below upper bound of -2.63408e+06
        2*Delta(log(L)) = 1725.34 (1702 data params - 31 model params = expected mean of 1671; p-value = 0.173228)
      Completed in 0.5s
    2*Delta(log(L)) = 1725.34
    Final MLGST took 0.5s
    
  Iterative MLGST Total Time: 3.8s
  -- 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 = 86.2545 (92 data params - 31 model params = expected mean of 61; p-value = 0.0183576)
    Completed in 98.0s
    2*Delta(log(L)) = 87.4462
    Iteration 1 took 98.1s
    
  --- Iterative MLGST: Iter 2 of 6  168 operation sequences ---: 
    --- Minimum Chi^2 GST ---
    Sum of Chi^2 = 146.49 (168 data params - 31 model params = expected mean of 137; p-value = 0.274036)
    Completed in 3.0s
    2*Delta(log(L)) = 148.699
    Iteration 2 took 3.0s
    
  --- Iterative MLGST: Iter 3 of 6  450 operation sequences ---: 
    --- Minimum Chi^2 GST ---
    Sum of Chi^2 = 440.728 (450 data params - 31 model params = expected mean of 419; p-value = 0.223352)
    Completed in 2.6s
    2*Delta(log(L)) = 445.969
    Iteration 3 took 2.6s
    
  --- Iterative MLGST: Iter 4 of 6  862 operation sequences ---: 
    --- Minimum Chi^2 GST ---
    Sum of Chi^2 = 883.111 (862 data params - 31 model params = expected mean of 831; p-value = 0.102268)
    Completed in 3.3s
    2*Delta(log(L)) = 890.996
    Iteration 4 took 3.3s
    
  --- Iterative MLGST: Iter 5 of 6  1282 operation sequences ---: 
    --- Minimum Chi^2 GST ---
    Sum of Chi^2 = 1325.24 (1282 data params - 31 model params = expected mean of 1251; p-value = 0.0709149)
    Completed in 2.7s
    2*Delta(log(L)) = 1333.63
    Iteration 5 took 2.7s
    
  --- Iterative MLGST: Iter 6 of 6  1702 operation sequences ---: 
    --- Minimum Chi^2 GST ---
    Sum of Chi^2 = 1837.81 (1702 data params - 31 model params = expected mean of 1671; p-value = 0.00250633)
    Completed in 5.5s
    2*Delta(log(L)) = 1846.55
    Iteration 6 took 5.5s
    
    Switching to ML objective (last iteration)
    --- MLGST ---
      Maximum log(L) = 921.987 below upper bound of -2.63408e+06
        2*Delta(log(L)) = 1843.97 (1702 data params - 31 model params = expected mean of 1671; p-value = 0.0018297)
      Completed in 1.9s
    2*Delta(log(L)) = 1843.97
    Final MLGST took 1.9s
    
  Iterative MLGST Total Time: 117.1s
  --- Re-optimizing logl after robust data scaling ---
    --- MLGST ---
      Maximum log(L) = 921.987 below upper bound of -2.63408e+06
        2*Delta(log(L)) = 1843.97 (1702 data params - 31 model params = expected mean of 1671; p-value = 0.0018297)
      Completed in 0.4s
  -- Performing 'single' gauge optimization on CPTP estimate --
  -- Conveying 'single' gauge optimization to CPTP.Robust+ 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 ***
/Users/enielse/research/pyGSTi/packages/pygsti/report/factory.py:785: UserWarning:

Idle tomography failed:
Label{layers}

  targetSpamBriefTable                          took 0.456289 seconds
  targetGatesBoxTable                           took 0.103372 seconds
  datasetOverviewTable                          took 0.071497 seconds
  bestGatesetSpamParametersTable                took 0.001049 seconds
  bestGatesetSpamBriefTable                     took 0.379651 seconds
  bestGatesetSpamVsTargetTable                  took 0.112113 seconds
  bestGatesetGaugeOptParamsTable                took 0.00072 seconds
  bestGatesetGatesBoxTable                      took 0.316536 seconds
  bestGatesetChoiEvalTable                      took 0.564329 seconds
  bestGatesetDecompTable                        took 0.384811 seconds
  bestGatesetEvalTable                          took 0.006007 seconds
  bestGermsEvalTable                            took 0.086904 seconds
  bestGatesetVsTargetTable                      took 0.331994 seconds
  bestGatesVsTargetTable_gv                     took 0.358619 seconds
  bestGatesVsTargetTable_gvgerms                took 0.462676 seconds
  bestGatesVsTargetTable_gi                     took 0.018499 seconds
  bestGatesVsTargetTable_gigerms                took 0.151713 seconds
  bestGatesVsTargetTable_sum                    took 0.312634 seconds
  bestGatesetErrGenBoxTable                     took 1.079022 seconds
  metadataTable                                 took 0.001188 seconds
  stdoutBlock                                   took 0.000593 seconds
  profilerTable                                 took 0.001878 seconds
  softwareEnvTable                              took 0.026952 seconds
  exampleTable                                  took 0.045064 seconds
  singleMetricTable_gv                          took 0.452879 seconds
  singleMetricTable_gi                          took 0.024732 seconds
  fiducialListTable                             took 0.000496 seconds
  prepStrListTable                              took 0.000221 seconds
  effectStrListTable                            took 0.000293 seconds
  colorBoxPlotKeyPlot                           took 0.051723 seconds
  germList2ColTable                             took 0.000277 seconds
  progressTable                                 took 5.41824 seconds
*** Generating plots ***
  gramBarPlot                                   took 0.0701 seconds
  progressBarPlot                               took 0.197948 seconds
  progressBarPlot_sum                           took 0.000816 seconds
  finalFitComparePlot                           took 0.058429 seconds
  bestEstimateColorBoxPlot                      took 19.434083 seconds
  bestEstimateTVDColorBoxPlot                   took 19.108907 seconds
  bestEstimateColorScatterPlot                  took 22.517147 seconds
  bestEstimateColorHistogram                    took 19.467219 seconds
  progressTable_scl                             took 2.817503 seconds
  progressBarPlot_scl                           took 0.151075 seconds
  bestEstimateColorBoxPlot_scl                  took 9.869324 seconds
  bestEstimateColorScatterPlot_scl              took 11.671722 seconds
  bestEstimateColorHistogram_scl                took 9.346774 seconds
  dataScalingColorBoxPlot                       took 0.119282 seconds
*** Merging into template file ***
  Rendering topSwitchboard                      took 0.00011 seconds
  Rendering maxLSwitchboard1                    took 8.1e-05 seconds
  Rendering targetSpamBriefTable                took 0.067154 seconds
  Rendering targetGatesBoxTable                 took 0.060814 seconds
  Rendering datasetOverviewTable                took 0.001027 seconds
  Rendering bestGatesetSpamParametersTable      took 0.00212 seconds
  Rendering bestGatesetSpamBriefTable           took 0.293808 seconds
  Rendering bestGatesetSpamVsTargetTable        took 0.002717 seconds
  Rendering bestGatesetGaugeOptParamsTable      took 0.001973 seconds
  Rendering bestGatesetGatesBoxTable            took 0.556903 seconds
  Rendering bestGatesetChoiEvalTable            took 0.278714 seconds
  Rendering bestGatesetDecompTable              took 0.149818 seconds
  Rendering bestGatesetEvalTable                took 0.026117 seconds
  Rendering bestGermsEvalTable                  took 0.087169 seconds
  Rendering bestGatesetVsTargetTable            took 0.001762 seconds
  Rendering bestGatesVsTargetTable_gv           took 0.004305 seconds
  Rendering bestGatesVsTargetTable_gvgerms      took 0.007829 seconds
  Rendering bestGatesVsTargetTable_gi           took 0.004855 seconds
  Rendering bestGatesVsTargetTable_gigerms      took 0.004935 seconds
  Rendering bestGatesVsTargetTable_sum          took 0.004524 seconds
  Rendering bestGatesetErrGenBoxTable           took 0.577129 seconds
  Rendering metadataTable                       took 0.005254 seconds
  Rendering stdoutBlock                         took 0.001616 seconds
  Rendering profilerTable                       took 0.003169 seconds
  Rendering softwareEnvTable                    took 0.002233 seconds
  Rendering exampleTable                        took 0.020732 seconds
  Rendering metricSwitchboard_gv                took 3.9e-05 seconds
  Rendering metricSwitchboard_gi                took 3.9e-05 seconds
  Rendering singleMetricTable_gv                took 0.008638 seconds
  Rendering singleMetricTable_gi                took 0.006742 seconds
  Rendering fiducialListTable                   took 0.003064 seconds
  Rendering prepStrListTable                    took 0.002028 seconds
  Rendering effectStrListTable                  took 0.00199 seconds
  Rendering colorBoxPlotKeyPlot                 took 0.0257 seconds
  Rendering germList2ColTable                   took 0.004417 seconds
  Rendering progressTable                       took 0.012155 seconds
  Rendering gramBarPlot                         took 0.021662 seconds
  Rendering progressBarPlot                     took 0.041203 seconds
  Rendering progressBarPlot_sum                 took 0.052368 seconds
  Rendering finalFitComparePlot                 took 0.02458 seconds
  Rendering bestEstimateColorBoxPlot            took 0.415696 seconds
  Rendering bestEstimateTVDColorBoxPlot         took 0.466314 seconds
  Rendering bestEstimateColorScatterPlot        took 0.740952 seconds
  Rendering bestEstimateColorHistogram          took 0.445746 seconds
  Rendering progressTable_scl                   took 0.005789 seconds
  Rendering progressBarPlot_scl                 took 0.022603 seconds
  Rendering bestEstimateColorBoxPlot_scl        took 0.201241 seconds
  Rendering bestEstimateColorScatterPlot_scl    took 0.353307 seconds
  Rendering bestEstimateColorHistogram_scl      took 0.231134 seconds
  Rendering dataScalingColorBoxPlot             took 0.047566 seconds
Output written to ../tutorial_files/gettingStartedReport directory
*** Report Generation Complete!  Total time 131.707s ***
Out[2]:
<pygsti.report.workspace.Workspace at 0x10aee2c50>

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 [ ]: