From theory to a trainable experiment
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.
Measured quantum model
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.
Exact derivatives from shifted circuits
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 θ.
The objective geometry
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.
Actual training trajectory
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.
Derivation and numerical interpretation
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β.
where c=1 for one qubit and c=cosβ for the two-qubit preset.
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.
Try → explain → extend
Questions about real trainability
- Gradient verification. Set θ=1 and x=0.3. Read f(θ±π/2) and compare their difference with the analytic derivative and the loss-gradient sign.
- 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?
- 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.