Recommended resources
The freely available resources this lesson will direct you to.
Introduction
Hello again. In our previous lesson, we established the theoretical foundation of randomized benchmarking (RB). We learned how applying sequences of random Clifford gates, followed by an inverse, allows us to measure gate performance. The key insight was that averaging over many such sequences—a process called twirling—transforms any gate-independent Markovian noise into a simple depolarizing channel. This leads to the characteristic exponential decay of the sequence fidelity:
From the fitted decay parameter , we can extract the average Error Per Clifford (EPC), for a single qubit, in a way that is robust to state preparation and measurement (SPAM) errors.
Today, we will transition from theory to practice. Our objective is to implement a single-qubit randomized benchmarking experiment on a noisy simulator to extract the average gate fidelity. This will involve setting up a simulated quantum environment with a defined noise model, running the RB protocol using a modern quantum software framework, and performing the data analysis to extract the key performance metrics.
Preparing the "Noisy Device": A Simulated Backend
Before we can benchmark our gates, we need a quantum processor to run them on. For this lesson, we will use a software simulator. A key advantage of a simulator is that we can precisely define the noise characteristics, allowing us to verify that our RB implementation correctly measures the noise we introduce.
We will use Qiskit, a popular open-source framework for quantum computing. To simulate a realistic, noisy device, we will use Qiskit's AerSimulator and configure it with a NoiseModel. In line with the theory from our last lesson, we will use a depolarizing error model. This model assumes that after each gate, there's a certain probability that the qubit's state is completely randomized.
The code to set up a simple noise model where single-qubit gates (sx, x) have a 0.5% error probability and two-qubit gates (cx) have a 5% error probability looks like this:
# For simulation
from qiskit_aer import AerSimulator
from qiskit_aer.noise import NoiseModel, depolarizing_error
# Create an empty noise model
noise_model = NoiseModel()
# Add depolarizing error to single-qubit gates
p_1q_error = 0.005
noise_model.add_all_qubit_quantum_error(depolarizing_error(p_1q_error, 1), ["sx", "x"])
# Add depolarizing error to two-qubit gates
p_2q_error = 0.05
noise_model.add_all_qubit_quantum_error(depolarizing_error(p_2q_error, 2), ["cx"])
# Create a backend simulator with the noise model
backend = AerSimulator(noise_model=noise_model)
This backend object now represents our simulated noisy quantum computer, ready for characterization.
Implementing the Randomized Benchmarking Experiment
With our noisy backend defined, we can now set up the RB experiment. While one could implement the Clifford generation, inversion, and circuit construction from scratch, modern frameworks like qiskit-experiments provide high-level tools to automate this process.
We will use the StandardRB class, which requires three main parameters that should be familiar from our last lesson:
qubits: The physical qubit(s) to run the experiment on.lengths: A list of sequence lengths,m, to be tested.num_samples: The number of different random Clifford sequences,K, to generate and average over for each lengthm.
Randomized Benchmarking - Qiskit Experiments 0.13.0
The following Qiskit documentation page explains the parameters and provides a complete code example for a single-qubit RB experiment. This is the core of today's implementation task.
First, review the section "Standard RB experiment" to familiarize yourself with the parameters of the Qiskit experiment. Then, study the code in the section "Running a 1-qubit RB experiment". Trace the steps: defining experiment parameters, instantiating StandardRB, running it, and displaying the results. We will analyze the output in detail next.
As you saw in the resource, after setting the parameters and running exp.run(backend), the library automatically handles:
- Generating
num_samplesrandom Clifford sequences for each lengthm. - Calculating the correct inverse gate for each sequence.
- Transpiling these logical Clifford operations into the backend's basis gates (e.g.,
sx,rz). - Executing the circuits on the
backend. - Averaging the "survival probabilities" for each
mto get . - Fitting the results to the exponential model .
The analysis produces a plot and a table of results. The plot shows your experimental data points and the best-fit exponential curve—a direct visualization of the theory we discussed. The analysis results provide the fitted parameters, most importantly alpha (our ) and the Error Per Clifford (EPC), which is our .
Single-qubit randomized benchmarking results
This figure from the Qiskit documentation shows the output of a single-qubit RB experiment. The plot displays the measured sequence fidelities (data points) and the exponential fit (solid line). The table below summarizes the key analysis results, including the alpha parameter and the crucial EPC and EPG values.
Test your understanding!
The analysis from the Qiskit experiment reports a fitted alpha value of 0.99. What is the corresponding Error Per Clifford (EPC)?
Show answer
The parameter alpha in the Qiskit fit is the same as the depolarizing parameter p in our theoretical model. For a single qubit (), the Error Per Clifford r (or EPC) is given by:
Plugging in :
So, the EPC is 0.5%.
From Error Per Clifford (EPC) to Error Per Gate (EPG)
The EPC is a useful metric, but it tells us the error of an abstract Clifford operation. What we often want to know is the error of the physical, elementary gates that the quantum computer actually executes (e.g., rotations like the sx gate). This is the Error Per Gate (EPG).
To convert EPC to EPG, we need to know, on average, how many elementary gates are required to construct a single Clifford gate. Since the Clifford gates are chosen randomly, we need the average number of elementary gates per Clifford, denoted . If we assume the errors from each elementary gate add incoherently, we can approximate the relationship as:
The value of depends on the specific choice of elementary gates and the compiler's efficiency.
Hands-on introduction to randomized benchmarking
To see a formal calculation of this conversion, let's return to the "Hands-on introduction" paper. It provides a concrete example for a common set of elementary gates.
Please read the portion of Section 1.4, "Benchmarking a real device", that discusses the re-scaling of fidelity. Start from the paragraph beginning "The set of average gate-set fidelities..." and read through to the end of Equation (33). Note the calculation of ¯n_SQC (our ¯n_gates) and how it's used in Equation (33) to relate the Clifford error r_C1 to the elementary gate error r_SQ.
As the paper demonstrates, for a basis gate set of and rotations around the X and Y axes, the single-qubit Clifford group can be synthesized with an average of elementary gates per Clifford.
Qiskit's StandardRB analysis automates this conversion. It knows the average number of gates per Clifford for its standard basis set (sx, rz, x). Furthermore, it allows for a more nuanced model where you can specify the expected gate_error_ratio. For instance, you might assume virtual rz gates are error-free ('rz': 0), while sx and x gates contribute equally to the error ('sx': 1, 'x': 1). The analysis then distributes the total EPC among the basis gates according to these ratios and their average counts per Clifford, providing an estimated EPG for each basis gate.
Conclusion
In this lesson, we bridged the gap between the theory of randomized benchmarking and its practical implementation. We've seen how to use a software framework to carry out the full RB workflow on a simulated noisy quantum device.
Key Takeaways:
- RB Implementation: The process involves (1) defining a (simulated) noisy backend, (2) using a library like
qiskit-experimentsto generate and run the RB sequences for various lengthsm, and (3) fitting the resulting fidelity decay curve. - From Fit to Fidelity: The fit to yields the depolarizing parameter (often called
alpha), which is then used to compute the Error Per Clifford (EPC). - EPC vs. EPG: The EPC measures the error of an average Clifford operation. To find the more fundamental Error Per Gate (EPG) for the physical basis gates, we must re-scale the EPC by the average number of elementary gates per Clifford ().
- Practical Tools: Modern quantum SDKs provide powerful, automated tools for performing complex characterization experiments like RB, handling the low-level details of sequence generation and analysis.
Preview of the next lesson:
Randomized benchmarking provides a single number—the average gate fidelity—which is an incredibly useful and scalable metric. However, it doesn't tell us the whole story. What kind of errors are happening? Is the gate over-rotating, or is it introducing dephasing? To get this level of detail, we need a more comprehensive tool. In the next lesson, we will compare and contrast randomized benchmarking with quantum process tomography, a technique that can reconstruct the full mathematical description of a noisy gate, and discuss the trade-offs between the information they provide and their experimental cost.