Starting point: Chapters 1 to 3, and linear algebra including positive semi-definite matrices.
Anchor example: A ten-qubit hardware-efficient layer, priced in parameters, settings, and shots.
Method: Count the parameters, plan the measurements, then price the training loop.
Watch for: Reading a flat loss as convergence rather than as a property of the landscape.
This lesson includes explanations, worked examples, and problems with solutions. Results quoted from the literature are identified as theorems with their hypotheses.
Chapter 3 treated a quantum model as a kernel: fix a feature map, measure overlaps, and hand the resulting matrix to a classical solver. That view is honest but narrow, because most proposed quantum models are variational—a circuit with adjustable angles whose output is measured, trained by a classical optimiser against a loss. This chapter builds that object carefully, from the ansatz down to the last shot. Chapter 5 supplies the optimiser, and Chapter 6 explains the failure mode that decides most of these models' fate.
4.1 Building a variational ansatz
An ansatz is a circuit family with free parameters. The name suggests a guess, and that is accurate: every structural decision—which gates, which connectivity, how deep—is a prior about the solution, made before any data is seen.
4.1.1 The four choices that define a model
A variational model is fixed by four decisions, and confusing them is a common source of muddled comparisons.
The first is the data-encoding map \(x\mapsto\rho(x)\) or \(x\mapsto|\psi(x)\rangle\), which Chapter 2 analysed. The second is the ansatz \(U(\mathbf\theta)\), the parameterised circuit applied after—or interleaved with—the encoding. The third is the readout: which observables are measured and how their expectation values are combined into a scalar. The fourth is the training rule: the loss, the optimiser, and the stopping condition. Only the second is usually called "the ansatz", yet all four determine what the model can represent, and the readout alone can change a trainable model into an untrainable one (Section 4.3.2).
where \(O\) is a Hermitian observable. Since \(\mathbf\theta\) enters through unitary gates, \(\hat y\) is a smooth, bounded, periodic function of each angle: a trigonometric polynomial. That single fact explains both the smoothness that optimisers exploit and the redundancies that make parameter space larger than it needs to be.
Worked example
A hardware-efficient layer on \(n=10\) qubits applies \(R_y\) and \(R_z\) to every qubit, then a ladder of \(n-1\) nearest-neighbour CNOTs. Count the parameters and two-qubit gates for \(L=3\) layers.
Solution and reasoning
Each layer carries \(2n=20\) angles and \(n-1=9\) CNOTs, so three layers give \(p=60\) parameters and 27 CNOTs. Compare that with the \(2^{11}-2=2046\) real parameters of a general 10-qubit pure state: the ansatz explores a 60-dimensional slice of a 2046-dimensional manifold. That ratio is the useful statement of expressivity, and it is why "the state space is exponentially large" says nothing about the model. It also sets the scale for generalisation questions in Chapter 7: 60 parameters against a few hundred samples is a very different statistical situation from 2046.
4.1.2 Hardware-efficient and problem-inspired circuits
Two families dominate practice, and they sit at opposite ends of a trade-off between what the hardware likes and what the problem knows.
Hardware-efficient ansätze use gates that the device executes natively—single-qubit rotations and the entanglers available on its connectivity graph—arranged in repeating layers. They are shallow, calibration-friendly, and problem-agnostic: nothing about the circuit knows whether the task is chemistry, classification, or optimisation. Their weakness is that being agnostic they must be expressive, and expressiveness is exactly what Section 4.1.3 and Chapter 6 identify as dangerous.
Problem-inspired ansätze borrow structure. The Hamiltonian variational ansatz and the unitary coupled-cluster family build layers from the terms of the problem Hamiltonian, so the circuit conserves particle number and symmetry by construction; QAOA alternates a problem phase separator with a mixer. These circuits are far less expressive, and that is the point: if the target state lies in the family, restricting the search is a gain, not a loss. The risk moves elsewhere—an over-restricted ansatz can miss the ground state entirely, and the residual error looks like an optimisation failure when it is a modelling one.
Four ansatz families and the properties that decide where each belongs.
Family
Built from
Expressibility
Entanglement
Main risk
Fits
Hardware-efficient
Native rotations plus device entanglers
High; rises quickly with depth
Tuned by the entangler pattern
Concentration and plateaus
Near-term devices, generic tasks
Hamiltonian variational
Terms of the problem Hamiltonian
Restricted by construction
Follows the interaction graph
Cannot reach states outside the family
Ground-state problems with known structure
Unitary coupled cluster
Fermionic excitations
Restricted; symmetry-preserving
Grows with excitation rank
Circuit depth from Trotterisation
Molecular energies
Data re-uploading
Repeated encoding interleaved with rotations
High in the number of uploads
Optional
Encoding cost; periodicity (Chapter 2)
Small classification tasks
Worked example
A molecular Hamiltonian ansatz uses one layer per Hamiltonian term, each term being a Trotterised excitation with depth 6. The Hamiltonian has 84 terms. Estimate the circuit depth, and say what happens to accuracy if the depth budget is 200.
Solution and reasoning
One layer costs about 6 gates deep and there are 84 terms, so a single sweep needs roughly 500 operations—already more than twice the stated budget. With a budget of 200 the experimenter must either truncate the term list (losing the correlation energy those terms carry) or use a shallower Trotter step. Both are legitimate, but each must be reported, because a variational energy computed from a truncated ansatz is an upper bound for a different Hamiltonian than the one in the abstract. This is the practical content of "problem-inspired": you inherit the physics and its cost at the same time.
4.1.3 Depth, entanglement, and what a shallow circuit cannot do
Depth is not a free resource, and it has a precise consequence for entanglement that is worth stating as a bound rather than a worry.
Cut a circuit's qubits into two groups. Every entangling gate straddling the cut is a two-qubit gate, and a two-qubit gate can at most double the Schmidt rank across that cut. A circuit of depth \(L\)—that is, \(L\) layers, each acting on all qubits—therefore produces a state whose Schmidt rank across any contiguous cut is at most \(2^{L}\). For \(n=10\) qubits cut into \(5+5\), a maximally entangled state needs rank \(2^{5}=32\), so \(L=3\) layers can supply at most rank 8. If the target state requires more, the ansatz has a floor in its loss that no amount of training removes.
This is a statement about what shallow circuits cannot do, and it is easy to over-read. Most learning targets are not maximally entangled; a classical model's target function is usually low-complexity, and the corresponding quantum state may be reachable at modest depth. The useful discipline is to ask, for a given target, which side of the bound you are on, and to test it by measuring the rank or the entanglement entropy of the trained state.
Expressibility is measured rather than assumed. The Meyer–Wallach measure
is zero for product states and grows as the state's local entanglement grows, and the frame potential or a divergence from the Haar measure compares an ansatz's output distribution with the uniform one. The empirical regularity, documented across many ansatz families, is that expressibility and trainability pull in opposite directions: the circuits expressive enough to contain the target are often the ones whose gradients vanish. Chapter 6 quantifies that.
Worked example
Compute the Meyer–Wallach measure for \(|000\rangle\) and for the three-qubit GHZ state \((|000\rangle+|111\rangle)/\sqrt2\).
Solution and reasoning
For \(|000\rangle\) every single-qubit reduced state is pure, so \(\operatorname{tr}(\rho_k^2)=1\) and \(Q=0\). For GHZ every single-qubit reduced state is maximally mixed, \(\operatorname{tr}(\rho_k^2)=1/2\), so \(Q=1-\tfrac13\cdot\tfrac32=1/2\). A non-zero \(Q\) therefore certifies genuine multipartite entanglement—but \(Q\) cannot distinguish a state that is useful for a task from one that is merely entangled, and it takes no account of the circuit cost of preparing the state. It is a diagnostic of the ansatz, not an objective.
4.2 From expectation value to loss
A circuit on its own produces nothing usable. Between the unitary and the optimiser sit three steps with their own costs: decomposing the observable, choosing measurement settings, and paying for statistical precision.
4.2.1 Pauli decomposition and measurement settings
Almost every observable of interest is a sum of Pauli strings,
Each \(P_j\) has to be estimated, and a single circuit run yields one bit-string, so it estimates many \(P_j\) at once only if they can be measured in the same basis. Two Pauli strings are qubit-wise commuting when, on every qubit, they either share the same Pauli or one of them is the identity; such a set can be read out from a single setting by rotating each qubit into the right basis. Strings that commute but are not qubit-wise commuting can also be grouped, at the price of extra basis-changing gates inside the circuit. The grouping problem is a graph-colouring problem, and it is worth solving before writing any code, because the number of settings multiplies every subsequent cost.
Grouping eight Pauli terms into measurement settings. All six all-Z strings share one basis. The \(XXII\) and \(YYII\) strings commute with nothing in that group and anticommute with each other, so each needs its own setting: eight terms become three circuit runs per iteration, not eight.
Worked example
An operator on four qubits has the eight terms grouped in Figure 4-2 with coefficients \(0.5,0.5,-0.2,-0.2,0.3,0.1,0.15,0.15\). Estimate how many settings are needed and how they are measured.
Solution and reasoning
Three settings suffice. The six \(Z\)-type strings are measured together after no basis change. \(XXII\) requires a Hadamard on qubits 1 and 2 before readout and \(YYII\) requires the \(Y\)-basis rotation \(S^{\dagger}H\) on both. Note that a commutation-based grouping would do no better here: \(XXII\) and \(YYII\) anticommute on qubits 1 and 2. In larger Hamiltonians the gain from grouping is substantial—typically an order of magnitude in the number of settings—which is why measurement planning is a first-class part of the compilation problem rather than an afterthought.
4.2.2 Shot noise and the precision target
Every expectation value is an estimate. For a Pauli string \(P\) measured in \(S\) shots, the estimator \(\hat{\langle P\rangle}\) has variance
so its standard deviation is at worst \(1/\sqrt S\). To resolve a quantity to \(\pm\epsilon\) you need \(S\approx1/\epsilon^2\) shots: two decimal digits cost ten thousand shots, three digits a million. Because the terms combine, the error on the total is
which tells you where to spend: terms with large coefficients deserve most of the shots, and this allocation problem has a closed-form solution when the variances are known or can be estimated from a pilot run.
The consequence for training is severe and easy to forget. A gradient or a finite difference is a difference of expectation values, so its signal is the small quantity while the noise is the same large quantity. If the loss is measured to \(\pm0.01\) and the gradient signal is \(0.005\), the optimiser is following noise. Precision requirements therefore have to be set per training run, and they grow with the number of parameters and iterations.
Worked example
A Hamiltonian estimator is built from the eight terms above with \(S_j=2000\) shots each, and all expectation values are taken to be zero for a worst-case bound. Estimate the standard deviation of the energy.
Solution and reasoning
The coefficients squared sum to \(0.25+0.25+0.04+0.04+0.09+0.01+0.0225+0.0225=0.7175\). Dividing by 2000 gives \(3.59\times10^{-4}\), so \(\sigma_O\approx0.019\). A chemical accuracy target of \(1.6\times10^{-3}\) hartree then needs roughly \((0.019/0.0016)^2\approx140\) times more shots for the same allocation, and much of that has to be repeated at every optimisation step. This is why variational chemistry proposals quote shot budgets explicitly: an energy curve with \(10^{-3}\) error bars is a different claim from one with \(2\times10^{-2}\) error bars.
4.2.3 Readout error and calibration
Measurement is not ideal. A qubit read out as 1 was sometimes 0, and the effect is systematic rather than random. For a single qubit with symmetric flip probability \(\varepsilon\), the observed and true distributions are related by an assignment matrix,
which can be estimated by preparing every computational basis state and inverting. Two cautions follow. The inversion amplifies noise by \(1/(1-2\varepsilon)^2\), so 3% readout error costs about 13% more shots—small—but 15% error costs more than twice as many, and the matrix becomes ill-conditioned. For \(n\) qubits the full matrix has \(4^{n}\) entries, which is why practitioners use a tensored or correlated model fitted to a limited set of calibration circuits, accepting residual bias for tractability.
The same logic governs gate error, but there the mitigation is different: errors accumulate with depth, so a deeper ansatz needs either error mitigation, which trades shots for accuracy, or error correction, which trades qubits. Both change the accounting, and neither is free.
Worked example
A qubit has symmetric readout error \(\varepsilon=0.03\) and the measured excited-state population is \(0.55\). Correct it, and state the cost on the estimator's variance.
Solution and reasoning
Inverting gives \(p^{\text{true}}=(0.55-0.03)/0.94=0.5521\), so the raw number was biased low by about 0.002. The variance inflation is \(1/(1-2\varepsilon)^2=1/0.8836\approx1.13\), so 13% more shots are needed for the same precision. Both effects are small here, and the example is included precisely to make the point that readout mitigation is a correction with a measurable price, not a free improvement—and to give you the arithmetic to check a claimed improvement rather than accepting it.
4.3 The optimisation problem in parameter space
Training means minimising a loss over the \(p\) angles. Everything depends on the shape of that function, and the shape is set by choices made in Section 4.1—before any data arrived.
4.3.1 The landscape is a function of the circuit
Write the empirical loss as \(L(\mathbf\theta)=\frac1N\sum_i\ell\bigl(\hat y(x_i;\mathbf\theta),y_i\bigr)\). It is smooth, because each \(\hat y\) is a trigonometric polynomial in the angles. It is bounded. It is not convex in general, and cannot be made so without giving up the model.
A one-dimensional slice through a two-parameter landscape, with the initial point on the slope of the shallower well. Gradient descent from here finds the local minimum and reports a converged loss. The reported value is an upper bound on the best available loss, and the gap between the two minima is what an unlucky initialisation costs.
Two structural features are worth naming. First, parameter redundancy: because the circuit is periodic in each angle, distinct parameter vectors produce identical states, so the landscape has flat directions and the Hessian is singular. Second, the map from parameters to loss can be highly curved in some directions and almost flat in others—an ill-conditioned landscape that a first-order optimiser will crawl along. Both are properties of the ansatz, and both are visible before training by examining the spectrum of the classical Fisher information or the Hessian at a few random points.
The practical point is that "the optimiser failed" is a diagnosis of last resort. It is usually a statement about the landscape, and the landscape is a design decision.
4.3.2 Global versus local cost functions
How the measured terms are combined into one number changes trainability, not just scale. A global cost takes the whole observable at once, for instance \(L=1-\langle H\rangle/\|H\|_{\infty}\), where \(H\) may have exponentially many terms. A local cost averages individual low-weight terms, \(L=1-\frac1m\sum_j\langle P_j\rangle\) with \(m\) terms of bounded weight.
The difference is measurable. For global costs, the variance of the gradient at random initialisation decays exponentially in the number of qubits even at shallow depth; for local costs of bounded weight the decay is polynomial at shallow depth, becoming exponential only as depth grows. This is the cost-function-dependent barren-plateau result of Cerezo and colleagues (2021), and it is one of the few pieces of variational-circuit theory with direct design consequences: define the loss over local terms and combine the results classically.
Worked example
A gradient component decays like \(2^{-n}\) while the shot noise on its estimate stays fixed. How many more shots are needed at \(n=10\) to keep the same relative precision as at \(n=1\)?
Solution and reasoning
Relative precision requires \(S\propto 1/g^2\) for a signal \(g\), so a signal smaller by \(2^{-n}\) costs \(4^{n}\) times more shots. At \(n=10\) that is \(4^{10}\approx1.05\times10^{6}\)—a million times the shots for the same relative accuracy. Note the trap in the word "relative": if the noise decayed as fast as the signal, the shot count would not change at all, and a plot of signal-to-noise would look flat while both quantities vanished. Always ask which of the two is decaying.
4.3.3 Regularisation, early stopping, and the prior you did not choose
A variational model with \(p\) angles fitted to \(N\) samples will interpolate whenever \(p\gtrsim N\), and interpolation is not generalisation. Three regularisers are available, and only one of them is usually discussed.
Early stopping is the cheapest: monitor a validation set and stop when its loss turns upward. Since the parameters move slowly near flat regions, the number of iterations acts as an implicit constraint on the distance travelled from initialisation, and that constraint is a real prior. Explicit penalties—adding \(\lambda\|\mathbf\theta\|^2\) to the loss, or constraining the parameter range—make the prior visible and tunable. The third and least discussed is the ansatz itself: choosing a circuit that conserves particle number, or that only entangles nearest neighbours, has already excluded most functions, and that exclusion is worth more than any amount of tuning in the small-sample regime.
The consequence for reporting is blunt. Two papers comparing quantum and classical models with different inductive biases are comparing the biases, not the hardware. State the ansatz, the parameter count, the regularisation, and the stopping rule, or the comparison cannot be interpreted. Chapter 7 develops the statistical side of this, and Chapter 8 turns it into a checklist for advantage claims.
Cost accounting for one training run of the four-qubit example above.
Stage
Settings
Shots per setting
Repetitions
Total shots
Readout calibration
16 basis states
5,000
1
80,000
Optimisation loop
3
2,000
150 iterations
900,000
Final evaluation
3
20,000
1
60,000
Total
1,040,000
About a million shots, or roughly one second of pure shot time at a microsecond per shot—and that number is misleading in the direction people least expect. On real hardware the wall-clock cost is dominated by latency, reset, and compilation, so a million shots may take hours. The arithmetic above is a lower bound on cost and an upper bound on optimism.
Further reading
These sources cover the ansatz families, the measurement problem, and the landscape results used in this chapter.
A variational model is four decisions: encoding, ansatz, readout, and training rule; only the second is usually called the ansatz.
Measurement cost is settings times shots, and precision scales as 1/epsilon^2, so each decimal digit is a hundredfold increase.
Shallow depth bounds entanglement across a cut, and how the measured terms are combined decides whether gradients survive.
Questions and worked problems
These exercises draw on the whole chapter. Attempt each question before opening a hint, explain your reasoning, then compare it with the worked solution.
Name the four choices that define a variational model, and say which one is usually called the ansatz.
Hint 1
Think encoding, circuit, measurement, optimiser.
Worked solution
The data-encoding map, the parameterised circuit, the readout observables, and the training rule. Only the parameterised circuit is normally called the ansatz, yet all four determine what the model can represent, and the readout alone can decide whether it trains.
A six-qubit hardware-efficient layer applies R_y and R_z to every qubit, then a ring of six CNOTs. Count the parameters and CNOTs for two layers.
Hint 1
Two angles per qubit per layer; a ring has one CNOT per qubit.
Worked solution
Each layer has 2 x 6 = 12 angles and 6 CNOTs, so p = 24 and 12 CNOTs. Compare with the 2^7 - 2 = 126 real parameters of a general six-qubit pure state: the model is a 24-dimensional slice.
An eight-qubit circuit is cut into two groups of four. What is the largest Schmidt rank a two-layer ansatz can produce across that cut, and what does a maximally entangled state need?
Hint 1
Each straddling two-qubit gate can at most double the rank.
Worked solution
Two layers give rank at most 2^2 = 4, while a maximally entangled 4|4 state needs rank 2^4 = 16. No training schedule can close that gap; the ansatz, not the optimiser, sets the floor.
Counts from 1,000 shots of a two-qubit experiment are 450 for 00, 50 for 01, 60 for 10, and 440 for 11. Estimate the expectation of Z on the first qubit and of Z (x) Z.
Hint 1
Sum counts with the sign of each eigenvalue.
Worked solution
For Z on qubit 1 the sign is + for 00 and 01, so (450 + 50 - 60 - 440)/1000 = 0. For Z (x) Z the sign is + only for 00 and 11, giving (450 + 440 - 50 - 60)/1000 = 0.78. The two marginals are balanced while the correlation is strong, which a single-qubit readout would have missed entirely.
How many shots are needed to resolve a single Pauli expectation value to plus or minus 0.005?
Hint 1
Worst-case standard deviation is 1/sqrt(S).
Worked solution
S = 1/0.005^2 = 40,000 shots, and that is for one term only. Three decimal digits on a full Hamiltonian is a million-shot-per-term proposition unless the allocation is optimised.
Two terms have coefficients 0.5 and 0.3 with 1,000 and 5,000 shots. Estimate the standard deviation of the combined estimator, then propose a better allocation for a fixed total of 6,000 shots.
Hint 1
Errors add in quadrature; allocate shots in proportion to the coefficient magnitude.
Worked solution
The variances are 0.25/1000 = 2.5e-4 and 0.09/5000 = 1.8e-5, summing to 2.68e-4, so the deviation is about 0.016. Allocating shots as |c_j| splits 6,000 into 3,750 and 2,250, giving 0.25/3750 + 0.09/2250 = 1.07e-4, a deviation of about 0.010 with the same budget.
A qubit has symmetric readout error 0.08 and the measured excited-state population is 0.60. Correct it and give the variance penalty.
Hint 1
Invert the assignment matrix, then look at the denominator.
Worked solution
The corrected value is (0.60 - 0.08)/0.84 = 0.619, so the raw number was biased low by about 0.019. The variance is inflated by 1/(0.84)^2 = 1.42, so about 42% more shots are needed. At 15% error the factor exceeds two and the inversion becomes unreliable.
An optimiser needs 60 measurement settings for a 200-term Hamiltonian, 2,000 shots per setting, and 150 iterations. Count the shots and the time at one microsecond each.
Hint 1
Settings x shots x iterations.
Worked solution
60 x 2,000 x 150 = 1.8 x 10^7 shots, about 18 seconds of pure shot time. Wall-clock time on hardware is dominated by latency and reset, so a run of this size takes hours, not seconds; and a gradient-based optimiser multiplies the per-iteration cost again.
Adding layers makes a variational model better, because more depth means more expressibility.
Hint 1
Consider the two directions the trade-off runs in.
Worked solution
No. Depth raises expressibility and, past a point, destroys trainability: gradients concentrate and hardware error accumulates with every layer. The useful depth is the smallest one whose reachable set contains a good solution, which is why adaptive schemes add layers only when the loss stops improving.
Design a measurement plan for the four-qubit Heisenberg Hamiltonian with six XX+YY+ZZ bond terms plus four field terms, and state how many settings you need.
Hint 1
Group by qubit-wise commuting sets; note that XX, YY, and ZZ on the same bond do not commute.
Worked solution
ZZ on the four bonds plus the four Z field terms are all qubit-wise commuting, so they share one setting. XX terms on different bonds overlap, so a chain needs two alternating settings for the XX strings and two for YY; with the field terms folded in, five to seven settings is realistic. Estimating each setting to plus or minus 0.01 costs 10^4 shots each, so one energy evaluation is roughly 5 x 10^4 to 7 x 10^4 shots before any optimisation.