Download

Download this file as Jupyter notebook: estimate_collections.ipynb.

Parsing Estimate Collections

The standard workflow for diagnostic and suppression protocols is to invoke their generation functions to create a circuit collection, run each of the circuits on a device or simulator, populate each circuit’s results with the observed data, and finally invoke the fit() method to produce estimates of the quantities of interest.

We now follow this procedure to create a rich EstimateCollection instance that can be used throughout this guide. First, we create a large circuit collection with many types of circuits.

[2]:
import trueq as tq
import trueq.simulation as tqs

# add single-qubit simultaneous SRB, XRB, IRB on a 4 qubit system
circuits = tq.make_srb(range(4), [2, 16, 32])
circuits += tq.make_xrb(range(4), [2, 16, 32])
circuits += tq.make_irb({range(4): tq.Gate.h}, [2, 8, 16])

# add two-qubit simultaneous SRB, XRB, IRB on a 4 qubit system
circuits += tq.make_srb([[0, 1], [2, 3]], [2, 10, 20])
circuits += tq.make_irb({(0, 1): tq.Gate.cx, (2, 3): tq.Gate.cx}, [2, 10, 20])

# add CB for two cycles on a 4 qubit system
circuits += tq.make_cb({(0, 1): tq.Gate.cz, (2, 3): tq.Gate.cz}, [2, 10, 20])
circuits += tq.make_cb({(0, 1): tq.Gate.cx, (2, 3): tq.Gate.cx}, [2, 10, 20])

# add single-body noise reconstruction for two cycles on a 4 qubit system
pauli_twirl = tq.Twirl("P", range(4))
circuits += tq.make_knr({(0, 1): tq.Gate.cz}, [2, 10, 20], twirl=pauli_twirl)
circuits += tq.make_knr({(0, 1): tq.Gate.cx}, [2, 10, 20], twirl=pauli_twirl)

# add some readout calibration circuits
circuits += tq.make_rcal(range(4))

Next, we simulate all of the circuits with a noisy simulator.

[3]:
sim = tq.Simulator()
sim.add_overrotation(0.04, 0.03)
for label, p in enumerate([0.01, 0.005, 0.03, 0.02]):
    sim.add_stochastic_pauli(pz=p, match=tqs.LabelMatch(label))
sim.add_stochastic_pauli(px=0.01, match=tqs.GateMatch(tq.Gate.cx))
sim.add_readout_error([0.01, 0.05])

# run RCAL with more shots than any other protocol
sim.run(circuits.subset(protocol="RCAL"), n_shots=4096)
sim.run(circuits.subset(has_results=False), n_shots=64)

Finally, we produce an EstimateCollection from these simulations by calling fit() with the default options.

[4]:
fit = circuits.fit()

What is an Estimate Collection

The variable fit, defined just above, is an EstimateCollection, which itself is a list-like object whose entries are Estimate objects. Each individual estimate object contains estimated values for some particular context. For example, the SRB diagnostic protocol produces an estimate object for each subsystem, each of which contains estimated values for the subsystem infidelity e_F, the SPAM constant A, and the decay parameter p.

[5]:
# number of estimates in the collection
len(fit)
[5]:
25
[6]:
# the first estimate object
fit[0]
[6]:
True-Q formatting will not be loaded without trusting this notebook or rerunning the affected cells. Notebooks can be marked as trusted by clicking "File -> Trust Notebook".
SRB
Streamlined Randomized Benchmarking
Cliffords
(0,)
Key:
  • labels: (0,)
  • protocol: SRB
  • twirl: Cliffords on [0, 1, 2, 3]
${e}_{F}$
The probability of an error acting on the targeted systems during a random gate.
1.2e-02 (1.1e-03)
0.012113202540744161, 0.001062603536338273
${p}$
Decay parameter of the exponential decay $Ap^m$.
9.8e-01 (1.4e-03)
0.9838490632790078, 0.001416804715117697
${A}$
SPAM parameter of the exponential decay $Ap^m$.
1.0e+00 (1.5e-02)
1.0227375131686498, 0.015086902227019888

The context of an estimate includes information such as what protocol it corresponds to, which subsystem it pertains to, what the cycle of interest is, which twirling group was used for randomization, and so on. This information is stored on the key attribute of each estimate, see Keys: Storing and Filtering Metadata for more information about using keys.

[7]:
# display the KeySet of all unique keys in the collection
fit.keys()
[7]:
True-Q formatting will not be loaded without trusting this notebook or rerunning the affected cells. Notebooks can be marked as trusted by clicking "File -> Trust Notebook".
KeySet
List of all the keys in the KeySet
protocol
The characterization protocol used to generate a circuit.
cycles labels twirl
The twirling group used to generate a circuit.
subsystems
The subsystems to analyze for a given protocol.
Key
Key:
  • cycles: (Cycle((0, 1): Gate.cx, (2, 3): Gate.cx),)
  • labels: (0, 1, 2, 3)
  • protocol: CB
  • twirl: Paulis on [0, 1, 2, 3]
CB (Cycle((0, 1): Gate.cx, (2, 3): Gate.cx),) (0, 1, 2, 3) Paulis on [0, 1, 2, 3]
Key
Key:
  • cycles: (Cycle((0, 1): Gate.cz, (2, 3): Gate.cz),)
  • labels: (0, 1, 2, 3)
  • protocol: CB
  • twirl: Paulis on [0, 1, 2, 3]
CB (Cycle((0, 1): Gate.cz, (2, 3): Gate.cz),) (0, 1, 2, 3) Paulis on [0, 1, 2, 3]
Key
Key:
  • cycles: (Cycle((0, 1): Gate.cx, (2, 3): Gate.cx),)
  • labels: (0, 1)
  • protocol: IRB
  • twirl: Cliffords on [(0, 1), (2, 3)]
IRB (Cycle((0, 1): Gate.cx, (2, 3): Gate.cx),) (0, 1) Cliffords on [(0, 1), (2, 3)]
Key
Key:
  • cycles: (Cycle((0, 1): Gate.cx, (2, 3): Gate.cx),)
  • labels: (2, 3)
  • protocol: IRB
  • twirl: Cliffords on [(0, 1), (2, 3)]
IRB (Cycle((0, 1): Gate.cx, (2, 3): Gate.cx),) (2, 3) Cliffords on [(0, 1), (2, 3)]
Key
Key:
  • cycles: (Cycle((0,): Gate.h, (1,): Gate.h, (2,): Gate.h, (3,): Gate.h),)
  • labels: (0,)
  • protocol: IRB
  • twirl: Cliffords on [0, 1, 2, 3]
IRB (Cycle((0,): Gate.h, (1,): Gate.h, (2,): Gate.h, (3,): Gate.h),) (0,) Cliffords on [0, 1, 2, 3]
Key
Key:
  • cycles: (Cycle((0,): Gate.h, (1,): Gate.h, (2,): Gate.h, (3,): Gate.h),)
  • labels: (1,)
  • protocol: IRB
  • twirl: Cliffords on [0, 1, 2, 3]
IRB (Cycle((0,): Gate.h, (1,): Gate.h, (2,): Gate.h, (3,): Gate.h),) (1,) Cliffords on [0, 1, 2, 3]
Key
Key:
  • cycles: (Cycle((0,): Gate.h, (1,): Gate.h, (2,): Gate.h, (3,): Gate.h),)
  • labels: (2,)
  • protocol: IRB
  • twirl: Cliffords on [0, 1, 2, 3]
IRB (Cycle((0,): Gate.h, (1,): Gate.h, (2,): Gate.h, (3,): Gate.h),) (2,) Cliffords on [0, 1, 2, 3]
Key
Key:
  • cycles: (Cycle((0,): Gate.h, (1,): Gate.h, (2,): Gate.h, (3,): Gate.h),)
  • labels: (3,)
  • protocol: IRB
  • twirl: Cliffords on [0, 1, 2, 3]
IRB (Cycle((0,): Gate.h, (1,): Gate.h, (2,): Gate.h, (3,): Gate.h),) (3,) Cliffords on [0, 1, 2, 3]
Key
Key:
  • cycles: (Cycle((0, 1): Gate.cx),)
  • labels: (0, 1)
  • protocol: KNR
  • subsystems: ((0, 1),)
  • twirl: Paulis on [0, 1, 2, 3]
KNR (Cycle((0, 1): Gate.cx),) (0, 1) Paulis on [0, 1, 2, 3] ((0, 1),)
Key
Key:
  • cycles: (Cycle((0, 1): Gate.cx),)
  • labels: (2,)
  • protocol: KNR
  • subsystems: ((2,),)
  • twirl: Paulis on [0, 1, 2, 3]
KNR (Cycle((0, 1): Gate.cx),) (2,) Paulis on [0, 1, 2, 3] ((2,),)
Key
Key:
  • cycles: (Cycle((0, 1): Gate.cx),)
  • labels: (3,)
  • protocol: KNR
  • subsystems: ((3,),)
  • twirl: Paulis on [0, 1, 2, 3]
KNR (Cycle((0, 1): Gate.cx),) (3,) Paulis on [0, 1, 2, 3] ((3,),)
Key
Key:
  • cycles: (Cycle((0, 1): Gate.cz),)
  • labels: (0, 1)
  • protocol: KNR
  • subsystems: ((0, 1),)
  • twirl: Paulis on [0, 1, 2, 3]
KNR (Cycle((0, 1): Gate.cz),) (0, 1) Paulis on [0, 1, 2, 3] ((0, 1),)
Key
Key:
  • cycles: (Cycle((0, 1): Gate.cz),)
  • labels: (2,)
  • protocol: KNR
  • subsystems: ((2,),)
  • twirl: Paulis on [0, 1, 2, 3]
KNR (Cycle((0, 1): Gate.cz),) (2,) Paulis on [0, 1, 2, 3] ((2,),)
Key
Key:
  • cycles: (Cycle((0, 1): Gate.cz),)
  • labels: (3,)
  • protocol: KNR
  • subsystems: ((3,),)
  • twirl: Paulis on [0, 1, 2, 3]
KNR (Cycle((0, 1): Gate.cz),) (3,) Paulis on [0, 1, 2, 3] ((3,),)
Key
Key:
  • labels: (0, 1, 2, 3)
  • protocol: RCAL
RCAL (0, 1, 2, 3)
Key
Key:
  • labels: (0,)
  • protocol: SRB
  • twirl: Cliffords on [0, 1, 2, 3]
SRB (0,) Cliffords on [0, 1, 2, 3]
Key
Key:
  • labels: (0, 1)
  • protocol: SRB
  • twirl: Cliffords on [(0, 1), (2, 3)]
SRB (0, 1) Cliffords on [(0, 1), (2, 3)]
Key
Key:
  • labels: (1,)
  • protocol: SRB
  • twirl: Cliffords on [0, 1, 2, 3]
SRB (1,) Cliffords on [0, 1, 2, 3]
Key
Key:
  • labels: (2,)
  • protocol: SRB
  • twirl: Cliffords on [0, 1, 2, 3]
SRB (2,) Cliffords on [0, 1, 2, 3]
Key
Key:
  • labels: (2, 3)
  • protocol: SRB
  • twirl: Cliffords on [(0, 1), (2, 3)]
SRB (2, 3) Cliffords on [(0, 1), (2, 3)]
Key
Key:
  • labels: (3,)
  • protocol: SRB
  • twirl: Cliffords on [0, 1, 2, 3]
SRB (3,) Cliffords on [0, 1, 2, 3]
Key
Key:
  • labels: (0,)
  • protocol: XRB
  • twirl: Cliffords on [0, 1, 2, 3]
XRB (0,) Cliffords on [0, 1, 2, 3]
Key
Key:
  • labels: (1,)
  • protocol: XRB
  • twirl: Cliffords on [0, 1, 2, 3]
XRB (1,) Cliffords on [0, 1, 2, 3]
Key
Key:
  • labels: (2,)
  • protocol: XRB
  • twirl: Cliffords on [0, 1, 2, 3]
XRB (2,) Cliffords on [0, 1, 2, 3]
Key
Key:
  • labels: (3,)
  • protocol: XRB
  • twirl: Cliffords on [0, 1, 2, 3]
XRB (3,) Cliffords on [0, 1, 2, 3]

Filtering Estimates

As discussed in Filtering Based on Keys, we can filter the list of all estimates by calling subset(). For example, if we only want to display estimates from IRB and SRB, then we can construct an estimate subcollection as follows:

[8]:
fit.subset(protocol={"IRB", "SRB"})
[8]:
True-Q formatting will not be loaded without trusting this notebook or rerunning the affected cells. Notebooks can be marked as trusted by clicking "File -> Trust Notebook".
SRB
Streamlined Randomized Benchmarking
Cliffords
(0,)
Key:
  • labels: (0,)
  • protocol: SRB
  • twirl: Cliffords on [0, 1, 2, 3]
Cliffords
(1,)
Key:
  • labels: (1,)
  • protocol: SRB
  • twirl: Cliffords on [0, 1, 2, 3]
Cliffords
(2,)
Key:
  • labels: (2,)
  • protocol: SRB
  • twirl: Cliffords on [0, 1, 2, 3]
Cliffords
(3,)
Key:
  • labels: (3,)
  • protocol: SRB
  • twirl: Cliffords on [0, 1, 2, 3]
Cliffords
(0, 1)
Key:
  • labels: (0, 1)
  • protocol: SRB
  • twirl: Cliffords on [(0, 1), (2, 3)]
Cliffords
(2, 3)
Key:
  • labels: (2, 3)
  • protocol: SRB
  • twirl: Cliffords on [(0, 1), (2, 3)]
${e}_{F}$
The probability of an error acting on the targeted systems during a random gate.
1.2e-02 (1.1e-03)
0.012113202540744161, 0.001062603536338273
7.7e-03 (9.3e-04)
0.007748197166483672, 0.0009257882301837448
3.0e-02 (2.9e-03)
0.030106619488102837, 0.002895863218123038
2.3e-02 (1.7e-03)
0.022868790496913677, 0.0016757276966393696
1.7e-03 (9.8e-04)
0.0017498738118882848, 0.000983064891684749
6.6e-04 (1.2e-03)
0.0006561232103625969, 0.0012428941277052002
${p}$
Decay parameter of the exponential decay $Ap^m$.
9.8e-01 (1.4e-03)
0.9838490632790078, 0.001416804715117697
9.9e-01 (1.2e-03)
0.9896690704446884, 0.0012343843069116598
9.6e-01 (3.9e-03)
0.9598578406825296, 0.003861150957497384
9.7e-01 (2.2e-03)
0.9695082793374484, 0.0022343035955191596
1.0e+00 (1.0e-03)
0.9981334679339858, 0.0010486025511303987
1.0e+00 (1.3e-03)
0.9993001352422799, 0.0013257537362188802
${A}$
SPAM parameter of the exponential decay $Ap^m$.
1.0e+00 (1.5e-02)
1.0227375131686498, 0.015086902227019888
1.0e+00 (1.6e-02)
0.9993759958338462, 0.015850006267173578
9.8e-01 (3.5e-02)
0.9844565265830525, 0.03471167146846443
1.0e+00 (2.5e-02)
1.0105216957924983, 0.02507367810635242
9.7e-01 (1.9e-02)
0.971517500232779, 0.01878390707100737
1.0e+00 (1.5e-02)
0.9995561862221269, 0.015198074202310874
IRB
Interleaved Randomized Benchmarking
Cliffords

(0,) : Gate.h

(1,) : Gate.h

(2,) : Gate.h

(3,) : Gate.h

Key:
  • cycles: (Cycle((0,): Gate.h, (1,): Gate.h, (2,): Gate.h, (3,): Gate.h),)
  • labels: (0,)
  • protocol: IRB
  • twirl: Cliffords on [0, 1, 2, 3]
Cliffords

(0,) : Gate.h

(1,) : Gate.h

(2,) : Gate.h

(3,) : Gate.h

Key:
  • cycles: (Cycle((0,): Gate.h, (1,): Gate.h, (2,): Gate.h, (3,): Gate.h),)
  • labels: (1,)
  • protocol: IRB
  • twirl: Cliffords on [0, 1, 2, 3]
Cliffords

(0,) : Gate.h

(1,) : Gate.h

(2,) : Gate.h

(3,) : Gate.h

Key:
  • cycles: (Cycle((0,): Gate.h, (1,): Gate.h, (2,): Gate.h, (3,): Gate.h),)
  • labels: (2,)
  • protocol: IRB
  • twirl: Cliffords on [0, 1, 2, 3]
Cliffords

(0,) : Gate.h

(1,) : Gate.h

(2,) : Gate.h

(3,) : Gate.h

Key:
  • cycles: (Cycle((0,): Gate.h, (1,): Gate.h, (2,): Gate.h, (3,): Gate.h),)
  • labels: (3,)
  • protocol: IRB
  • twirl: Cliffords on [0, 1, 2, 3]
Cliffords

(0, 1) : Gate.cx

(2, 3) : Gate.cx

Key:
  • cycles: (Cycle((0, 1): Gate.cx, (2, 3): Gate.cx),)
  • labels: (0, 1)
  • protocol: IRB
  • twirl: Cliffords on [(0, 1), (2, 3)]
Cliffords

(0, 1) : Gate.cx

(2, 3) : Gate.cx

Key:
  • cycles: (Cycle((0, 1): Gate.cx, (2, 3): Gate.cx),)
  • labels: (2, 3)
  • protocol: IRB
  • twirl: Cliffords on [(0, 1), (2, 3)]
${e}_{F}$
The probability of an error acting on the targeted systems during a dressed gate of interest.
3.0e-02 (2.6e-03)
0.029655142369107518, 0.0026133825733803146
1.4e-02 (2.0e-03)
0.014080920788882623, 0.002013654982758003
7.2e-02 (6.4e-03)
0.07231545530475969, 0.00644712703013451
4.6e-02 (3.2e-03)
0.04632564003622891, 0.003169773847185242
2.2e-02 (2.2e-03)
0.021718326613751858, 0.002159290328283832
2.2e-02 (1.7e-03)
0.022136912198051674, 0.0016629124158864036
${e}_{IU}$
An upper bound on the inferred value of $e_F$ that accounts for systematic errors in the interleaved estimate.
3.8e-02 (6.9e-03)
0.038201934546746336, 0.00689329325579239
2.3e-02 (5.1e-03)
0.0228017812417958, 0.005114157961552127
9.6e-02 (1.5e-02)
0.09603389228763573, 0.015163536320667784
6.0e-02 (8.5e-03)
0.059715638795711096, 0.00853817306293084
3.6e-02 (5.2e-03)
0.03567985662832122, 0.005191377176747723
3.0e-02 (8.6e-03)
0.030353303232364334, 0.008608530499594183
${e}_{IL}$
A lower bound on the inferred value of $e_F$ that accounts for systematic errors in the interleaved estimate.
8.3e-03 (2.7e-03)
0.008260327329037948, 0.0026846083389349415
1.8e-03 (1.2e-03)
0.0017814635866146566, 0.0011691582775738305
2.0e-02 (6.6e-03)
0.01973899666084991, 0.006551976004876707
9.7e-03 (3.0e-03)
0.009661028009702949, 0.0030492779977000254
1.1e-02 (2.9e-03)
0.011175468316869698, 0.002924675905570761
1.5e-02 (6.1e-03)
0.015201781895079897, 0.006117156692910396
${p}$
Decay parameter of the exponential decay $Ap^m$.
9.6e-01 (3.5e-03)
0.9604598101745233, 0.0034845100978404195
9.8e-01 (2.7e-03)
0.9812254389481565, 0.0026848733103440043
9.0e-01 (8.6e-03)
0.9035793929269871, 0.00859616937351268
9.4e-01 (4.2e-03)
0.9382324799516948, 0.004226365129580322
9.8e-01 (2.3e-03)
0.9768337849453314, 0.0023032430168360876
9.8e-01 (1.8e-03)
0.9763872936554115, 0.0017737732436121638
${A}$
SPAM parameter of the exponential decay $Ap^m$.
1.0e+00 (2.2e-02)
1.0223109518088942, 0.022434453380195955
9.8e-01 (1.7e-02)
0.9778091767952731, 0.01680677105699193
1.0e+00 (5.1e-02)
1.028654100253339, 0.05083700522295603
1.0e+00 (2.9e-02)
1.0174902275934967, 0.02872702930399803
9.8e-01 (2.0e-02)
0.9824788320713597, 0.019869134608480044
1.0e+00 (1.6e-02)
1.0136546452579924, 0.01647069551219846

Finding Particular Estimates

Estimate collections, such as the one called fit being considered in this guide, often contain many individual estimate objects. Looping through these objects and manually checking conditions in order to extract certain desired data can be tedious, and therefore this section and the next section Extracting Arrays and Dataframes highlight methods that simplify this process.

The simplest is the method one_or_none() which can be used to extract a single estimate given enough information to uniquely identify it in the collection. For example, below we extract the SRB estimate for the qubit labeled 2 by providing the protocol name and the label subset. If we didn’t provide either of these values, the request would be ambiguous and None would be returned. One can display the key table to figure out the available keynames and values to match against.

[9]:
est = fit.one_or_none(protocol="SRB", labels=(2,))

# the infidelity of the estimate we found
est.e_F
[9]:
EstimateTuple(name='e_F', val=0.030106619488102837, std=0.002895863218123038)

In practice, this might be used in a loop in combination with subset() and keys(), as in the following example.

[10]:
# identify all twirling groups used by SRB and loop through them
twirls = fit.subset(protocol="SRB").keys().twirl
for twirl in twirls:
    print(f"SRB Twirl: {twirl}")
    # get the estimates associated with SRB and this twirling group
    subset = fit.subset(protocol="SRB", twirl=twirl)
    # find out the labels in these estimates and loop through them
    for labels in sorted(subset.keys().labels):
        est = subset.one_or_none(labels=labels)
        print(f"{str(labels):>10}: {est.e_F.val:.2g}")
    print("")
SRB Twirl: Cliffords on [(0, 1), (2, 3)]
    (0, 1): 0.0017
    (2, 3): 0.00066

SRB Twirl: Cliffords on [0, 1, 2, 3]
      (0,): 0.012
      (1,): 0.0077
      (2,): 0.03
      (3,): 0.023

The contents of fit will generally match the order of the circuits encountered inside of the circuit collection, though this is not guaranteed. We can produce new estimate collections that are sorted according to provided keynames.

[11]:
sorted_fit = fit.sorted("protocol", "labels")
sorted_fit[-1]
[11]:
True-Q formatting will not be loaded without trusting this notebook or rerunning the affected cells. Notebooks can be marked as trusted by clicking "File -> Trust Notebook".
XRB
Extended Randomized Benchmarking
Cliffords
(3,)
Key:
  • labels: (3,)
  • protocol: XRB
  • twirl: Cliffords on [0, 1, 2, 3]
${e}_{U}$
The process infidelity of the coherent error acting on the specifed systems during a random gate.
5.4e-03 (1.9e-03)
0.005366430371802483, 0.001934885949415383
${e}_{S}$
The probability of a stochastic error acting on the specified systems during a random gate.
1.8e-02 (9.7e-04)
0.017502360125111194, 0.0009673263792333906
${u}$
The unitarity of the noise, that is, the average decrease in the purity of an initial state.
9.5e-01 (2.5e-03)
0.9537354831463024, 0.0025343890255614078
${A}$
SPAM parameter of the exponential decay $Au^m$.
1.1e+00 (3.6e-02)
1.059277532170979, 0.035707366667531285

Extracting Arrays and Dataframes

The contents of an estimate collection can generally be quite ragged, containing different types of estimates with different sizes from different protocols with different parameters of interest. Therefore, estimate collections themselves are not generally conducive to rectangular data storage formats.

However, you may know that a rectangular structure of data exists within your particular estimate collection. The array() method exists to extract these (nearly-) rectangular data.

The first argument is mandatory and specifies a parameter name (or name pattern) to extract. A parameter name is a string like "e_F" (infidelity), and a name pattern is a string like "e_." specifying a regular expression for all parameter names to match. In the latter case, one axis of the extracted array will sweep over the parameter names that were matched. The remaining arguments must be keynames, and they define the subsequent axes of the extracted array, where each axis is indexed by the values of that keyname present in the collection.

In the first example, we extract an array of infidelity estimates ("e_F") for the IRB and SRB protocols, where the first axis is over protocols, and the second is over qubit labels. We can consult the key table to see which keywords and values are available.

[12]:
array = fit.subset(protocol={"IRB", "SRB"}).array("e_F", "protocol", "labels")
array
[12]:
True-Q formatting will not be loaded without trusting this notebook or rerunning the affected cells. Notebooks can be marked as trusted by clicking "File -> Trust Notebook".
labels (0,) (0, 1) (1,) (2,) (2, 3) (3,)
protocol
IRB 2.97e-02 (2.61e-03)
val=0.0296551
std=0.00261338
2.17e-02 (2.16e-03)
val=0.0217183
std=0.00215929
1.41e-02 (2.01e-03)
val=0.0140809
std=0.00201365
7.23e-02 (6.45e-03)
val=0.0723155
std=0.00644713
2.21e-02 (1.66e-03)
val=0.0221369
std=0.00166291
4.63e-02 (3.17e-03)
val=0.0463256
std=0.00316977
SRB 1.21e-02 (1.06e-03)
val=0.0121132
std=0.0010626
1.75e-03 (9.83e-04)
val=0.00174987
std=0.000983065
7.75e-03 (9.26e-04)
val=0.0077482
std=0.000925788
3.01e-02 (2.90e-03)
val=0.0301066
std=0.00289586
6.56e-04 (1.24e-03)
val=0.000656123
std=0.00124289
2.29e-02 (1.68e-03)
val=0.0228688
std=0.00167573

Here, array is an EstimateArray instance that has the attribute vals which is a NumPy array of estimate values, the attribute stds which is a NumPy array of the same shape containing associated standard deviations of the estimates, and the attribute axes which is a tuple of ArrayAxis instances detailing each axis.

[13]:
# get the estimate value at this index
array.vals[1, 3]
[13]:
0.030106619488102837
[14]:
# display the axis information
array.axes
[14]:
(ArrayAxis('protocol', ('IRB', 'SRB')),
 ArrayAxis('labels', ((0,), (0, 1), (1,), (2,), (2, 3), (3,))))

If the optional dependency pandas is installed, then the array can be converted to a dataframe.

[15]:
array.to_dataframe()
[15]:
labels (0,) (0, 1) (1,) (2,) (2, 3) (3,)
val std val std val std val std val std val std
protocol
IRB 0.029655 0.002613 0.021718 0.002159 0.014081 0.002014 0.072315 0.006447 0.022137 0.001663 0.046326 0.003170
SRB 0.012113 0.001063 0.001750 0.000983 0.007748 0.000926 0.030107 0.002896 0.000656 0.001243 0.022869 0.001676

In the second example, we use the name pattern "e__[XY]" to match single-qubit X and Y errors from our KNR data. Since we have KNR data for two different cycles, we add "cycles" as an axis in addition to the qubit label. Note that, in contrast to the previous example, since multiple parameter names match the pattern, the parameter name itself will be the 0’th axis (or some other axis if name_axis is specified) of this 3-D array. Note that for the purpose of presenting a fancy view of the array in notebooks, the last index of the array appears as columns, while the remaining axes are flattened into rows.

[16]:
fit.subset(protocol={"KNR"}).array("e__[XY]", "labels", "cycles")
[16]:
True-Q formatting will not be loaded without trusting this notebook or rerunning the affected cells. Notebooks can be marked as trusted by clicking "File -> Trust Notebook".
cycles (Cycle((0, 1): Gate.cx),) (Cycle((0, 1): Gate.cz),)
name labels
e__X (2,) 8.27e-04 (1.84e-03)
val=0.000826784
std=0.00183722
3.16e-04 (1.84e-03)
val=0.000315863
std=0.00183576
(3,) 1.38e-03 (1.37e-03)
val=0.00138184
std=0.00137382
1.85e-03 (1.11e-03)
val=0.00184692
std=0.0011055
e__Y (2,) 2.64e-03 (1.84e-03)
val=0.00264011
std=0.00183722
3.18e-03 (1.84e-03)
val=0.00318372
std=0.00183576
(3,) 1.37e-03 (1.37e-03)
val=0.00137364
std=0.00137382
1.17e-03 (1.11e-03)
val=0.00117276
std=0.0011055

Finally, note that the extracted arrays were perfectly (hyper-)rectangular in the previous two examples. If this is not the case, instead of failing, the array() method will place a numpy.nan value in every entry with no corresponding estimate. In the following example, the SRB and IRB protocols don’t have a parameter named "e_S", and therefore the corresponding array entries are NaN.

[17]:
array = fit.subset(protocol={"IRB", "SRB", "XRB"}).array("e_.", "protocol", "labels")
[18]:
array.vals[0, 2, 0]
[18]:
nan

KNR Data Tables

KNR results can be displayed as a heatmap as a part of the plotting suite.

[19]:
fit.plot.knr_heatmap(graph=tq.visualization.Graph.linear(range(4)), cutoff=0)
Warning: The set_constrained_layout_pads function will be deprecated in a future version. Use figure.get_layout_engine().set() instead.
         (/home/jenkins/workspace/release trueq/trueq/visualization/plotters/nr.py:197)
../../_images/guides_fundamentals_estimate_collections_33_1.png

KNR estimates are no different than any other estimate and can be extracted using any of the methods outlined in earlier sections. For reference, one estimate object is constructed for every marginal distribution. For example, one estimate object might contain errors for I, X, Y, and Z for some particular single-qubit subsystem. In the heatmap, these appear as colums of sub-blocks, possibly with some entries missing if they are below the cutoff.

However, you might also be interested in extracting the numbers in an order exactly as shown in the heatmap. First note, as seen in this example, that these heatmaps need not be rectangular; differing degeneracies across gates can cause discrepancies in the y-axis labels. However, we can access sub-rectangles of data using the class KnrDataTable, which is used by the heatmap to organize data, and can also be used by you.

[20]:
table = tq.estimate.KnrDataTable(fit)
# if necessary, set the truncation level, which will affect the amount of data shown
table.set_truncation(0)

If we access the top-left cell of data, we see that it has 3 rows for the three Pauli errors, and two columns, one for each idling subsystem.

[21]:
# access the top-left cell seen in the figure
table.get_cell(0, 0)
[21]:
Cell(mean=array([[0.0323307 , 0.02204237],
       [0.00082678, 0.00138184],
       [0.00264011, 0.00137364]]), std=array([[0.00183722, 0.00137382],
       [0.00183722, 0.00137382],
       [0.00183722, 0.00137382]]), subcycles=[{(2,): Gate.id}, {(3,): Gate.id}])
[22]:
# access the exterior x-axis information of the first column
table.col_info[0]
[22]:
Col(name='', cycles=(Cycle((0, 1): Gate.cx),), twirl=Twirl({(0,): 'P', (1,): 'P', (2,): 'P', (3,): 'P'}, dim=2))
[23]:
# access the exterior y-axis information of the top row
table.row_info[0]
[23]:
Row(sort_key=(False, 1, (1,)), degens=[(('Z',),), (('X',),), (('Y',),)], param_names=['e__Z', 'e__X', 'e__Y'], latex=['$e_{Z}$', '$e_{X}$', '$e_{Y}$'])

Download

Download this file as Jupyter notebook: estimate_collections.ipynb.