#1970·warp

Support first-sample FEM interpolation with row compression

Author: maxkra15Created Sep 17, 2026Updated Sep 17, 2026
Labelswarp.fem

Description

Allow fem.interpolate(..., reduction="first", bsr_options={"construction": "row_compress"}) with a space restriction. At 0e76b6a0e21ce0b06e1dab3b98efd8b5afa9f4f9, this combination raises RuntimeError; callers must use triplet construction.

This matters for preallocated FEM contact maps: millions of reserved candidates may contain only tens of thousands of active blocks. Row compression can avoid sorting the entire reservation.

Reproduction

python
import warp as wp
import warp.fem as fem
import warp.sparse as sp

@fem.integrand
def identity(s: fem.Sample, u: fem.Field):
    return u(s)

wp.set_device("cpu")
grid = fem.Grid3D(res=wp.vec3i(2))
domain = fem.Subdomain(fem.Cells(grid), element_indices=wp.array([1, 3, 5, 6], dtype=int))
space = fem.make_polynomial_space(grid, degree=3, element_basis=fem.ElementBasis.SERENDIPITY)
trial_space = fem.make_polynomial_space(grid, degree=1, discontinuous=True)
restriction = fem.make_space_restriction(space_topology=space.topology, domain=domain)
matrix = sp.bsr_zeros(space.node_count(), trial_space.node_count(), float)
fem.interpolate(
    identity, dest=matrix, dest_space=space, at=restriction,
    fields={"u": fem.make_trial(trial_space, domain=domain)},
    reduction="first", bsr_options={"construction": "row_compress"},
)

Expected behavior

Match triplet construction's owning sample, topology, and value bits on CPU and CUDA, including changing restrictions during CUDA Graph replay. No host readback should be required during capture.

Experimental implementation: #1940. Related row-capacity support: #1537. Verified that the reproduction fails on the reference above and succeeds with the proposed implementation.