Lesson 52 · 90 min · advanced
Error Mitigation: ZNE & Readout Correction
Noisy quantum processors cannot yet afford quantum error correction, but many applications only need expectation values, and those can be corrected statistically. This lesson derives three error-mitigation techniques from first principles. Zero-noise extrapolation measures an observable at amplified noise levels produced by global unitary folding and extrapolates to with the Richardson weights , which cancel the noise expansion up to order ; the price is a variance amplified by for the nodes . Readout mitigation inverts the column-stochastic confusion matrix of the measurement, qubit by qubit, and repairs negative quasi-probabilities. Probabilistic error cancellation writes the inverse of a noise channel as a signed mixture of implementable operations and pays a sampling overhead per gate.
Prerequisites: Noise, Decoherence, $T_1$ and $T_2$
Objectives and key results
Derive the Richardson weights as Lagrange interpolation at , prove and for , and compute for the nodes .
Explain what global folding builds and prove that it multiplies first-order gate noise by , stating the assumptions on the noise.
Compute the variance amplification of an extrapolated estimate and the shot budget it requires.
Model readout errors by a column-stochastic confusion matrix, invert it in closed form and for tensor products of qubits, and repair negative quasi-probabilities by clipping or by Euclidean projection onto the probability simplex.
Construct the quasi-probability decomposition of the inverse depolarizing channel and derive the sampling overhead of probabilistic error cancellation.
Run noise-scaled circuits on the platform's density-matrix engine and mitigate expectation values and measured distributions by hand and in code.
- formula · Richardson extrapolation to zero noise
- theorem · Cancellation of the noise expansion
- identity · Variance amplification
- formula · Inverse of a single-qubit confusion matrix
- formula · Probabilistic error cancellation of depolarizing noise
Mitigation instead of correction#
The previous lesson modelled decoherence and gate errors as quantum channels and showed how quickly they degrade a computation: local depolarizing noise of strength on both qubits of a Bell state lowers its fidelity to with , and every additional gate compounds the damage. Quantum error correction removes such errors by encoding each logical qubit into many physical qubits and measuring syndromes continuously, but its overhead of hundreds to thousands of physical qubits per logical qubit is beyond today's noisy intermediate-scale (NISQ) processors.
Variational algorithms and quantum machine learning models, however, rarely need the full output state. They need expectation values of a few observables, estimated from many repetitions of a circuit. Error mitigation exploits this: it runs additional or modified noisy circuits and combines their measured averages classically so that the combination estimates the noiseless value . No qubits are added, but nothing is free either: every mitigation scheme trades a reduction of the bias for an increase of the variance, which must be paid for with more shots. This lesson derives the three most widely used schemes and their costs: zero-noise extrapolation, readout-error mitigation and probabilistic error cancellation.
Definition
Noise-scaled expectation value
Fix a circuit, an input state and an observable with . Suppose the strength of all noise processes in the circuit can be multiplied by a factor without changing anything else; is the native noise of the device. The noise-scaled expectation value is the exact (infinite-shot) expectation of at scale , and is the noiseless value we want. Zero-noise extrapolation (ZNE) assumes that is smooth near and admits the expansion measures at a few nodes , and extrapolates to . If the native noise has a small strength , the coefficients scale as .
Richardson extrapolation#
Given measured values at distinct nodes, the most natural estimate of interpolates the data with the unique polynomial of degree at most and evaluates it at . Because interpolation is linear in the data, this estimate is a fixed linear combination whose weights depend only on the nodes. The weights are designed so that the combination annihilates the low powers of in the noise expansion; this idea goes back to L. F. Richardson's extrapolation of numerical step sizes to zero and was introduced for quantum circuits by Temme, Bravyi and Gambetta.
Richardson weights cancel the noise expansion up to order m − 1
Let be distinct and nonzero, and define Then (i) ; (ii) for ; (iii) . Consequently, if with , the Richardson estimate satisfies and if its leading bias is . With the bias is , whereas the unmitigated value has bias .
Proof (7 steps)
- Step 1:The Lagrange basis polynomials of the nodes: each has degree , vanishes at every node except , and equals there. They exist because the nodes are distinct.
- Step 2:The difference of the two sides is a polynomial of degree at most with the roots , so it is the zero polynomial.
- Step 3:Multiply numerator and denominator of every factor by . The Richardson weights are the Lagrange basis polynomials evaluated at .
- Step 4:Evaluate the interpolation identity at . For this is , statement (i); for it is statement (ii). In matrix form the weights solve the Vandermonde system with , which is nonsingular because .
- Step 5:The left side is monic of degree (the sum has degree at most ) and vanishes at all nodes, so it equals the monic polynomial with these roots. Multiplying by gives statement (iii).
- Step 6:Insert the expansion and use (i) and (ii): the constant survives with weight one and every term of order cancels exactly.
- Step 7:Triangle inequality for the bound; statement (iii) for the leading term. With every remaining term carries at least the factor .
∎
The weights for the nodes {1, 3, 5}
- Step 1:Each weight is the product over the two other nodes of .
- Step 2:Statements (i) and (ii) of the theorem with : the constant is reproduced, the linear and quadratic terms cancel.
- Step 3:Statement (iii): the leading bias of the three-node estimate is ; the next term contributes .
- Step 4:The Richardson estimate through , implemented by the engine function richardsonExtrapolate (and, for arbitrary nodes, by richardsonZeroNoise).
- Step 5:Two-node (linear) extrapolations cancel only the linear term. Their bias is and , respectively: the farther apart the nodes, the larger the uncancelled curvature.
Result
The weights alternate in sign and exceed one in magnitude: the estimate is an extrapolation, not an average. For the lab data , , the three points lie on the parabola , and the Richardson estimate is its value at . A straight line through the nodes and would give , one through and would give , and the least-squares line through all three points would give ; all three miss the curvature.
Quick check
An expectation value measured at the noise scales and gives and . What is the two-node Richardson (linear) estimate of ?
Scaling the noise by global unitary folding#
Pulse stretching requires access to the control electronics. Giurgica-Tiron et al. proposed a purely digital alternative that works on any gate-based device: replace the circuit by a longer circuit that implements the same unitary but contains times as many gates. Since , appending copies of leaves the ideal output unchanged while every noisy gate is executed times.
Definition
Global unitary folding
Let be a circuit of gates (applied in the order ). For an odd scale factor , the globally folded circuit is executed as the gate sequence followed times by the inverse block and the forward block ; it contains gates. The engine function foldGlobal builds exactly this sequence: it inverts rotations by negating their angles (), maps and , keeps the self-inverse gates , replaces any other gate by its conjugate transpose, repeats noise channels in reverse order instead of inverting them (a channel has no physical inverse), and moves terminal measurements to the end. Only odd scales are possible with global folding; intermediate values require folding a subset of the gates.
Circuit · 2 qubits
foldGlobal at of the Bell circuit : the gate sequence . Without noise the folded circuit prepares the same state and has the same unitary as .
Global folding multiplies first-order gate noise by λ = 2k + 1
Write and compose superoperators from right to left. Let the circuit run as , where the noise of gate is a channel on the qubits of (weak, Markovian, time-independent noise of strength ; does not depend on ). Let , and , so that .
(a) Folding as foldGlobal does, with the inverse block (each channel repeated, in reverse order), gives for (b) If every executed inverse gate is followed by its own noise, (the usual situation on hardware), then with ; this equals (a) whenever , in particular when commutes with , as for depolarizing noise after a single-qubit gate.
Proof (7 steps)
- Step 1:Multiply out any sequence of ideal gates and noisy locations : a first-order term picks at exactly one location and at all others; is the product of the ideal gates before location and the product after it.
- Step 2:The ideal gates of the folded sequence multiply to because , so the zeroth-order term is the noiseless value for every .
- Step 3:Before the noise of in the -th forward block come complete pairs and the gates ; after it come and pairs . Complete pairs act as the identity, so this location contributes .
- Step 4:In foldGlobal's order the inverse block runs . Before the ideal gates net to followed by , i.e. ; after it come and gates netting to , i.e. . This location also contributes .
- Step 5:There are forward blocks and inverse blocks, each containing the noise of every gate once. This proves (a).
- Step 6:In hardware order the noise of acts after it, one gate earlier in the ideal circuit's coordinates: the error sits between and . Counting blocks as before gives (b).
- Step 7:Use and . The depolarizing channel commutes with every single-qubit unitary conjugation, so the condition holds for depolarizing noise after single-qubit gates.
∎
Zero-noise extrapolation of the noisy Bell circuit, exactly
- Step 1:The worked example: the Bell circuit with a depolarizing channel after every gate on each qubit the gate touches, .
- Step 2:Heisenberg picture: the adjoint channels act on the observable in reverse order. The Kraus operators of are Hermitian, so ; a Pauli commutes with itself and anticommutes with the two other Paulis, which gives .
- Step 3:CNOT maps and under conjugation; on qubit does not touch the second tensor factor.
- Step 4:The two channels after the CNOT each meet a and contribute ; the channel after meets the identity on qubit and contributes nothing. With : .
- Step 5:Propagating backwards through an inverse block of foldGlobal: and the channel on qubit leave unchanged, the CNOT maps it to , and the two channels on qubits contribute . Each of the blocks therefore contributes , and the operator reaching is .
- Step 6:The three values measured with the engine (density backend on foldGlobal of the noisy circuit) agree with to . This noise model is exactly exponential in , not polynomial.
- Step 7:With the theorem's moment sums for predict the bias. The unmitigated bias shrinks by a factor of about ; the linear estimate through , , keeps a bias of .
Result
The plot above runs the same folded Bell circuit with , where and the noisy values are , , . Richardson extrapolation returns , while an exponential fit of against recovers exactly, because the model is itself exponential. The code cell below reproduces the numbers of the derivation with the platform's engine: it folds the noisy circuit with foldGlobal, evaluates on the density-matrix backend, extrapolates, and then mitigates readout errors with the functions of the next sections.
import { foldGlobal, mitigateReadout, noisyDistribution, richardsonExtrapolate, richardsonZeroNoise, runCircuit } from '@/lib/quantum-simulator';
// H(0) then CNOT(0,1), with a depolarizing channel (p = 0.01) after every gate on each qubit the gate touches.
const p = 0.01;
const dep = (q: number) => ({ kind: 'channel', channel: 'depolarizing', targets: [q], params: [p] });
const bell = {
version: 1, numQubits: 2, numClbits: 0,
ops: [
{ kind: 'gate', gate: 'H', targets: [0] }, dep(0),
{ kind: 'gate', gate: 'CNOT', targets: [0, 1] }, dep(0), dep(1),
],
};
const ZZ = [{ coeff: 1, ops: 'ZZ' }];
const f = 1 - (4 * p) / 3;
const fmt = (v: number) => v.toFixed(10);
// Global folding U (U^dagger U)^k gives the noise scale 2k + 1; channels are repeated in reverse order.
const E: number[] = [];
for (const scale of [1, 3, 5]) {
const folded = foldGlobal(bell, scale);
const gates = folded.ops.filter((op) => op.kind === 'gate').length;
const channels = folded.ops.filter((op) => op.kind === 'channel').length;
const value = runCircuit(folded, { backend: 'density', observables: [ZZ] }).expectations![0]!;
E.push(value);
console.log('scale ' + scale + ': ' + gates + ' gates, ' + channels + ' channels, <ZZ> = ' + fmt(value) + ' f^(2 scale) = ' + fmt(f ** (2 * scale)));
}
const e0 = richardsonExtrapolate(E[0]!, E[1]!, E[2]!);
const e0General = richardsonZeroNoise([{ scale: 1, value: E[0]! }, { scale: 3, value: E[1]! }, { scale: 5, value: E[2]! }]);
console.log('Richardson {1,3,5}: ' + fmt(e0) + ' (general nodes: ' + fmt(e0General) + '), error ' + (e0 - 1).toExponential(3));
console.log('linear {1,3}: ' + fmt(1.5 * E[0]! - 0.5 * E[1]!) + ', error ' + (1.5 * E[0]! - 0.5 * E[1]! - 1).toExponential(3) + '; unmitigated error ' + (E[0]! - 1).toExponential(3));
// Readout error p01 = 0.05, p10 = 0.10: forward model, then inversion.
const one = { p01: [0.05], p10: [0.1] };
const measured = noisyDistribution(Float64Array.from([0.8, 0.2]), one);
const fixed = mitigateReadout({ '0': measured[0]!, '1': measured[1]! }, one);
console.log('one qubit: true (0.8, 0.2) -> measured (' + fmt(measured[0]!) + ', ' + fmt(measured[1]!) + ') -> mitigated (' + fmt(fixed['0'] ?? 0) + ', ' + fmt(fixed['1'] ?? 0) + ')');
// Two qubits with independent readout errors (qubit 0 = leftmost bit).
const two = { p01: [0.05, 0.02], p10: [0.1, 0.08] };
const fixed2 = mitigateReadout({ '00': 0.4695, '01': 0.0555, '10': 0.0605, '11': 0.4145 }, two);
console.log('two qubits: mitigated ' + ['00', '01', '10', '11'].map((k) => k + ' ' + fmt(fixed2[k] ?? 0)).join(', '));
// A measured (0.97, 0.03) inverts to the quasi-probabilities (1.0235..., -0.0235...); the engine clips and renormalises.
const clipped = mitigateReadout({ '0': 0.97, '1': 0.03 }, one);
console.log('from (0.97, 0.03): mitigated (' + fmt(clipped['0'] ?? 0) + ', ' + fmt(clipped['1'] ?? 0) + ')');Expected output
scale 1: 2 gates, 3 channels, <ZZ> = 0.9735111111 f^(2 scale) = 0.9735111111
scale 3: 6 gates, 9 channels, <ZZ> = 0.9226197308 f^(2 scale) = 0.9226197308
scale 5: 10 gates, 15 channels, <ZZ> = 0.8743887542 f^(2 scale) = 0.8743887542
Richardson {1,3,5}: 0.9999544527 (general nodes: 0.9999544527), error -4.555e-5
linear {1,3}: 0.9989568013, error -1.043e-3; unmitigated error -2.649e-2
one qubit: true (0.8, 0.2) -> measured (0.7800000000, 0.2200000000) -> mitigated (0.8000000000, 0.2000000000)
two qubits: mitigated 00 0.5000000000, 01 0.0000000000, 10 0.0000000000, 11 0.5000000000
from (0.97, 0.03): mitigated (1.0000000000, 0.0000000000)Quick check
A circuit of gates is folded globally to the scale factor . How many gates does the folded circuit contain?
The price of extrapolation: variance amplification#
On hardware each is estimated from a finite number of shots, so the extrapolated value is a random variable. The weights that remove the bias have magnitudes above one, and they multiply the statistical fluctuations of every node.
Variance of the Richardson estimate and optimal shot allocation
Let be the mean of independent single-shot outcomes at node , each with variance (for a observable ), and let the estimates at different nodes be independent. Then satisfies With equal and the variance is times that of a single unmitigated estimate from shots. For a fixed total budget the variance is minimal for , where it equals .
Proof (5 steps)
- Step 1:Linearity of expectation; each sample mean is unbiased for its node. The Richardson estimate inherits only the extrapolation bias, not a statistical one.
- Step 2:Bilinearity of the covariance; estimates from different circuits are independent, so the off-diagonal covariances vanish.
- Step 3:The variance of a mean of independent, identically distributed outcomes.
- Step 4:Cauchy–Schwarz inequality for the vectors and .
- Step 5:Square the inequality and divide by ; Cauchy–Schwarz is an equality exactly when the two vectors are parallel.
∎
The amplification factor for the nodes {1, 3, 5}
- Step 1:Square the weights over the common denominator .
- Step 2:With equal shots per node and equal , the standard deviation of is times that of . Matching the unmitigated standard error therefore requires about times as many shots at each node, times in total.
- Step 3:The optimal allocation of the proposition with equal : , so the total budget grows by instead of .
- Step 4:Adding a fourth node cancels the cubic term too but more than doubles the variance factor: higher-order extrapolation trades bias for variance.
Result
The plot shows the lab data with the Richardson parabola through the three points, the least-squares line and an exponential fit, together with the weights and the factor . The default plot below uses a synthetic exponential decay . Here Richardson extrapolation through gives , a residual bias of that comes from the cubic and higher terms of the exponential, while the exponential fit is exact. Which model to trust is a physical question: depolarizing noise on Clifford circuits produces sums of exponentials, gate-dependent coherent errors do not. Polynomial extrapolation is agnostic but amplifies variance; exponential extrapolation has lower variance but is biased when the decay is not exponential.
Quick check
By what factor does linear Richardson extrapolation through the two nodes amplify the variance, for equal shots and equal single-shot variance at both nodes?
Readout-error mitigation#
Measurement is often the least accurate operation of a superconducting processor: a qubit in can relax during the readout pulse and be reported as , and thermal excitation or overlapping signal distributions can report a as . These errors act after the quantum state has been converted into classical bits, so they can be described by a classical stochastic matrix and undone by linear algebra on the measured histogram. The error rates are calibrated by preparing the basis states and recording how often each is misread.
Definition
Confusion matrix of a readout
For one qubit let and . The confusion matrix has entries , columns labelled by the true bit and rows by the read bit: It is column-stochastic: its entries are non-negative and each column sums to . If is the distribution of the true outcomes, the law of total probability gives the distribution of the reported outcomes, . The engine implements this convention in confusionMatrix, noisyDistribution and mitigateReadout.
Inverse of the single-qubit confusion matrix
, so is invertible if and only if , and then The columns of sum to , so sums to whenever does, but its entries can be negative. If is estimated by measured frequencies, is an unbiased estimate of .
Proof (5 steps)
- Step 1:The determinant of a matrix is ; the products cancel.
- Step 2:The adjugate formula with , , , ; it exists exactly when .
- Step 3:Direct verification: the diagonal entries equal and the off-diagonal entries cancel.
- Step 4:Column-stochasticity is ; multiply from the right by . Explicitly, the first column of sums to , and so does the second.
- Step 5:Linearity of expectation and unbiasedness of measured frequencies. For an individual finite sample, however, can produce negative entries, as the example with , shows: a nearly pure histogram is over-corrected.
∎
Independent readout errors: tensored confusion matrices
If qubits are misread independently, with confusion matrices , then with the platform's bit ordering (qubit is the most significant bit) the confusion matrix is and can be computed by applying each inverse to its own bit, in operations instead of the of a dense matrix–vector product.
Proof (4 steps)
- Step 1:Independence of the bit flips given the true bitstring .
- Step 2:Definition of the Kronecker product: the block of is . Row and column indices put qubit in the most significant position, matching the index of the statevector; induction on gives the general case.
- Step 3:The mixed-product property ; the same holds for any number of factors.
- Step 4:Mixed-product property again: the tensored inverse factors into one operation per bit, each applied to pairs of entries whose indices differ in that bit, as in the strided single-qubit gate kernel of the simulator.
∎
Mitigating one and two measured qubits
- Step 1:The lab's qubit, and .
- Step 2:The measured came from the true : .
- Step 3:A Bell state measured with and : the first and last columns of the matrix above, averaged. About of the shots land on the impossible outcomes and .
- Step 4:Applying the two single-qubit inverses bit by bit restores the Bell-state statistics exactly, because these measured frequencies carry no sampling noise.
Real histograms contain shot noise, and then often returns small negative quasi-probabilities, as in the example above. Expectation values computed linearly from a quasi-probability vector remain unbiased, but a vector with negative entries is not a distribution, cannot be sampled, and can produce expectation values outside . Two repairs are common. Clip and renormalise sets negative entries to zero and rescales the rest; the engine's mitigateReadout does this. The Euclidean projection onto the probability simplex returns the closest distribution in the -norm. Smolin, Gambetta and Smith showed that the same projection, applied to eigenvalues, yields the maximum-likelihood density matrix under Gaussian noise.
Euclidean projection onto the probability simplex
Let and . The unique minimiser of over is where is the unique number with . Sorting decreasingly as , with .
Proof (5 steps)
- Step 1:A strictly convex objective on a nonempty compact convex set has exactly one minimiser, and with affine constraints the Karush–Kuhn–Tucker conditions are necessary and sufficient.
- Step 2:Stationarity in , dual feasibility and complementary slackness.
- Step 3:The two cases of complementary slackness combine into one formula: a coordinate is shifted down by and cut at zero.
- Step 4:is strictly decreasing wherever it is positive, so it takes the value exactly once; this fixes by primal feasibility .
- Step 5:The sorted entries give the candidates , and holds for only. Clip-and-renormalise gives instead , at Euclidean distance from versus for the projection.
∎
Quick check
A qubit has and , and the measured frequencies are . What is the mitigated probability ?
Probabilistic error cancellation#
Zero-noise extrapolation reduces the bias but never removes it, because the extrapolation model is only approximate. Probabilistic error cancellation (PEC), proposed by Temme, Bravyi and Gambetta and developed by Endo, Benjamin and Li, is unbiased under a fully characterised noise model: it inverts the noise channel of every gate on average, by sampling from a signed mixture of operations that the device can implement.
Definition
Quasi-probability decomposition
Let be an ideal operation and a set of operations the noisy device can implement. A quasi-probability decomposition of is an identity between linear maps on density matrices. If all and are trace preserving, then , but individual may be negative. The cost of the decomposition is , with exactly when all , i.e. when is itself a probabilistic mixture of implementable operations.
The inverse of the depolarizing channel as a quasi-probability mixture
- Step 1:The PennyLane convention of the previous lesson; on a Pauli , the conjugations by the two anticommuting Paulis give .
- Step 2:Every density matrix is ; the inverse map divides the Bloch vector by . It exists for , i.e. , and is not completely positive for because it lengthens Bloch vectors.
- Step 3:Each Pauli channel , , maps a Pauli to if and commute and to if they anticommute.
- Step 4:Match on : the identity commutes with all four Paulis, and commutes with and only.
- Step 5:Subtracting the equations pairwise gives ; then and , so . Since for , the three Pauli weights are negative.
- Step 6:and . At : , , , and .
Result
The PEC estimator is unbiased, with sampling overhead γ² per gate
Let with cost , and let satisfy . Draw with probability , run the circuit with in place of , measure a single-shot outcome of , and output . Then and . For a circuit of gates, each decomposed with cost , the product decomposition has cost , which is for equal costs, and samples reach precision : the overhead relative to a noiseless device is .
Proof (5 steps)
- Step 1:Law of total expectation; ; the trace is linear.
- Step 2:The estimator is bounded by instead of : the signs make the samples cancel on average, which inflates their spread.
- Step 3:Composition of linear maps distributes over sums: the circuit is a quasi-probability mixture of circuit variants with weights .
- Step 4:The sum of a product over independent indices factorises. Sampling each gate's variant independently samples the product decomposition.
- Step 5:Hoeffding's inequality for independent samples in ; without mitigation the range is , so the number of shots grows by the factor .
∎
To cancel the depolarizing noise that follows a gate , one implements : run the noisy gate and then, with probability , an extra Pauli , recording the sign of . The derivation assumes that the inserted Pauli is itself noiseless; in practice it is merged into the next layer of single-qubit gates. At the overhead per gate is . At the more realistic , and the cost is per gate, so noisy gates multiply the required number of shots by , and gates by about . PEC is therefore exact but exponentially expensive in the circuit volume, while ZNE has a polynomial cost and a residual bias.
Quick check
What is the PEC cost of inverting a single-qubit depolarizing channel with ?
Numerical checks and the labs#
The NumPy cell below re-derives the lesson's numbers independently of the platform's engine: the Richardson weights from the Lagrange formula and from a Vandermonde solve, their moments , the variance factors and , the lab extrapolations, the exact Bell-circuit decay with its Richardson bias, the single-qubit and tensored readout inversions, both repairs of a quasi-probability vector, and the quasi-probability decomposition of the inverse depolarizing channel, checked on a random density matrix.
import numpy as np
def fmt(v, d=10):
v = np.atleast_1d(np.asarray(v, dtype=float))
v = np.where(np.abs(v) < 5e-11, 0.0, v)
return "(" + ", ".join(f"{x:.{d}f}" for x in v) + ")"
# (1) Richardson weights: Lagrange basis polynomials at lambda = 0, and the same weights from a Vandermonde solve
def richardson_weights(nodes):
nodes = np.asarray(nodes, dtype=float)
m = len(nodes)
return np.array([np.prod([nodes[j] / (nodes[j] - nodes[i]) for j in range(m) if j != i]) for i in range(m)])
nodes = np.array([1.0, 3.0, 5.0])
g = richardson_weights(nodes)
V = np.vander(nodes, increasing=True).T # row k holds lambda_i^k, k = 0, 1, 2
print("gamma =", fmt(g), "| Vandermonde solve =", fmt(np.linalg.solve(V, [1.0, 0.0, 0.0])))
print("moments sum gamma_i lambda_i^k, k = 0..4:", fmt([g @ nodes**k for k in range(5)], 6))
print("sum gamma^2 =", f"{g @ g:.5f}", "| std factor sqrt =", f"{np.sqrt(g @ g):.4f}", "| (sum |gamma|)^2 =", f"{np.abs(g).sum()**2:.4f}")
# the lab data
E = np.array([0.80, 0.56, 0.40])
slope, intercept = np.polyfit(nodes, E, 1)
print("Richardson E0 =", f"{g @ E:.10f}", "| quadratic through the data:", fmt(np.polyfit(nodes, E, 2)[::-1], 6))
print("linear {1,3} =", f"{richardson_weights([1, 3]) @ E[:2]:.10f}", "| linear {1,5} =", f"{richardson_weights([1, 5]) @ E[[0, 2]]:.10f}",
"| least-squares intercept =", f"{intercept:.10f}")
# exponential decay E = exp(-kappa lambda) from the folded Bell circuit with p = 0.01: E(lambda) = f^(2 lambda)
f = 1 - 4 * 0.01 / 3
Eb = f ** (2 * nodes)
print("Bell <ZZ> at 1,3,5:", fmt(Eb), "| Richardson:", f"{g @ Eb:.10f}", "| error:", f"{g @ Eb - 1:.4e}")
# (4) readout: A = [[1 - p01, p10], [p01, 1 - p10]], column = true bit
def confusion(p01, p10):
return np.array([[1 - p01, p10], [p01, 1 - p10]])
A = confusion(0.05, 0.10)
Ainv_formula = np.array([[0.90, -0.10], [-0.05, 0.95]]) / (1 - 0.05 - 0.10)
print("det A =", f"{np.linalg.det(A):.10f}", "| formula inverse matches:", np.allclose(Ainv_formula, np.linalg.inv(A), atol=1e-14, rtol=0))
print("A^-1 (0.78, 0.22) =", fmt(Ainv_formula @ [0.78, 0.22]), "| A (0.8, 0.2) =", fmt(A @ [0.8, 0.2]))
# two qubits, qubit 0 = most significant bit: A = A_0 kron A_1 and (A_0 kron A_1)^-1 = A_0^-1 kron A_1^-1
A0, A1 = confusion(0.05, 0.10), confusion(0.02, 0.08)
A01 = np.kron(A0, A1)
print("kron inverse rule:", np.allclose(np.linalg.inv(A01), np.kron(np.linalg.inv(A0), np.linalg.inv(A1)), atol=1e-14, rtol=0),
"| columns sum to 1:", np.allclose(A01.sum(axis=0), 1, atol=1e-15, rtol=0))
measured = np.array([0.4695, 0.0555, 0.0605, 0.4145])
print("A (0.5, 0, 0, 0.5) =", fmt(A01 @ [0.5, 0, 0, 0.5], 4), "| mitigated:", fmt(np.linalg.solve(A01, measured)))
# repairing negative quasi-probabilities
def clip_renormalise(q):
c = np.clip(q, 0, None)
return c / c.sum()
def project_simplex(q):
u = np.sort(q)[::-1]
css = np.cumsum(u)
k = np.arange(1, len(q) + 1)
rho = k[u - (css - 1) / k > 0][-1]
tau = (css[rho - 1] - 1) / rho
return np.maximum(q - tau, 0)
q = Ainv_formula @ [0.97, 0.03]
print("A^-1 (0.97, 0.03) =", fmt(q), "-> clip:", fmt(clip_renormalise(q)), "| simplex:", fmt(project_simplex(q)))
q4 = np.array([0.60, 0.45, -0.10, 0.05])
c4, s4 = clip_renormalise(q4), project_simplex(q4)
print("q =", fmt(q4, 2), "-> clip:", fmt(c4, 6), "dist", f"{np.linalg.norm(c4 - q4):.6f}", "| simplex:", fmt(s4, 6), "dist", f"{np.linalg.norm(s4 - q4):.6f}")
# (5) probabilistic error cancellation for the depolarizing channel E(rho) = (1-p) rho + p/3 (X rho X + Y rho Y + Z rho Z)
X = np.array([[0, 1], [1, 0]], dtype=complex)
Y = np.array([[0, -1j], [1j, 0]])
Z = np.diag([1.0 + 0j, -1.0])
def depolarize(rho, p):
return (1 - p) * rho + p / 3 * (X @ rho @ X + Y @ rho @ Y + Z @ rho @ Z)
p = 0.1
fp = 1 - 4 * p / 3
qI, qP = (1 + 3 / fp) / 4, (1 - 1 / fp) / 4
rng = np.random.default_rng(7)
M = rng.normal(size=(2, 2)) + 1j * rng.normal(size=(2, 2))
rho = M @ M.conj().T
rho /= np.trace(rho)
noisy = depolarize(rho, p)
undone = qI * noisy + qP * (X @ noisy @ X + Y @ noisy @ Y + Z @ noisy @ Z)
print("q_I =", f"{qI:.10f}", "| q_X = q_Y = q_Z =", f"{qP:.10f}", "| sum q =", f"{qI + 3 * qP:.10f}")
print("sum_P q_P P E(rho) P = rho:", np.allclose(undone, rho, atol=1e-14, rtol=0),
"| gamma = sum |q| =", f"{abs(qI) + 3 * abs(qP):.10f}", "= (3/f - 1)/2 =", f"{(3 / fp - 1) / 2:.10f}")
gam = lambda pp: (3 / (1 - 4 * pp / 3) - 1) / 2
print("sampling overhead gamma^(2G): p = 0.1, G = 1:", f"{gam(0.1) ** 2:.4f}", "| p = 0.01, G = 100:", f"{gam(0.01) ** 200:.2f}")Expected output
gamma = (1.8750000000, -1.2500000000, 0.3750000000) | Vandermonde solve = (1.8750000000, -1.2500000000, 0.3750000000)
moments sum gamma_i lambda_i^k, k = 0..4: (1.000000, 0.000000, 0.000000, 15.000000, 135.000000)
sum gamma^2 = 5.21875 | std factor sqrt = 2.2845 | (sum |gamma|)^2 = 12.2500
Richardson E0 = 0.9500000000 | quadratic through the data: (0.950000, -0.160000, 0.010000)
linear {1,3} = 0.9200000000 | linear {1,5} = 0.9000000000 | least-squares intercept = 0.8866666667
Bell <ZZ> at 1,3,5: (0.9735111111, 0.9226197308, 0.8743887542) | Richardson: 0.9999544527 | error: -4.5547e-05
det A = 0.8500000000 | formula inverse matches: True
A^-1 (0.78, 0.22) = (0.8000000000, 0.2000000000) | A (0.8, 0.2) = (0.7800000000, 0.2200000000)
kron inverse rule: True | columns sum to 1: True
A (0.5, 0, 0, 0.5) = (0.4695, 0.0555, 0.0605, 0.4145) | mitigated: (0.5000000000, 0.0000000000, 0.0000000000, 0.5000000000)
A^-1 (0.97, 0.03) = (1.0235294118, -0.0235294118) -> clip: (1.0000000000, 0.0000000000) | simplex: (1.0000000000, 0.0000000000)
q = (0.60, 0.45, -0.10, 0.05) -> clip: (0.545455, 0.409091, 0.000000, 0.045455) dist 0.121117 | simplex: (0.566667, 0.416667, 0.000000, 0.016667) dist 0.115470
q_I = 1.1153846154 | q_X = q_Y = q_Z = -0.0384615385 | sum q = 1.0000000000
sum_P q_P P E(rho) P = rho: True | gamma = sum |q| = 1.2307692308 = (3/f - 1)/2 = 1.2307692308
sampling overhead gamma^(2G): p = 0.1, G = 1: 1.5148 | p = 0.01, G = 100: 55.34The first lab gives three noise-scaled measurements and asks for the Richardson estimate through all three nodes; the second gives readout error rates and a measured distribution and asks for the mitigated distribution.
References
- K. Temme, S. Bravyi and J. M. Gambetta, Error mitigation for short-depth quantum circuits, Physical Review Letters 119, 180509 (2017).doi:10.1103/PhysRevLett.119.180509
- A. Kandala, K. Temme, A. D. Córcoles, A. Mezzacapo, J. M. Chow and J. M. Gambetta, Error mitigation extends the computational reach of a noisy quantum processor, Nature 567, 491–495 (2019).doi:10.1038/s41586-019-1040-7
- T. Giurgica-Tiron, Y. Hindy, R. LaRose, A. Mari and W. J. Zeng, Digital zero noise extrapolation for quantum error mitigation, 2020 IEEE International Conference on Quantum Computing and Engineering (QCE), 306–316 (2020); arXiv:2005.10921.doi:10.1109/QCE49297.2020.00045
- S. Endo, S. C. Benjamin and Y. Li, Practical quantum error mitigation for near-future applications, Physical Review X 8, 031027 (2018).doi:10.1103/PhysRevX.8.031027
- S. Bravyi, S. Sheldon, A. Kandala, D. C. Mckay and J. M. Gambetta, Mitigating measurement errors in multiqubit experiments, Physical Review A 103, 042605 (2021).doi:10.1103/PhysRevA.103.042605
- J. A. Smolin, J. M. Gambetta and G. Smith, Efficient method for computing the maximum-likelihood quantum state from measurements with additive Gaussian noise, Physical Review Letters 108, 070502 (2012).doi:10.1103/PhysRevLett.108.070502
- W. Wang and M. Á. Carreira-Perpiñán, Projection onto the probability simplex: an efficient algorithm with a simple proof, and an application, arXiv:1309.1541 (2013).arxiv.org
- E. van den Berg, Z. K. Minev, A. Kandala and K. Temme, Probabilistic error cancellation with sparse Pauli–Lindblad models on noisy quantum processors, Nature Physics 19, 1116–1121 (2023).doi:10.1038/s41567-023-02042-2
Hands-on labs
Zero-noise extrapolation with Richardson weights
1 step · auto-gradedOpen labAn expectation value was measured at the noise scale factors produced by global unitary folding. Combine the three measurements with the Richardson (Lagrange) weights into an estimate of the noiseless value .
Readout-error mitigation by confusion-matrix inversion
1 step · auto-gradedOpen labA qubit's readout flips with probability and with probability . Undo this classical noise on a measured distribution by inverting the confusion matrix.