Skip to content

geope.jax.hessian¤

Second derivatives of the pulse model, by two independent routes.

The manual propagator functions exploit the product-of-exponentials structure of geope.geometry.chart, in three shapes. hvp_propagator gets a single direction in \(O(G)\) with one jax.lax.scan. hessian_vjp_propagator gets every pair, contracted against one ambient covector, by splitting the middle propagator so that each half depends on one gate index only — two \(O(G)\)-propagated derivative trajectories and one Gram matrix, which is the acceleration of Goodwin & Vinding, Phys. Rev. Research 5, L012042 (2023), §III. hessian_propagator materialises the dense \((G, G, d, d, K, K)\) tensor at \(O(G^2K^2d^3)\) and \(O(G^2K^2d^2)\), and is the reference the pullback is checked against — the same standing geope.geometry.chart.get_jacobian_fn has one order down.

The first two are live, landed on the base point by geope.geometry.chart.get_chart_hvp_fn and geope.geometry.chart.get_chart_hessian_vjp_fn and read off geope.geometry.tangent.TangentBundle. Note these are derivatives of the propagator, not of an objective: Manifold.hessian assembles the infidelity Hessian from the pullback plus the manifold's own cost derivatives.

The autodiff pair works on any chart, including the param_transform path where no exponential-product structure exists — which is why Manifold.hessian falls back to it there. It is also the reference the manual path is tested against.

su_hessian_quadratic_form and stiefel_hessian_quadratic_form are a different object: the Riemannian Hessian of the squared geodesic distance, which supplies SpecialUnitaryGroup.hessian_quadratic_form and Stiefel.hessian_quadratic_form, and the curvature the second-order line searches seed their step from. The two are shaped very differently — a bi-invariant group's is a scalar function \(\frac{\mathrm{ad}}2\coth \frac{\mathrm{ad}}2\) of one adjoint operator, evaluated without ever forming it, while a general Stiefel manifold is not symmetric and needs the blocks of an operator exponential solving the Jacobi equation.

Manual propagator derivatives¤

geope.jax.hessian.hvp_propagator(params, direction, step_fn) ¤

Directional second derivative (HVP) of the product unitary in \(O(G)\).

Computes the value and the first and second single-direction derivatives of the product unitary along a parameter-space direction \(p\), without forming the full Jacobian or the dense \((G, G, d, d, K, K)\) Hessian of hessian_propagator. With the product convention of :func:geope.geometry.chart.compute_matrices_params_list_fn, \(\phi(\theta) = U_{G-1} \cdots U_1 U_0\) with each gate left-multiplied, define the partial product \(X_g = U_g \cdots U_0\) with derivatives \(V_g = \dot X_g(0)\), \(W_g = \ddot X_g(0)\) along \(\theta(t) = \theta + t p\). Since \(X_g(t) = U_g(t) X_{g-1}(t)\), the product rule gives the linear-time recursion (the left-multiply mirror of the note's convention)

\[X_g = U_g X_{g-1}, \qquad V_g = U_g V_{g-1} + E_g X_{g-1},$$ $$W_g = U_g W_{g-1} + 2\,E_g V_{g-1} + G_g X_{g-1},\]

with \(X_{-1} = I\), \(V_{-1} = W_{-1} = 0\), where \(U_g = \exp(A_g)\), \(E_g = D\exp(A_g)[B_g]\), and \(G_g = D^2\exp(A_g)[B_g, B_g]\) are the per-gate value and directional derivatives (step_fn). After all \(G\) gates, \(X_{G-1} = \phi(\theta)\), \(V_{G-1} = D\phi_\theta[p]\), and \(W_{G-1} = D^2\phi_\theta[p, p]\). The cross term \(2\,E_g V_{g-1}\) collects every cross-pulse interaction, so no explicit \(O(G^2)\) double sum is needed; the recursion is a single jax.lax.scan. This is the second-order sibling of geope.jax.jacobian.jvp_propagator.

Parameters:

Name Type Description Default
params Array

Parameter Array of shape (G, K).

required
direction Array

Direction Array of shape (G, K) (the \(p\) above).

required
step_fn Callable[[Array, Array], tuple[Array, Array, Array]]

Per-gate step (x, p) -> (U, E, G) mapping a gate's coefficients and direction to its value and first/second directional derivatives (e.g. geope.jax.expm_hvp_eig).

required

Returns:

Type Description
Array

Tuple (X, V, W) of matrices of shape (d, d): the product unitary

Array

\(\phi(\theta)\), its directional derivative \(D\phi_\theta[p]\), and its

Array

directional second derivative \(D^2\phi_\theta[p, p]\).

geope.jax.hessian.get_hvp_propagator(gate_basis, method='eig', hermitian=True) ¤

Create a JIT-compiled directional-HVP propagator for a given gate basis.

Wraps hvp_propagator with a per-gate step built from gate_basis and is wrapped in jax.jit so it compiles once and is reused across calls.

Parameters:

Name Type Description Default
gate_basis Array

Generator Array of shape (K, d, d) — skew-Hermitian in the pipeline (geope.geometry.basis.Basis.algebra).

required
method str

Per-gate method. "eig" (default) uses the spectral geope.jax.expm_hvp_eig; "block" uses the block-exponential geope.jax.expm_hvp (ignores hermitian).

'eig'
hermitian bool

Assume real parameters and use the eigh-based per-gate step. Set False for complex-valued parameters. Only affects method="eig".

True

Returns:

Type Description
Callable[[Array, Array], tuple[Array, Array, Array]]

A Callable[[Array, Array], tuple[Array, Array, Array]] accepting

Callable[[Array, Array], tuple[Array, Array, Array]]

parameters and a direction, both of shape (G, K), and returning the

Callable[[Array, Array], tuple[Array, Array, Array]]

triple (phi, Dphi[p], D2phi[p, p]) of shape (d, d).

geope.jax.hessian.hessian_vjp_propagator(params, Ui_fn, jac_fn, hess_step_fn, right=None) ¤

Pullback of the propagator Hessian — every pair, no \((G, G, d, d, K, K)\).

Returns (U, pullback) in the shape of jax.vjp, and for the same reason vjp_propagator does: the covector a cost hands back is a function of the value, so the two cannot be asked for in one call, and returning them together is what lets them share the gate exponentials, their two partial products and the per-gate derivatives.

pullback contracts a single ambient covector \(C\) against all \((GK)^2\) blocks of the propagator Hessian at once,

\[T_{(i,k),(j,l)} = \mathrm{Tr}\Bigl(C^\dagger\, \frac{\partial^2 (U x_0)}{\partial x_{i,k}\,\partial x_{j,l}}\Bigr),\]

which is what the chain rule for a cost's Hessian actually needs.

The trick, and why it is \(O(G)\) propagations. With the middle product \(M_{ij} = R_i(U_jR_j)^\dagger\) of hessian_propagator, the off-diagonal block depends on \(i\) and \(j\) through that middle, which is what makes the dense route quadratic in propagations. Splitting it and using \(U = L_jU_jR_j\) sends each half back to the base point, where it depends on one index only:

\[T_{(i,k),(j,l)} = \mathrm{Tr}\bigl[ \underbrace{(C^\dagger J_{i,k})}_{A_{i,k}}\; \underbrace{(U^\dagger J_{j,l}\,x_0)}_{B_{j,l}}\bigr], \qquad i > j,\]

with \(J_{i,k} = L_i(\partial_kU_i)R_i\) the propagator Jacobian (jacobian_propagator). \(A\) and \(B\) are Goodwin & Vinding's adjoint and forward derivative trajectories: two stacks of \(GK\) blocks, each built in \(O(GKmd^2)\) from partial products that already cost \(O(G)\), after which the whole pair table is one Gram matrix — a single gemm of \(O(G^2K^2md)\). Nothing quadratic is ever propagated, and the dense tensor is never formed: \(O(GKmd + (GK)^2)\) of memory against \(O(G^2K^2d^2)\).

The diagonal (\(i = j\)) blocks are a different object — the same gate's second derivative — and go through the covector \(B_i = L_i^\dagger(Cx_0^\dagger) R_i^\dagger\) of vjp_propagator, contracted against hess_step_fn's per-gate \((d, d, K, K)\) tensor. That term is \(O(GK^2d^3)\) and is the one piece left un-accelerated; it only dominates the Gram when \(d > G\). A second-order sibling of geope.jax.adj_expm_eig — all \(K^2\) overlaps of one covector from one eigendecomposition — would bring it to \(O(G(Kd^3 + K^2d^2))\).

Parameters:

Name Type Description Default
params Array

Parameter Array of shape (G, K).

required
Ui_fn Callable[[Array], Array]

Callable mapping a coefficient Array to a unitary Array.

required
jac_fn Callable[[Array], Array]

Per-gate first derivative, (K,) -> (d, d, K) (e.g. dexpm_eig).

required
hess_step_fn Callable[[Array], Array]

Per-gate second derivative, (K,) -> (d, d, K, K) (e.g. d2expm_eig). Only the diagonal blocks need it.

required
right Array | None

The constant block every derivative is right-multiplied by — the chart's base point \(x_0\), of shape (d, m). None means the identity, i.e. the propagator is the point, and no multiplication is introduced. The branch is on a Python value, resolved at trace time.

None

Returns:

Type Description
Array

Tuple (U, pullback): the product unitary of shape (d, d), and a

Callable[[Array], Array]

callable taking an ambient covector of shape (d, m) — paired through

tuple[Array, Callable[[Array], Array]]

\(\mathrm{Tr}(C^\dagger\,\cdot)\), i.e. conjugated — to the complex

tuple[Array, Callable[[Array], Array]]

overlaps of shape (G, K, G, K). As vjp_propagator, the result is

tuple[Array, Callable[[Array], Array]]

not halved or realified: a real cost's Hessian takes

tuple[Array, Callable[[Array], Array]]

2 * jnp.real(...).

Note

The (G, K, G, K) layout is the row-major (gate, coefficient) flattening that phi.flatten() and the gradient use, so a caller reshapes to (P, P) with no transpose.

geope.jax.hessian.get_hessian_vjp_propagator(gate_basis, right=None, method='eig', hermitian=True) ¤

Create a pullback propagator-Hessian for a given gate basis.

Wraps hessian_vjp_propagator with per-gate derivatives built from gate_basis.

Unlike get_hessian_propagator the result is not jax.jit-wrapped — it returns a closure, which a jitted function cannot, and the same reasoning as geope.jax.get_vjp_propagator applies: it fuses into the enclosing @jax.jit that wants the Hessian, which is where the value and the pullback get to share their partial products.

Parameters:

Name Type Description Default
gate_basis Array

Generator Array of shape (K, d, d) — skew-Hermitian in the pipeline (geope.geometry.basis.Basis.algebra).

required
right Array | None

The chart's base point \(x_0\), of shape (d, m), or None for the identity. See hessian_vjp_propagator.

None
method str

Per-gate derivative method. "eig" (default) uses the spectral dexpm_eig / d2expm_eig; "block" uses the block-exponential dexpm / d2expm, which assume no skew-Hermitian structure and ignore hermitian.

'eig'
hermitian bool

Assume real parameters (skew-Hermitian generators) and use the faster eigh-based per-gate derivatives. Set False for complex-valued parameters. Only affects method="eig".

True

Returns:

Type Description
Callable[[Array], tuple[Array, Callable[[Array], Array]]]

A Callable[[Array], tuple[Array, Callable]] taking parameters of shape

Callable[[Array], tuple[Array, Callable[[Array], Array]]]

(G, K) to the pair hessian_vjp_propagator returns.

geope.jax.hessian.hessian_propagator(params, Ui_fn, jac_fn, hess_step_fn) ¤

Compute the full Hessian propagator of the product unitary.

Second-derivative analogue of geope.jax.jacobian_propagator. With the product convention \(U = U_{G-1} \cdots U_1 U_0\), \(U_i = \exp(\sum_k x_{i,k} E_k)\) (each gate left-multiplied), the mixed derivative with respect to gates \(i\) and \(j\) leaves all other gates untouched:

  • same gate (\(i = j\)): \(\partial^2 U / \partial x_{i,k}\partial x_{i,l} = L_i\,(\partial^2 U_i / \partial x_{i,k}\partial x_{i,l})\,R_i\);
  • distinct gates (\(i > j\)): \(\partial^2 U / \partial x_{i,k}\partial x_{j,l} = L_i\,(\partial U_i/\partial x_{i,k})\,M_{ij}\, (\partial U_j/\partial x_{j,l})\,R_j\),

where \(R_i = U_{i-1}\cdots U_0\) (exclusive prefix), \(L_i = U_{G-1}\cdots U_{i+1}\) (exclusive suffix), and \(M_{ij} = U_{i-1}\cdots U_{j+1} = R_i (U_j R_j)^\dagger\) (the middle product, using unitarity). The \(i < j\) blocks follow from symmetry, \(H_{ij,kl} = H_{ji,lk}\). Prefix/suffix/middle products are built with two jax.lax.scan passes and a single batched matmul; the assembly is a set of vectorised einsums (no Python loop over gates).

Memory note: the returned tensor is dense with shape (G, G, d, d, K, K), i.e. \(O(G^2 d^2 K^2)\), and the assembly costs \(O(G^2 K^2 d^3)\). This is the reference, not the live path. A cost Hessian contracts every one of those blocks against one ambient covector immediately, and hessian_vjp_propagator does that without building any of them — which is what geope.geometry.manifold.Manifold.hessian calls. Reach for this one when you genuinely want the matrix-valued \(\mathrm D^2\Phi\) itself.

Parameters:

Name Type Description Default
params Array

Parameter Array of shape (G, K).

required
Ui_fn Callable[[Array], Array]

Callable mapping a coefficient Array to a unitary Array.

required
jac_fn Callable[[Array], Array]

Per-gate first derivative, (K,) -> (d, d, K) (e.g. dexpm).

required
hess_step_fn Callable[[Array], Array]

Per-gate second derivative, (K,) -> (d, d, K, K) (e.g. d2expm).

required

Returns:

Type Description
Array

An Array of shape (G, G, d, d, K, K) with

Array

H[i, j, :, :, k, l] = d^2 U / d x_{i,k} d x_{j,l}.

geope.jax.hessian.get_hessian_propagator(gate_basis, method='eig', hermitian=True) ¤

Create a JIT-compiled manual propagator-Hessian function.

Wrapped in jax.jit so it compiles once and is reused across calls.

Parameters:

Name Type Description Default
gate_basis Array

Generator Array of shape (K, d, d) — skew-Hermitian in the pipeline (geope.geometry.basis.Basis.algebra).

required
method str

Per-step derivative method. "eig" (default) uses the spectral per-step derivatives (dexpm_eig / d2expm_eig); "block" uses the block-exponential derivatives (dexpm / d2expm), which assume no skew-Hermitian structure and ignore hermitian.

'eig'
hermitian bool

Assume real parameters (skew-Hermitian generators) and use the faster eigh-based per-gate derivatives. Set False for complex-valued parameters. Only affects method="eig".

True

Returns:

Type Description
Callable[[Array], Array]

A Callable[[Array], Array] accepting a parameter array of shape

Callable[[Array], Array]

(G, K) and returning the Hessian of shape (G, G, d, d, K, K).

Autodiff¤

geope.jax.hessian.hvp_forward_over_reverse(f, params, v) ¤

Compute a Hessian-vector product via forward-over-reverse mode.

The chart-agnostic counterpart of hvp_propagator: it differentiates any scalar callable rather than exploiting the product-of-exponentials structure, so it works on the param_transform path where the manual propagator cannot.

Parameters:

Name Type Description Default
f Callable[[Array], Array]

Scalar-valued callable of params.

required
params Array

Parameter Array at which to evaluate.

required
v Array

Tangent Array for the Hessian-vector product.

required

Returns:

Type Description
Array

The Hessian-vector product \(\nabla^2 f \cdot v\).

geope.jax.hessian.get_hessian_fn(infid_fn) ¤

Build the full Hessian function via forward-over-reverse HVPs.

Materialises the Hessian of infid_fn by mapping hvp_forward_over_reverse over the identity matrix's columns — the autodiff drop-in for get_hessian_propagator, and what geope.geometry.Manifold.hessian falls back to when no analytic form is available. Returned un-jitted so it fuses into the enclosing @jax.jit update step.

Parameters:

Name Type Description Default
infid_fn Callable[[Array], Array]

Scalar-valued infidelity callable of the free parameters.

required

Returns:

Type Description
Callable[[Array], Array]

A Callable[[Array], Array] hess(y) returning the Hessian.

Riemannian curvature¤

geope.jax.hessian.su_hessian_quadratic_form(A, Omega) ¤

The Riemannian-Hessian quadratic form of the squared geodesic distance.

Evaluates \(\langle\Omega,\mathcal K_A\Omega\rangle_F\), the intrinsic term of the second derivative of \(F=\tfrac12 d_g(\cdot,y)^2\) along a curve with left-trivialised velocity \(\Omega\), where

\[\mathcal K_A=\frac{\operatorname{ad}_A}{2} \coth\!\left(\frac{\operatorname{ad}_A}{2}\right)\]

is the left-trivialised Riemannian Hessian at \(x\) with \(A=\log_{\min}(y^\dagger x)\).

No operator is ever formed. \(\mathcal K_A\) is diagonal in the eigenbasis of \(A\): since \(A\in\mathfrak{su}(N)\) is skew-Hermitian, \(-iA\) is Hermitian and a single eigh gives \(A=Q\,i\operatorname{diag}(\theta)\,Q^\dagger\). On the root plane of the pair \((j,k)\) the operator \(\operatorname{ad}_A\) has eigenvalue \(i\delta_{jk}\) with \(\delta_{jk}=\theta_j-\theta_k\), so \(\mathcal K_A\) has the real eigenvalue \(h(\delta_{jk})\) and, with \(\tilde\Omega=Q^\dagger\Omega Q\),

\[\langle\Omega,\mathcal K_A\Omega\rangle_F =\sum_{j,k}h(\delta_{jk})\,\bigl|\tilde\Omega_{jk}\bigr|^2, \qquad h(\delta)=\frac{\delta}{2}\cot\!\left(\frac{\delta}{2}\right), \quad h(0)=1,\]

which is manifestly real.

Unlike the surrogate \(\|\Omega\|_F^2\), this is exact for an arbitrary \(\Omega\) — it does not assume the tangent matching \(\Omega\parallel A\). The two agree exactly when \(\Omega\parallel A\), because \([A,A]=0\) gives \(\mathcal K_AA=A\) (the radial eigenvalue is \(1\)).

Since \(h\) decreases from \(1\) to \(0\) on \([0,\pi)\), the eigenphase spread \(\rho=\Delta(A)=\max_j\theta_j-\min_j\theta_j\) bounds the whole spectrum: for \(\rho<\pi\),

\[\mu(\rho)I\preceq\mathcal K_A\preceq I, \qquad \mu(\rho)=\frac{\rho}{2}\cot\!\left(\frac{\rho}{2}\right)>0,\]

so \(\|\Omega\|_F^2\) is always an upper bound on the returned value there. Beyond \(\rho=\pi\) the form is indefinite, and \(h\) diverges as \(|\delta|\to2\pi\) — the cut locus, where \(\log_{\min}\) stops being unique. rho is returned alongside so callers can test for that.

Parameters:

Name Type Description Default
A Array

Skew-Hermitian Array of shape (d, d); the minimum-norm logarithm \(A=\log_{\min}(y^\dagger x)\), traceless for \(\mathfrak{su}(N)\).

required
Omega Array

Array of shape (d, d); the left-trivialised velocity \(\Omega=x^\dagger\,d\phi_\theta[p]\).

required

Returns:

Type Description
Array

A tuple (value, rho) of real scalars: the quadratic form

Array

\(\langle\Omega,\mathcal K_A\Omega\rangle_F\) and the eigenphase spread

tuple[Array, Array]

\(\rho=\Delta(A)\), both from the same eigendecomposition.

Example
# Radial direction: the form reduces to ||A||_F^2 exactly.
value, rho = su_hessian_quadratic_form(A, A)

geope.jax.hessian.stiefel_hessian_quadratic_form(point, delta, omega) ¤

The canonical-Stiefel Riemannian-Hessian quadratic form.

Evaluates \(g_Q(\Omega, \mathcal K^{\mathrm{St}}_\Delta\Omega)\), the intrinsic term of \(\psi''(0)\) for \(\psi = \tfrac12 d_g(\cdot, Q_\star)^2\) under the canonical metric \(g_Q(\Xi,\Upsilon) = \mathrm{Re}\,\mathrm{Tr} (\Xi^\dagger(\mathbb 1 - \tfrac12 QQ^\dagger)\Upsilon)\).

There is no eigenangle formula here. A general Stiefel manifold is normal homogeneous but not symmetric, so neither the group's \(\frac{\operatorname{ad}}2\coth\frac{\operatorname{ad}}2\) nor the sphere's \(\theta\cot\theta\) applies. What survives is that, once the logarithm is known, the Jacobi equation has constant coefficients in a homogeneous moving frame. With \(A = Q^\dagger\Delta\), \(Q_\perp B = (\mathbb 1 - QQ^\dagger)\Delta\) and a tangent written as \(\Xi = QC + Q_\perp D\),

\[\mathsf L_S(C,D) = \bigl([A,C] - B^\dagger D + D^\dagger B,\; BC - DA\bigr), \qquad \mathsf M_S(C,D) = \bigl(0,\; -(DB^\dagger - BD^\dagger)B\bigr),\]

and \(z'' + \mathsf L_Sz' - \mathsf M_Sz = 0\). Blocking the unit-time solution operator of that system as \(e^{\mathbb A_S} = \bigl(\begin{smallmatrix}E_{11} & E_{12}\\ E_{21} & E_{22}\end{smallmatrix}\bigr)\) with \(\mathbb A_S = \bigl(\begin{smallmatrix}0 & \mathbb 1\\ \mathsf M_S & -\mathsf L_S\end{smallmatrix}\bigr)\) gives \(\mathcal K^{\mathrm{St}}_S = E_{12}^{-1}E_{11} - \tfrac12\mathsf L_S\), and since \(\mathsf L_S\) is skew-adjoint the diagonal form drops its second term entirely.

The operator block-diagonalises, which is what makes this affordable. Choosing the complement as \(Q_\perp = (Q_1\mid Q_2)\) with \(\mathrm{range}((\mathbb 1 - QQ^\dagger)\Delta) \subseteq \mathrm{span}(Q_1)\) confines \(B\) to \(Q_1\), and both operators then split along \((C, D_1)\oplus D_2\). On \(D_2\) they reduce to right multiplications identical for every row (_jacobi_right_sector), so only \((C, D_1)\) needs a dense exponential (_jacobi_coupled_sector). The naive route over the whole \(2Nm - m^2\)-dimensional tangent space costs \(O((Nm)^3)\); this costs \(O(m^6)\), independent of \(N\), and never forms \(Q_2\). Prefer geope.line_searches.QuadraticArmijo once \(m\) grows past roughly 8.

Not even in \(\Delta\). Unlike su_hessian_quadratic_form, whose kernel \(h\) is even, this form genuinely depends on the sign: \(-\Delta\) points at the geodesic reflection of the target, which is a different Hessian. Only at \(m = N\), where the manifold is the group, does evenness return. Callers holding the context's A = -log(point, target) must negate it.

In the two limits it reduces correctly: at \(m = N\) the vertical space vanishes, \(\mathsf M_S = 0\), and this reproduces su_hessian_quadratic_form — value and rho alike — to double precision; at \(\Delta = 0\) both operators vanish, \(\mathcal K = \mathbb 1\), and the form is exactly \(\lVert\Omega\rVert_Q^2\).

Parameters:

Name Type Description Default
point Array

The base frame \(Q\), (N, m) with \(Q^\dagger Q = \mathbb 1_m\).

required
delta Array

The tangent \(\Delta = \mathrm{Log}_Q(Q_\star)\) at point, pointing toward the target.

required
omega Array

The tangent \(\Omega\) the form is evaluated on, (N, m).

required

Returns:

Type Description
Array

A tuple (value, rho) of real scalars: the quadratic form

Array

\(g_Q(\Omega, \mathcal K^{\mathrm{St}}_\Delta\Omega)\), and the eigenphase

tuple[Array, Array]

spread \(\rho\) of the horizontal lift \(S\) as the cut-locus diagnostic.

References

R. Zimmermann and K. Hüper, Computing the Riemannian logarithm on the Stiefel manifold, SIAM J. Matrix Anal. Appl. 43, 953 (2022).

W. Ziller, The Jacobi equation on naturally reductive compact Riemannian homogeneous spaces, Comment. Math. Helv. 52, 573 (1977).