Recommended resources
The freely available resources this lesson will direct you to.
- Quantum Error Mitigation and the Path to Useful Quantum Computingwww.youtube.com
- Digital Error Mitigation with Mitiq | Qiskit Seminar Series with Andrea Mariwww.youtube.com
- Digital Zero-Noise Extrapolation with Quantum Circuit ...arxiv.org
- Best practices for quantum error mitigation with digital zero- ...arxiv.org
Hello! Welcome to your next lesson on recent advances in quantum computing.
In the previous lesson, we established the high-level principles of Quantum Error Mitigation (QEM) as a pragmatic strategy for near-term devices. We contrasted it with the long-term vision of Quantum Error Correction (QEC) and conceptually introduced Zero-Noise Extrapolation (ZNE) as an intuitive, model-free approach.
Today, we transition from theory to practice. This lesson is designed to guide you through the implementation of ZNE and the analysis of its costs, directly addressing the learning outcome: Implement zero-noise extrapolation (ZNE) for a simple quantum circuit and analyze its sampling overhead.
We will cover the key steps of a ZNE workflow:
- Noise Scaling: How to digitally and controllably amplify the noise in a quantum circuit.
- Extrapolation: How to use the noisy results to infer the ideal, zero-noise outcome.
- Implementation: How to apply these techniques using standard Python libraries like Mitiq and Qiskit.
- Overhead Analysis: How to quantify the cost of ZNE in terms of the required number of measurements (shots).
1. The ZNE Workflow: Noise Scaling and Extrapolation
The core idea of ZNE is to measure an expectation value at several known noise levels and then extrapolate the results back to the ideal case where . This requires two components: a method to scale the noise and a model for the extrapolation.
Digital Error Mitigation with Mitiq | Qiskit Seminar Series with Andrea Mari
To start, let's watch a segment from the 'Digital Error Mitigation with Mitiq' seminar by Andrea Mari. This will give us a practical overview of the two core components of ZNE.
Please watch from 10:50 to 12:46, then from 13:34 to 17:53, and finally from 18:38 to 20:53. This covers the ZNE principle, digital noise scaling via folding, and the different extrapolation models available.
As the video explains, the ZNE process involves:
-
Noise Scaling: Since we can't turn down the hardware's intrinsic noise (), we instead run modified circuits that effectively amplify it to levels . The most common digital technique is unitary folding.
- Local Folding: Each gate is replaced by the sequence . Since in the ideal case, the logic is unchanged, but the number of gates (and thus the accumulated noise) increases. A scale factor of is achieved by replacing every gate with this three-gate sequence.
- Global Folding: The entire circuit unitary is replaced by . This also results in a scale factor of .
- Partial Folding: To achieve non-integer scale factors (e.g., ), only a fraction of the gates in the circuit are folded. This allows for a finer-grained control over the noise levels.
-
Extrapolation: After obtaining expectation values for a set of noise factors , we need to fit a model to extrapolate back to . Common choices include:
- Linear Extrapolation: Assumes .
- Richardson Extrapolation: A specific form of polynomial extrapolation.
- Exponential Extrapolation: Assumes , which is often well-motivated by models of incoherent noise leading to exponential decay of the signal.
The choice of folding strategy and extrapolation model is a subtle but critical aspect of applying ZNE effectively.
2. Implementation with Mitiq and Qiskit
Now, let's see how this workflow is implemented in code. We will use Mitiq, a library designed to be a hardware-agnostic layer on top of quantum programming frameworks like Qiskit.
The key abstraction Mitiq uses is the executor. This is a Python function you define that takes a quantum circuit as input, executes it on a backend (a simulator or real hardware), and returns the desired expectation value. Mitiq then uses this function as a black box to perform error mitigation.
Digital Error Mitigation with Mitiq | Qiskit Seminar Series with Andrea Mari
Let's watch the live demo section from Andrea Mari's talk. This provides a complete, practical example of implementing ZNE.
Watch from 38:19 to 51:23. Pay close attention to these key steps: Creating a noisy backend simulator in Qiskit. Defining the executor function that computes the expectation value. Applying ZNE simply using execute_with_zne. Customizing the process by explicitly choosing noise scaling functions (e.g., fold_global) and extrapolation factories (e.g., RichardsonFactory).
Let's walk through the essential code structure demonstrated in the video.
Step 1: Define a Circuit and a Noisy Executor
First, we need a quantum circuit and an executor function that runs it on a noisy simulator.
import qiskit
from qiskit.providers.fake_provider import FakeLima # A noisy simulator
import mitiq
# Assume 'circuit' is a qiskit.QuantumCircuit object
# Assume 'observable' is a qiskit.quantum_info.SparsePauliOp object
# 1. Define the noisy backend
noise_model = qiskit.providers.aer.noise.NoiseModel.from_backend(FakeLima())
backend = qiskit.Aer.get_backend("aer_simulator")
# 2. Define the executor function
def executor(circuit: qiskit.QuantumCircuit) -> float:
"""Executes a circuit on a noisy backend and returns an expectation value."""
# Transpile the circuit for the backend
circuit_t = qiskit.transpile(circuit, backend)
# Add measurements
circuit_t.measure_all()
# Execute and get counts
result = qiskit.execute(
circuit_t,
backend,
noise_model=noise_model,
shots=8192,
optimization_level=0, # Important: prevent compiler from undoing folds
).result()
# Calculate expectation value from counts (simplified)
# In a real scenario, you'd use Qiskit's Estimator primitive
# or calculate from counts based on the observable.
counts = result.get_counts()
# Let's say we measure the probability of the '00' state for a 2-qubit circuit
exp_val = counts.get("00", 0) / 8192
return exp_val
Step 2: Apply ZNE
With the executor defined, applying ZNE is straightforward. Mitiq handles the noise scaling, execution at different noise levels, and extrapolation behind the scenes.
from mitiq.zne import execute_with_zne
# The original noisy expectation value
noisy_value = executor(circuit)
# The error-mitigated expectation value using default ZNE settings
zne_value = execute_with_zne(circuit, executor)
print(f"Noisy value: {noisy_value}")
print(f"ZNE value: {zne_value}")
Step 3: Customize the ZNE Workflow
For more control, you can specify the noise scaling and extrapolation methods.
from mitiq.zne.scaling import fold_global
from mitiq.zne.inference import RichardsonFactory
# Define a noise scaling function
# Here, we choose global folding
scaling_f = fold_global
# Define an extrapolation factory with specific scale factors
# Here, we use Richardson extrapolation with scale factors 1, 3, and 5
factory = RichardsonFactory(scale_factors=[1, 3, 5])
# Execute with custom settings
custom_zne_value = execute_with_zne(
circuit,
executor,
scale_noise=scaling_f,
factory=factory,
)
print(f"Custom ZNE value: {custom_zne_value}")
This modular design allows you to experiment with different ZNE strategies to find what works best for your specific circuit and hardware.
3. Analysis of Sampling Overhead
Error mitigation is not free. While it doesn't require extra qubits like QEC, it imposes a sampling overhead: you need to take significantly more total measurements (shots) to achieve a given statistical precision compared to the unmitigated experiment.
Best practices for quantum error mitigation with digital zero- ...
For a rigorous analysis of this overhead, let's turn to the paper 'Best practices for quantum error mitigation with digital zero-noise extrapolation'. It provides a clear, quantitative discussion of shot noise scaling in ZNE.
Please read Section III, 'EXECUTION'. Focus on the paragraph titled 'Shots' and the accompanying Figure 5.
The key takeaways from this section are:
-
Source of Overhead: The overhead in ZNE comes from two main sources:
- Multiple Executions: You must run the experiment multiple times, at least once for each chosen noise scale factor . If you use scale factors, you run different circuits.
- Variance Amplification: The final extrapolated value is a linear combination of the measured expectation values: . The variance of this sum is . Since some coefficients are typically greater than 1, this process amplifies the shot noise from the individual measurements.
-
Scaling of Shot Noise: As shown in Figure 5 of the paper, the standard deviation of the final ZNE estimate due to finite shot noise still follows the expected statistical scaling:
where is the number of shots used for each noise level. However, the constant of proportionality, , is larger for the ZNE estimate than for a single noisy measurement. This constant depends on the extrapolation coefficients and the noise levels of the underlying measurements.
Let's define the total shot budget as , where is the number of noise levels. To achieve the same final precision as an unmitigated experiment with shots, a ZNE experiment will require a total shot budget . This ratio represents the sampling overhead.
Test your understanding!
Imagine you are using ZNE with linear extrapolation, using noise levels and . The extrapolated value is given by .
Assume the variance of each individual measurement is . What is the variance of the final ZNE estimate, ? How does this illustrate the concept of sampling overhead?
Show answer
Using the formula for the variance of a linear combination of independent random variables:
Since , we have:
This means the variance of the final mitigated result is 5 times larger than the variance of a single one of the input measurements. To reduce this variance back to , you would need to increase the number of shots for each measurement by a factor of 5. The total shot budget would be . This demonstrates how the extrapolation process significantly increases the sampling cost to achieve the same statistical confidence.
Conclusion
In this lesson, you have moved from the concept of ZNE to its practical implementation and analysis. You are now equipped to apply this powerful error mitigation technique to real quantum circuits.
Key Takeaways:
- ZNE is implemented by scaling noise (typically via unitary folding) and extrapolating results (using models like linear, Richardson, or exponential).
- Libraries like Mitiq provide a high-level, hardware-agnostic interface for applying ZNE by wrapping a user-defined
executorfunction. - Effective ZNE requires careful choices for noise scaling methods, scale factors, and extrapolation models. These choices are often problem-dependent.
- The primary cost of ZNE is sampling overhead. The total number of measurements required increases due to running experiments at multiple noise levels and the amplification of statistical variance during extrapolation.
- The standard deviation of the ZNE estimate scales as , but the prefactor is larger than in an unmitigated experiment.
Preview of the next lesson:
Now that you have hands-on experience with ZNE, we will turn our attention to the other major QEM technique: Probabilistic Error Cancellation (PEC). We will delve into its more complex theoretical foundation, including the quasi-probability decomposition that allows it to provide an unbiased estimate of the ideal result, and rigorously compare its resource requirements and limitations to those of ZNE.