Skip to content

geope.geometry¤

The geometry layer owns the space GEOPE walks, its tangent bundle, and every per-step geometric quantity the optimisers read.

One ambient space, several submanifolds¤

Every manifold in the library is a submanifold of one ambient space \(\mathcal A = \mathbb C^{N\times m}\), and each is the orbit of the same \(\mathrm U(N)\) action through a different base point:

base point \(x_0\) the orbit through it
\(\mathbb 1_N\) \(\mathrm U(N)\), \(\mathrm{SU}(N)\)
\((\mathbb 1_m;\,0)^\intercal\) \(\mathrm{St}_m(\mathbb C^N)\)
\(\lvert\psi_0\rangle\) \(S^{2N-1} \to \mathbb{CP}^{N-1}\)

The pulse acts on all of \(\mathcal A\) the same way, so everything valued in \(\mathcal A\) is shared, and everything happening inside a fibre \(T_x\mathcal M\) belongs to the submanifold. That single line is the layering:

ambient  A = C^{N×m}     Φ(φ) = U(φ)·x₀ ,  DΦ ,  D²Φ            chart.py
                         the coefficient frame
     │
     │   to_tangent :  A → T_x M         <- the only bridge
     ▼
submanifold  M ⊂ A       inner, coefficients, log,
                         tangent_acceleration,
                         hessian_quadratic_form, fidelity        Manifold hooks

Ownership¤

Manifold  --owns-->  base_point     (x₀ = Φ(0): where the orbit starts)
   |                 target         (the point being synthesised)
   |                 compute_point  (the chart Φ: parameters -> the manifold)
   |
   '-----owns-->  TangentBundle --owns-->  frame      (the ambient coefficient frame)
                                          jacobian   (the pushforward DΦ)
                                          vjp        (the pullback DΦᵀ)
                                          hvp        (D²Φ along one direction)
                                          hessian    (the dense D²Φ)

A manifold contributes only the point its orbit starts from; the pulse model supplies the rest. Manifold.bind composes the two and holds no mathematics of its own.

Nothing above this layer knows what space it is optimising on: Geope, the line searches and Gecko speak only to the interface below. A manifold that is not a Lie group — no identity, no left translation, point-dependent tangent spaces — satisfies exactly the same contract; geope.geometry.stiefel.sphere.StateSphere is the worked example.

The interface¤

geope.geometry.manifold.Manifold ¤

A Riemannian submanifold of the ambient space \(\mathcal A\).

Constructed with only its dimensions this is the pure space, and its geometric primitives already work — log, distance2, inner, norm2, fidelity, hessian_quadratic_form. bind attaches the run's chart, coefficient frame and target, which is what a per-step GeometricContext needs. (coefficients is the one exception: a coordinate choice is problem data, so it needs the frame that bind brings.)

Attributes:

Name Type Description
base_point

\(\Phi(0) \in \mathcal A\) — the point the chart's orbit starts from, and the whole of what a manifold contributes to its own chart. None means the pulse propagator is the point, which is the case on any matrix Lie group; a homogeneous space supplies the state or frame the pulse drives. Unlike the other three this is part of the space, set at construction rather than by bind.

target

The target point; None when unbound.

compute_point

The chart \(\Phi\), phi -> point; None when unbound.

tangent

The TangentBundle; None when unbound.

All four are keyword-only and defaulted, so a subclass can declare positional fields of its own.

fidelity_at cached property ¤

phi -> the fidelity of the pulse phi against the target.

Compiled and memoised rather than evaluated eagerly, because the host-side loops call it one trial pulse at a time: uncompiled, each call re-lowers the chart's jax.lax.scan, which cost ~100 ms per call on a 3-qubit, 20-step pulse and made geope.Geope's Gram-Schmidt fallback more expensive than the whole geodesic step it was replacing.

infidelity_at cached property ¤

phi -> the infidelity of the pulse phi — what GRAPE minimises.

Compiled and memoised, for the same reason as fidelity_at.

value_and_grad_autodiff cached property ¤

phi -> (infidelity, dinfidelity/dphi) by reverse-mode autodiff.

The reference the analytic path is checked against, and the fallback for a manifold that declines cost_gradient.

Note that differentiating infidelity_at holomorphically with respect to a complex128 array whose imaginary part is identically zero gives a gradient with a spurious imaginary part. value_and_grad does not.

value_and_grad cached property ¤

phi -> (infidelity, dinfidelity/dphi) (used by GRAPE).

Analytic when this manifold supplies cost_gradient: one pass over the pulse through geope.geometry.tangent.TangentBundle.vjp, which returns the point and a pullback sharing the gate exponentials and their partial products, then one ambient cost gradient through it,

\[\frac{\partial C}{\partial\phi_{g,k}} = 2\,\mathrm{Re}\,\mathrm{Tr}\bigl(\hat G^\dagger\,\partial_{g,k}\Phi\bigr),\]

which never forms the Jacobian. That the value comes back with the pullback is what keeps it to one pass: the covector \(\hat G\) is a function of the point, so a separate compute_point call would re-exponentiate every gate. Falls back to value_and_grad_autodiff otherwise.

The gradient is real by construction and returned in the parameter's own dtype, so it drops straight into geope.optimizers on the complex128 pulse arrays geope.parameters.Parameters.free hands out.

hessian_autodiff cached property ¤

The infidelity Hessian (P, P) by forward-over-reverse HVPs.

The reference the analytic path is checked against, and the fallback wherever the analytic one is unavailable — a manifold that declines cost_hessian_form, or the param_transform chart, which has no second differential to build one from.

Carries the same spurious imaginary part as value_and_grad_autodiff on a complex128 pulse whose imaginary part is identically zero — it differentiates the same holomorphic gradient. Its real part is right in every case, and it is exact on the float64 pulses of the param_transform path where it is actually used. Compare against it on real input.

hessian cached property ¤

The infidelity Hessian (P, P) (used by GRAPE's Newton methods).

Analytic when this manifold supplies cost_hessian_form and the chart has a second differential to offer (geope.geometry.tangent.TangentBundle.hessian_vjp). The assembly is the chain rule in two terms — the cost's own curvature and the chart's bending —

\[\partial_a\partial_b\,C(\Phi(\phi)) = \mathrm{Hess}_C[\mathrm D\Phi_a, \mathrm D\Phi_b] + 2\,\mathrm{Re}\bigl\langle \hat G,\ \mathrm D^2\Phi_{ab}\bigr\rangle,\]

the first from the hook and the second generic, since \(\hat G\) is just cost_gradient. Falls back to hessian_autodiff otherwise.

The second term never forms \(\mathrm D^2\Phi\): the pullback splits the pair table into a Gram matrix of two \(O(G)\)-propagated derivative trajectories — see geope.jax.hessian_vjp_propagator — so a Newton step costs \(O(GKd^3 + G^2K^2md)\) in flops and \(O(GKmd + (GK)^2)\) in memory rather than the dense route's \(O(G^2K^2d^3)\) and \(O(G^2K^2d^2)\). That the point comes back with the pullback keeps it to one pass over the pulse, exactly as in value_and_grad.

The Jacobian is built only for the projective \(\zeta\) term; a phase-sensitive cost's cost_hessian_form ignores its columns, and XLA eliminates the whole computation.

__abstractmethods__ class-attribute ¤

frozenset() -> empty frozenset object frozenset(iterable) -> frozenset object

Build an immutable unordered collection of unique elements.

__annotations__ class-attribute ¤

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

__dataclass_fields__ class-attribute ¤

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

__dataclass_params__ class-attribute ¤
__dict__ class-attribute ¤
__doc__ class-attribute ¤

str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.

__match_args__ class-attribute ¤

Built-in immutable sequence.

If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.

If the argument is a tuple, the return value is the same object.

__module__ class-attribute ¤

str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.

__weakref__ property ¤

list of weak references to the object

ambient_ndim property ¤

The number of array axes one point has.

ambient_shape property ¤

The shape of one point in the embedding space.

has_cost_gradient property ¤

Whether this manifold overrides cost_gradient.

A host-side capability probe — an identity check on the bound method's function, so nothing is traced and no exception has to be caught inside a jax.jit. value_and_grad reads it to pick its path.

has_cost_hessian_form property ¤

Whether this manifold overrides cost_hessian_form. See has_cost_gradient.

is_bound property ¤

Whether a chart, tangent bundle and target are attached.

manifold_dim property ¤

The intrinsic (real) dimension of the manifold.

to_tangent(point, ambient) ¤

Map an ambient velocity at point into this manifold's tangent representation.

The representation is whatever inner, coefficients and log all speak: left-trivialised algebra elements on a Lie group, ambient projections on a homogeneous space. Batches over leading axes.

Parameters:

Name Type Description Default
point Array

The base point, of shape ambient_shape.

required
ambient Array

Ambient velocities, shape (..., *ambient_shape).

required
inner(point, x, y) ¤

The Riemannian metric \(\langle x, y\rangle_{\text{point}}\).

Takes the base point because in general the metric depends on it (a bi-invariant group metric simply ignores it). Batches over leading axes.

coefficients(point, tangent) ¤

Linear coordinates for tangent vectors at point.

Must be faithful and metric-consistent up to a fixed constant \(c > 0\): \(\sum_k c_k(u)\,c_k(v) = c\,\langle u, v\rangle_{\text{point}}\). These are the coordinates the geodesic least-squares problem is posed in, so the constant cancels between its two operands.

log(x, y, key=None) ¤

\(\mathrm{Log}_x(y)\): the minimal-geodesic tangent at \(x\), pointing to \(y\).

Taking it at \(x\) rather than at \(y\) is what lets it be compared with a velocity at \(x\): on a general manifold \(T_x\) and \(T_y\) are unrelated spaces, and only a group's trivialisation makes the distinction vacuous.

Parameters:

Name Type Description Default
x Array

The base point.

required
y Array

The end point.

required
key Array | None

Optional JAX key, for implementations whose logarithm is randomised (the unitary-specialised one is not).

None
tangent_acceleration(point, v, w) ¤

\(\dot\Omega(0)\): the derivative of the tangent representation along the chart.

Given the ambient first and second directional derivatives \(V, W\) of a curve through point, return \(\frac{\mathrm d}{\mathrm dt}\,\texttt{to\_tangent}(c(t), \dot c(t))\) at \(t = 0\). This is the term that carries the chart's bending into the curvature of the objective, as distinct from the manifold's own curvature (hessian_quadratic_form). Finite-differencing to_tangent along the chart is the definitive check on an implementation.

hessian_quadratic_form(point, a, omega) ¤

\(\bigl(\langle\Omega,\mathcal K_A\Omega\rangle,\ \text{spread}\bigr)\).

The intrinsic term of the second derivative of \(\tfrac12 d_g(\cdot, y)^2\) along a curve with tangent \(\Omega\), where \(\mathcal K_A\) is the Riemannian Hessian of the squared distance at point, plus a scalar diagnostic of how close a is to the cut locus. Must be exact for an arbitrary \(\Omega\), and must reduce to \(\lVert A\rVert^2\) when \(\Omega = A\) (the radial direction).

a is the context's \(A = -\mathrm{Log}_x(y)\), pointing away from the target, so an implementation that cares about the sign must negate it. Most do not — on a bi-invariant group and on the sphere the kernel is even in \(A\) — but geope.geometry.stiefel.stiefel.Stiefel genuinely is not: \(-A\) addresses the geodesic reflection of the target, which has a different Hessian. Do not read the group's evenness as the contract.

A manifold may decline: raising NotImplementedError is the documented way to withdraw GeometricContext.q_exact and GeometricContext.rho (and with them geope.line_searches.ApproximateQuadraticArmijo) rather than return an inexact form, and tests/test_manifolds.py probes for the capability instead of assuming it.

fidelity(x, y) ¤

The convergence score between two points: 1 when they agree.

The optimisers' stopping test and every logged trajectory read this, so it should be normalised to \(1\) at the target whatever the manifold. "Fidelity" is GEOPE's name for that score; a manifold is free to define it however its geometry suggests.

infidelity(x, y) ¤

The cost the optimisers minimise: 0 when the two points agree.

Declared separately from fidelity rather than derived from it as 1 - fidelity: which cost a space is optimised against is the manifold's own business, and tying the two together here would impose a relation that only happens to hold for the trace fidelities.

cost_gradient(x, y) ¤

\(\partial C/\partial\bar x\): the ambient gradient of infidelity at x.

The Wirtinger derivative with respect to the conjugate point, so that the chain rule out of the ambient space reads

\[\frac{\partial\,C(\Phi(\phi))}{\partial\phi_a} = 2\,\mathrm{Re}\bigl\langle \hat G,\ \mathrm D\Phi_a \bigr\rangle, \qquad \hat G = \texttt{cost\_gradient}(x, y),\]

which is what makes this — rather than the full Jacobian — the object a gradient is built from: contracted through geope.geometry.tangent.TangentBundle.vjp it costs one pullback, and no \((*\text{ambient}, G, K)\) tensor is ever formed.

Declinable. The base implementation raises NotImplementedError, which withdraws the analytic value_and_grad in favour of autodiff — the same way hessian_quadratic_form may withdraw GeometricContext.q_exact. A manifold that declines still optimises; it just differentiates the slow way. Every manifold GEOPE ships implements it, in two lines, by delegating to geope.geometry.cost.trace_cost_gradient.

Parameters:

Name Type Description Default
x Array

The current point, of shape ambient_shape.

required
y Array

The target, of shape ambient_shape.

required

Returns:

Type Description
Array

An Array of shape ambient_shape.

Raises:

Type Description
NotImplementedError

If this manifold declines to supply one.

cost_hessian_form(x, y, u) ¤

The cost's own second-derivative form, \(\mathrm{Hess}_C[u_a, u_b]\).

Only the term that comes from the curvature of \(C\) in the ambient space. The other term — the chart's bending, \(2\,\mathrm{Re}\langle\hat G, \mathrm D^2\Phi_{ab}\rangle\) — is the chain rule applied to cost_gradient and is assembled generically by hessian, so an implementation here must not include it. A cost that is affine in the point (any phase-sensitive trace fidelity) returns zeros.

Parameters:

Name Type Description Default
x Array

The current point, of shape ambient_shape.

required
y Array

The target, of shape ambient_shape.

required
u Array

The chart's Jacobian columns, of shape (P, *ambient_shape) with P = G * K.

required

Returns:

Type Description
Array

A real Array of shape (P, P).

Raises:

Type Description
NotImplementedError

If this manifold declines to supply one, which withdraws the analytic hessian in favour of hessian_autodiff.

ambient_inner(x, y) ¤

\(\mathrm{Re}\sum \bar x\,y\) over the ambient axes — the metric of \(\mathcal A\).

The default building block for inner, and correct as it stands for any manifold whose metric is the one induced by the embedding — which includes a bi-invariant group metric, where it is \(\mathrm{Re}\,\mathrm{Tr}(x^\dagger y)\), and the round metric on the state sphere. A manifold whose metric is not the ambient one must say so: geope.geometry.stiefel.stiefel.Stiefel carries the canonical metric \(\mathrm{Re}\,\mathrm{Tr}(x^\dagger W_Q y)\) instead, which is what gives it different geodesics from the embedding's.

norm2(point, x) ¤

\(\lVert x\rVert^2_{\text{point}}\).

distance2(x, y, key=None) ¤

Half the squared geodesic distance, \(\tfrac12 d_g(x, y)^2\).

The objective the first- and second-order line searches minimise, and the quantity whose derivatives a GeometricContext reports. Costs one log.

bind(*, target, generators, frame=None, columns=None, wrap_chart=None) ¤

Attach this problem's chart, coefficient frame and target.

The seam between the two layers this package is built on, and it holds no mathematics of its own: geope.geometry.chart builds the ambient jet \((\Phi,\ \mathrm D\Phi,\ \mathrm D^2\Phi)\) from generators and this manifold's base_point, and everything else here is assembly.

Returns a new manifold — this one is frozen — so the unbound mathematical object stays reusable.

Parameters:

Name Type Description Default
target Array | ndarray | None

The point being synthesised, of shape ambient_shape, or None for a problem that names no target yet. The chart and the tangent bundle still attach, so the pulse stays computable and differentiable, but is_bound stays False and every target-dependent quantity raises.

required
generators Basis

The chart's generator sub-geope.geometry.lie.Basis — the proj+drift basis the pulse is expressed in.

required
frame Basis | None

The ambient coefficient frame coefficients resolves a tangent vector against, if this manifold coordinatises through one. None is not a degraded mode: it is the right answer for a manifold whose fibre coordinates are a real/imaginary split of the ambient array (see geope.geometry.stiefel.sphere.StateSphere), and it means no projector is ever built.

None
columns ndarray | None

Boolean mask over the chart's coefficient columns selecting those the geodesic solve may move. None means every column.

None
wrap_chart Callable[[Callable], Callable] | None

An opaque reparametrisation of the chart's input, or None. Its presence is the single param_transform signal: it drops both second differentials (the HVP, and with it the curvature tier, and the dense chart Hessian), turns the first one into its autodiff form in both directions, and frees every column. The manifold never inspects it, which is what keeps geope.parameters.Parameters out of this layer.

That it reparametrises the input is what lets it wrap the landed chart rather than the bare propagator: \(\mathrm{wrap}(\Phi)(\phi) = U(\tau(\phi))\,x_0\) either way, so the base point never has to be threaded through it.

None

Returns:

Type Description
Manifold

A bound Manifold of the same class.

Raises:

Type Description
ValueError

If this manifold is already bound, or if target is not of shape ambient_shape.

validate_point(point, what='point') ¤

Raise if point does not lie on this manifold.

The membership check — unitarity for a matrix group, unit norm on the sphere — as opposed to the shape check bind does.

Host-side only, and deliberately numpy. Membership of the target is a configuration-time question — Parameters.__init__ calls this once, before the chart exists, so that a bad target fails at construction rather than as a plausible-looking fidelity. Keeping it numpy is what makes the alternative unmakeable: inside a jax.jit even jnp.asarray(numpy_array) yields a tracer, so a jnp-based membership check raises ConcretizationTypeError instead of validating. That is the trap that killed validate_basis; keep membership checks host-side and numpy.

The base implementation accepts everything, so a manifold that cannot cheaply decide membership simply does not override it.

Parameters:

Name Type Description Default
point ndarray

The candidate point, of shape ambient_shape.

required
what str

Name of the offending argument, used in the error message.

'point'

Raises:

Type Description
ValueError

If point is not on the manifold.

context(free_params, delta_t=1.0) ¤

Open a GeometricContext at the pulse free_params.

Cheap: every quantity on the returned context is lazy, so this on its own evaluates nothing. Build one per optimisation step, inside the jitted update — see GeometricContext for why it must not leave that trace.

Parameters:

Name Type Description Default
free_params Array

The pulse, shape (G, K_free).

required
delta_t Array | float

The segment duration, threaded (as a traced scalar) into every chart evaluation the context performs. Defaults to 1.0.

1.0
__delattr__(name) ¤
__init__(*, base_point=None, target=None, compute_point=None, tangent=None) ¤
__repr__() ¤
__setattr__(name, value) ¤

The tangent bundle¤

geope.geometry.tangent.TangentBundle ¤

The fibre coordinates and the chart's differentials.

Data, not operations. The metric and the coefficient map are the geope.geometry.manifold.Manifold's, because in general both depend on the base point; what is left here is what a chart and a coordinate choice are made of.

Every callable field takes the segment duration delta_t (defaulting to 1.0) as its final argument, threaded down from geope.geometry.context.GeometricContext — a traced scalar, never baked into the closures.

The two geope.geometry.lie.Basis fields play different roles and are different sizes. frame is the ambient coefficient frame: the basis a manifold's Manifold.coefficients resolves a tangent vector against, i.e. params.basis. generators is the chart's own, smaller sub-basis (the proj+drift one), from which jacobian and hvp are built. Both are optional, and for unrelated reasons — see each below.

Attributes:

Name Type Description
frame

The ambient coefficient frame, or None. None is not a degraded mode: it is the right answer for a manifold whose fibre coordinates are a real/imaginary split of the ambient array rather than a resolution against a matrix frame — which is both Stiefel manifolds, and which is also cheaper, \(2Nm\) coefficients against a matrix frame's \(d^2\). It means no projector is ever built. The projector itself, and the >5-qubit on-the-fly switch, belong to the manifold that reads this (see geope.geometry.lie.groups.MatrixLieGroup), because which frame is needed is a property of its Manifold.coefficients.

jacobian

The pushforward of the chart, phi -> dPoint/dphi, of shape (*ambient_shape, G, K_free). None when unbound.

vjp

The chart's value and pullback, phi -> (point, pullback), where pullback(C) -> (G, K_free) is the complex \(\\mathrm{Tr}(C^\\dagger\\,\\partial\\Phi)\) for an ambient covector C of shape ambient_shape. The same differential as jacobian read in the other direction, and the one an objective's gradient actually needs — it never forms the Jacobian, so it costs \(O(G(d^3 + d^2K))\) against \(O(G d^3 K)\).

The jax.vjp shape is deliberate: the covector a cost hands back depends on the point, so value and pullback cannot be one call, and returning them together is what lets them share the gate exponentials instead of computing them twice. Present whenever jacobian is, analytic when generators are set and autodiff otherwise, so a gradient needs no branch. None when unbound.

hvp

The chart's second differential (phi, p) -> (point, V, W) with \(V = \\mathrm D\\Phi_\\phi[p]\) and \(W = \\mathrm D^2\\Phi_\\phi[p, p]\), built by Manifold.bind. None disables the curvature tier of a GeometricContext and nothing else.

hessian_vjp

The chart's second differential pulled back, phi -> (point, pullback) with pullback(C) -> (G, K_free, G, K_free) the complex \(\\mathrm{Tr}(C^\\dagger\\,\\partial^2\\Phi)\) for an ambient covector C — every pair, where hvp takes one direction. The same jax.vjp shape as vjp, for the same reason. It never forms the dense \(\\mathrm D^2\\Phi\): two \(O(G)\)-propagated derivative trajectories and one Gram matrix, \(O(GKmd + (GK)^2)\) of memory against the dense route's \(O(G^2K^2d^2)\). None disables the analytic objective Hessian and nothing else.

generators

The chart's generator sub-basis, present exactly when the chart is a plain product of exponentials in it. None under param_transform, which is the single signal that disables both second differentials (hvp, and with it every curvature quantity, and hessian) and turns vjp into its autodiff form.

columns

Boolean mask over the chart's coefficient columns selecting the ones the geodesic solve may move. None means "every column is free", which is what makes both restrict and embed no-ops under param_transform.

__annotations__ class-attribute ¤

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

__dataclass_fields__ class-attribute ¤

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

__dataclass_params__ class-attribute ¤
__dict__ class-attribute ¤
__doc__ class-attribute ¤

str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.

__match_args__ class-attribute ¤

Built-in immutable sequence.

If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.

If the argument is a tuple, the return value is the same object.

__module__ class-attribute ¤

str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.

__weakref__ property ¤

list of weak references to the object

__post_init__() ¤

The one co-invariant: the second differentials exist exactly when the generators do.

Both are propagator recursions in those generators, so a chart built from them has both and a param_transform chart has neither. The first differential is not part of this: jacobian and vjp are always present, autodiff-flavoured when the structure is missing. Manifold.bind sets the group in one branch, but this is reachable — the tests build bundles directly — so it keeps a hand-built one honest.

restrict(coefficients) ¤

Keep only the solvable coefficient columns (columns).

Parameters:

Name Type Description Default
coefficients Array

Array of shape (G, K_free, K).

required

Returns:

Type Description
Array

(G, K_solvable, K), or the input unchanged when columns is

Array

None.

embed(solution) ¤

Scatter a solved direction back over every chart column — restrict's inverse.

Parameters:

Name Type Description Default
solution Array

Array of shape (G, K_solvable).

required

Returns:

Type Description
Array

(G, K_free) with zeros outside columns, or the input

Array

unchanged when columns is None.

__delattr__(name) ¤
__init__(frame=None, jacobian=None, vjp=None, hvp=None, hessian_vjp=None, generators=None, columns=None) ¤
__repr__() ¤
__setattr__(name, value) ¤

The cost derivatives¤

What Manifold.cost_gradient and Manifold.cost_hessian_form delegate to on every manifold in the library — and, through them, what the objective's gradient and Hessian are built from. A shared implementation, not part of the interface: a manifold whose cost is not a function of the ambient overlap declines the hooks and gets autodiff instead.

geope.geometry.cost.ambient_overlap(x, y, ambient_ndim) ¤

\(z = \sum \bar y\,x\), contracted over the trailing ambient_ndim axes.

The Hermitian inner product every trace cost is a function of, batched over any leading axes so a stack of Jacobian columns resolves in one call.

Parameters:

Name Type Description Default
x Array

The point, or a batch of ambient vectors, of shape (..., *ambient_shape).

required
y Array

The target, of shape ambient_shape.

required
ambient_ndim int

How many trailing axes one ambient point has.

required

Returns:

Type Description
Array

A complex Array of the leading batch shape.

geope.geometry.cost.trace_cost_gradient(x, y, ambient_ndim, scale, projective) ¤

\(\partial C/\partial\bar x\): the ambient Wirtinger gradient of the infidelity.

For a real-valued \(C\) of a complex point, the chain rule out of the ambient space reads \(\partial_a C = 2\,\mathrm{Re}\langle \hat G, \partial_a x\rangle\) with \(\hat G = \partial C/\partial\bar x\), which is what makes this — and not the full Jacobian — the object a gradient needs. With \(z = \langle y, x\rangle\),

\[\hat G = -\frac{y}{2\kappa}\quad\text{(phase-sensitive)},\qquad \hat G = -\frac{z\,y}{2\kappa\lvert z\rvert}\quad\text{(projective)}.\]

The projective form is singular at \(z = 0\) — the near-identity / traceless-target gotcha the autodiff gradient has too, documented in docs/user_guide.md. It is guarded here only against a hard nan: at exactly \(z = 0\) the phase factor is taken to be \(1\), which is as arbitrary as the geometry is there.

Parameters:

Name Type Description Default
x Array

The current point, of shape ambient_shape.

required
y Array

The target, of shape ambient_shape.

required
ambient_ndim int

How many axes one ambient point has.

required
scale Array | float

The cost's normalisation \(\kappa\).

required
projective bool

Whether the cost quotients out a global phase.

required

Returns:

Type Description
Array

An Array of shape ambient_shape.

geope.geometry.cost.trace_cost_hessian_form(x, y, u, ambient_ndim, scale, projective) ¤

The intrinsic second-derivative form \(\mathrm{Hess}_C[u_a, u_b]\) of the cost.

The part of \(\partial_a\partial_b\,C(\Phi(\phi))\) that comes from the cost's curvature in the ambient space, as opposed to the chart's bending — the caller adds \(2\,\mathrm{Re}\langle\hat G, \mathrm D^2\Phi_{ab}\rangle\) for that.

A phase-sensitive cost is affine in the point, so its form vanishes identically. The projective one factors entirely through the scalars \(\zeta_a = \langle y, u_a\rangle\): writing \(r = \lvert z\rvert\),

\[\mathrm{Hess}_C[u_a, u_b] = -\frac1\kappa\left[ \frac{\mathrm{Re}(\bar\zeta_a\zeta_b) + \mathrm{Re}(\bar z\,\eta_{ab})}{r} - \frac{\mathrm{Re}(\bar z\zeta_a)\,\mathrm{Re}(\bar z\zeta_b)}{r^3}\right]\]

where the \(\eta_{ab}\) term is the chart's, supplied by the caller. Only the \(\zeta\)-dependent terms are returned here, so the whole \(P\times P\) form comes from \(P\) scalars: rank-structured, and never a \(P^2\)-sized ambient object.

Parameters:

Name Type Description Default
x Array

The current point, of shape ambient_shape.

required
y Array

The target, of shape ambient_shape.

required
u Array

The chart's Jacobian columns, of shape (P, *ambient_shape).

required
ambient_ndim int

How many axes one ambient point has.

required
scale Array | float

The cost's normalisation \(\kappa\).

required
projective bool

Whether the cost quotients out a global phase.

required

Returns:

Type Description
Array

A real Array of shape (P, P).

The per-step context¤

geope.geometry.context.GeometricContext ¤

Every per-step geometric quantity, derived lazily in cost tiers.

Built by Manifold.context once per optimisation step, inside the jitted update. Every quantity is a cached_property, tier 0 included, so the tiers are a description of what a given consumer pays, not of what is computed: Gecko reads only omegas and therefore never traces the matrix logarithm.

tier quantities cost
0 base point point, jacobian, A, A_norm2, F0, gammas, omegas, infidelity, fidelity one propagator, one Jacobian, one logarithm
0′ the cost value_and_grad, gradient one pullback pass
1 direction V, Omega, omega_norm2, velocity, xi_rel, slope free: one contraction of tier 0's Jacobian
2 curvature W, acceleration, chi, q, q_exact, rho, cost_hessian one directional HVP plus the manifold's Riemannian Hessian
3 ray point_at, infidelity_at, fidelity_at, distance_at one propagator per trial point

Only tiers 0 and 0′ are direction-free. Tiers 1–3 need the search direction, tier 3 because the ray is free_params + t * coeffs; it arrives through set_direction after the least-squares solve (which needs this context's own gammas and omegas), and may be set once. That single rule replaces any list of what to invalidate: every direction-dependent property raises while coeffs is None, and a raising cached_property memoises nothing, so no value computed for one direction can survive into another.

Tier 2 additionally needs TangentBundle.hvp, which is None under param_transform; tiers 0, 0′, 1 and 3 work there, and so does cost_hessian, which falls back to autodiff.

Tier 0′ is a second route to the same base point, not an extension of tier 0. geope.Grape walks the infidelity's own gradient rather than a geodesic, so it reads value_and_grad — one TangentBundle.vjp pass that returns the point and a pullback sharing the gate exponentials — and must read nothing from tier 0: point, infidelity and fidelity would each re-exponentiate the whole pulse, and A would drag in the matrix logarithm it has no use for. Conversely infidelity is deliberately not re-expressed through value_and_grad, which would make a Geope step compute a gradient it never reads. The two tiers are alternatives; a consumer picks one. This is the same laziness discipline Gecko relies on by reading only omegas.

The context is trace-time only. Never register it as a pytree, return it from a jitted function, or put it in a scan/while_loop carry: its memo is valid only inside the trace that built it. A property must also be first read outside any lax control flow you intend to read it from.

Attributes:

Name Type Description
manifold

The bound Manifold this context is opened on.

free_params

The pulse \(\phi\) at the base point, shape (G, K_free).

delta_t

The segment duration, threaded into every chart evaluation. A traced scalar at trace time — safe, because the context itself is trace-time-only. Defaults to 1.0.

point cached property ¤

The pulse's point on the manifold, \(\Phi(\phi)\). One propagator.

jacobian cached property ¤

\(\partial\Phi/\partial\phi\), shape (*ambient, G, K_free). One Jacobian.

A cached property ¤

The geodesic tangent \(A = -\mathrm{Log}_U(V)\). The only logarithm.

The minimal-geodesic tangent at the base point, negated so that it points away from the target: it is the Riemannian gradient of the squared distance \(\tfrac{1}{2} d_g(\cdot, V)^2\). The geodesic solve matches the tangent to it, so geope.Geope steps along the negated solution — a descent direction, on which velocity is negative and the line-search bracket is \([0, \alpha_{\max}]\).

Taking it at \(U\) rather than at the target is what makes it comparable with Omega on a general manifold — \(T_U\) and \(T_V\) are unrelated spaces unless a group's trivialisation identifies them.

A_norm2 cached property ¤

\(\lVert A\rVert_F^2 = 2 F_0\).

F0 cached property ¤

The squared-geodesic-distance objective \(F_0 = \tfrac12\lVert A\rVert_F^2\).

gammas cached property ¤

The geodesic tangent's coefficients — the least-squares target.

\(\gamma = \mathrm{coeff}(A)\), in whatever linear coordinates the manifold puts on \(T_U\). omegas goes through the same map, so the arbitrary constant in Manifold.coefficients cancels between the two operands and the solve is the metric-orthogonal projection it is defined to be.

omegas cached property ¤

The left-trivialised Jacobian's coefficients — the least-squares matrix.

\(\omega_{g,k} = \mathrm{coeff}\bigl(\texttt{to\_tangent}(U, \partial_{g,k}U)\bigr)\), restricted to the solvable columns. Shape (G, K_solvable, K).

Resolved as one flat batch of \(G\,K_{\text{free}}\) tangents, not gate by gate. Manifold.coefficients is already batched over leading axes — on a group it is one einsum against the frame and does not even read point — so a Python loop over gates buys nothing and costs a great deal: it unrolls at trace time into \(G\) separate call sites, making the jaxpr, and with it the compile time, grow linearly in the pulse length. Measured on a one-qubit chart at \(G = 2000\) that was 14334 equations and 21.7 s to compile, against 206 equations and 0.36 s here, with bit-identical output. Worse at run time: the \(G\) call sites are \(G\) separate consumers of the gate chain, which XLA is free to rematerialise per consumer rather than keep, so the projection went quadratic in \(G\) — \(O(G^{1.8})\) measured, and 17× slower than this at \(G = 1000\) once the gates were cheap enough for rematerialisation to look attractive.

The loop it replaces was there to keep the on-the-fly Pauli projector's batch small above 5 qubits (geope.geometry.basis.get_project_omegas_fn_otf vmaps over the input batch and over all \(4^n-1\) Pauli strings, so its working set goes as the product). That projector now sees a batch of \(G\,K_{\text{free}}\) rather than \(K_{\text{free}}\), which is the one thing this trades away: if it runs out of memory on a large system, its batch_size argument — which scans over the combinations instead of vmapping them — is the knob, and it is the right place to spend the memory rather than here.

infidelity cached property ¤

The infidelity at the base point. Free, given point.

fidelity cached property ¤

The fidelity at the base point. Free, given point.

value_and_grad cached property ¤

(infidelity, \partial C/\partial\phi) at the base point.

One Manifold.value_and_grad call: a single TangentBundle.vjp pass that returns the point together with a pullback sharing the gate exponentials, then one ambient cost gradient through it — the Jacobian is never formed.

The first element equals infidelity, by a different route. Read one or the other, never both: infidelity goes through point, so asking for it as well re-exponentiates the whole pulse. See the class docstring.

gradient cached property ¤

\(\partial C/\partial\phi\), shape (G, K_free). Free, given value_and_grad.

Real by construction on the analytic path, though carried in the pulse's own dtype — geope.optimizers takes its real part before accumulating any moments, because the autodiff fallback is not real.

V cached property ¤

The ambient velocity \(V = \mathrm D\Phi_\phi[p]\).

A contraction of tier 0's Jacobian, so it costs nothing beyond it — which is what makes the slope available even where the HVP is not.

Omega cached property ¤

The velocity in the manifold's tangent representation, \(\Omega\).

omega_norm2 cached property ¤

\(\lVert\Omega\rVert_F^2\).

velocity cached property ¤

The slope \(\psi'(0) = \langle A, \Omega\rangle_F\) of distance_at.

Negative at a descent direction.

xi_rel cached property ¤

The relative tangent-matching error: \(\sin\angle(\Omega, A)\).

slope cached property ¤

The slope \(\langle\nabla C, p\rangle\) of infidelity_at at \(\alpha = 0\).

The infidelity's counterpart to velocity, which is the slope of distance_at — the two objectives have different derivatives and a consumer must not substitute one for the other. Free once gradient exists: one contraction, no propagator. Tier 1 for exactly the reason velocity is, and with the same consequence: it survives under param_transform, where the curvature does not.

The flat parameter-space pairing, not Manifold.inner — gradient is a covector in the same coordinates as coeffs, not a tangent vector.

Negative at a descent direction, matching velocity: geope.Grape and geope.Geope share the textbook convention, so coeffs points downhill and the accepted step is positive.

Both operands are real-valued but carried in the pulse's dtype, so the real parts are taken explicitly rather than relying on a complex inner product.

W cached property ¤

The ambient acceleration \(W = \mathrm D^2\Phi_\phi[p, p]\). One HVP.

acceleration cached property ¤

The extrinsic term \(\langle A, V^\dagger V + U^\dagger W\rangle_F\).

The part of the curvature that comes from the chart bending, as opposed to the manifold's own curvature.

chi cached property ¤

The dimensionless radial bending coefficient \(\chi_\phi = \mathrm{accel}/\lVert\Omega\rVert_F^2\).

q cached property ¤

The curvature \(\psi''(0)\) with the radial surrogate \(\lVert\Omega\rVert_F^2\) for the intrinsic term.

Exact only when \(\Omega\parallel A\), i.e. when the geodesic direction is exactly reachable (xi_rel == 0). See q_exact.

q_exact cached property ¤

The curvature \(\psi''(0)\) with the exact intrinsic term \(\langle\Omega,\mathcal K_A\Omega\rangle_F\).

Since \(\mathcal K_A\preceq I\), q_exact <= q always, with equality iff xi_rel vanishes.

rho cached property ¤

The eigenphase spread \(\rho = \Delta(A)\).

Below \(\pi\) the intrinsic Hessian is positive definite; \(2\pi\) is the cut locus, where the minimal geodesic stops being unique.

cost_hessian cached property ¤

The dense infidelity Hessian \(\partial^2 C/\partial\phi^2\), shape (P, P).

P = free_params.size, flattened row-major over (gate, coefficient) so it pairs with gradient.flatten() — which is what geope.Grape's Newton methods solve against.

Named apart from TangentBundle.hessian_vjp, which is the chart's \(\mathrm D^2\Phi\); this is the objective's. Unlike W it needs no direction and no _require_curvature guard: Manifold.hessian falls back to autodiff when the chart has no second differential, so it works under param_transform too. Dense in the parameters — \((P, P)\) — but assembled without ever forming \(\mathrm D^2\Phi\); see Manifold.hessian.

__dict__ class-attribute ¤
__doc__ class-attribute ¤

str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.

__module__ class-attribute ¤

str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.

__weakref__ property ¤

list of weak references to the object

coeffs property ¤

The search direction, or None before set_direction.

tangent property ¤

The manifold's TangentBundle.

target property ¤

The target point being synthesised.

__init__(manifold, free_params, delta_t=1.0) ¤
set_direction(coeffs) ¤

Attach the search direction, once.

Parameters:

Name Type Description Default
coeffs Array

The direction (G, K_free), in the same parameter space as free_params.

required

Raises:

Type Description
ValueError

If a direction has already been set. Open a new context instead — the memoised tier-0 quantities are direction-free and cost nothing to keep, but a second direction would silently reuse tier-1/2 values computed for the first.

point_at(step_size) ¤

The point at \(\phi + \alpha\,p\), \(\alpha\) = step_size — the single gate for all of tier 3.

infidelity_at(step_size) ¤

The infidelity along the ray. One propagator.

fidelity_at(step_size) ¤

The fidelity along the ray. One propagator.

distance_at(step_size) ¤

The squared-geodesic-distance objective \(\tfrac12 d_g(\cdot, V)^2\) along the ray, whose derivatives velocity, q and q_exact describe.

One propagator plus one logarithm.