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, meaningnscalar inputs, or a sequence of types, one per input:warp.float32,warp.vec2,warp.vec3orwarp.quat. A spring over two nodes is(warp.vec3, warp.vec3), with width 6.dtype – Scalar type the jets are built on. Inferred from
slotswhen they are Warp types;warp.float32whenslotsis an integer or contains only Pythonfloat.
- Returns:
A namespace holding the generated jet types (
scalar,vec2,vec3,quat), the types of a scalar jet’sgradandhessfields (grad_type_scalar,hess_type_scalar), the helpers that construct jets, includingexp_map, andjet_type(t), which looks a jet type up by the Warp type of the value as inwarp.JetSpace().
The width is always the total number of scalar components in
slots: unlikewarp.JetSpace(), there is nowidthargument and nodirectional.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 inwarp.JetSpace(). Withspring_energyan ordinary@warp.functhat 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 samespring_energyalso runs onwarp.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 theenable_backwardmodule option toFalse: 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 withwidth**2, so for wider energies prefer a first-order jet with a reverse sweep over it (viawarp.Tape, or in-kernel withwarp.grad()), which reaches the same Hessian with linear state.