Lesson 44 · 100 min · advanced
Hardware-Efficient Ansatz
The hardware-efficient ansatz (HEA) builds the trainable unitary of a variational circuit from the gates a device executes natively: single-qubit and rotations on every qubit, followed by a ladder of nearest-neighbour CNOTs, repeated times. This lesson counts its resources ( parameters, CNOTs, a ladder of depth exactly ), proves that the all-zero initialisation outputs because the ladder permutes basis states by prefix parities, tracks basis states to show that a single non-zero angle in the last layer prepares the GHZ state while the same angle in the first layer only reaches fidelity , derives the Haar fidelity density behind the expressibility measure of Sim, Johnson and Aspuru-Guzik, and relates expressibility to trainability and to the connectivity of real hardware.
Prerequisites: Variational Quantum Circuits: Architecture
Objectives and key results
Write the layer of a hardware-efficient ansatz and draw it as a circuit with the CNOT ladder .
Count parameters (), CNOTs () and depth, prove that the ladder has depth exactly and compute the depth of a scheduled -layer circuit.
Prove that the ladder maps to the prefix parities of , hence and the zero initialisation outputs .
Track basis states through a parameterised circuit to find angles that prepare a target state, and explain why the layer in which a rotation sits matters.
Define expressibility as and derive from Gaussian vectors and the Gamma–Beta relation.
Explain the tension between expressibility and trainability, and estimate the SWAP overhead that non-native connectivity would add.
- definition · Hardware-efficient layer
- formula · Resource counts on a line
- identity · Ladder action and identity at zero
- theorem · Haar fidelity density
- definition · Expressibility (Sim et al. 2019)
- theorem · Cost concentration for Haar-random states
Layers built from native gates#
The previous lesson split a variational quantum circuit into a feature map , a trainable unitary and an observable . It left open how should be chosen. Two design goals pull in different directions. Physics-inspired ansätze, such as the unitary coupled-cluster ansatz of quantum chemistry, encode knowledge of the problem but compile into long sequences of gates that a noisy device cannot execute faithfully. Hardware-efficient ansätze, introduced for the variational eigensolver experiments of Kandala et al. (2017), take the opposite view: use only the gates the processor implements natively and only couplings between qubits that are physically connected, stack as many layers as the coherence time allows, and let the optimiser find the angles. This lesson studies the simplest member of that family, which is also the default template of most QML libraries: and rotations on every qubit followed by a ladder of CNOTs between neighbours.
Definition
Hardware-efficient ansatz (HEA)
Let qubits be arranged on a line, the number of layers, and with , , the parameter array. Write for acting on qubit (tensored with identities). The CNOT ladder and the layer are with for , and the hardware-efficient ansatz with its output state is In time order, every layer applies and then to each qubit, then , then , and so on down to . Rotations on different qubits act on different tensor factors and commute, so the order of the factors in is irrelevant; on one qubit the order matters, because and do not commute.
Circuit · 3 qubits
The template of the lab: qubits, layers, all angles set to . Each layer is a column of , a column of , then and . In the lab every angle is a named trainable parameter .
Parameter count, CNOT count and depth
For qubits and layers the hardware-efficient ansatz has (a) parameters; (b) CNOT gates, each between neighbouring qubits , so a linear coupling map needs no SWAP gates; (c) a CNOT ladder of depth exactly ; (d) layers of depth exactly , so that the circuit executed layer after layer has depth . Here a moment is a set of gates acting on pairwise disjoint qubits, and the depth of a gate sequence is the smallest number of consecutive moments into which it can be scheduled such that two gates sharing a qubit keep their order.
Proof (8 steps)
- Step 1:Each layer has one and one angle per qubit, and every angle is an independent parameter.
- Step 2:The ladder contains one CNOT per neighbouring pair. On a line every such pair is physically coupled, so each CNOT is native and no routing is required.
- Step 3:An explicit schedule: one CNOT per moment, in ladder order. It respects the order of all gates and uses moments.
- Step 4:Two gates on a common qubit cannot be in the same moment, and the earlier gate must stay earlier.
- Step 5:Induction on with the previous inequality. Together with the explicit schedule, : consecutive CNOTs of the ladder share a qubit, so no two of them can run in parallel.
- Step 6:Moment diagram of one layer for ( control, target): all fit into moment and all into moment because they act on distinct qubits; the ladder is a staircase occupying moments to .
- Step 7:The diagram schedules a layer in moments. Conversely, in this chain of gates each gate shares a qubit with the next one, so the chain needs distinct, ordered moments.
- Step 8:If every layer is executed as a separate block (as a compiler does when layers are separated by barriers), the depths of the blocks add. The next proposition shows that a scheduler which starts each gate as soon as its qubits are free can overlap consecutive layers.
∎
As-soon-as-possible scheduling overlaps consecutive layers
Schedule each gate of in the first moment after the last moment used on any of its qubits (as-soon-as-possible, ASAP, scheduling, which is how the platform's depth counter packs gates). Then and no valid schedule is shorter. For both formulas give (depth for the lab template); for and the ASAP depth is strictly smaller than , because the rotations of the next layer start on the top qubits while the ladder is still running down the chain.
Proof (9 steps)
- Step 1:Definition of ASAP: is the previous gate on qubit . By induction over the gate sequence, every valid schedule places each gate at a moment , so ASAP is optimal and its depth is the length of the longest chain of gates in which consecutive gates share a qubit.
- Step 2:For all rotations act on one qubit. For each layer ends with , which touches both qubits, so the next layer cannot start before it: .
- Step 3:The first layer starts on idle qubits, so it is scheduled exactly as in the moment diagram. Note .
- Step 4:is the last moment of layer on qubit : for the last gate on is , which comes after ; for it is .
- Step 5:On each qubit the next layer's follows immediately, at , and its at .
- Step 6:ASAP for the ladder of layer . Qubit because . In the inductive step both arguments of the maximum equal .
- Step 7:The last CNOT of the ladder. Moreover for all , which is the hypothesis for layer .
- Step 8:Unrolling from . No gate ends later than the last CNOT of the last layer. For this is ; for it is smaller than whenever .
- Step 9:ASAP moment diagram for , (, : the rotations of layer ): depth , one moment less than . Qubit starts layer in moment , while of layer is still running.
∎
Quick check
How many trainable parameters does a hardware-efficient ansatz with qubits and layers have?
Quick check
What is the depth of a hardware-efficient ansatz with qubits and layers when the layers are executed one after the other as separate blocks?
The ladder as a permutation and the zero initialisation#
Before training, all angles must be given values. The most common choice in practice is . To understand what the circuit computes there, we first describe the CNOT ladder exactly: it never creates superpositions, it only relabels the computational basis states, and the relabelling is a simple parity rule.
The CNOT ladder computes prefix parities
For and every bit string , Hence , , ( exactly for even ), and is a permutation matrix.
Proof (7 steps)
- Step 1:Definition : the target bit is flipped exactly when the control bit is ; all other bits are unchanged.
- Step 2:Each CNOT maps a basis state to a basis state, so it suffices to follow the label. We prove the claim by induction on the number of ladder gates applied.
- Step 3:Base case: no gate applied; the prefix parity of length one is itself.
- Step 4:Inductive step: gate is , with control bit (a prefix parity by hypothesis) and target bit (still untouched).
- Step 5:After all gates every position holds its prefix parity.
- Step 6:Every prefix of has parity ; every prefix of contains exactly one ; the prefix of of length has parity . For : .
- Step 7:The map can be inverted (consecutive differences), so sends the basis vectors to the basis vectors bijectively: it is a permutation matrix, in particular real and unitary.
∎
Unitary verified: (max deviation 0.0e+0)
Identity at zero
For all and : for every layer, , and So the all-zero initialisation outputs the input state , and the fidelity of the initial circuit with a target is ; for it is . As an operator, however, is not the identity in general: has order , the smallest power of two that is , so exactly when is a multiple of that order.
Proof (8 steps)
- Step 1:at .
- Step 2:Every rotation factor of every layer is the identity.
- Step 3:The lemma ( for ), or directly: every CNOT of the ladder sees a control bit and acts trivially. Induction on .
- Step 4:and are orthonormal. In the lab the template starts at fidelity before any angle is changed.
- Step 5:By the lemma, acts on labels as the lower-triangular all-ones matrix ; is strictly lower triangular, so . acts as , hence if and only if .
- Step 6:and commute, and the binomial coefficients with are even (by induction, ).
- Step 7:counts mod the strictly decreasing index paths of length ; from to there is exactly one, so for , while .
- Step 8:For : the order divides , so it is a power of two, and it is not a smaller power since . Examples: : , order ; : order (for the lab, ); : order .
∎
Quick check
A hardware-efficient ansatz on qubits with layers is initialised with all angles equal to . Which statement is correct?
Reaching the GHZ state with one angle#
The lab asks for angles of the -qubit, -layer template that prepare . The template starts at with fidelity . Because the ladder permutes basis states, the effect of a few non-zero angles can be computed by following a handful of basis states through the circuit, without multiplying matrices. We write for the angle that the lab calls .
One rotation in the last layer prepares GHZ
- Step 1:The candidate: a single angle on qubit in layer , the last layer.
- Step 2:Layer has only zero angles, so it acts as , which fixes (identity at zero).
- Step 3:The first column of at ; all other rotations of layer are . This is .
- Step 4:Control bit : the first term has and is unchanged; in the second term flips. By linearity the CNOT acts term by term.
- Step 5:Control bit : in the first term, in the second. Equivalently, by the prefix-parity lemma.
- Step 6:The output equals the target exactly. This is the lab's reference solution.
- Step 7:The same computation for a general angle, with . The grader's threshold means , i.e. (mod ). For the output is and .
- Step 8:An additional angle on qubit in the last layer becomes the relative phase of the GHZ state; the global phase drops out of the fidelity, and .
Result
The same rotation in the first layer only reaches fidelity 1/4
- Step 1:The tempting alternative: put the rotation in the first layer.
- Step 2:Layer now performs exactly the computation of the previous derivation: after the first layer the register already holds GHZ.
- Step 3:All rotations of layer are zero, but its CNOT ladder is still applied.
- Step 4:In the control flips from to .
- Step 5:Now the control is in both terms. In one line: .
- Step 6:Expand both states in the orthonormal computational basis; only the components overlap.
- Step 7:This is the value detected by the lab's diagnostic. The state is a Bell pair between qubits and , with qubit unentangled.
Result
The general lesson is that every ladder after the last non-trivial rotation keeps acting. Earlier ladders relabel the basis states that the later rotations see, and later ladders relabel the result. A rotation in an early layer is therefore not "the same" as a rotation in the last layer. Keeping , no choice of the layer- angles can repair the damage: those rotations act on the GHZ state as a local unitary , and would require (invert the prefix parities: maps to ). That is impossible, because a local unitary conjugates every one-qubit reduced state and so preserves its entropy, which is bit for each qubit of GHZ and for the product state . The meter below runs the reference solution: every single-qubit cut of the GHZ state has entanglement entropy bit, the maximum for one qubit.
Quick check
In the lab template you set and, in addition, the angle on the same qubit and layer. What is the fidelity with ?
Expressibility and the Haar fidelity distribution#
A layer of the HEA can be repeated as often as the hardware allows. How much does each additional layer add? Sim, Johnson and Aspuru-Guzik (2019) proposed to measure how uniformly an ansatz covers the state space: draw two independent parameter vectors, compute the fidelity of the two output states, and compare the distribution of this fidelity with the one obtained for Haar-random states, i.e. states drawn from the unique probability distribution on unit vectors that is invariant under every unitary. A circuit whose states cover the state space uniformly reproduces the Haar distribution; a circuit confined to a small region produces fidelities that pile up near .
Definition
Fidelity distribution and expressibility
Let be the output of a parameterised circuit with parameters on qubits, , and let be independent and uniform on . The fidelity distribution is the law of . Split into bins , (the last bin closed), sample pairs and let be the fraction of fidelities in . With the Haar bin probabilities , the expressibility is the Kullback–Leibler divergence Smaller values mean a fidelity distribution closer to Haar, i.e. a more expressive circuit.
The Kullback–Leibler divergence is nonnegative
If for all and is a probability vector, then , with equality if and only if .
Proof (4 steps)
- Step 1:decreases on and increases on , so its minimum is .
- Step 2:Apply the inequality with ; the bins with contribute nothing by the convention , and the over a subset of bins sum to at most .
- Step 3:Both inequalities must be equalities; the second forces outside the support of , which together with the first gives .
- Step 4:Every term is finite; the theorem below shows that all Haar bin probabilities are positive.
∎
Normalised complex Gaussian vectors are Haar-random states
Let have independent real and imaginary parts, all distributed as . Then is Haar-distributed: has the same law as for every unitary . Consequently, for independent Haar-random ,
Proof (6 steps)
- Step 1:The density of is ; independence multiplies the densities on .
- Step 2:is real-linear on and preserves the Euclidean norm , so it is orthogonal and its Jacobian has modulus .
- Step 3:Change of variables for the invertible linear map : the vector has the same density as .
- Step 4:Normalisation is defined almost surely and commutes with ; equal laws of and give equal laws of the normalised vectors.
- Step 5:The unitary group acts transitively on the unit sphere, and a transitive action of a compact group admits exactly one invariant probability measure; it is by definition the distribution of Haar-random states.
- Step 6:Condition on and choose a unitary that maps it to the first basis vector; by invariance and independence, is again Haar-random. Hence has the law of .
∎
Squared moduli of complex Gaussians are exponential
The variables , , are independent with for : each is , with density .
Proof (4 steps)
- Step 1:Each is a function of the pair , and these pairs are independent for different , so the are independent.
- Step 2:Integrate the joint density of the real and imaginary parts over the exterior of the disc of radius .
- Step 3:Polar coordinates , with .
- Step 4:Differentiate the survival function; , so this is the density.
∎
Gamma ratios are Beta-distributed (the Dirichlet aggregation)
Let and be independent, with densities and on , . Then and are independent, , and with density In particular, by induction, for independent .
Proof (8 steps)
- Step 1:Independence: the joint density is the product of the marginal densities.
- Step 2:A smooth bijection with the stated inverse.
- Step 3:Jacobian of the change of variables.
- Step 4:and .
- Step 5:A joint density that factorises into a function of times a function of makes the variables independent with marginals proportional to the factors; the only normalised density proportional to is the density.
- Step 6:The joint density integrates to , and by definition of . This evaluates the Beta integral .
- Step 7:Normalise the factor .
- Step 8:Induction on the number of summands with , , using that is independent of the earlier ones. The vector is the Dirichlet distribution, and the lemma aggregates its coordinates.
∎
Fidelity density of Haar-random states
For independent Haar-random pure states in ( for qubits), : The Haar bin probabilities are , and , . For one qubit () the density is uniform on .
Proof (8 steps)
- Step 1:The Gaussian lemma, with .
- Step 2:The exponential lemma and the induction of the Gamma–Beta lemma; depends only on .
- Step 3:The Gamma–Beta lemma with , , and for integers.
- Step 4:Integrate the density; the antiderivative of is .
- Step 5:Difference of the CDF at the bin edges (single points have probability ). It is positive because and is strictly increasing on for .
- Step 6:For a variable with values in , (write and exchange expectation and integral). For qubits this is , the mean kernel value of the concentration analysis in the quantum-kernel lesson.
- Step 7:The same argument with , then the substitution .
- Step 8:One qubit: every fidelity in is equally likely, which the next derivation confirms geometrically.
∎
Check for one qubit: Archimedes on the Bloch sphere
- Step 1:For pure qubit states (quantum-kernel lesson, Bloch lemma).
- Step 2:Haar measure is invariant under rotations of the Bloch sphere, so we may rotate to the north pole; is the height of .
- Step 3:The area element of the unit sphere in spherical coordinates; with , (Archimedes' hat-box theorem).
- Step 4:The uniform distribution on the sphere gives every zone of equal height equal probability, and an affine map of a uniform variable is uniform: the same result as at .
Result
Second fidelity moment of the one-qubit HEA
For the one-qubit HEA with layers and i.i.d. uniform angles on , The second moment exceeds the Haar value for every , so the fidelity distribution is never exactly Haar, but the gap shrinks by a factor per layer. For , .
Proof (11 steps)
- Step 1:are the Bloch vectors of the two independent output states; expand the square and use independence for the cross term.
- Step 2:; independence factorises each term, and has the same law as .
- Step 3:rotates the Bloch vector by the angle about the axis (Bloch-sphere lessons of Stage 2).
- Step 4:Averages over a full period for ; and .
- Step 5:For an independent uniform angle: , and the off-diagonal averages, e.g. and , vanish by the previous line. So a diagonal stays diagonal.
- Step 6:Already the first rotation with a uniform angle averages the Bloch vector to zero, and later rotations are linear. Then , the Haar value.
- Step 7:Start from , . One layer applies (mixing and : both become ) and then (mixing and ), so the entry after the layer is , and because pure states have .
- Step 8:Subtract the fixed point of and iterate from .
- Step 9:Both sides equal ; insert , so .
- Step 10:Insert into the first line with . For Haar states and , which reproduces .
- Step 11:Where the excess comes from: uniform angles make the height of the Bloch vector arcsine-distributed (density largest near the poles ) instead of uniform, so very similar and very different pairs of states are over-represented.
∎
The finite-sample floor of the KL estimate
- Step 1:Even a perfect Haar sampler produces a histogram that fluctuates around ; both vectors sum to .
- Step 2:Taylor expansion with .
- Step 3:Sum over the bins; the linear terms add up to .
- Step 4:The count of bin among independent samples is binomial with success probability .
- Step 5:Leading order in , using . A KL estimate of order with these settings cannot be distinguished from Haar: only differences well above this floor are meaningful.
Result
The gallery samples random parameter vectors of the chosen ansatz (here the HEA with qubits and layers), draws the histogram of pairwise fidelities against the Haar bin probabilities for , and reports the KL divergence. For the Haar density is concentrated near with mean . Increase the number of layers and watch the histogram approach the Haar curve. With a single layer the circuit only produces the images under of product states; since is unitary, is then a product of three independent one-qubit HEA fidelities, so by the one-qubit moment theorem above agrees with Haar while is far above the Haar value : the one-layer histogram has a much heavier tail towards large fidelities.
Real-amplitude circuits have a different fidelity law
If is uniformly distributed on the real unit sphere of and is a fixed real unit vector, then , with and . For the density is , unbounded at . More generally, for every distribution of real unit vectors, . Hence an ansatz built from rotations and CNOTs only, whose states have real amplitudes, can never reproduce the Haar fidelity distribution, at any depth and for any distribution of its parameters.
Proof (10 steps)
- Step 1:The proof of the Gaussian lemma with orthogonal instead of unitary maps: the real Gaussian density is invariant under orthogonal maps, which act transitively on the real sphere.
- Step 2:Differentiate with the chain rule () and use : each is .
- Step 3:The Gamma–Beta lemma, first for the sum (induction) and then for the ratio with , .
- Step 4:Moments of the Beta law from the Beta integral evaluated in the lemma.
- Step 5:with , .
- Step 6:The second moments differ, so the two laws differ. Combined with the bound of the next steps, no distribution of real states has the complex Haar second moment.
- Step 7:Any law of real unit vectors, with independent and identically distributed: expand and factorise the expectation.
- Step 8:Each of the three terms of contracts to . In each term has squared norm , and each of the ordered cross products, e.g. , forces and equals .
- Step 9:Cauchy–Schwarz inequality in the Euclidean space of -index tensors. The uniform law on the real sphere attains the bound, as computed above.
- Step 10:. The density diverges at , while the complex Haar density equals there.
∎
The second gallery uses the R_Y–CNOT ansatz on qubits with one layer. All its gates have real matrices, so every output state has real amplitudes and, by the proposition, its fidelity histogram cannot converge to the Haar curve however many layers are added. Compare its KL divergence with the HEA at the same size: the rotations of the HEA are what give access to complex relative phases.
The TypeScript cell estimates the expressibility of the one-qubit HEA with the platform's simulator. It samples pairs for layers and for exact Haar states generated from Gaussian amplitudes (the Box–Muller transform produces , the variable of the lemma), and prints the sample moments next to the exact value and the KL divergence next to the floor .
import { Statevector, mulberry32, runStatevector } from '@/lib/quantum-simulator';
// One-qubit hardware-efficient ansatz with L layers: R_Y(a_l) then R_Z(b_l) per layer (n = 1: no CNOT ladder).
function hea1(angles: number[]): Statevector {
const ops = [];
for (let k = 0; k < angles.length; k += 2) {
ops.push({ kind: 'gate' as const, gate: 'RY' as const, targets: [0], params: [angles[k]] });
ops.push({ kind: 'gate' as const, gate: 'RZ' as const, targets: [0], params: [angles[k + 1]] });
}
return runStatevector({ version: 1, numQubits: 1, numClbits: 0, ops });
}
const B = 20; // histogram bins on [0, 1]
const N = 20000; // sampled pairs of states per ansatz
const d = 2; // Hilbert-space dimension of one qubit
const rng = mulberry32(44);
// Haar bin probabilities from the CDF 1 - (1 - F)^(d - 1); for d = 2 every bin has probability 1/B.
const haarBin = (j: number) => (1 - j / B) ** (d - 1) - (1 - (j + 1) / B) ** (d - 1);
// Haar-random qubit state g/|g| with Re g_k, Im g_k ~ N(0, 1/2): Box-Muller with |g_k|^2 = -ln u ~ Exp(1).
function haar1(): Statevector {
const amp = () => {
const r = Math.sqrt(-Math.log(1 - rng()));
const phi = 2 * Math.PI * rng();
return { re: r * Math.cos(phi), im: r * Math.sin(phi) };
};
return Statevector.fromAmplitudes([amp(), amp()], { normalize: true });
}
// Fidelity histogram of N independent pairs, its moments, and the expressibility KL(P_hat || P_Haar).
function expressibility(label: string, sample: () => Statevector, exactSecondMoment: number) {
const counts = new Array<number>(B).fill(0);
let m1 = 0;
let m2 = 0;
for (let s = 0; s < N; s++) {
const F = sample().fidelity(sample());
counts[Math.min(B - 1, Math.floor(F * B))]++;
m1 += F / N;
m2 += (F * F) / N;
}
let kl = 0;
for (let j = 0; j < B; j++) {
const p = counts[j] / N;
if (p > 0) kl += p * Math.log(p / haarBin(j));
}
console.log(label + ': E[F] = ' + m1.toFixed(4) + ' E[F^2] = ' + m2.toFixed(4) + ' (exact ' + exactSecondMoment.toFixed(4) + ') KL = ' + kl.toFixed(4));
}
for (const L of [1, 2, 3]) {
const angles = () => Array.from({ length: 2 * L }, () => 2 * Math.PI * rng());
expressibility('HEA n = 1, L = ' + L, () => hea1(angles()), 1 / 3 + 16 ** -L / 6);
}
expressibility('Haar (Gaussian)', haar1, 1 / 3);
console.log('finite-sample floor (B - 1)/(2N) = ' + ((B - 1) / (2 * N)).toFixed(6));Expected output
HEA n = 1, L = 1: E[F] = 0.5014 E[F^2] = 0.3451 (exact 0.3438) KL = 0.0103 HEA n = 1, L = 2: E[F] = 0.4987 E[F^2] = 0.3323 (exact 0.3340) KL = 0.0003 HEA n = 1, L = 3: E[F] = 0.4981 E[F^2] = 0.3308 (exact 0.3334) KL = 0.0004 Haar (Gaussian): E[F] = 0.5040 E[F^2] = 0.3381 (exact 0.3333) KL = 0.0005 finite-sample floor (B - 1)/(2N) = 0.000475
The output agrees with the theory. For the sample second moment is close to and the KL divergence is far above the floor: one layer covers the Bloch sphere, but with the wrong (arcsine) weights. Already for the KL estimate is of the order of the sampling floor, and the Haar sampler itself lands at the floor. Expressibility is a property of the circuit and of the parameter distribution: drawing with density on instead of uniformly would make the one-layer one-qubit HEA exactly Haar.
Quick check
For two qubits () and bins, what is the Haar probability of the first bin?
Expressibility versus trainability, and hardware connectivity#
High expressibility sounds desirable: the target state should be reachable. But a circuit whose outputs are spread like Haar-random states also has a cost function that is almost the same everywhere. The following theorem makes this precise for the simplest cost, the expectation value of on one qubit.
Cost values of Haar-random states concentrate exponentially
Let be Haar-random on qubits, , and with . Then
Proof (7 steps)
- Step 1:is diagonal in the computational basis with eigenvalue ; exactly half of the basis states have .
- Step 2:The Gaussian representation, applied to each coordinate (permuting coordinates is a unitary, so all have the same law); moments from the Haar fidelity theorem.
- Step 3:All pairs have the same joint law by permutation invariance; solve for the common value.
- Step 4:Linearity of expectation.
- Step 5:Expand the square; and .
- Step 6:Combine the last two lines.
- Step 7:Chebyshev's inequality. With qubits, fewer than one Haar-random state in a hundred has : over almost the entire state space the cost is flat at .
∎
From flat costs to vanishing gradients. If the states produced by an ansatz are distributed like Haar-random states, the theorem says that the cost takes essentially the same value almost everywhere in parameter space, and resolving its differences needs a number of measurement shots of order . McClean et al. (2018) showed that the same exponential suppression holds for the partial derivatives whenever the circuit parts before or after are random enough (unitary 2-designs): the barren plateau phenomenon, derived in full in the lesson on barren plateaus. Holmes et al. (2022) turned this into a quantitative trade-off: the more expressive an ansatz, measured exactly by how close its distribution is to Haar, the smaller the variance of its gradients. A deep HEA with random initialisation is the textbook example of a circuit that is expressive and therefore hard to train. Shallow HEAs with local cost functions avoid the plateau (Cerezo et al. 2021): at depth the variance of the gradient of a cost built from few-qubit observables decays at most polynomially in . Initialising at , where the circuit outputs , is another way of starting far away from the Haar-like region.
Rotations about X and Y from Z rotations and fixed gates
For every angle : and . Hence an HEA layer can be compiled into the parameter-free gates , , , CNOT and the rotations , which superconducting processors implement as "virtual" gates by shifting the phase of later control pulses, at zero duration (McKay et al. 2017).
Proof (4 steps)
- Step 1:Conjugation by a unitary is multiplicative, , and continuous, so it passes through the exponential series.
- Step 2:Matrix multiplication with .
- Step 3:Matrix multiplication with .
- Step 4:Substitute the first identity into the second. A layer thus costs two parameterised gates and four fixed gates per qubit.
∎
SWAP overhead of non-adjacent CNOTs on a line
(a) . (b) On a line of qubits coupled only to their neighbours, a CNOT between two qubits at distance implemented with nearest-neighbour SWAPs needs at least SWAPs, and moving one qubit next to the other and back costs CNOTs. (c) The ladder of the HEA consists of distance- CNOTs only, so its routing overhead is zero, whereas an all-to-all entangler on qubits routed this way costs CNOTs instead of .
Proof (5 steps)
- Step 1:Track the basis labels: and .
- Step 2:Two linear maps that agree on a basis are equal (the lab of the SWAP lesson in Stage 2 builds exactly this circuit).
- Step 3:A SWAP of two neighbouring sites moves at most the two logical qubits on those sites, each by one position. If it exchanges and themselves their distance stays ; otherwise at most one of them moves, by one. Reducing the distance from to needs at least SWAPs.
- Step 4:Move step by step towards , apply the now-local CNOT, and move back so that the qubit layout is restored; each SWAP costs three CNOTs by (a).
- Step 5:An all-to-all entangler has CNOTs: three pairs at distance , two at distance and one at distance . The HEA ladder with its CNOTs needs no routing at all.
∎
Quick check
On a line of qubits, how many CNOTs does a single CNOT between qubits at distance cost when it is routed by nearest-neighbour SWAPs there and back?
The NumPy cell rebuilds the HEA from explicit Kronecker products: it reproduces the four lab fidelities ( at zero, and for , for the rotation in the wrong layer), prints the prefix-parity permutation of the ladder and its order for , checks the normalisation, the mean, the second moment and the bin probabilities of the Haar density by Gauss–Legendre quadrature (exact for polynomials of degree below ), and iterates the averaged Bloch second-moment matrix of the one-qubit HEA layer by layer against .
import numpy as np
I2 = np.eye(2)
def ry(t):
c, s = np.cos(t / 2), np.sin(t / 2)
return np.array([[c, -s], [s, c]], dtype=complex)
def rz(t):
return np.diag([np.exp(-0.5j * t), np.exp(0.5j * t)])
def on(q, g, n):
out = np.array([[1.0 + 0j]])
for k in range(n):
out = np.kron(out, g if k == q else I2)
return out
def cnot(c, t, n):
U = np.zeros((2 ** n, 2 ** n))
for x in range(2 ** n):
bits = [(x >> (n - 1 - k)) & 1 for k in range(n)]
bits[t] ^= bits[c]
U[int("".join(map(str, bits)), 2), x] = 1
return U
def ladder(n):
E = np.eye(2 ** n)
for q in range(n - 1):
E = cnot(q, q + 1, n) @ E
return E
def hea_state(theta): # theta[l, q, k]: layer l, qubit q, k = 0 (R_Y) or 1 (R_Z)
L, n, _ = theta.shape
psi = np.zeros(2 ** n, dtype=complex)
psi[0] = 1
for l in range(L):
for q in range(n):
psi = on(q, rz(theta[l, q, 1]) @ ry(theta[l, q, 0]), n) @ psi
psi = ladder(n) @ psi
return psi
# (1) The lab: fidelity with GHZ = (|000> + |111>)/sqrt(2) for the 3-qubit, 2-layer template.
ghz = np.zeros(8)
ghz[0] = ghz[7] = 1 / np.sqrt(2)
def lab(**angles):
theta = np.zeros((2, 3, 2))
for name, value in angles.items():
_, l, q, k = name.split("_")
theta[int(l), int(q), int(k)] = value
return abs(np.vdot(ghz, hea_state(theta))) ** 2
for label, kw in [("all zero", {}), ("t_1_0_0 = +pi/2", {"t_1_0_0": np.pi / 2}),
("t_1_0_0 = -pi/2", {"t_1_0_0": -np.pi / 2}), ("t_0_0_0 = +pi/2", {"t_0_0_0": np.pi / 2})]:
print(f"{label:16s} F = {lab(**kw):.6f}")
# (2) The ladder is the prefix-parity permutation, and its order is the smallest power of two >= n.
E3 = ladder(3)
print("E:", " ".join(f"{x:03b}->{int(np.argmax(E3[:, x])):03b}" for x in range(8)))
orders = []
for n in range(2, 7):
E, P, r = ladder(n), ladder(n), 1
while not np.allclose(P, np.eye(2 ** n)):
P, r = E @ P, r + 1
orders.append(f"n={n}: {r}")
print("order of E:", ", ".join(orders))
# (3) Haar fidelity density (d - 1)(1 - F)^(d - 2): Gauss-Legendre quadrature is exact for these polynomials.
nodes, weights = np.polynomial.legendre.leggauss(20)
F, w = (nodes + 1) / 2, weights / 2
for d in (2, 4, 8):
dens = (d - 1) * (1 - F) ** (d - 2)
j = np.arange(20)
Q = (1 - j / 20) ** (d - 1) - (1 - (j + 1) / 20) ** (d - 1)
print(f"d = {d}: mass = {np.sum(w * dens):.10f} E[F] = {np.sum(w * F * dens):.10f} (1/d = {1 / d:.10f})"
f" E[F^2] = {np.sum(w * F ** 2 * dens):.10f} (2/(d(d+1)) = {2 / (d * (d + 1)):.10f}) sum Q_j = {Q.sum():.10f} Q_0 = {Q[0]:.6f}")
# (4) One-qubit HEA: average the Bloch second-moment matrix over uniform R_Y and R_Z angles, layer by layer.
def rot_avg(M, axis): # 8 equispaced angles average cos^2, sin^2, sin cos exactly
out = np.zeros((3, 3))
for a in 2 * np.pi * np.arange(8) / 8:
c, s = np.cos(a), np.sin(a)
R = np.array([[c, 0, s], [0, 1, 0], [-s, 0, c]]) if axis == "y" else np.array([[c, -s, 0], [s, c, 0], [0, 0, 1]])
out += R @ M @ R.T / 8
return out
M = np.diag([0.0, 0.0, 1.0])
for L in range(1, 5):
M = rot_avg(rot_avg(M, "y"), "z")
p, q = M[0, 0], M[2, 2]
print(f"L = {L}: M = diag({p:.6f}, {M[1, 1]:.6f}, {q:.6f}) E[F^2] = {(1 + np.sum(M ** 2)) / 4:.10f}"
f" 1/3 + 16^-L/6 = {1 / 3 + 16.0 ** -L / 6:.10f}")Expected output
all zero F = 0.500000 t_1_0_0 = +pi/2 F = 1.000000 t_1_0_0 = -pi/2 F = 0.000000 t_0_0_0 = +pi/2 F = 0.250000 E: 000->000 001->001 010->011 011->010 100->111 101->110 110->100 111->101 order of E: n=2: 2, n=3: 4, n=4: 4, n=5: 8, n=6: 8 d = 2: mass = 1.0000000000 E[F] = 0.5000000000 (1/d = 0.5000000000) E[F^2] = 0.3333333333 (2/(d(d+1)) = 0.3333333333) sum Q_j = 1.0000000000 Q_0 = 0.050000 d = 4: mass = 1.0000000000 E[F] = 0.2500000000 (1/d = 0.2500000000) E[F^2] = 0.1000000000 (2/(d(d+1)) = 0.1000000000) sum Q_j = 1.0000000000 Q_0 = 0.142625 d = 8: mass = 1.0000000000 E[F] = 0.1250000000 (1/d = 0.1250000000) E[F^2] = 0.0277777778 (2/(d(d+1)) = 0.0277777778) sum Q_j = 1.0000000000 Q_0 = 0.301663 L = 1: M = diag(0.250000, 0.250000, 0.500000) E[F^2] = 0.3437500000 1/3 + 16^-L/6 = 0.3437500000 L = 2: M = diag(0.312500, 0.312500, 0.375000) E[F^2] = 0.3339843750 1/3 + 16^-L/6 = 0.3339843750 L = 3: M = diag(0.328125, 0.328125, 0.343750) E[F^2] = 0.3333740234 1/3 + 16^-L/6 = 0.3333740234 L = 4: M = diag(0.332031, 0.332031, 0.335938) E[F^2] = 0.3333358765 1/3 + 16^-L/6 = 0.3333358765
References
- A. Kandala, A. Mezzacapo, K. Temme, M. Takita, M. Brink, J. M. Chow and J. M. Gambetta, Hardware-efficient variational quantum eigensolver for small molecules and quantum magnets, Nature 549, 242–246 (2017).doi:10.1038/nature23879
- S. Sim, P. D. Johnson and A. Aspuru-Guzik, Expressibility and entangling capability of parameterized quantum circuits for hybrid quantum-classical algorithms, Advanced Quantum Technologies 2, 1900070 (2019).doi:10.1002/qute.201900070
- J. R. McClean, S. Boixo, V. N. Smelyanskiy, R. Babbush and H. Neven, Barren plateaus in quantum neural network training landscapes, Nature Communications 9, 4812 (2018).doi:10.1038/s41467-018-07090-4
- Z. Holmes, K. Sharma, M. Cerezo and P. J. Coles, Connecting ansatz expressibility to gradient magnitudes and barren plateaus, PRX Quantum 3, 010313 (2022).doi:10.1103/PRXQuantum.3.010313
- M. Cerezo, A. Sone, T. Volkoff, L. Cincio and P. J. Coles, Cost function dependent barren plateaus in shallow parametrized quantum circuits, Nature Communications 12, 1791 (2021).doi:10.1038/s41467-021-21728-w
- E. Grant, L. Wossnig, M. Ostaszewski and M. Benedetti, An initialization strategy for addressing barren plateaus in parametrized quantum circuits, Quantum 3, 214 (2019).doi:10.22331/q-2019-12-09-214
- D. C. McKay, C. J. Wood, S. Sheldon, J. M. Chow and J. M. Gambetta, Efficient Z gates for quantum computing, Physical Review A 96, 022330 (2017).doi:10.1103/PhysRevA.96.022330
Hands-on labs
Train a hardware-efficient ansatz to GHZ
1 step · auto-gradedOpen labThe circuit is a fixed hardware-efficient ansatz on qubits with layers: in each layer every qubit gets then , followed by the CNOT ladder , . All angles start at , where the circuit outputs . Choose angle values so that the output is the GHZ state , using the identity-at-zero and basis-state tracking arguments of the lesson.