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.5e-02 (1.2e-03)
0.014867475927071078, 0.0011506414120584483
${p}$
Decay parameter of the exponential decay $Ap^m$.
9.8e-01 (1.5e-03)
0.9801766987639052, 0.0015341885494112647
${A}$
SPAM parameter of the exponential decay $Ap^m$.
1.0e+00 (1.8e-02)
1.0236077934807672, 0.017698252800957184

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.5e-02 (1.2e-03)
0.014867475927071078, 0.0011506414120584483
6.4e-03 (8.7e-04)
0.006395925765392524, 0.0008672041970720191
3.4e-02 (3.2e-03)
0.03417279486487565, 0.0031730441791908205
2.4e-02 (1.8e-03)
0.024215272706917895, 0.00177688250340946
2.8e-03 (1.1e-03)
0.0028451466404193562, 0.0010710950171612097
4.0e-03 (1.0e-03)
0.004031299457212777, 0.001049940692382499
${p}$
Decay parameter of the exponential decay $Ap^m$.
9.8e-01 (1.5e-03)
0.9801766987639052, 0.0015341885494112647
9.9e-01 (1.2e-03)
0.9914720989794766, 0.001156272262762692
9.5e-01 (4.2e-03)
0.9544362735134991, 0.004230725572254427
9.7e-01 (2.4e-03)
0.9677129697241095, 0.002369176671212613
1.0e+00 (1.1e-03)
0.996965176916886, 0.0011425013516386236
1.0e+00 (1.1e-03)
0.9956999472456397, 0.0011199367385413325
${A}$
SPAM parameter of the exponential decay $Ap^m$.
1.0e+00 (1.8e-02)
1.0236077934807672, 0.017698252800957184
9.9e-01 (1.5e-02)
0.9902045227948687, 0.014983018124694025
1.0e+00 (3.8e-02)
1.0190112153482338, 0.03829685917401981
1.0e+00 (2.5e-02)
1.0227621599766619, 0.025479959761184282
1.0e+00 (1.1e-02)
1.0364900979056533, 0.011039666534373483
1.0e+00 (1.4e-02)
1.038172519464768, 0.01415535724443186
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.
2.5e-02 (2.6e-03)
0.025093016980288763, 0.002566627459495493
1.6e-02 (2.3e-03)
0.015650211111083306, 0.002254479533781282
5.8e-02 (6.0e-03)
0.05791713903998702, 0.005987477950464103
4.1e-02 (3.7e-03)
0.04058971087132446, 0.003671272019153114
2.0e-02 (1.9e-03)
0.02047256041925516, 0.001880189214619033
2.3e-02 (2.1e-03)
0.02324570205338352, 0.0021230712302103293
${e}_{IU}$
An upper bound on the inferred value of $e_F$ that accounts for systematic errors in the interleaved estimate.
4.2e-02 (6.0e-03)
0.04214486479619883, 0.005996317347811408
1.7e-02 (6.3e-03)
0.017088876674066278, 0.006336849568774092
9.6e-02 (1.4e-02)
0.095622872775909, 0.013633213225724068
4.7e-02 (9.6e-03)
0.04691002763441807, 0.00964557380837548
3.8e-02 (4.7e-03)
0.03842449600009148, 0.004665849232796865
4.6e-02 (4.6e-03)
0.04639678467686398, 0.004613474060004318
${e}_{IL}$
A lower bound on the inferred value of $e_F$ that accounts for systematic errors in the interleaved estimate.
2.5e-03 (1.3e-03)
0.002540785994467998, 0.0012887962500542042
5.1e-03 (2.9e-03)
0.0050860639494395565, 0.002910222558184435
6.2e-03 (3.4e-03)
0.006239838691695282, 0.0033746708859614762
6.0e-03 (2.9e-03)
0.006023951016172452, 0.002937334675695014
8.1e-03 (2.2e-03)
0.008086656921395992, 0.002158086295396702
8.0e-03 (1.9e-03)
0.007957302854045278, 0.001930565184297093
${p}$
Decay parameter of the exponential decay $Ap^m$.
9.7e-01 (3.4e-03)
0.9665426440262816, 0.003422169945993991
9.8e-01 (3.0e-03)
0.9791330518518889, 0.003005972711708376
9.2e-01 (8.0e-03)
0.922777147946684, 0.007983303933952137
9.5e-01 (4.9e-03)
0.9458803855049007, 0.004895029358870819
9.8e-01 (2.0e-03)
0.9781626022194612, 0.0020055351622603017
9.8e-01 (2.3e-03)
0.9752045844763909, 0.0022646093122243513
${A}$
SPAM parameter of the exponential decay $Ap^m$.
9.9e-01 (2.2e-02)
0.9949104490942099, 0.021690970149644356
9.8e-01 (1.9e-02)
0.9834351691638958, 0.018587224862841947
9.4e-01 (4.2e-02)
0.9448966208674027, 0.041746731997525
9.5e-01 (3.3e-02)
0.9528862106627006, 0.032628969582886434
9.7e-01 (1.9e-02)
0.9700278421750674, 0.018801529685252474
1.0e+00 (2.1e-02)
1.0319334427584124, 0.020959178370754894

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.03417279486487565, std=0.0031730441791908205)

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.0028
    (2, 3): 0.004

SRB Twirl: Cliffords on [0, 1, 2, 3]
      (0,): 0.015
      (1,): 0.0064
      (2,): 0.034
      (3,): 0.024

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.
4.8e-03 (2.2e-03)
0.004836532031433055, 0.002160616558905072
${e}_{S}$
The probability of a stochastic error acting on the specified systems during a random gate.
1.9e-02 (1.2e-03)
0.01937874067548484, 0.0012292080717649584
${u}$
The unitarity of the noise, that is, the average decrease in the purity of an initial state.
9.5e-01 (3.2e-03)
0.9488240723189308, 0.0032143668461493665
${A}$
SPAM parameter of the exponential decay $Au^m$.
1.1e+00 (4.3e-02)
1.1335450376134095, 0.04301249246119796

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.51e-02 (2.57e-03)
val=0.025093
std=0.00256663
2.05e-02 (1.88e-03)
val=0.0204726
std=0.00188019
1.57e-02 (2.25e-03)
val=0.0156502
std=0.00225448
5.79e-02 (5.99e-03)
val=0.0579171
std=0.00598748
2.32e-02 (2.12e-03)
val=0.0232457
std=0.00212307
4.06e-02 (3.67e-03)
val=0.0405897
std=0.00367127
SRB 1.49e-02 (1.15e-03)
val=0.0148675
std=0.00115064
2.85e-03 (1.07e-03)
val=0.00284515
std=0.0010711
6.40e-03 (8.67e-04)
val=0.00639593
std=0.000867204
3.42e-02 (3.17e-03)
val=0.0341728
std=0.00317304
4.03e-03 (1.05e-03)
val=0.0040313
std=0.00104994
2.42e-02 (1.78e-03)
val=0.0242153
std=0.00177688

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.03417279486487565
[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.025093 0.002567 0.020473 0.001880 0.015650 0.002254 0.057917 0.005987 0.023246 0.002123 0.040590 0.003671
SRB 0.014867 0.001151 0.002845 0.001071 0.006396 0.000867 0.034173 0.003173 0.004031 0.001050 0.024215 0.001777

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,) -6.49e-04 (1.35e-03)
val=-0.000649444
std=0.00134849
6.04e-04 (1.02e-03)
val=0.000604488
std=0.0010233
(3,) 1.39e-03 (7.83e-04)
val=0.00138822
std=0.000783205
2.40e-03 (7.40e-04)
val=0.00240487
std=0.000739951
e__Y (2,) 3.69e-03 (1.35e-03)
val=0.00368963
std=0.00134849
2.42e-03 (1.02e-03)
val=0.00242202
std=0.0010233
(3,) 1.87e-03 (7.83e-04)
val=0.00187225
std=0.000783205
1.01e-03 (7.40e-04)
val=0.00100803
std=0.000739951

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)
../../_images/guides_fundamentals_estimate_collections_33_0.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.03296667,  0.02177763],
       [-0.00064944,  0.00138822],
       [ 0.00368963,  0.00187225]]), std=array([[0.00134849, 0.00078321],
       [0.00134849, 0.00078321],
       [0.00134849, 0.00078321]]), 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.