Randomized Benchmarking

Randomized benchmarking (RB) is a popular protocol for characterizing the error rate of quantum processors. An RB experiment consists of the generation of random Clifford circuits on the given qubits such that the unitary computed by the circuits is the identity. After running the circuits, the number of shots resulting in an error (i.e. an output different from the ground state) are counted, and from this data one can infer error estimates for the quantum device, by calculating the Error Per Clifford. See the Qiskit Textbook for an explanation on the RB method, which is based on Refs. [1] [2].

Note

This tutorial requires the qiskit-aer and qiskit-ibm-runtime packages to run simulations. You can install them with python -m pip install qiskit-aer qiskit-ibm-runtime.

import numpy as np
from qiskit_experiments.library import StandardRB, InterleavedRB
from qiskit_experiments.framework import ParallelExperiment, BatchExperiment
import qiskit.circuit.library as circuits

# For simulation
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime.fake_provider import FakePerth

backend = AerSimulator.from_backend(FakePerth())

Standard RB experiment

To run the RB experiment we need to provide the following RB parameters, in order to generate the RB circuits and run them on a backend:

  • qubits: The number of qubits or list of physical qubits for the experiment

  • lengths: A list of RB sequences lengths

  • num_samples: Number of samples to generate for each sequence length

  • seed: Seed or generator object for random number generation. If None then default_rng will be used

  • full_sampling: If True all Cliffords are independently sampled for all lengths. If False for sample of lengths longer sequences are constructed by appending additional Clifford samples to shorter sequences. The default is False

The analysis results of the RB Experiment may include:

  • EPC: The estimated Error Per Clifford

  • alpha: The depolarizing parameter. The fitting function is aαm+b, where m is the Clifford length

  • EPG: The Error Per Gate calculated from the EPC, only for 1-qubit or 2-qubit quantum gates (see [3])

Running a 1-qubit RB experiment

The standard RB experiment will provide you gate errors for every basis gate constituting an averaged Clifford gate. Note that you can only obtain a single EPC value E from a single RB experiment. As such, computing the error values for multiple gates {gi} requires some assumption of contribution of each gate to the total depolarizing error. This is provided by the gate_error_ratio analysis option.

Provided that we have ni gates with independent error ei per Clifford, the total EPC is estimated by the composition of error from every basis gate,

E=1i(1ei)niiniei+O(e2),

where ei1 and the higher order terms can be ignored.

We cannot distinguish ei with a single EPC value E as explained, however by defining an error ratio ri with respect to some standard value e0, we can compute EPG ei for each basis gate.

Ee0iniri

The EPG of the i th basis gate will be

eirie0=riEiniri.

Because EPGs are computed based on this simple assumption, this is not necessarily representing the true gate error on the hardware. If you have multiple kinds of basis gates with unclear error ratio ri, interleaved RB experiment will always give you accurate error value ei.

lengths = np.arange(1, 800, 200)
num_samples = 10
seed = 1010
qubits = [0]

# Run an RB experiment on qubit 0
exp1 = StandardRB(qubits, lengths, num_samples=num_samples, seed=seed)
expdata1 = exp1.run(backend).block_for_results()

# View result data
print("Gate error ratio: %s" % expdata1.experiment.analysis.options.gate_error_ratio)
display(expdata1.figure(0))
display(expdata1.analysis_results(dataframe=True))
Gate error ratio: {'x': 1.0, 'rz': 0.0, 'sx': 1.0}
../../_images/randomized_benchmarking_1_1.png
name experiment components value quality backend run_time chisq
b3b4fbdd alpha StandardRB [Q0] 0.99929+/-0.00029 good aer_simulator_from(fake_perth) None 0.040618
c05fc32a EPC StandardRB [Q0] 0.00036+/-0.00014 good aer_simulator_from(fake_perth) None 0.040618
05bb41bf EPG_x StandardRB [Q0] 0.00046+/-0.00019 good aer_simulator_from(fake_perth) None 0.040618
f9e2f806 EPG_rz StandardRB [Q0] 0.0+/-0 good aer_simulator_from(fake_perth) None 0.040618
e5f872dc EPG_sx StandardRB [Q0] 0.00046+/-0.00019 good aer_simulator_from(fake_perth) None 0.040618

Running a 2-qubit RB experiment

In the same way we can compute EPC for two-qubit RB experiment. However, the EPC value obtained by the experiment indicates a depolarization which is a composition of underlying error channels for 2Q gates and 1Q gates in each qubit. Usually 1Q gate contribution is small enough to ignore, but in case this contribution is significant comparing to the 2Q gate error, we can decompose the contribution of 1Q gates [3].

α2Q,C=15(α0N1/2+α1N1/2+3α0N1/2α1N1/2)α01N2,

where αi is the single qubit depolarizing parameter of channel i, and α01 is the two qubit depolarizing parameter of interest. N1 and N2 are total count of single and two qubit gates, respectively.

Note that the single qubit gate sequence in the channel i may consist of multiple kinds of basis gates {gij} with different EPG eij. Therefore the αiN1/2 should be computed from EPGs, rather than directly using the αi, which is usually a composition of depolarizing maps of every single qubit gate. As such, EPGs should be measured in the separate single-qubit RBs in advance.

αiN1/2=αi0ni0αi1ni1...,

where αijnij indicates a depolarization due to a particular basis gate j in the channel i. Here we assume EPG eij corresponds to the depolarizing probability of the map of gij, and thus we can express αij with EPG.

eij=2n12n(1αij)=1αij2,

for the single qubit channel n=1. Accordingly,

αiN1/2=j(12eij)nij,

as a composition of depolarization from every primitive gates per qubit. This correction will give you two EPC values as a result of the two-qubit RB experiment. The corrected EPC must be closer to the outcome of interleaved RB. The EPGs of two-qubit RB are analyzed with the corrected EPC if available.

lengths_2_qubit = np.arange(1, 200, 30)
lengths_1_qubit = np.arange(1, 800, 200)
num_samples = 10
seed = 1010
qubits = (1, 2)

# Run a 1-qubit RB experiment on qubits 1, 2 to determine the error-per-gate of 1-qubit gates
single_exps = BatchExperiment(
    [
        StandardRB((qubit,), lengths_1_qubit, num_samples=num_samples, seed=seed)
        for qubit in qubits
    ]
)
expdata_1q = single_exps.run(backend).block_for_results()
# Run an RB experiment on qubits 1, 2
exp_2q = StandardRB(qubits, lengths_2_qubit, num_samples=num_samples, seed=seed)

# Use the EPG data of the 1-qubit runs to ensure correct 2-qubit EPG computation
exp_2q.analysis.set_options(epg_1_qubit=expdata_1q.analysis_results(dataframe=True))

# Run the 2-qubit experiment
expdata_2q = exp_2q.run(backend).block_for_results()

# View result data
print("Gate error ratio: %s" % expdata_2q.experiment.analysis.options.gate_error_ratio)
display(expdata_2q.figure(0))
display(expdata_2q.analysis_results(dataframe=True))
Gate error ratio: {'cx': 1.0}
../../_images/randomized_benchmarking_3_1.png
name experiment components value quality backend run_time chisq
f2e3302c alpha StandardRB [Q1, Q2] 0.9751+/-0.0007 good aer_simulator_from(fake_perth) None 1.359995
9c59879c EPC StandardRB [Q1, Q2] 0.0186+/-0.0005 good aer_simulator_from(fake_perth) None 1.359995
08c64633 EPC_corrected StandardRB [Q1, Q2] 0.0169+/-0.0007 good aer_simulator_from(fake_perth) None 1.359995
08d9dc78 EPG_cx StandardRB [Q1, Q2] 0.0120+/-0.0005 good aer_simulator_from(fake_perth) None 1.359995

Note that EPC_corrected value is smaller than one of raw EPC, which indicates contribution of depolarization from single-qubit error channels. If you don’t need EPG value, you can skip its computation by exp_2q.analysis.set_options(gate_error_ratio=False).

Displaying the RB circuits

The default RB circuit output shows Clifford blocks:

# Run an RB experiment on qubit 0
exp = StandardRB(physical_qubits=(0,), lengths=[2], num_samples=1, seed=seed)
c = exp.circuits()[0]
c.draw(output="mpl", style="iqp")
../../_images/randomized_benchmarking_4_0.png

You can decompose the circuit into underlying gates:

c.decompose().draw(output="mpl", style="iqp")
../../_images/randomized_benchmarking_5_0.png

And see the transpiled circuit using the basis gate set of the backend:

from qiskit import transpile
transpile(c, backend, **vars(exp.transpile_options)).draw(output="mpl", style="iqp", idle_wires=False)
../../_images/randomized_benchmarking_6_0.png

Note

In 0.5.0, the default value of optimization_level in transpile_options changed from 0 to 1 for RB experiments. Transpiled circuits may have less number of gates after the change.

Interleaved RB experiment

The interleaved RB experiment is used to estimate the gate error of the interleaved gate (see [4]). In addition to the usual RB parameters, we also need to provide:

  • interleaved_element: the element to interleave, given either as a group element or as an instruction/circuit

The analysis results of the RB Experiment includes the following:

  • EPC: The estimated error of the interleaved gate

  • alpha and alpha_c: The depolarizing parameters of the original and interleaved RB sequences respectively

Extra analysis results include

  • EPC_systematic_err: The systematic error of the interleaved gate error [4]

  • EPC_systematic_bounds: The systematic error bounds of the interleaved gate error [4]

Let’s run an interleaved RB experiment on two qubits:

lengths = np.arange(1, 200, 30)
num_samples = 10
seed = 1010
qubits = (1, 2)

# The interleaved gate is the CX gate
int_exp2 = InterleavedRB(
    circuits.CXGate(), qubits, lengths, num_samples=num_samples, seed=seed)

int_expdata2 = int_exp2.run(backend).block_for_results()
int_results2 = int_expdata2.analysis_results(dataframe=True)
# View result data
display(int_expdata2.figure(0))
display(int_results2)
../../_images/randomized_benchmarking_8_0.png
name experiment components value quality backend run_time chisq EPC_systematic_err EPC_systematic_bounds
5c413b75 alpha InterleavedRB [Q1, Q2] 0.9756+/-0.0004 good aer_simulator_from(fake_perth) None 1.72862 None None
6b2644a2 alpha_c InterleavedRB [Q1, Q2] 0.9852+/-0.0007 good aer_simulator_from(fake_perth) None 1.72862 None None
932245b9 EPC InterleavedRB [Q1, Q2] 0.0111+/-0.0005 good aer_simulator_from(fake_perth) None 1.72862 0.025521 [0, 0.03663914511567723]

References

See also