# Extended Randomized Benchmarking (XRB)

This example illustrates how to generate extended randomized benchmarking (XRB) circuits and use them to estimate the probability of a stochastic error acting on the specified system(s) during a random gate. While this example uses a simulator to execute the circuits, the same procedure can be followed for hardware applications.

## Isolated XRB

This section illustrates how to generate XRB circuits to characterize a pair of qubits in isolation. Here, we are performing two-qubit XRB which learns the stochastic infidelity over the two-qubit Clifford gateset.

import trueq as tq

# generate XRB circuits to characterize a pair of qubits [0, 1]
# with 9 * 30 random circuits for each circuit depth [2, 4, 16]
circuits = tq.make_xrb([[0, 1]], [2, 4, 16], 30)

# initialize a noisy simulator with stochastic Pauli and overrotation

# run the circuits on the simulator to populate their results
sim.run(circuits, n_shots=1000)

# plot the exponential decay of the purities
circuits.plot.raw()


Print the fit summary:

circuits.fit()

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 (0, 1) Key: labels: (0, 1) protocol: XRB twirl: Cliffords on [(0, 1)] ${e}_{S}$ The probability of a stochastic error acting on the specified systems during a random gate. 3.8e-02 (7.9e-04) 0.03757411766520158, 0.0007928364915681076 ${u}$ The unitarity of the noise, that is, the average decrease in the purity of an initial state. 9.2e-01 (1.6e-03) 0.9213478175871096, 0.0016278322345486121 ${A}$ SPAM parameter of the exponential decay $Au^m$. 9.7e-01 (8.4e-03) 0.9715946003571244, 0.008371271321779814

## Simultaneous XRB

This section demonstrates how to generate XRB circuits that characterize the amount of stochastic noise while gates are applied simultaneously on a device.

For example, to generate XRB circuits to simultaneously characterize a single qubit [0], a pair of qubits [1, 2], and another single qubit [3] with $9 \times 30$ random circuits for each circuit depth [2, 4, 16], we can write:

circuits = tq.make_xrb([[0], [1, 2], [3]], [2, 4, 16], 30)

# initialize a noisy simulator with stochastic Pauli and overrotation

# run the circuits on the simulator to populate their results
sim.run(circuits, n_shots=1000)

# plot the exponential decay of the purities
circuits.plot.raw()


Print the fit summary:

circuits.fit()

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 (0,) Key: labels: (0,) protocol: XRB twirl: Cliffords on [0, (1, 2), 3] Cliffords (1, 2) Key: labels: (1, 2) protocol: XRB twirl: Cliffords on [0, (1, 2), 3] Cliffords (3,) Key: labels: (3,) protocol: XRB twirl: Cliffords on [0, (1, 2), 3] ${e}_{S}$ The probability of a stochastic error acting on the specified systems during a random gate. 2.1e-02 (8.9e-04) 0.020777234836502845, 0.0008895842310736692 4.0e-02 (7.2e-04) 0.039737040272781354, 0.0007168242203610337 2.0e-02 (9.7e-04) 0.01971658134127563, 0.0009670229094987978 ${u}$ The unitarity of the noise, that is, the average decrease in the purity of an initial state. 9.5e-01 (2.3e-03) 0.9451696317525939, 0.0023229363482608046 9.2e-01 (1.5e-03) 0.9169119486123498, 0.0014684581278891567 9.5e-01 (2.5e-03) 0.9479407745296478, 0.002527884063052767 ${A}$ SPAM parameter of the exponential decay $Au^m$. 9.8e-01 (1.1e-02) 0.9764326968224961, 0.011440703458461427 9.9e-01 (8.6e-03) 0.9892326124040982, 0.008608716917013292 9.7e-01 (1.1e-02) 0.974224706405603, 0.01120696256933586

## Simultaneous XRB on Qudits

The make_xrb() function can be used for qudits of higher dimension in exactly the same way as for qubits. For example, consider the same simultaneous characterization configuration as in the example above but with qutrits instead of qubits:

# set the global dimension to 3 for qutrits
tq.settings.set_dim(3)

# create circuits for the simultaneous characterization of
# qutrit 1, the qutrit pair (1, 2) and qutrit 3:
circuits = tq.make_xrb([[0], [1, 2], [3]], [2, 4, 16], 30)

# display a sample circuit
circuits[0].draw()


We again initialize a noisy simulator with overrotation errors and stochastic Pauli noise. The add_overrotation() method works natively for qudits of higher dimension. To implement the stochastic noise, we use a probabilistic sum of Weyl operators, analogous to the stochastic Pauli channel used for qubits. We add this noise to our simulator using the add_stochastic_weyl() method. For this example, we add a small qutrit $X$ and $X^2$ error:

sim = tq.Simulator().add_stochastic_pauli(W10=0.02, W20=0.01).add_overrotation(0.04)

# run the circuits on the simulator to populate their results
sim.run(circuits, n_shots=1000)

# plot the exponential decay of the purities
circuits.plot.raw()


Display the fit parameter:

circuits.fit()

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 (0,) Key: labels: (0,) protocol: XRB twirl: Cliffords on [0, (1, 2), 3] Cliffords (1, 2) Key: labels: (1, 2) protocol: XRB twirl: Cliffords on [0, (1, 2), 3] Cliffords (3,) Key: labels: (3,) protocol: XRB twirl: Cliffords on [0, (1, 2), 3] ${e}_{S}$ The probability of a stochastic error acting on the specified systems during a random gate. 2.9e-02 (1.1e-03) 0.029442738671238367, 0.0011108722516605118 5.6e-02 (1.1e-03) 0.056232269664836076, 0.0010951970189803 3.0e-02 (8.5e-04) 0.029744506753276112, 0.0008465458561324587 ${u}$ The unitarity of the noise, that is, the average decrease in the purity of an initial state. 9.3e-01 (2.4e-03) 0.9347290722077344, 0.002425871543079918 8.9e-01 (2.1e-03) 0.8893312479322616, 0.0020930634998675723 9.3e-01 (1.8e-03) 0.934070187447374, 0.0018480729761949802 ${A}$ SPAM parameter of the exponential decay $Au^m$. 9.8e-01 (1.1e-02) 0.9834350709952646, 0.010757099989135495 9.7e-01 (9.4e-03) 0.9691661110684998, 0.009386790377451224 9.8e-01 (1.0e-02) 0.9817318190505321, 0.010152970913026142

Total running time of the script: ( 0 minutes 16.943 seconds)

Gallery generated by Sphinx-Gallery