Some parts of pygsti are works-in-progress. Here, we investigate how to do the task of "model selection" within GST, essentially answering the question "Can we do a better job of modeling the experiment by changing the assumptions within GST?".

Testing variable-gateset-dimension GST with model selection

Setup

In [1]:
import pygsti
In [2]:
#Load gateset and some string lists
gs_target = pygsti.io.load_gateset("tutorial_files/Example_Gateset.txt")
fiducialList = pygsti.io.load_gatestring_list("tutorial_files/Example_FiducialList.txt")
germList = pygsti.io.load_gatestring_list("tutorial_files/Example_GermsList.txt")
specs = pygsti.construction.build_spam_specs(fiducialList)
expList = [1,2,4]
In [3]:
#Create some testing gate string lists
lgstList = pygsti.construction.list_lgst_gatestrings(specs, gs_target.gates.keys())
lsgstLists = [ lgstList[:] ]
for exp in expList:
    gsList = pygsti.construction.create_gatestring_list(
                "f0+germ*exp+f1", f0=fiducialList, f1=fiducialList,
                germ=germList, exp=exp, order=['germ','f0','f1'])
    lsgstLists.append( lsgstLists[-1] +  gsList )
    
dsList = pygsti.remove_duplicates( lsgstLists[-1] )
In [4]:
#Test on fake data by depolarizing target set, increasing its dimension,
# and adding leakage to the gates into the new dimension.

gs_dataGen4 = gs_target.depolarize(gate_noise=0.1)
gs_dataGen5 = gs_dataGen4.increase_dimension(5)
leakGate = pygsti.construction.build_gate( [2,1],[('Q0',),('L0',)] , "LX(pi/4.0,0,2)","gm") # X(pi,Q0)*LX(pi,0,2)

gs_dataGen5['Gx'] = pygsti.objects.compose( gs_dataGen5['Gx'], leakGate)
gs_dataGen5['Gy'] = pygsti.objects.compose( gs_dataGen5['Gy'], leakGate)
print gs_dataGen5.gates.keys()

#Some debugging...
#NOTE: with LX(pi,0,2) above, dim 5 test will choose a dimension 3 gateset, which may be sensible
#       looking at the gate matrices in this case... but maybe LX(pi,...) is faulty?
#print gs_dataGen4
#print gs_dataGen5

#Jmx = GST.JOps.jamiolkowski_iso(gs_dataGen4['Gx'])
#Jmx = GST.JOps.jamiolkowski_iso(gs_dataGen5['Gx'],dimOrStateSpaceDims=[2,1])
#print "J = \n",Jmx
#print "evals = ",eigvals(Jmx)

dsFake4 = pygsti.construction.generate_fake_data(gs_dataGen4, dsList, nSamples=1000000, sampleError="binomial", seed=1234)
dsFake5 = pygsti.construction.generate_fake_data(gs_dataGen5, dsList, nSamples=1000000, sampleError="binomial", seed=1234)
['Gi', 'Gx', 'Gy']
In [5]:
print "Number of gates = ",len(gs_target.gates.keys())
print "Number of fiducials =",len(fiducialList)
print "Maximum length for a gate string in ds =",max(map(len,dsList))
print "Number of LGST strings = ",len(lgstList)
print "Number of LSGST strings = ",map(len,lsgstLists)
Number of gates =  3
Number of fiducials = 6
Maximum length for a gate string in ds = 30
Number of LGST strings =  92
Number of LSGST strings =  [92, 488, 884, 1280]

Test using dimension-4 fake data

In [6]:
#Run LGST to get an initial estimate for the gates in gs_target based on the data in ds
# NOTE: with nSamples less than 1M (100K, 10K, 1K) this routine will choose a higher-than-4 dimensional gateset
ds = dsFake4
gs_lgst4 = pygsti.do_lgst(ds, specs, targetGateset=gs_target, svdTruncateTo=4, verbosity=3)
gs_lgst6 = pygsti.do_lgst(ds, specs, targetGateset=gs_target, svdTruncateTo=6, verbosity=3)

#Print chi^2 of 4-dim and 6-dim estimates
chiSq4 = pygsti.chi2(ds, gs_lgst4, lgstList, minProbClipForWeighting=1e-4)
chiSq6 = pygsti.chi2(ds, gs_lgst6, lgstList, minProbClipForWeighting=1e-4)
print "LGST dim=4 chiSq = ",chiSq4
print "LGST dim=6 chiSq = ",chiSq6

# Least squares GST with model selection
gs_lsgst = pygsti.do_iterative_mc2gst_with_model_selection(ds, gs_lgst4, 1, lsgstLists, verbosity=2,
                                                           minProbClipForWeighting=1e-3, probClipInterval=(-1e5,1e5))
LGST: Singular values of I_tilde (truncating to first 4 of 6) = 
[  3.00484791e+00   8.25822588e-01   6.70903966e-01   6.65330643e-01
   1.32123551e-03   7.62101431e-04]

--- LGST ---
LGST: Singular values of I_tilde (truncating to first 6 of 6) = 
[  3.00484791e+00   8.25822588e-01   6.70903966e-01   6.65330643e-01
   1.32123551e-03   7.62101431e-04]
LGST: Padding target B with sqrt of low singular values of I_tilde: 
[ 0.00132124  0.0007621 ]

--- LGST ---
LGST dim=4 chiSq =  584.010103572
LGST dim=6 chiSq =  218.874929215

--- Iterative MC2GST: Beginning iter 1 of 4 : 92 gate strings ---
--- Minimum Chi^2 GST with model selection (starting dim = 4) ---
--- Minimum Chi^2 GST ---
  Sum of Chi^2 = 58.5712 (92 data params - 40 model params = expected mean of 52; p-value = 0.247042)
Dim 4: chi^2 = 58.5712, nGateStrings=92, nParams=56 (so expected mean = 36)
--- Minimum Chi^2 GST ---
  Sum of Chi^2 = 5.5151e+06 (92 data params - 24 model params = expected mean of 68; p-value = 0)
Rejected dim 3: chi^2 = 5.5151e+06 (+5.51505e+06 w.r.t. expected mean of 92 strings - 33 params = 59) (dChi^2=5515046, 2*dParams=-46)
--- Minimum Chi^2 GST ---
  Sum of Chi^2 = 36.8586 (92 data params - 60 model params = expected mean of 32; p-value = 0.254144)
Rejected dim 5: chi^2 = 36.8586 (+29.8586 w.r.t. expected mean of 92 strings - 85 params = 7) (dChi^2=-21, 2*dParams=58)

--- Iterative MC2GST: Beginning iter 2 of 4 : 488 gate strings ---
--- Minimum Chi^2 GST with model selection (starting dim = 4) ---
--- Minimum Chi^2 GST ---
  Sum of Chi^2 = 437.023 (488 data params - 40 model params = expected mean of 448; p-value = 0.635868)
Dim 4: chi^2 = 437.023, nGateStrings=488, nParams=56 (so expected mean = 432)
--- Minimum Chi^2 GST ---
  Sum of Chi^2 = 2.7208e+07 (488 data params - 24 model params = expected mean of 464; p-value = 0)
Rejected dim 3: chi^2 = 2.7208e+07 (+2.72075e+07 w.r.t. expected mean of 488 strings - 33 params = 455) (dChi^2=27207546, 2*dParams=-46)
--- Minimum Chi^2 GST ---
  Sum of Chi^2 = 384.271 (488 data params - 60 model params = expected mean of 428; p-value = 0.93647)
Rejected dim 5: chi^2 = 384.271 (-18.7287 w.r.t. expected mean of 488 strings - 85 params = 403) (dChi^2=-52, 2*dParams=58)

--- Iterative MC2GST: Beginning iter 3 of 4 : 884 gate strings ---
--- Minimum Chi^2 GST with model selection (starting dim = 4) ---
--- Minimum Chi^2 GST ---
  Sum of Chi^2 = 859.588 (884 data params - 40 model params = expected mean of 844; p-value = 0.347053)
Dim 4: chi^2 = 859.588, nGateStrings=884, nParams=56 (so expected mean = 828)
--- Minimum Chi^2 GST ---
  Sum of Chi^2 = 4.28947e+07 (884 data params - 24 model params = expected mean of 860; p-value = 0)
Rejected dim 3: chi^2 = 4.28947e+07 (+4.28939e+07 w.r.t. expected mean of 884 strings - 33 params = 851) (dChi^2=42893853, 2*dParams=-46)
--- Minimum Chi^2 GST ---
  Sum of Chi^2 = 813.395 (884 data params - 60 model params = expected mean of 824; p-value = 0.597126)
Rejected dim 5: chi^2 = 813.395 (+14.3953 w.r.t. expected mean of 884 strings - 85 params = 799) (dChi^2=-46, 2*dParams=58)

--- Iterative MC2GST: Beginning iter 4 of 4 : 1280 gate strings ---
--- Minimum Chi^2 GST with model selection (starting dim = 4) ---
--- Minimum Chi^2 GST ---
  Sum of Chi^2 = 1262.44 (1280 data params - 40 model params = expected mean of 1240; p-value = 0.322292)
Dim 4: chi^2 = 1262.44, nGateStrings=1280, nParams=56 (so expected mean = 1224)
--- Minimum Chi^2 GST ---
  Sum of Chi^2 = 6.04917e+07 (1280 data params - 24 model params = expected mean of 1256; p-value = 0)
Rejected dim 3: chi^2 = 6.04917e+07 (+6.04904e+07 w.r.t. expected mean of 1280 strings - 33 params = 1247) (dChi^2=60490400, 2*dParams=-46)
--- Minimum Chi^2 GST ---
  Sum of Chi^2 = 1223.14 (1280 data params - 60 model params = expected mean of 1220; p-value = 0.469327)
Rejected dim 5: chi^2 = 1223.14 (+28.1377 w.r.t. expected mean of 1280 strings - 85 params = 1195) (dChi^2=-39, 2*dParams=58)
In [7]:
print gs_lsgst
rho0 =    0.7071  -0.0242   0.0257   0.7454


E0 =    0.6852   0.0149  -0.0109  -0.6492


Gi = 
   1.0000        0        0        0
  -0.0030   0.9001  -0.0001  -0.0003
   0.0028        0   0.8998  -0.0002
  -0.0036   0.0001  -0.0002   0.9000


Gx = 
   1.0000        0        0        0
  -0.0027   0.8993   0.0119   0.0190
  -0.0044   0.0243  -0.0108  -0.9823
  -0.0578   0.0184   0.8249   0.0112


Gy = 
   1.0000        0        0        0
   0.0041  -0.0197   0.0023   0.9987
   0.0025  -0.0077   0.8998  -0.0041
  -0.0579  -0.8113  -0.0281   0.0197



Test using dimension-5 fake data

In [8]:
#Run LGST to get an initial estimate for the gates in gs_target based on the data in ds
ds = dsFake5
gs_lgst4 = pygsti.do_lgst(ds, specs, targetGateset=gs_target, svdTruncateTo=4, verbosity=3)
gs_lgst6 = pygsti.do_lgst(ds, specs, targetGateset=gs_target, svdTruncateTo=6, verbosity=3)

#Print chi^2 of 4-dim and 6-dim estimates
chiSq4 = pygsti.chi2(ds, gs_lgst4, lgstList, minProbClipForWeighting=1e-2)
chiSq6 = pygsti.chi2(ds, gs_lgst6, lgstList, minProbClipForWeighting=1e-2)
print "LGST dim=4 chiSq = ",chiSq4
print "LGST dim=6 chiSq = ",chiSq6

# Least squares GST with model selection
gs_lsgst = pygsti.do_iterative_mc2gst_with_model_selection(ds, gs_lgst4, 1, lsgstLists, verbosity=2, minProbClipForWeighting=1e-3, probClipInterval=(-1e5,1e5), useFreqWeightedChiSq=False, regularizeFactor=1.0, check=False, check_jacobian=False)
LGST: Singular values of I_tilde (truncating to first 4 of 6) = 
[  2.36368304e+00   6.59319496e-01   4.68883491e-01   4.54819490e-01
   3.15418560e-03   8.91359166e-04]

--- LGST ---
LGST: Singular values of I_tilde (truncating to first 6 of 6) = 
[  2.36368304e+00   6.59319496e-01   4.68883491e-01   4.54819490e-01
   3.15418560e-03   8.91359166e-04]
LGST: Padding target B with sqrt of low singular values of I_tilde: 
[ 0.00315419  0.00089136]

--- LGST ---
LGST dim=4 chiSq =  1316593.37275
LGST dim=6 chiSq =  580943.33613

--- Iterative MC2GST: Beginning iter 1 of 4 : 92 gate strings ---
--- Minimum Chi^2 GST with model selection (starting dim = 4) ---
--- Minimum Chi^2 GST ---
  Sum of Chi^2 = 143358 (92 data params - 40 model params = expected mean of 52; p-value = 0)
Dim 4: chi^2 = 143358, nGateStrings=92, nParams=56 (so expected mean = 36)
--- Minimum Chi^2 GST ---
  Sum of Chi^2 = 3.0845e+06 (92 data params - 24 model params = expected mean of 68; p-value = 0)
Rejected dim 3: chi^2 = 3.0845e+06 (+3.08444e+06 w.r.t. expected mean of 92 strings - 33 params = 59) (dChi^2=2941144, 2*dParams=-46)
--- Minimum Chi^2 GST ---
  Sum of Chi^2 = 48.7083 (92 data params - 60 model params = expected mean of 32; p-value = 0.0295689)
Selected dim 5: chi^2 = 48.7083 (+41.7083 w.r.t. expected mean of 92 strings - 85 params = 7) (dChi^2=-143309, 2*dParams=58)

--- Iterative MC2GST: Beginning iter 2 of 4 : 488 gate strings ---
--- Minimum Chi^2 GST with model selection (starting dim = 5) ---
--- Minimum Chi^2 GST ---
  Sum of Chi^2 = 401.245 (488 data params - 60 model params = expected mean of 428; p-value = 0.818942)
Dim 5: chi^2 = 401.245, nGateStrings=488, nParams=85 (so expected mean = 403)
--- Minimum Chi^2 GST ---
  Sum of Chi^2 = 870355 (488 data params - 40 model params = expected mean of 448; p-value = 0)
Rejected dim 4: chi^2 = 870355 (+869923 w.r.t. expected mean of 488 strings - 56 params = 432) (dChi^2=869953, 2*dParams=-58)
--- Minimum Chi^2 GST ---
  Sum of Chi^2 = 332.472 (488 data params - 84 model params = expected mean of 404; p-value = 0.996076)
Rejected dim 6: chi^2 = 332.472 (-35.5283 w.r.t. expected mean of 488 strings - 120 params = 368) (dChi^2=-68, 2*dParams=70)

--- Iterative MC2GST: Beginning iter 3 of 4 : 884 gate strings ---
--- Minimum Chi^2 GST with model selection (starting dim = 5) ---
--- Minimum Chi^2 GST ---
  Sum of Chi^2 = 820.581 (884 data params - 60 model params = expected mean of 824; p-value = 0.527076)
Dim 5: chi^2 = 820.581, nGateStrings=884, nParams=85 (so expected mean = 799)
--- Minimum Chi^2 GST ---
  Sum of Chi^2 = 1.73941e+06 (884 data params - 40 model params = expected mean of 844; p-value = 0)
Rejected dim 4: chi^2 = 1.73941e+06 (+1.73858e+06 w.r.t. expected mean of 884 strings - 56 params = 828) (dChi^2=1738590, 2*dParams=-58)
--- Minimum Chi^2 GST ---
  Sum of Chi^2 = 747.344 (884 data params - 84 model params = expected mean of 800; p-value = 0.90819)
Selected dim 6: chi^2 = 747.344 (-16.6564 w.r.t. expected mean of 884 strings - 120 params = 764) (dChi^2=-73, 2*dParams=70)
--- Minimum Chi^2 GST ---
  Sum of Chi^2 = 683.368 (884 data params - 112 model params = expected mean of 772; p-value = 0.990126)
Rejected dim 7: chi^2 = 683.368 (-39.6317 w.r.t. expected mean of 884 strings - 161 params = 723) (dChi^2=-63, 2*dParams=82)

--- Iterative MC2GST: Beginning iter 4 of 4 : 1280 gate strings ---
--- Minimum Chi^2 GST with model selection (starting dim = 6) ---
--- Minimum Chi^2 GST ---
  Sum of Chi^2 = 1128.3 (1280 data params - 84 model params = expected mean of 1196; p-value = 0.918863)
Dim 6: chi^2 = 1128.3, nGateStrings=1280, nParams=120 (so expected mean = 1160)
--- Minimum Chi^2 GST ---
  Sum of Chi^2 = 1230.81 (1280 data params - 60 model params = expected mean of 1220; p-value = 0.40843)
Rejected dim 5: chi^2 = 1230.81 (+35.805 w.r.t. expected mean of 1280 strings - 85 params = 1195) (dChi^2=102, 2*dParams=-70)
--- Minimum Chi^2 GST ---
  Sum of Chi^2 = 1062.22 (1280 data params - 112 model params = expected mean of 1168; p-value = 0.987598)
Rejected dim 7: chi^2 = 1062.22 (-56.778 w.r.t. expected mean of 1280 strings - 161 params = 1119) (dChi^2=-66, 2*dParams=82)
In [9]:
print gs_lsgst
rho0 =    0.7070   0.0603  -0.0151   0.7760  -0.0095   0.0158


E0 =    0.5855   0.0091   0.0128  -0.5340   0.0464   0.0305


Gi = 
   1.0001        0        0        0   0.0001  -0.0011
   0.0084   0.8976   0.0018        0   0.0176  -0.0098
  -0.0007   0.0038   0.8961  -0.0010  -0.0234   0.0291
  -0.0239   0.0076  -0.0077   0.8986  -0.0493   0.0658
  -0.0006  -0.0111   0.0027   0.0035   0.9996   0.0326
   0.0525  -0.0456   0.0995   0.0003   0.1297  -0.3321


Gx = 
   1.0001        0   0.0002        0   0.0002  -0.0030
  -0.0240   0.8344  -0.0233  -0.0689  -0.0311  -0.1043
  -0.0668   0.0705  -0.0224  -0.9550  -0.4569   0.0830
  -0.1303   0.0487   0.7074   0.0442  -0.1713  -0.0527
  -0.2126   0.0187   0.0018  -0.0713   0.7293   0.2121
   0.0292  -0.0464   0.0757  -0.0732   0.1010  -1.0748


Gy = 
   1.0001        0   0.0001        0   0.0002  -0.0014
   0.1532  -0.0769   0.0321   0.9472   0.4151   0.0603
   0.0421   0.0218   0.8258   0.0322   0.0159   0.0634
  -0.0673  -0.7057   0.0370   0.0841  -0.1810   0.0183
  -0.1955  -0.0674  -0.0054  -0.0057   0.7689   0.0715
   0.0334  -0.0233   0.1058  -0.0292   0.1057  -0.5537



In [10]:
 
In [10]: