warp.JetSpace2#

warp.JetSpace2(slots, dtype=None)[source]#

Return second-order (forward-over-forward) jet types for a set of differentiated inputs.

Experimental

Forward-mode jets are experimental and subject to change without a formal deprecation cycle.

A width-k second-order jet tracks value, gradient, and the full k x k Hessian; propagating it through a scalar function in one forward pass yields the local Hessian with no reverse pass. Per-intermediate state is O(k^2), so this suits small k.

Parameters:
  • slots – The inputs differentiated with respect to. Either an integer n, meaning n scalar inputs, or a sequence of types, one per input: warp.float32, warp.vec2, warp.vec3 or warp.quat. A spring over two nodes is (warp.vec3, warp.vec3), with width 6.

  • dtype – Scalar type the jets are built on. Inferred from slots when they are Warp types; warp.float32 when slots is an integer or contains only Python float.

Returns:

A namespace holding the generated jet types (scalar, vec2, vec3, quat), the types of a scalar jet’s grad and hess fields (grad_type_scalar, hess_type_scalar), the helpers that construct jets, including exp_map, and jet_type(t), which looks a jet type up by the Warp type of the value as in warp.JetSpace().

The width is always the total number of scalar components in slots: unlike warp.JetSpace(), there is no width argument and no directional.

seed(*values) takes one value per slot and returns one jet per slot, with the derivative directions numbered slot by slot in the order the components appear, as in warp.JetSpace(). With spring_energy an ordinary @warp.func that is generic over its argument types:

J2 = wp.JetSpace2((wp.vec3, wp.vec3))  # two 3D points, width 6


@wp.func
def spring_hessian(x0: wp.vec3, x1: wp.vec3):
    x0_jet, x1_jet = J2.seed(x0, x1)
    return spring_energy(x0_jet, x1_jet).hess  # the 6 x 6 Hessian

Vector jets support the same arithmetic and geometry as first-order ones (dot, cross, length, normalize, indexing), so the same spring_energy also runs on warp.JetSpace() jets. A second-order vector jet is one scalar jet per component, so it carries the same state as the function written out per component. variable(x, direction) seeds a single scalar, for use in a loop.

A second-order jet carries the Hessian forward, so a kernel that only uses second-order jets needs no reverse-mode code. Declare it with @warp.kernel(enable_backward=False), or set the enable_backward module option to False: otherwise Warp still generates the unused adjoint, which dominates compile time for long jet chains.

As with warp.JetSpace(), the width is a compile-time constant and the types are for local derivatives of fixed, statically known arity. The quadratic state makes that limit tighter here: register pressure and compile time both grow with width**2, so for wider energies prefer a first-order jet with a reverse sweep over it (via warp.Tape, or in-kernel with warp.grad()), which reaches the same Hessian with linear state.