Lesson 49 · 95 min · advanced
Quantum Natural Gradient & the Fubini–Study Metric
Gradient descent measures the length of a step in parameter space, although only the change of the quantum state matters. This lesson derives the natural distance between quantum states, the Fubini–Study distance between rays, and its infinitesimal form, the metric , which is invariant under parameter-dependent global phases. For layered circuits it proves that the in-layer blocks of are covariances of the gate generators, measurable on hardware; it derives the quantum natural gradient as steepest descent under a metric constraint by Lagrange multipliers, together with its pseudo-inverse and Tikhonov forms and its invariance under reparametrisation; it computes the metric of a qubit, , in two ways; and it relates to the quantum Fisher information , to Amari's natural gradient and to imaginary-time evolution.
Prerequisites: The Parameter-Shift Rule, The Bloch Sphere
Objectives and key results
Expand the fidelity of two nearby states to second order and derive the Fubini–Study metric of a parameterised state, and prove that it does not depend on a parameter-dependent global phase.
Prove that for a layer of commuting gates the metric block equals on the state before the layer, state what the block-diagonal and diagonal approximations discard, and explain how the variances are measured on hardware.
Derive the quantum natural gradient as the solution of subject to , handle singular metrics with the pseudo-inverse and Tikhonov regularisation, and prove its invariance under reparametrisation to first order.
Compute the metric of from the definition and from the layerwise formula, and recognise it as the round metric of a sphere of radius .
Derive the relation between the metric and the quantum Fisher information of a pure state, state the Braunstein–Caves inequality , and show that a natural-gradient step is an Euler step of variational imaginary-time evolution.
Perform natural-gradient updates by hand and with the platform's engine, and compare them with vanilla gradient descent.
- definition · Fubini–Study metric of a parameterised state
- theorem · Layerwise block of the metric
- formula · Metric of a qubit
- algorithm · Quantum natural gradient update
- identity · Quantum Fisher information of a pure state
Distances between quantum states#
The previous lessons of this module computed the gradient of a variational loss exactly with the parameter-shift rule. Vanilla gradient descent then updates . This update hides a choice of geometry: among all steps of a fixed Euclidean length , the vector decreases the linearised loss the most. The Euclidean length of a parameter step, however, says little about how far the quantum state moves. On the Bloch sphere, a change of the azimuth by moves the state by a large amount on the equator and by nothing at all at the north pole, where only multiplies the state by a global phase. A rescaling of a rotation angle makes vanilla gradient steps nine times longer in although the model is unchanged. The natural gradient removes this arbitrariness by measuring step lengths in the space of quantum states. This lesson constructs the required distance, computes it for circuits, and derives the resulting optimiser.
Definition
Rays, fidelity and the Fubini–Study distance
Two nonzero vectors describe the same physical state if for some : no measurement distinguishes them. The equivalence class is a ray, and the set of rays is the projective Hilbert space . The fidelity of two rays is which is unchanged when either vector is multiplied by a nonzero constant, and the Fubini–Study distance is . For normalised vectors is the probability that passes a projective test for .
Infinitesimal distance between rays
Let be normalised and let be a small displacement. Then the leading term equals , the squared length of the component of orthogonal to , and has the same expansion.
Proof (6 steps)
- Step 1:Expand the inner products by sesquilinearity, using and .
- Step 2:.
- Step 3:Definition of the fidelity with ; add and subtract in the numerator.
- Step 4:by Cauchy–Schwarz and ; a geometric series expands the denominator, and the product of an term with an correction is .
- Step 5:is an orthogonal projector (), so . The component of along only rescales the vector (to first order it changes the norm and the global phase) and does not move the ray.
- Step 6:, and , so .
∎
The Fubini–Study metric of a parameterised state
Let , , be twice continuously differentiable and normalised, and write . Define the quantum geometric tensor and the Fubini–Study metric . Then and is real, symmetric and positive semidefinite.
Proof (6 steps)
- Step 1:First-order Taylor expansion of the state; the second-order remainder contributes only at order to the quadratic quantities below.
- Step 2:Insert the expansion into both slots; the parameters are real, so they leave the bra unconjugated.
- Step 3:.
- Step 4:Subtract the two lines and apply the theorem on the infinitesimal distance between rays.
- Step 5:is Hermitian, so is symmetric and is antisymmetric; an antisymmetric matrix contributes nothing to a quadratic form with a real vector.
- Step 6:The identity of the previous proof with : is positive semidefinite, and exactly when moving along changes only along itself.
∎
The quantum geometric tensor is invariant under parameter-dependent phases
Let be differentiable and . Then for all , so . In contrast, depends on : the second term of is exactly what removes the unphysical phase.
Proof (5 steps)
- Step 1:Product rule; is real, so in every inner product below.
- Step 2:The bra of is ; multiply out the four terms with .
- Step 3:The same expansion with one slot replaced by .
- Step 4:Multiply the two factors; gives the last term.
- Step 5:The three -dependent terms of the second line and the fourth line coincide and cancel in the difference.
∎
Quick check
Why does the Fubini–Study metric subtract from ?
The metric of a qubit: a sphere of radius ½#
The simplest nontrivial model has one qubit and two parameters: the circuit followed by , which prepares . Up to a global phase this is the Bloch-sphere parametrisation with polar angle and azimuth , so every pure qubit state is reached. The circuit below binds and ; its statevector is . The metric is computed here directly from the definition; the next section obtains it a second time from the layerwise formula.
Circuit · 1 qubit
The model circuit then with , . The statevector is .
Unitary verified: (max deviation 1.1e-16)
The metric of R_Z(φ)R_Y(θ)|0⟩ from the definition
- Step 1:The first column of the matrix above.
- Step 2:, and .
- Step 3:The phases have modulus one, and .
- Step 4:Conjugate the components of the bra; . The result is purely imaginary.
- Step 5:Inner products with the state itself; .
- Step 6:Insert into ; the projector term vanishes except in the entry, where it subtracts .
- Step 7:The off-diagonal entries of are imaginary, so the metric is diagonal and independent of . At : .
Result
The Fubini–Study geometry of a qubit is the Bloch sphere of radius ½
For pure qubit states with Bloch vectors , Consequently is the round metric of a sphere of radius , and Fubini–Study distances are arc lengths on that sphere.
Proof (5 steps)
- Step 1:For pure states ; the Pauli matrices are traceless with .
- Step 2:Pure states have unit Bloch vectors.
- Step 3:is the angle between the Bloch vectors; . Orthogonal states (antipodal points, ) are at the maximal distance .
- Step 4:and are orthogonal with squared lengths and .
- Step 5:Combine the exact identity with ; this agrees with the direct derivation of , as the proposition on the Fubini–Study metric requires.
∎
Quick check
For the model , what is the metric entry at ?
The layerwise block-diagonal approximation#
For a general circuit with parameters the metric has independent entries, each an overlap of two derivative states. A simulator computes them exactly from the statevector, which is what the platform's engine does. On hardware, overlaps such as require interference circuits (Hadamard tests with controlled generators) for every pair . Stokes, Izaac, Killoran and Carleo observed that a large and cheap part of the metric needs no interference at all: when the parameters of a circuit are arranged in layers of commuting gates, every in-layer block is a covariance matrix of the generators in a state that the circuit prepares anyway.
Definition
Layered parameterised circuit
A layered circuit prepares where the parameters are partitioned into layers , the are fixed unitaries, and the Hermitian generators of one layer commute pairwise, for ; the standard case is a layer of Pauli rotations on distinct qubits, with acting on qubit . The state immediately before layer is , which depends only on the parameters of the earlier layers, and expectation values in it are written .
In-layer blocks of the metric are generator covariances
For a layered circuit and in the same layer , Entries with , , , depend on the gates between the two layers and are in general nonzero. The block-diagonal approximation replaces by , dropping all cross-layer blocks; the diagonal approximation keeps only .
Proof (8 steps)
- Step 1:Split the circuit at layer . Neither the unitary (the gates after the layer) nor (the gates before it) depends on a parameter with .
- Step 2:Commuting generators: for . Differentiating the factor gives , and commutes with every other factor, so it can be placed on either side of .
- Step 3:Product rule: only depends on .
- Step 4:The bra of is ( Hermitian), and . Unitary invariance: and , so all gates after the layer drop out.
- Step 5:The same cancellation with one derivative replaced by the state; the second identity is the complex conjugate of the first with (expectation values of Hermitian operators are real).
- Step 6:Definition of the quantum geometric tensor.
- Step 7:The product of two commuting Hermitian operators is Hermitian, so the in-layer block of is already real.
- Step 8:The same computation with and : the gates after layer cancel, but the gates between the layers do not. The entry is a covariance of with the generator transported back through , which in general does not commute with ; it depends on the intermediate gates and is complex. The approximation sets these blocks to zero: it is exact when they vanish (as for the qubit model below) and an approximation otherwise.
∎
The qubit metric from the layerwise formula
- Step 1:The circuit then consists of two one-gate layers with ; has generator .
- Step 2:and .
- Step 3:and . The state before the gate matters: on the variance of would be .
- Step 4:The block-diagonal approximation drops the cross-layer entry ; the direct derivation showed that its exact value is . For this model the approximation is exact: block-diagonal full metric.
Result
Quick check
Two qubits are prepared in the Bell state (a Hadamard on qubit 0, then a CNOT), followed by one layer . What is the in-layer metric entry ?
The natural gradient as steepest descent#
With the metric in hand, a step in parameter space has a physical length: by the proposition on the Fubini–Study metric, the state moves by the distance to leading order. The natural gradient asks for the step that lowers the linearised loss the most among all steps that move the state by a fixed distance. This idea goes back to Amari's natural gradient for statistical models, where the metric is the classical Fisher information; Stokes et al. transferred it to parameterised quantum circuits with the Fubini–Study metric.
Steepest descent under a metric constraint
Let be symmetric positive definite, and . The problem has the unique solution with minimal value . For it is the direction of vanilla gradient descent.
Proof (6 steps)
- Step 1:Lagrangian of the equality-constrained problem with multiplier ; the factor is a convenient normalisation. The constraint set is a compact ellipsoid and the objective is continuous, so a minimiser exists and satisfies the Lagrange conditions (the constraint gradient is nonzero on the ellipsoid).
- Step 2:for symmetric . would force , which is excluded, and is invertible.
- Step 3:Insert into the constraint; is symmetric, and because is positive definite.
- Step 4:The two stationary points are the steepest descent (, negative value) and the steepest ascent (); the minimum is attained at , which gives .
- Step 5:An independent proof of global optimality and uniqueness: defines an inner product, and the Cauchy–Schwarz inequality holds with equality only if is a negative multiple of ; the constraint fixes the multiple.
- Step 6:The objective is the first-order change of the loss and the constraint fixes the first-order Fubini–Study length of the step. Absorbing into a learning rate gives the quantum natural gradient update .
∎
Singular metrics: the gradient lies in the range of g
Let for a Hermitian and let . Then . Hence , the Moore–Penrose pseudo-inverse satisfies , and is the solution of minimal Euclidean norm of .
Proof (6 steps)
- Step 1:is the directional derivative; the last step of the proposition on the Fubini–Study metric shows , and a vector with no component orthogonal to is a multiple of it.
- Step 2:The state is normalised for every .
- Step 3:is real, so is purely imaginary. Moving along only changes the global phase, which no expectation value detects.
- Step 4:Spectral theorem for the real symmetric positive semidefinite with orthonormal eigenvectors ; is the orthogonal projector onto .
- Step 5:The first three steps show ; for symmetric , . Every solution of is with , and has the smallest norm.
- Step 6:At the north pole of the qubit model is a pure phase direction, so for every observable, and the pseudo-inverse leaves unchanged.
∎
Tikhonov regularisation and the proximal form of the update
- Step 1:Replace the hard constraint by a quadratic penalty on the step length in the regularised metric , which is positive definite even when is singular.
- Step 2:The objective is strictly convex (positive definite Hessian ), so the unique minimiser is its stationary point.
- Step 3:Eigen-decomposition of . Directions with tiny eigenvalues are damped to instead of being amplified by , which keeps the step finite near singular points; since , the limit is the pseudo-inverse step.
- Step 4:A large regulariser turns the natural gradient back into vanilla gradient descent with learning rate . The platform's engine uses (a numerical safeguard for a Cholesky solve) and the QNGvsGD widget uses by default.
Result
The natural gradient is invariant under reparametrisation
Let with a differentiable map whose Jacobian is invertible, and let , be the metrics in the two coordinates. Then , , and the natural-gradient step in induces the parameter change the natural-gradient step in . The vanilla step in induces , which differs from the vanilla step in unless .
Proof (5 steps)
- Step 1:Chain rule.
- Step 2:Both terms of are linear in each tangent vector and is real; take real parts. Equivalently, with is a property of the states, not of the coordinates.
- Step 3:for invertible square matrices.
- Step 4:First-order Taylor expansion of ; . For an affine the remainder vanishes and the two steps agree exactly.
- Step 5:The vanilla step depends on the coordinates through .
∎
Example: rescaling the rotation angle, θ = 3ξ
- Step 1:The same states, parameterised by ; the metric transforms with .
- Step 2:Chain rule at .
- Step 3:Vanilla gradient descent: the same learning rate produces a nine times longer step after the rescaling, .
- Step 4:The natural-gradient steps coincide, as the proposition predicts; the TypeScript cell below reproduces both with the engine (an affine scale of a gate angle is a valid circuit parameter).
Result
Natural-gradient updates for the qubit model
- Step 1:The -component is ; at the poles the pseudo-inverse gives the same .
- Step 2:For this loss the natural gradient is vanilla gradient descent with a four times larger learning rate, because is constant.
- Step 3:Divide each gradient component by the corresponding diagonal metric entry.
- Step 4:The Fubini–Study length of the azimuthal part of a step is the arc on the circle of latitude of radius . Near the pole the vanilla step barely moves the state, while the natural step moves it by a distance independent of .
Result
The widget above minimises from with and the regulariser . Both trajectories run down a meridian towards the south pole, where ; the natural gradient travels almost four times as fast in , as the update rule predicts (with the regulariser the factor is ). The second instance starts close to the north pole at and minimises , whose minimum lies on the equator at . Vanilla gradient descent first crawls in , because is small near the pole, while the natural gradient rescales that component by and turns towards the minimum along a nearly geodesic path.
The TypeScript cell below uses the engine functions fubiniStudyMetric, parameterShiftGradient and qngStep. It prints the exact metric of the qubit model for three polar angles, performs one natural-gradient step and one vanilla step on from , runs both optimisers for steps on from , and repeats the reparametrisation example . After ten steps the natural gradient has reached , while vanilla gradient descent is still at .
import { fubiniStudyMetric, parameterShiftGradient, qngStep } from '@/lib/quantum-simulator';
// The model |psi(theta, phi)> = RZ(phi) RY(theta)|0>: RY acts first, then RZ, with R_P(t) = exp(-i t P / 2).
const model = {
version: 1, numQubits: 1, numClbits: 0,
parameters: [{ name: 'theta', value: 0 }, { name: 'phi', value: 0 }],
ops: [
{ kind: 'gate', gate: 'RY', targets: [0], params: [{ param: 'theta' }] },
{ kind: 'gate', gate: 'RZ', targets: [0], params: [{ param: 'phi' }] },
],
};
const Z = [{ coeff: 1, ops: 'Z' }];
const X = [{ coeff: 1, ops: 'X' }];
const fmt = (v: number) => (Math.abs(v) < 5e-13 ? 0 : v).toFixed(6);
// (1) The exact Fubini-Study metric is diag(1/4, sin^2(theta)/4), whatever the value of phi.
for (const theta of [Math.PI / 6, Math.PI / 2, 2.5]) {
const g = fubiniStudyMetric(model, { bindings: { theta, phi: 0.7 } }).metric;
console.log('theta = ' + fmt(theta) + ': g = [[' + fmt(g[0][0]) + ', ' + fmt(g[0][1]) + '], [' + fmt(g[1][0]) + ', ' + fmt(g[1][1]) + ']] sin^2(theta)/4 = ' + fmt(Math.sin(theta) ** 2 / 4));
}
// (2) One step on L = <Z> = cos(theta) from (pi/6, 0) with eta = 0.1: the natural step is 4 times longer in theta.
const start = { theta: Math.PI / 6, phi: 0 };
const grad = parameterShiftGradient(model, Z, { bindings: start });
const natural = qngStep(model, Z, 0.1, { bindings: start });
console.log('gradient (' + fmt(grad.gradient.theta) + ', ' + fmt(grad.gradient.phi) + ') GD theta = ' + fmt(start.theta - 0.1 * grad.gradient.theta) + ' QNG theta = ' + fmt(natural.bindings.theta) + ', phi = ' + fmt(natural.bindings.phi));
// (3) Minimise L = <X> = sin(theta) cos(phi) from (0.3, 2.5), close to the pole where the phi-gradient is small.
const lr = 0.05;
let gd = { theta: 0.3, phi: 2.5 };
let ng = { theta: 0.3, phi: 2.5 };
for (let k = 0; k <= 40; k++) {
const a = parameterShiftGradient(model, X, { bindings: gd });
const b = qngStep(model, X, lr, { bindings: ng });
if (k % 10 === 0) console.log('step ' + k + ': GD L = ' + fmt(a.value) + ' at (' + fmt(gd.theta) + ', ' + fmt(gd.phi) + ') QNG L = ' + fmt(b.value) + ' at (' + fmt(ng.theta) + ', ' + fmt(ng.phi) + ')');
gd = { theta: gd.theta - lr * a.gradient.theta, phi: gd.phi - lr * a.gradient.phi };
ng = { theta: b.bindings.theta, phi: b.bindings.phi };
}
// (4) Reparametrise theta = 3 xi. Gradient descent changes, the natural-gradient step does not.
const scaled = { ...model, parameters: [{ name: 'xi', value: 0 }, { name: 'phi', value: 0 }], ops: [{ kind: 'gate', gate: 'RY', targets: [0], params: [{ param: 'xi', scale: 3 }] }, model.ops[1]] };
const at = { xi: Math.PI / 18, phi: 0 };
const gXi = parameterShiftGradient(scaled, Z, { bindings: at });
const nXi = qngStep(scaled, Z, 0.1, { bindings: at });
console.log('in xi: g_xixi = ' + fmt(nXi.metric[0][0]) + ', dL/dxi = ' + fmt(gXi.gradient.xi) + ' GD theta = ' + fmt(3 * (at.xi - 0.1 * gXi.gradient.xi)) + ' QNG theta = ' + fmt(3 * nXi.bindings.xi));Expected output
theta = 0.523599: g = [[0.250000, 0.000000], [0.000000, 0.062500]] sin^2(theta)/4 = 0.062500 theta = 1.570796: g = [[0.250000, 0.000000], [0.000000, 0.250000]] sin^2(theta)/4 = 0.250000 theta = 2.500000: g = [[0.250000, 0.000000], [0.000000, 0.089542]] sin^2(theta)/4 = 0.089542 gradient (-0.500000, 0.000000) GD theta = 0.573599 QNG theta = 0.723599, phi = 0.000000 step 0: GD L = -0.236754 at (0.300000, 2.500000) QNG L = -0.236754 at (0.300000, 2.500000) step 10: GD L = -0.537879 at (0.667508, 2.623782) QNG L = -0.984420 at (1.394575, 3.127851) step 20: GD L = -0.774000 at (0.975289, 2.778876) QNG L = -0.999819 at (1.551806, 3.140133) step 30: GD L = -0.906291 at (1.198246, 2.908859) QNG L = -0.999998 at (1.568757, 3.141436) step 40: GD L = -0.964375 at (1.343799, 2.998404) QNG L = -1.000000 at (1.570577, 3.141576) in xi: g_xixi = 2.250000, dL/dxi = -1.500000 GD theta = 0.973599 QNG theta = 0.723599
Quick check
For the loss of the qubit model at any , by what factor is the -component of the natural-gradient step larger than that of the vanilla gradient step with the same learning rate?
Fisher information and imaginary-time evolution#
The Fubini–Study metric is not an isolated construction. In quantum estimation theory it appears, up to a factor , as the quantum Fisher information, which bounds how precisely a parameter can be inferred from measurements on . In statistics, Amari's natural gradient uses the classical Fisher information of a probability model as its metric. And in quantum simulation, the variational approximation to imaginary-time evolution turns out to be a continuous-time natural-gradient flow. This section derives the first and the last of these relations and states the second.
The quantum Fisher information of a pure state is 4g
Let be a smooth family of pure states. The symmetric logarithmic derivatives , defined by , can be chosen as , and the quantum Fisher information equals
Proof (6 steps)
- Step 1:Differentiate the projector identity of a pure state with the product rule: solves the defining equation.
- Step 2:for Hermitian , so the two traces are complex conjugates.
- Step 3:Product rule for the outer product; normalisation makes purely imaginary.
- Step 4:; and .
- Step 5:Multiply out, using and ; with the terms and .
- Step 6:Again . The trace is the quantum geometric tensor, and its real part is the metric.
∎
Fidelity susceptibility and the Bures distance
- Step 1:The proposition on the Fubini–Study metric.
- Step 2:Differentiate the quadratic form twice; is symmetric. The QFI is minus twice the Hessian of the fidelity, the fidelity susceptibility; the tests of this lesson compute it by finite differences and compare it with .
- Step 3:. This is the Bures distance, whose infinitesimal form Braunstein and Caves identified with ; for pure states it reduces to the Fubini–Study metric.
Result
The Braunstein–Caves inequality. Measuring the state with a POVM produces outcome probabilities , whose classical Fisher information is . Braunstein and Caves (1994) proved in the sense of quadratic forms, for every POVM, with equality for a single parameter when one measures in the eigenbasis of the symmetric logarithmic derivative. By the Cramér–Rao bound, repetitions of an unbiased estimate of one parameter have variance at least , so is the largest information about that any measurement can extract. Amari's natural gradient preconditions the gradient of a statistical model with , the inverse of the Fisher–Rao metric, which is the essentially unique metric invariant under sufficient statistics (Chentsov's theorem). The quantum natural gradient replaces by : it measures distance in the space of quantum states instead of the space of measurement distributions of one fixed measurement. A constant factor between the two metrics only rescales the learning rate.
Classical versus quantum Fisher information for a Z measurement on the qubit model
- Step 1:The phases drop out of the moduli: the statistics do not depend on .
- Step 2:for ; common denominator with .
- Step 3:, so all -entries of vanish. The measurement is optimal for (equality) and blind to ; estimating requires measuring in the -plane of the Bloch sphere.
Result
Variational imaginary-time evolution is a natural-gradient flow
- Step 1:Differentiate the normalised state: and . For large the state converges to a ground state of (when overlaps it).
- Step 2:McLachlan's variational principle: choose the parameter velocity whose tangent vector is closest to the exact one. The projected tangent vectors remove the global-phase direction, which does not change the ray.
- Step 3:Normal equations of the real least-squares problem: the derivative of with respect to is .
- Step 4:and the definition of the metric.
- Step 5:, by normalisation, and .
- Step 6:An explicit Euler step of the variational imaginary-time flow is a quantum natural-gradient step on the energy with learning rate (McArdle et al. 2019).
- Step 7:For the qubit model with and . The exact state stays real, so it is with .
- Step 8:Differentiate in . The variational flow coincides with the exact evolution, because the ansatz reaches every state that the evolution visits; the NumPy cell confirms for .
Result
Quick check
What is the quantum Fisher information of the qubit model on the equator, ?
Numerical checks and the lab#
The NumPy cell below verifies the derivations of this lesson independently of the platform's engine. It builds the quantum geometric tensor of the qubit model from finite-difference tangent vectors and recovers at together with ; it multiplies the state by the parameter-dependent phase and shows that is unchanged while changes completely; it compares the infidelity with for shrinking ; it computes and the classical Fisher information of a measurement; it evaluates the lab's natural-gradient and vanilla steps; and it integrates the imaginary-time flow with a fourth-order Runge–Kutta method.
import numpy as np
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)])
ket0 = np.array([1, 0], dtype=complex)
def psi(th, ph, alpha=lambda th, ph: 0.0):
# |psi> = RZ(phi) RY(theta)|0>, optionally multiplied by a parameter-dependent global phase e^{i alpha}
return np.exp(1j * alpha(th, ph)) * (rz(ph) @ ry(th) @ ket0)
def tangents(th, ph, alpha=lambda th, ph: 0.0, h=1e-6):
d_th = (psi(th + h, ph, alpha) - psi(th - h, ph, alpha)) / (2 * h)
d_ph = (psi(th, ph + h, alpha) - psi(th, ph - h, alpha)) / (2 * h)
return psi(th, ph, alpha), [d_th, d_ph]
def qgt(th, ph, alpha=lambda th, ph: 0.0):
# quantum geometric tensor G_ij = <d_i psi|d_j psi> - <d_i psi|psi><psi|d_j psi>
p, d = tangents(th, ph, alpha)
return np.array([[np.vdot(a, b) - np.vdot(a, p) * np.vdot(p, b) for b in d] for a in d])
def naive(th, ph, alpha=lambda th, ph: 0.0):
_, d = tangents(th, ph, alpha)
return np.array([[np.vdot(a, b) for b in d] for a in d])
def show(m):
m = np.where(np.abs(m) < 5e-9, 0.0, m)
return "[[" + "], [".join(", ".join(f"{v:.6f}" for v in row) for row in m) + "]]"
th, ph = np.pi / 3, 0.4
G = qgt(th, ph)
print("g = Re G at (pi/3, 0.4):", show(G.real), "| diag(1/4, sin^2(theta)/4) =", show(np.diag([0.25, np.sin(th) ** 2 / 4])))
print(f"Im G_theta_phi = {G[0, 1].imag:.6f} = sin(theta)/4 = {np.sin(th) / 4:.6f}")
# Phase invariance: a parameter-dependent global phase leaves G unchanged but changes <d_i psi|d_j psi>.
alpha = lambda th, ph: th ** 2 + 3 * ph
print("max |G' - G| < 1e-8 under psi -> e^{i(theta^2 + 3 phi)} psi:", bool(np.abs(qgt(th, ph, alpha) - G).max() < 1e-8),
"| naive <d psi|d psi> changes from", show(naive(th, ph).real), "to", show(naive(th, ph, alpha).real))
# Projective distance: 1 - |<psi(theta)|psi(theta + delta)>|^2 = g(delta, delta) + O(delta^3).
v = np.array([0.6, -0.8])
for delta in (1e-1, 1e-2, 1e-3):
infid = 1 - abs(np.vdot(psi(th, ph), psi(th + delta * v[0], ph + delta * v[1]))) ** 2
print(f"delta = {delta:.0e}: (1 - F)/delta^2 = {infid / delta ** 2:.8f}, v^T g v = {v @ G.real @ v:.8f}")
# Quantum Fisher information 4g versus the classical Fisher information of a Z measurement.
def fisher_z(th, ph, i, h=1e-6):
p = lambda a, b: np.abs(psi(a, b)) ** 2
dp = (p(th + h, ph) - p(th - h, ph)) / (2 * h) if i == 0 else (p(th, ph + h) - p(th, ph - h)) / (2 * h)
return float(np.sum(dp ** 2 / p(th, ph)))
print(f"F_Q = 4g = {show(4 * G.real)}; classical Fisher of a Z measurement: F_theta = {fisher_z(th, ph, 0):.6f}, F_phi = {fisher_z(th, ph, 1):.6f}")
# One QNG step and one vanilla step on L = <Z> = cos(theta) from (pi/3, 0) with eta = 0.1.
eta, t0 = 0.1, np.pi / 3
grad = np.array([-np.sin(t0), 0.0])
g = np.diag([0.25, np.sin(t0) ** 2 / 4])
print(f"QNG: theta' = {t0 - eta * np.linalg.solve(g, grad)[0]:.10f} (pi/3 + 0.2 sqrt 3 = {t0 + 0.2 * np.sqrt(3):.10f}); GD: theta' = {t0 - eta * grad[0]:.10f}")
# Imaginary-time evolution under H = Z: the variational flow theta' = -1/2 g^{-1} dE/dtheta = 2 sin(theta) is exact.
tau, n = 0.5, 1000
flow = lambda t: 2 * np.sin(t)
t, dt = 0.3, tau / n
for _ in range(n): # classical Runge-Kutta 4 integration of the parameter flow
k1 = flow(t); k2 = flow(t + dt * k1 / 2); k3 = flow(t + dt * k2 / 2); k4 = flow(t + dt * k3)
t += dt * (k1 + 2 * k2 + 2 * k3 + k4) / 6
exact = 2 * np.arctan(np.exp(2 * tau) * np.tan(0.3 / 2))
evolved = np.diag([np.exp(-tau), np.exp(tau)]) @ ry(0.3) @ ket0
evolved /= np.linalg.norm(evolved)
print(f"imaginary time tau = {tau}: flow theta = {t:.6f}, 2 atan(e^(2 tau) tan(0.15)) = {exact:.6f}, from e^(-tau Z) = {2 * np.arctan2(evolved[1].real, evolved[0].real):.6f}")Expected output
g = Re G at (pi/3, 0.4): [[0.250000, 0.000000], [0.000000, 0.187500]] | diag(1/4, sin^2(theta)/4) = [[0.250000, 0.000000], [0.000000, 0.187500]]
Im G_theta_phi = 0.216506 = sin(theta)/4 = 0.216506
max |G' - G| < 1e-8 under psi -> e^{i(theta^2 + 3 phi)} psi: True | naive <d psi|d psi> changes from [[0.250000, 0.000000], [0.000000, 0.250000]] to [[4.636491, 5.759587], [5.759587, 7.750000]]
delta = 1e-01: (1 - F)/delta^2 = 0.21384541, v^T g v = 0.21000000
delta = 1e-02: (1 - F)/delta^2 = 0.21041262, v^T g v = 0.21000000
delta = 1e-03: (1 - F)/delta^2 = 0.21004154, v^T g v = 0.21000000
F_Q = 4g = [[1.000000, 0.000000], [0.000000, 0.750000]]; classical Fisher of a Z measurement: F_theta = 1.000000, F_phi = 0.000000
QNG: theta' = 1.3936077127 (pi/3 + 0.2 sqrt 3 = 1.3936077127); GD: theta' = 1.1338000916
imaginary time tau = 0.5: flow theta = 0.779612, 2 atan(e^(2 tau) tan(0.15)) = 0.779612, from e^(-tau Z) = 0.779612With the larger learning rate the natural gradient on overshoots less than one might fear: the update is a contraction near the minimum , since the derivative of the update map there is . (The widget keeps its default regulariser , so its factor is instead of , and the derivative at is .) For the fixed point would become unstable, so a natural-gradient learning rate must still be chosen with the local curvature in mind. The lab asks for the metric of the qubit model at and for one natural-gradient step on from with .
References
- J. Stokes, J. Izaac, N. Killoran and G. Carleo, Quantum natural gradient, Quantum 4, 269 (2020).doi:10.22331/q-2020-05-25-269
- S. Amari, Natural gradient works efficiently in learning, Neural Computation 10(2), 251–276 (1998).doi:10.1162/089976698300017746
- S. L. Braunstein and C. M. Caves, Statistical distance and the geometry of quantum states, Physical Review Letters 72, 3439–3443 (1994).doi:10.1103/PhysRevLett.72.3439
- S. McArdle, T. Jones, S. Endo, Y. Li, S. C. Benjamin and X. Yuan, Variational ansatz-based quantum simulation of imaginary time evolution, npj Quantum Information 5, 75 (2019).doi:10.1038/s41534-019-0187-2
- J. J. Meyer, Fisher information in noisy intermediate-scale quantum applications, Quantum 5, 539 (2021).doi:10.22331/q-2021-09-09-539
- J. P. Provost and G. Vallee, Riemannian structure on manifolds of quantum states, Communications in Mathematical Physics 76, 289–301 (1980).doi:10.1007/BF02193559
Hands-on labs
The Fubini–Study metric and one natural-gradient step
2 steps · auto-gradedOpen labCompute the Fubini–Study metric of the single-qubit model at , then use it to take one quantum-natural-gradient step on the loss and compare it with the vanilla gradient step.