Skip to content

[BUG] fem.integrate failing with double precision polynomial space vectors #418

Closed
0 of 1 issue completed
Closed

Description

@cmflannery

Bug Description

fem.integrate is failing with double precision vectors. Updating the fem.make_polynomial_space dtype from wp.vec2 to wp.vec2d causes fem.integrate to fail with the following error:

Module warp.fem.space.restriction.dyn.fill_element_node_indices_Grid2D_BoundarySides_GridBipolynomialSpaceTopology_9_Trace_Whole 25805a8 load on device 'cuda:0' took 0.39 ms  (cached)
Module warp.fem.utils 8b39cbb load on device 'cuda:0' took 0.28 ms  (cached)
Module warp.fem.space.restriction 4263cdf load on device 'cuda:0' took 0.29 ms  (cached)
Module __main__.mass_form e618e55 load on device 'cuda:0' took 30.84 ms
Traceback (most recent call last):
  File "/.../lib/python3.11/site-packages/warp/codegen.py", line 1006, in build
    adj.eval(adj.tree.body[0])
  File "/.../lib/python3.11/site-packages/warp/codegen.py", line 2700, in eval
    return emit_node(adj, node)
           ^^^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.11/site-packages/warp/codegen.py", line 1611, in emit_FunctionDef
    adj.eval(f)
  File "/.../lib/python3.11/site-packages/warp/codegen.py", line 2700, in eval
    return emit_node(adj, node)
           ^^^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.11/site-packages/warp/codegen.py", line 2558, in emit_Return
    var = (adj.eval(node.value),)
           ^^^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.11/site-packages/warp/codegen.py", line 2700, in eval
    return emit_node(adj, node)
           ^^^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.11/site-packages/warp/codegen.py", line 2238, in emit_Call
    args = tuple(adj.resolve_arg(x) for x in node.args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.11/site-packages/warp/codegen.py", line 2238, in <genexpr>
    args = tuple(adj.resolve_arg(x) for x in node.args)
                 ^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.11/site-packages/warp/codegen.py", line 2141, in resolve_arg
    var = adj.eval(arg)
          ^^^^^^^^^^^^^
  File "/.../lib/python3.11/site-packages/warp/codegen.py", line 2700, in eval
    return emit_node(adj, node)
           ^^^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.11/site-packages/warp/codegen.py", line 2242, in emit_Call
    out = adj.add_call(func, args, kwargs, type_args, min_outputs=min_outputs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.11/site-packages/warp/codegen.py", line 1324, in add_call
    return_type = func.value_func(
                  ^^^^^^^^^^^^^^^^
  File "/.../lib/python3.11/site-packages/warp/builtins.py", line 831, in vector_value_func
    raise RuntimeError()

.....
          raise RuntimeError(
RuntimeError: Error while parsing function "integrate_kernel_fn" at /.../lib/python3.11/site-packages/warp/fem/integrate.py:926:
            val = integrand_func(sample, fields, values)
;Error while parsing function "mass_form" at /.../scripts/warp_min.py:13:
    return wp.dot(u(s), v(s))
;Error while parsing function "eval_test_inner" at /.../lib/python3.11/site-packages/warp/fem/field/virtual.py:60:
    dof_value = self.space.node_basis_element(get_node_coord(dof))
;Error while parsing function "node_basis_element" at /.../lib/python3.11/site-packages/warp/fem/space/basis_function_space.py:90:
    return basis_element(self.dof_dtype(0.0), dof_coord)

Minimal Example

import warp as wp
import warp.fem as fem


@fem.integrand
def mass_form(
    s: fem.Sample,
    u: fem.Field,
    v: fem.Field,
) -> wp.float64:
    """Mass form for L2 projection of vector fields."""
    # For vector fields, we want the dot product of the vectors
    return wp.dot(u(s), v(s))


def main():
    geo = fem.Grid2D(res=wp.vec2i(3))
    boundary = fem.BoundarySides(geo)

    # Fails with dtype=wp.vec2d
    u_space = fem.make_polynomial_space(geo, degree=2, dtype=wp.vec2d)
    
    # # Passes with dtype=wp.vec2
    # u_space = fem.make_polynomial_space(geo, degree=2, dtype=wp.vec2)

    u_test = fem.make_test(space=u_space, domain=boundary)
    u_trial = fem.make_trial(space=u_space, domain=boundary)
    u_projector = fem.integrate(
        mass_form, fields={"u": u_trial, "v": u_test}, nodal=True
    )
    print("Successfully created projector")


if __name__ == "__main__":
    wp.init()
    main()

System Information

Python

  • Python 3.11.10
  • Poetry package manager
  • warp 1.5.0

Hardware and CUDA Version

CUDA Toolkit 12.6, Driver 12.4
Devices:
"cpu" : "x86_64"
"cuda:0" : "NVIDIA L40S" (44 GiB, sm_89, mempool enabled)

Activity

  1. changed the title [-][BUG][/-] [+][BUG] fem.integrate failing with double precision polynomial space vectors[/+] on Jan 7, 2025
  2. gdaviet commented on Jan 8, 2025

    @gdaviet
    Contributor

    Hi @cmflannery, indeed double-precision-valued spaces are not currently supported by fem.integrate.
    Currently, the rationale has been to stay in single-precision for quantities evaluated at any single sample point, then switch to double precision to perform accumulation over the different samples.
    While this strategy usually gives a good performance vs numerical stability compromise, I understand that there are cases where having the full evaluation done in full precision would be necessary, so support for double-precision fields and geometries is definitely on the roadmap (as well as complex-valued, eventually).
    In any case, the error message should be made more indicative of the current limitation

  3. cmflannery commented on Jan 10, 2025

    @cmflannery
    Author

    Gotcha, thanks for the clarification. A more indicative error message would definitely be appreciated!

  4. added this to the 1.7.0 milestone on Feb 19, 2025
  5. modified the milestones: 1.7.0, 1.7.1 on Mar 5, 2025
  6. modified the milestones: 1.7.1, Backlog on Apr 13, 2025
  7. added
    feature requestRequest for something to be added
    and removed
    bugSomething isn't working
    on Mar 24, 2026
  8. modified the milestones: Backlog, 1.13.0 on Mar 31, 2026
  9. shi-eric commented on Apr 14, 2026

    @shi-eric
    Contributor

    @gdaviet added support for double precision in warp.fem a few weeks ago: 9d913f8 this will be released in Warp 1.13 at the start of May.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

feature requestRequest for something to be addedwarp.femwarp.fem module

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions