In [1]:

```
from __future__ import print_function
```

In [2]:

```
import os
import sys
import time
import json
import pygsti
from pygsti.construction import std1Q_XYI
%pylab inline
```

Populating the interactive namespace from numpy and matplotlib

In [3]:

```
#Get a GST estimate (similar to Tutorial 0)
# 1) get the target GateSet
gs_target = std1Q_XYI.gs_target
# 2) get the building blocks needed to specify which gate sequences are needed
prep_fiducials, meas_fiducials = std1Q_XYI.prepStrs, std1Q_XYI.effectStrs
germs = std1Q_XYI.germs
maxLengths = [1,2,4,8,16]
# 3) generate "fake" data from a depolarized version of gs_target
gs_datagen = gs_target.depolarize(gate_noise=0.1, spam_noise=0.001)
listOfExperiments = pygsti.construction.make_lsgst_experiment_list(
gs_target, prep_fiducials, meas_fiducials, germs, maxLengths)
ds = pygsti.construction.generate_fake_data(gs_datagen, listOfExperiments, nSamples=1000,
sampleError="binomial", seed=1234)
results = pygsti.do_stdpractice_gst(ds, gs_target, prep_fiducials, meas_fiducials,
germs, maxLengths, modes="TP")
estimated_gateset = results.estimates['TP'].gatesets['single']
```

Here we do parametric bootstrapping, as indicated by the 'parametric' argument below. The output is eventually stored in the "mean" and "std" GateSets, which hold the mean and standard deviation values of the set of bootstrapped gatesets (after gauge optimization). It is this latter "standard deviation Gateset" which holds the collection of error bars. Note: due to print setting issues, the outputs that are printed here will not necessarily reflect the true accuracy of the estimates made.

In [4]:

```
#The number of simulated datasets & gatesets made for bootstrapping purposes.
# For good statistics, should probably be greater than 10.
numGatesets=10
param_boot_gatesets = pygsti.drivers.make_bootstrap_gatesets(
numGatesets, ds, 'parametric', prep_fiducials, meas_fiducials, germs, maxLengths,
inputGateSet=estimated_gateset, startSeed=0, returnData=False,
verbosity=2)
```

In [5]:

```
gauge_opt_pboot_gatesets = pygsti.drivers.gauge_optimize_gs_list(param_boot_gatesets, estimated_gateset,
plot=False) #plotting support removed w/matplotlib
```

In [6]:

```
pboot_mean = pygsti.drivers.to_mean_gateset(gauge_opt_pboot_gatesets, estimated_gateset)
pboot_std = pygsti.drivers.to_std_gateset(gauge_opt_pboot_gatesets, estimated_gateset)
#Summary of the error bars
print("Parametric bootstrapped error bars, with", numGatesets, "resamples\n")
print("Error in rho vec:")
print(pboot_std['rho0'], end='\n\n')
print("Error in effect vecs:")
print(pboot_std['Mdefault'], end='\n\n')
print("Error in Gi:")
print(pboot_std['Gi'], end='\n\n')
print("Error in Gx:")
print(pboot_std['Gx'], end='\n\n')
print("Error in Gy:")
print(pboot_std['Gy'])
```

Here we do non-parametric bootstrapping, as indicated by the 'nonparametric' argument below. The output is again eventually stored in the "mean" and "std" GateSets, which hold the mean and standard deviation values of the set of bootstrapped gatesets (after gauge optimization). It is this latter "standard deviation Gateset" which holds the collection of error bars. Note: due to print setting issues, the outputs that are printed here will not necessarily reflect the true accuracy of the estimates made.

(Technical note: ddof = 1 is by default used when computing the standard deviation -- see numpy.std -- meaning that we are computing a standard deviation of the sample, not of the population.)

In [7]:

```
#The number of simulated datasets & gatesets made for bootstrapping purposes.
# For good statistics, should probably be greater than 10.
numGatesets=10
nonparam_boot_gatesets = pygsti.drivers.make_bootstrap_gatesets(
numGatesets, ds, 'nonparametric', prep_fiducials, meas_fiducials, germs, maxLengths,
targetGateSet=estimated_gateset, startSeed=0, returnData=False, verbosity=2)
```

In [8]:

```
gauge_opt_npboot_gatesets = pygsti.drivers.gauge_optimize_gs_list(nonparam_boot_gatesets, estimated_gateset,
plot=False) #plotting removed w/matplotlib
```

In [9]:

```
npboot_mean = pygsti.drivers.to_mean_gateset(gauge_opt_npboot_gatesets, estimated_gateset)
npboot_std = pygsti.drivers.to_std_gateset(gauge_opt_npboot_gatesets, estimated_gateset)
#Summary of the error bars
print("Non-parametric bootstrapped error bars, with", numGatesets, "resamples\n")
print("Error in rho vec:")
print(npboot_std['rho0'], end='\n\n')
print("Error in effect vecs:")
print(npboot_std['Mdefault'], end='\n\n')
print("Error in Gi:")
print(npboot_std['Gi'], end='\n\n')
print("Error in Gx:")
print(npboot_std['Gx'], end='\n\n')
print("Error in Gy:")
print(npboot_std['Gy'])
```

In [10]:

```
loglog(npboot_std.to_vector(),pboot_std.to_vector(),'.')
loglog(np.logspace(-4,-2,10),np.logspace(-4,-2,10),'--')
xlabel('Non-parametric')
ylabel('Parametric')
xlim((1e-4,1e-2)); ylim((1e-4,1e-2))
title('Scatter plot comparing param vs. non-param bootstrapping error bars.')
```

Out[10]:

Text(0.5,1,'Scatter plot comparing param vs. non-param bootstrapping error bars.')

In [ ]:

```
```