Skip to content

geope.jax.jacobian¤

First derivatives of the pulse model, in both directions.

jacobian_propagator builds the whole \((G, d, d, K)\) tensor \(\partial U/\partial\phi_{g,k}\); vjp_propagator contracts an ambient covector against every one of those columns without building it. Both share the two jax.lax.scan partial products (the gates before and after the one being differentiated), and both are exact — they differ only in what they are for. A Jacobian is what the geodesic least-squares problem needs, one column per parameter; a gradient is not, and paying \(O(G\,d^3K)\) to build a tensor you immediately contract away is the difference between the two paths.

jvp_propagator is the third direction: one parameter-space direction pushed forward, in \(O(G)\), without either.

The Jacobian¤

geope.jax.jacobian.jacobian_propagator(params, Ui_fn, jac_fn) ¤

Compute the full Jacobian propagator of the product unitary.

The product unitary follows the convention of :func:geope.geometry.chart.compute_matrices_params_list_fn, where each gate is left-multiplied onto the accumulator,

\[U = U_{G-1} \cdots U_1 U_0, \qquad U_i = \exp\!\Big(\sum_k x_{i,k} E_k\Big).\]

The derivative with respect to a parameter of gate \(i\) leaves every other gate untouched, so it is a product with a single factor replaced by the per-gate derivative:

\[\frac{\partial U}{\partial x_{i,k}} = \underbrace{U_{G-1} \cdots U_{i+1}}_{L_i}\, \frac{\partial U_i}{\partial x_{i,k}}\, \underbrace{U_{i-1} \cdots U_0}_{R_i}.\]

Both the left (\(L_i\), exclusive suffix product) and right (\(R_i\), exclusive prefix product) partial products are obtained in \(O(G)\) matrix multiplications with two jax.lax.scan passes, after which the per-gate derivative blocks are combined with a single vectorised einsum. This is the equivalent of differentiating the whole sequence with autodiff, but built explicitly from the per-gate derivative jac_fn.

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]

Callable computing the per-gate Jacobian Array of shape (d, d, K) (e.g. :func:geope.jax.dexpm).

required

Returns:

Type Description
Array

An Array of shape (G, d, d, K) containing the full Jacobian.

geope.jax.jacobian.get_jacobian_propagator(gate_basis, method='eig', hermitian=True) ¤

Create a JIT-compiled manual Jacobian function for a given gate basis.

The returned function is wrapped in jax.jit so it is compiled once and 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 derivative method. "eig" (default) uses the spectral method (geope.jax.dexpm_eig); "block" uses the block-exponential method (geope.jax.dexpm), which assumes no skew-Hermitian structure and ignores hermitian.

'eig'
hermitian bool

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

True

Returns:

Type Description
Callable[[Array], Array]

A Callable[[Array], Array] that accepts a parameter array

Callable[[Array], Array]

of shape (G, K) and returns the Jacobian of shape

Callable[[Array], Array]

(G, d, d, K).

The pullback¤

geope.jax.jacobian.vjp_propagator(params, Ui_fn, adj_fn) ¤

Pullback (VJP) of the product unitary — every partial, no Jacobian.

Returns (U, pullback) in the shape of jax.vjp, and for the same reason: the covector a cost hands back is a function of the value, so the two cannot be asked for in one call. Splitting them this way means the gate exponentials and their two partial products are computed once and shared — a caller that evaluated the chart separately would pay for them twice.

pullback contracts a single ambient covector \(C\) against all \(G\times K\) columns of the Jacobian at once,

\[t_{i,k} = \mathrm{Tr}\Bigl(C^\dagger\,\frac{\partial U}{\partial x_{i,k}}\Bigr),\]

which is what a chain rule out of the ambient space actually needs. jacobian_propagator would build the whole \((G, d, d, K)\) tensor first; here the partial products land on the covector instead. Using

\[\Bigl\langle C,\ L_i\,\frac{\partial U_i}{\partial x_{i,k}}\,R_i \Bigr\rangle = \Bigl\langle L_i^\dagger C R_i^\dagger,\ \frac{\partial U_i}{\partial x_{i,k}} \Bigr\rangle,\]

each gate needs one \(d \times d\) covector \(B_i = L_i^\dagger C R_i^\dagger\) — two matrix products — after which adj_fn returns all \(K\) overlaps for that gate without ever forming its \((d, d, K)\) derivative. The whole call is \(O(G(d^3 + d^2 K))\) in flops and \(O(G d^2)\) in memory, against the Jacobian route's \(O(G d^3 K)\) and \(O(G d^2 K)\).

The pullback's result is complex, and deliberately not halved or realified. A real-valued cost \(C(\phi)\) whose ambient Wirtinger gradient is \(\hat G\) has \(\partial_{i,k} C = 2\,\mathrm{Re}\,t_{i,k}\) for a cotangent of \(\hat G\), so the gradient is one 2 * jnp.real(...) away; but a projective cost also needs the complex overlaps \(\langle y, \partial U\rangle\) for its second-order term, and returning the raw value serves both from one primitive.

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
adj_fn Callable[[Array, Array], Array]

Per-gate adjoint (x, b) -> (K,) returning \(\mathrm{Tr}(b^\dagger \partial_k U_i)\) (e.g. geope.jax.adj_expm_eig).

required

Returns:

Type Description
Array

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

Callable[[Array], Array]

callable taking an ambient covector (d, d) — 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).

geope.jax.jacobian.get_vjp_propagator(gate_basis, method='eig', hermitian=True) ¤

Create a pullback propagator for a given gate basis.

Wraps vjp_propagator with a per-gate adjoint built from gate_basis.

Unlike get_jacobian_propagator the result is not jax.jit-wrapped — it returns a closure, which a jitted function cannot. That is the right default anyway: it fuses into the enclosing @jax.jit that actually wants the gradient, 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
method str

Per-gate adjoint method. "eig" (default) uses the spectral geope.jax.adj_expm_eig, which never forms the (d, d, K) per-gate derivative; "block" uses geope.jax.adj_expm, which does (it ignores hermitian and assumes no skew structure).

'eig'
hermitian bool

Assume real parameters (skew-Hermitian generators) and use the faster eigh-based per-gate adjoint. 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

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

shape (G, K) to the pair vjp_propagator returns.

The pushforward¤

geope.jax.jacobian.jvp_propagator(params, direction, step_fn) ¤

Directional first derivative (JVP) of the product unitary in \(O(G)\).

Computes the value and the single-direction derivative of the product unitary along a parameter-space direction \(p\), without forming the full Jacobian. 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\) and its derivative \(V_g = \dot 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

\[X_g = U_g X_{g-1}, \qquad V_g = U_g V_{g-1} + E_g X_{g-1},\]

with \(X_{-1} = I\), \(V_{-1} = 0\), where \(U_g = \exp(A_g)\) and \(E_g = D\exp(A_g)[B_g]\) are the per-gate value and directional derivative (step_fn). After all \(G\) gates, \(X_{G-1} = \phi(\theta)\) and \(V_{G-1} = D\phi_\theta[p]\). The recursion is a single jax.lax.scan; this is the forward-mode (JVP) analogue of jacobian_propagator, and the first-order sibling of geope.jax.hessian.hvp_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]]

Per-gate step (x, p) -> (U, E) mapping a gate's coefficients and direction to its value and directional derivative (e.g. geope.jax.expm_jvp_eig).

required

Returns:

Type Description
Array

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

Array

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

geope.jax.jacobian.get_jvp_propagator(gate_basis, method='eig', hermitian=True) ¤

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

Wraps jvp_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_jvp_eig; "block" uses the block-exponential geope.jax.expm_jvp (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]]

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

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

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

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

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