Experiment 04 · Measured learning dynamics

Can a quantum circuit really learn from measurements?

Build a one- or two-qubit model, predict its expectation value and gradient, execute parameter-shift updates, and compare ideal learning with finite-shot estimates of the very same objective.

20–35 min guided experimentMeasured Z expectationParameter-shift gradientsIdeal versus finite-shot training

Where do loss gradients come from when a model is measured?

A parameterized quantum circuit produces a physical state and a measurable expectation fθ(x). The target y and loss function specify a learning problem. Under a two-eigenvalue rotation generator, the parameter-shift rule evaluates an exact derivative using two shifted circuit measurements. With finite shots, these expectations and the estimated gradient fluctuate.

Predict first: set the one-qubit model to x=0, θ≈1, target y=1 and a moderate learning rate. The exact gradient indicates which direction should reduce the loss. Now reduce the number of shots: do the individual updates always move downhill?

State preparation and circuit structure

Ry(φ)=exp(−iφσᵧ/2); the Z readout is the expectation of the measured Pauli observable, computed by repeated ±1 outcomes in the finite-shot model.

How the parameter shift determines a gradient

Teal: f(θ). Orange and blue points: f(θ+π/2) and f(θ−π/2); their difference divided by two equals the exact derivative at θ.

Exact loss landscape and gradient direction

L(θ)=[f(θ)−y]²/2 for one training input x. A gradient step changes θ by −η ∂L/∂θ. A large η or noisy estimate can increase the next loss.

Ideal gradient versus independent finite-shot evaluations

Press “Execute one update” to inspect training incrementally, or run the chosen number of updates. The ideal and finite-shot curves use the same starting θ, data point and loss; they evolve independently once gradients are computed. The finite-shot curve uses three fresh, independent groups of ±1 measurement samples per update.

Vertical axis: true physical loss evaluated at each trained parameter, for both trajectories. Orange corresponds to the finite-shot update; blue to the ideal gradient. Random sampling uses a fixed documented seed for repeatability.

Inspect the noise-free expectation and the analytic gradient before beginning training.

Build the gradient from measurable quantities

For |ψ〉=Ry(θ+x)|0〉, and Z=diag(1,−1), the measured expectation is f(θ,x)=cos(θ+x). For the two-qubit controlled-NOT circuit measured on q₁, f gains a multiplicative cosβ.

∂θ f = ½ [f(θ+π/2) − f(θ−π/2)] = −sin(θ+x) × c,

where c=1 for one qubit and c=cosβ for the two-qubit preset.

L(θ)=½[f(θ)−y]²;   ∂θL=(f−y) ∂θf;   θ′=θ−η∂θL.
Derive the parameter-shift identity

Any expectation depending on one rotation Ry(θ) with generator σᵧ/2 is of the form A+Bcosθ+Csinθ. Subtracting its values at θ+π/2 and θ−π/2 yields 2(−Bsinθ+Ccosθ), twice the analytic derivative. The shifted formula is exact in the ideal expectation, and its sampling noise comes solely from finite measurements.

Where does shot noise enter?

A Pauli measurement gives ±1. For true expectation f and N independent shots, E[f̂]=f and Var(f̂)=(1−f²)/N. For independent shifted measurements f̂₊ and f̂₋, the gradient estimator ĝ=(f̂₊−f̂₋)/2 has variance [(1−f₊²)+(1−f₋²)]/(4N). In the experiment, the estimated loss gradient uses (f̂−y)ĝ with an independently sampled f̂.

Does the two-qubit circuit create entanglement?

After CNOT the target qubit contains information about the control. With a=θ+x, the reduced state of q₀ has Bloch components (sin a sinβ,0,cos a), giving purity Tr(ρ₀²)=[1+cos²a+sin²a sin²β]/2. Its purity is below one when the joint output is entangled. The measured target Z expectation is cos a cosβ; at β=π/2 the readout loses all θ-dependence for this chosen observable even though the model still contains a trainable gate.

Questions about real trainability

  1. Gradient verification. Set θ=1 and x=0.3. Read f(θ±π/2) and compare their difference with the analytic derivative and the loss-gradient sign.
  2. Shot budget. Compare 16 with 2048 shots. Keep the same learning rate and initial condition. Which trajectory is more variable, and why do independent sampling fluctuations sometimes produce uphill steps?
  3. Measured observable matters. Select the two-qubit circuit and increase β toward π/2. The exact Z₁ output and gradient shrink. Evaluate the reduced purity and ask whether apparent training difficulty originates in the chosen readout rather than a general result about all quantum models.

Self-check: Increasing the shot count by a factor of 16 changes the standard error of a Pauli expectation by what factor?

Interpretation, limitations and textbook references

This experiment is a transparent small-dimensional single-datum supervised learning model, with one trainable rotation and an exactly computable objective. The two-qubit CNOT may create entanglement, but its Z₁ expectation admits a simple classical formula. Larger quantum models involve different generator spectra, many training points, gradient concentration, noise sources and optimization difficulties. Training this toy model does not establish a quantum speedup or learning advantage.

See quantum-circuit learning setup, parameter-shift gradient and shot noise, and limitations and trainability.