Once we have data for GST, there are several algorithms we can run on it to produce tomographic estimates. Depending on the amount of data you have, and time available for running Gate Set Tomography, one algorithm may be preferable over the others.
Currently, pygsti
provides support for the following GST algorithms:
Linear Gate Set Tomography (LGST): Uses short gate sequences to quickly compute a rough (low accuracy) estimate of a gate set by linear inversion.
Extended Linear Gate Set Tomography (eLGST or EXLGST): Minimizes the sub-of-squared errors between independent LGST estimates and the estimates obtained from a single gate set to find a best-estimate gate set. This is typically done in an interative fashion, using LGST estimates for longer and longer sequences.
Minimum-$\chi^2$ Gate Set Tomography (MC2GST): Minimizes the $\chi^{2}$ statistic of the data frequencies and gate set probabilities to find a best-estimate gate set. Typically done in an interative fashion, using successively larger sets of longer and longer gate sequences.
Maximum-Likelihood Gate Set Tomography (MLGST): Maximizes the log-likelihood statistic of the data frequencies and gate set probabilities to find a best-estimate gate set. Typically done in an interative fashion similar to MC2GST. This maximum likelihood estimation (MLE) is very well-motivated from a statistics standpoint and should be the most accurate among the algorithms.
If you're curious, the implementation of the algorithms for LGST, EXLGST, MC2GST, and MLGST may be found in the pygsti.algorithms.core
module. In this tutorial, we'll show how to invoke each of these algorithms.
The ingredients needed to as input to the GST algorithms are:
GateSet
which defines the desired gates. This gate set is used by LGST to specify the various gate, state preparation, POVM effect, and SPAM labels, as well as to provide an initial guess for the gauge degrees of freedom.DataSet
containing the data that GST attempts to fit using the probabilities generated by a single GateSet
. This data set must at least contain the data for the gate sequences required by the algorithm that is chosen.GateString
objects, which specify which gate strings are used during each iteration of the algorithm (the length of the top-level list defines the number of interations). Note that which gate strings are included in these lists is different for EXLGST than it is for MC2GST and MLGST.from __future__ import print_function
import pygsti
import json
#Load target gateset, dataset, and list of fiducial gate strings.
#In this case we load directly from files created in past tutorials
gs_target = pygsti.io.load_gateset("tutorial_files/Example_Gateset.txt")
ds = pygsti.io.load_dataset("tutorial_files/Example_Dataset.txt", cache=True)
dsLowCounts = pygsti.io.load_dataset("tutorial_files/Example_Dataset_LowCnts.txt", cache=True)
fiducialList = pygsti.io.load_gatestring_list("tutorial_files/Example_FiducialList.txt")
depol_gateset = gs_target.depolarize(gate_noise=0.1)
#Could also load a fiducial dictionary file like this:
#fiducialDict = GST.load_gatestring_dict("Example_FiducialList.txt")
#fiducialList = fiducialDict.values() #all we really need are the fiducial strings themselves
print("Loaded target gateset with gate labels: ", gs_target.gates.keys())
print("Loaded fiducial list of length: ", len(fiducialList))
print("Loaded dataset of length: ", len(ds))
An important and distinguising property of the LGST algorithm is that it does not require an initial-guess GateSet
as an input. It uses linear inversion and short sequences to obtain a rough gate set estimate. As such, it is very common to use the LGST estimate as the initial-guess starting point for more advanced forms of GST.
#Run LGST to get an initial estimate for the gates in gs_target based on the data in ds
#create "spam specs" from the list of fiducial gate strings. See the gate strings tutorial for more info.
specs = pygsti.construction.build_spam_specs(fiducialGateStrings=fiducialList)
#run LGST
gs_lgst = pygsti.do_lgst(ds, specs, targetGateset=gs_target, svdTruncateTo=4, verbosity=1)
#Gauge optimize the result to match the target gateset
gs_lgst_after_gauge_opt = pygsti.optimize_gauge(gs_lgst, "target", targetGateset=gs_target)
#Contract the result to CPTP, guaranteeing that the gates are CPTP
gs_clgst = pygsti.contract(gs_lgst_after_gauge_opt, "CPTP")
print(gs_lgst)
EXLGST requires a list-of-lists of gate strings, one per iteration. The elements of these lists are typically repetitions of short "germ" strings such that the final strings does not exceed some maximum length. We created such lists in the gate string tutorial. Now, we just load these lists from the text files they were saved in.
#Get rho and E specifiers, needed by LGST
specs = pygsti.construction.build_spam_specs(fiducialGateStrings=fiducialList)
germList = pygsti.io.load_gatestring_list("tutorial_files/Example_GermsList.txt")
maxLengthList = json.load(open("tutorial_files/Example_maxLengths.json","r"))
elgstListOfLists = [ pygsti.io.load_gatestring_list("tutorial_files/Example_eLGSTlist%d.txt" % l) for l in maxLengthList]
#run EXLGST. The result, gs_exlgst, is a GateSet containing the estimated quantities
gs_exlgst = pygsti.do_iterative_exlgst(ds, gs_clgst, specs, elgstListOfLists, targetGateset=gs_target,
svdTruncateTo=4, verbosity=2)
MC2GST and MLGST also require a list-of-lists of gate strings, one per iteration. However, the elements of these lists are typically repetitions of short "germ" strings sandwiched between fiducial strings such that the repeated-germ part of the string does not exceed some maximum length. We created such lists in the gate string tutorial. Now, we just load these lists from the text files they were saved in.
#Get lists of gate strings for successive iterations of LSGST to use
specs = pygsti.construction.build_spam_specs(fiducialGateStrings=fiducialList)
germList = pygsti.io.load_gatestring_list("tutorial_files/Example_GermsList.txt")
maxLengthList = json.load(open("tutorial_files/Example_maxLengths.json","r"))
lsgstListOfLists = [ pygsti.io.load_gatestring_list("tutorial_files/Example_LSGSTlist%d.txt" % l) for l in maxLengthList]
#run MC2GST. The result is a GateSet containing the estimated quantities
gs_mc2 = pygsti.do_iterative_mc2gst(ds, gs_clgst, lsgstListOfLists, verbosity=2)
#Write the resulting EXLGST and MC2GST results to gate set text files for later reference.
pygsti.io.write_gateset(gs_exlgst, "tutorial_files/Example_eLGST_Gateset.txt","# Example result from running eLGST")
pygsti.io.write_gateset(gs_mc2, "tutorial_files/Example_MC2GST_Gateset.txt","# Example result from running MC2GST")
#Run MC2GST again but use a DataSet with a lower number of counts
gs_mc2_lowcnts = pygsti.do_iterative_mc2gst(dsLowCounts, gs_clgst, lsgstListOfLists, verbosity=2)
Executing MLGST is very similar to MC2GST: the same gate string lists can be used and calling syntax is nearly identitcal.
maxLengthList = json.load(open("tutorial_files/Example_maxLengths.json","r"))
lsgstListOfLists = [ pygsti.io.load_gatestring_list("tutorial_files/Example_LSGSTlist%d.txt" % l) for l in maxLengthList]
#run MLGST. The result is a GateSet containing the estimated quantities
gs_mle = pygsti.do_iterative_mlgst(ds, gs_clgst, lsgstListOfLists, verbosity=2)
#Run MLGST again but use a DataSet with a lower number of counts
gs_mle_lowcnts = pygsti.do_iterative_mlgst(dsLowCounts, gs_clgst, lsgstListOfLists, verbosity=2)
Both MLGST and MC2GST use a $\chi^{2}$ optimization procedure for all but the final iteration. For the last set of gatestrings (the last iteration), MLGST uses a maximum likelihood estimation. Below, we show how close the two estimates are to one another. First, we optimize the gauge so the estimated gates are as close to the target gates as the gauge degrees of freedom allow.
# We optimize over the gate set gauge
gs_mle = pygsti.optimize_gauge(gs_mle,"target",targetGateset=depol_gateset)
gs_mle_lowcnts = pygsti.optimize_gauge(gs_mle_lowcnts,"target",targetGateset=depol_gateset)
gs_mc2 = pygsti.optimize_gauge(gs_mc2,"target",targetGateset=depol_gateset)
gs_mc2_lowcnts = pygsti.optimize_gauge(gs_mc2_lowcnts,"target",targetGateset=depol_gateset)
print("Frobenius diff btwn MLGST and datagen = {0}".format(round(gs_mle.frobeniusdist(depol_gateset), 6)))
print("Frobenius diff btwn MC2GST and datagen = {0}".format(round(gs_mc2.frobeniusdist(depol_gateset), 6)))
print("Frobenius diff btwn MLGST and LGST = {0}".format(round(gs_mle.frobeniusdist(gs_clgst), 6)))
print("Frobenius diff btwn MLGST and MC2GST = {0}".format(round(gs_mle.frobeniusdist(gs_mc2), 6)))
print("Chi^2 ( MC2GST ) = {0}".format(round(pygsti.chi2(ds, gs_mc2, lsgstListOfLists[-1]), 4)))
print("Chi^2 ( MLGST ) = {0}".format(round(pygsti.chi2(ds, gs_mle, lsgstListOfLists[-1] ), 4)))
print("LogL ( MC2GST ) = {0}".format(round(pygsti.logl(gs_mc2, ds, lsgstListOfLists[-1]), 4)))
print("LogL ( MLGST ) = {0}".format(round(pygsti.logl(gs_mle, ds, lsgstListOfLists[-1]), 4)))
Notice that, as expected, the MC2GST estimate has a slightly lower $\chi^{2}$ score than the MLGST estimate, and the MLGST estimate has a slightly higher loglikelihood than the MC2GST estimate. In addition, both are close (in terms of the Frobenius difference) to the depolarized gateset. Which is good - it means GST is giving us estimates which are close to the true gateset used to generate the data. Performing the same analysis with the low-count data shows larger differences between the two, which is expected since the $\chi^2$ and loglikelihood statistics are more similar at large $N$, that is, for large numbers of samples.
print("LOW COUNT DATA:")
print("Frobenius diff btwn MLGST and datagen = {0}".format(round(gs_mle_lowcnts.frobeniusdist(depol_gateset), 6)))
print("Frobenius diff btwn MC2GST and datagen = {0}".format(round(gs_mc2_lowcnts.frobeniusdist(depol_gateset), 6)))
print("Frobenius diff btwn MLGST and LGST = {0}".format(round(gs_mle_lowcnts.frobeniusdist(gs_clgst), 6)))
print("Frobenius diff btwn MLGST and MC2GST = {0}".format(round(gs_mle_lowcnts.frobeniusdist(gs_mc2), 6)))
print("Chi^2 ( MC2GST ) = {0}".format(round(pygsti.chi2(dsLowCounts, gs_mc2_lowcnts, lsgstListOfLists[-1]), 4)))
print("Chi^2 ( MLGST ) = {0}".format(round(pygsti.chi2(dsLowCounts, gs_mle_lowcnts, lsgstListOfLists[-1] ), 4)))
print("LogL ( MC2GST ) = {0}".format(round(pygsti.logl(gs_mc2_lowcnts, dsLowCounts, lsgstListOfLists[-1]), 4)))
print("LogL ( MLGST ) = {0}".format(round(pygsti.logl(gs_mle_lowcnts, dsLowCounts, lsgstListOfLists[-1]), 4)))