Quantum error mitigation in Python is a measurement problem as much as a circuit problem. This guide shows how to build a noisy baseline, apply measurement calibration and zero-noise extrapolation, compare ideal, noisy, and mitigated results, and decide whether an apparent improvement is statistically credible.
Overview
Noise mitigation does not make a quantum processor error-free. Instead, it uses additional circuit executions and assumptions about the error process to estimate what a lower-noise result might have been. That distinction matters: a mitigated expectation value can be useful while individual sampled bitstrings remain imperfect.
A practical workflow has five stages:
- Run an ideal reference on a noiseless simulator when the circuit is small enough.
- Run the same experiment with an explicit noise model or hardware backend.
- Correct readout distortion with a calibration matrix when measurement errors are material.
- Repeat the circuit at several effective noise levels and extrapolate toward zero noise.
- Validate the result with uncertainty, calibration quality, runtime, and physical constraints.
These methods address different error sources. Measurement mitigation targets errors introduced when qubit states are converted into classical bits. Zero-noise extrapolation, or ZNE, targets the broader effect of circuit noise by evaluating the computation at deliberately increased noise levels. Neither method replaces circuit simplification, good qubit mapping, or repeated hardware characterization.
How to estimate
Start by choosing one scalar quantity to compare, such as the probability of a bitstring or the expectation value of a Pauli observable. Comparing a single quantity is easier to validate than comparing complete count dictionaries.
For a Qiskit-style experiment, an explicit simulator noise model can be assembled with gate and readout errors. Package names and primitive interfaces change over time, so keep the circuit definition separate from execution code and check the installed Qiskit and Aer documentation before adapting this example:
from qiskit import QuantumCircuit, transpile
from qiskit_aer import AerSimulator
from qiskit_aer.noise import NoiseModel, depolarizing_error, ReadoutError
circuit = QuantumCircuit(2, 2)
circuit.h(0)
circuit.cx(0, 1)
circuit.measure([0, 1], [0, 1])
noise = NoiseModel()
two_qubit_error = depolarizing_error(0.01, 2)
noise.add_all_qubit_quantum_error(two_qubit_error, ["cx"])
readout = ReadoutError([[0.97, 0.03], [0.04, 0.96]])
noise.add_all_qubit_readout_error(readout)
simulator = AerSimulator(noise_model=noise)
compiled = transpile(circuit, simulator)
result = simulator.run(compiled, shots=4000, seed_simulator=7).result()
counts = result.get_counts()
Use the same shot count, seed policy, transpilation settings, and observable definition for every comparison. A useful estimate table records the number of shots, circuit depth after transpilation, number of executions, elapsed time, and the uncertainty of the reported value.
For ZNE, create equivalent circuits with increased noise exposure. Local folding is a common conceptual approach: replace a gate sequence with an equivalent sequence such as G G† G. The logical operation is preserved, while the circuit contains more opportunities for noise. Run scale factors such as 1, 3, and 5, then fit the measured observable against the scale factor and evaluate the fit at zero.
A simple linear estimator is:
import numpy as np
scales = np.array([1.0, 3.0, 5.0])
values = np.array([0.81, 0.75, 0.69])
coefficients = np.polyfit(scales, values, deg=1)
mitigated_value = np.polyval(coefficients, 0.0)
print(mitigated_value)
This is an illustrative estimator, not a guarantee that a linear model is appropriate. If the extrapolated value is outside the observable's physical range, unstable under small changes in scale factors, or dominated by a high-degree fit, treat it as a warning rather than a successful mitigation.
Inputs and assumptions
Record these inputs before interpreting the result:
- Circuit structure: qubit count, two-qubit gate count, depth, measurements, and transpiled basis gates.
- Noise assumptions: gate error probabilities, readout confusion probabilities, relaxation or dephasing parameters, and whether errors are independent.
- Sampling budget: shots per circuit, number of calibration circuits, number of folded variants, and any queue or execution overhead.
- Estimator: bitstring probability, parity, Pauli expectation, energy, or another explicitly defined quantity.
- Uncertainty method: binomial intervals for simple probabilities, bootstrap intervals for transformed estimates, or repeated-run variability.
Measurement calibration commonly uses circuits intended to prepare computational-basis states. Their observed counts form a confusion matrix. Applying its inverse, or a regularized inverse, estimates corrected probabilities. Calibration can become costly as the number of measured qubits grows, and an unstable matrix inverse can amplify sampling noise. For larger systems, consider a structured or local correction model and document the approximation.
Use this decision guide:
| Situation | First method to test | Main caution |
|---|---|---|
| Readout errors dominate a shallow circuit | Measurement calibration | Calibration circuits consume shots and can age on hardware |
| Expectation value from a noisy circuit | ZNE with two or three scale factors | Extrapolation can increase variance and runtime |
| Deep circuit with strong coherent errors | Circuit reduction, layout changes, then mitigation | ZNE assumptions may not hold under coherent or non-smooth errors |
| Small simulator study | Compare ideal, noisy, and mitigated outputs | A simulator model is not evidence of hardware performance |
| Variational algorithm | Mitigate the objective estimate consistently | Optimizer noise can react to mitigation variance |
For broader circuit resource checks, pair this workflow with quantum circuit resource estimation in Python. If the experiment is part of VQE or QAOA, the objective-function and optimizer choices described in Quantum Variational Algorithms in Python affect how much mitigation variance the algorithm can tolerate.
Worked examples
Suppose an ideal simulator estimates a parity expectation of 0.84. The noisy baseline produces 0.68 with a standard uncertainty estimate of 0.02. Measurement calibration changes it to 0.73 ± 0.03. ZNE using three scale factors produces 0.79 ± 0.06.
The result is not simply “ZNE won.” The mitigated estimate is closer to the ideal reference in this example, but its uncertainty is larger and its cost includes extra folded circuits. Report all three values, the ideal reference, the shot count, the scale factors, the fit used, and the runtime. Then repeat the experiment with different random seeds or independent batches. If the ordering changes across batches, the apparent improvement may be sampling variation.
A compact validation record can look like this:
record = {
"observable": "Z0 * Z1 parity",
"shots_per_circuit": 4000,
"ideal": {"value": 0.84},
"noisy": {"value": 0.68, "uncertainty": 0.02},
"readout_mitigated": {"value": 0.73, "uncertainty": 0.03},
"zne": {"value": 0.79, "uncertainty": 0.06},
"zne_scales": [1, 3, 5],
"runtime_seconds": 12.4
}
On hardware, replace the ideal value with a trusted reference only when one is available. Otherwise, validate through symmetries, conservation laws, known limiting cases, circuit inverses, or comparisons across layouts. A mitigation method should improve a defined metric across repeated runs, not merely produce a visually attractive histogram.
For probability and confidence-interval details, see Quantum Measurement Results in Python. Add regression tests around count parsing and observable calculation using the patterns in Testing Quantum Circuits in Python.
When to recalculate
Recalculate mitigation whenever the underlying noise or execution plan changes. That includes moving from a simulator to hardware, selecting a different backend, changing qubit layout or transpilation optimization, altering circuit depth, changing shot counts, or updating the SDK and provider integration. Measurement calibration should also be refreshed when its age may no longer represent the experiment conditions.
Revisit the methodology after a major SDK release because primitive interfaces, supported noise models, and backend options can change. Keep environment versions, circuit hashes, transpiler settings, calibration timestamps, scale factors, and random seeds with each result. This makes a later comparison meaningful rather than anecdotal.
Before accepting a mitigation result, use this checklist:
- Define one observable and its physical range.
- Run ideal and noisy references under matched circuit settings.
- Measure uncertainty, not only the central estimate.
- Compare mitigation improvement against added shots and runtime.
- Repeat with independent batches or seeds.
- Reject unstable extrapolations and document failed attempts.
The most defensible quantum error mitigation report is therefore a small experiment log: assumptions, raw results, corrected results, uncertainty, cost, and validation evidence. That record lets you decide whether mitigation is helping the application—or only making the analysis more complicated.