Skip to content

Cleanup function spec, plus adding a few functionals#1457

Open
loliverhennigh wants to merge 10 commits intoNVIDIA:mainfrom
loliverhennigh:split-functional-arch-interp-spec-bench
Open

Cleanup function spec, plus adding a few functionals#1457
loliverhennigh wants to merge 10 commits intoNVIDIA:mainfrom
loliverhennigh:split-functional-arch-interp-spec-bench

Conversation

@loliverhennigh
Copy link
Collaborator

PhysicsNeMo Pull Request

Description

This PR is a cleanup pass for physicsnemo.nn.functional plus interpolation/test/benchmark updates. This PR will be followed by one more concentrated on CI integration with Github actions.

What’s included:

  • Reorganized functionals into clearer category folders (fourier_spectral, geometry, neighbors, interpolation, regularization_parameterization). This mimics the Docs while not changing API or import paths. Imports still come from nn.functional.xyz, this is cleans stuff up internally.
  • Migrated interpolation to the newer grid_to_point_interpolation structure with proper warp support and backward pass. Also added a point_to_grid_interpolation for fun and completness.
  • Added two other functionals from ongoing work, mesh_to_voxel_fraction and mesh_poisson_disk_sample. If its too much to review these I can remove them.
  • Updated unit tests for functionals so they all follow the same structure. This required some small but important changes with base FunctionSpec implementation.
  • Refreshed benchmark scripts/registry and docs paths so plots/docs line up with the new organization.

Overall goal: make functionals easier to navigate, easier to test, and easier to benchmark.


from benchmarks.physicsnemo.nn.functional.registry import FUNCTIONAL_SPECS

_PHASE_ORDER = ("forward", "backward")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now run benchmarks on forward and backward (if backward exists). I generate two bar plots now for these instead of just the forward pass before.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, these files are kinda throw away until I have the ASV setup with the CI/CD system.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 26, 2026

Greptile Summary

This PR successfully reorganizes the functional architecture into clearer category folders while maintaining backward compatibility and improving the interpolation implementation.

Key Changes

  • Functional Reorganization: Moved functionals into category folders (fourier_spectral, geometry, neighbors, interpolation, regularization_parameterization). Public API imports remain unchanged, maintaining backward compatibility.

  • Interpolation Improvements: Migrated to new grid_to_point_interpolation with proper Warp support, backward pass implementation, and comprehensive test coverage. The old interpolation function is deprecated with a warning.

  • FunctionSpec Enhancements: Added make_inputs_forward/make_inputs_backward and compare_forward/compare_backward methods while maintaining backward compatibility with old make_inputs/compare API through fallback hooks.

  • Benchmark Infrastructure: Enhanced ASV benchmarks with forward/backward phase support, environment-based filtering, and improved label extraction without full tensor materialization.

  • Documentation: Updated CODING_STANDARDS/FUNCTIONAL_APIS.md to reflect new patterns and added FNC-007 rule for benchmark registry.

Code Quality

The refactoring is well-executed with:

  • Comprehensive test coverage including backend parity, error handling, and backward pass validation
  • Clean separation of concerns with backend implementations in dedicated modules
  • Proper adherence to the documented coding standards (FNC-000 through FNC-007)
  • Backward compatibility maintained throughout

Notes

Several functionals (KNN, RadiusSearch, SignedDistanceField) have compare methods marked with TODO comments to implement output comparison in a follow-up PR. This is intentional and doesn't block the current refactoring.

Important Files Changed

Filename Overview
physicsnemo/nn/functional/init.py Updated imports to reflect reorganized functional structure into category folders (fourier_spectral, geometry, neighbors, regularization_parameterization). Added grid_to_point_interpolation export. Public API remains unchanged.
physicsnemo/core/function_spec.py Added backward-compatible hooks for make_inputs_forward/backward and compare_forward/backward while maintaining old make_inputs/compare methods. Added label extraction helpers. Well-structured backward compatibility.
physicsnemo/nn/functional/interpolation/grid_to_point_interpolation/grid_to_point_interpolation.py New grid_to_point_interpolation implementation with warp and torch backends. Includes backward pass support, proper tolerance configuration, and deprecation alias for old interpolation function. Follows FunctionSpec patterns correctly.
test/nn/functional/test_grid_to_point_interpolation_functional.py Comprehensive test coverage for grid_to_point_interpolation including backend parity tests, error handling, deprecation warnings, backward pass validation, and non-contiguous input handling.
benchmarks/physicsnemo/nn/functional/registry.py Updated registry to include all reorganized FunctionSpec classes (DropPath, KNN, GridToPointInterpolation, RadiusSearch, SignedDistanceField, RFFT, RFFT2, IRFFT, IRFFT2) for ASV benchmarking.
benchmarks/physicsnemo/nn/functional/benchmark_functionals.py Enhanced benchmark infrastructure with forward/backward phase support, environment-based phase filtering, gradient clearing for reusable inputs, and label extraction without full materialization.
physicsnemo/nn/functional/neighbors/knn/knn.py Moved to neighbors folder with custom dispatch for device-based auto-selection. Has TODO for compare method implementation. Properly implements make_inputs_forward/backward.
CODING_STANDARDS/FUNCTIONAL_APIS.md Updated documentation to reflect make_inputs_forward/backward and compare_forward/backward patterns. Added FNC-007 rule for benchmark registry. Documentation aligns with implementation changes.

Last reviewed commit: a1183b8

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

79 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@loliverhennigh loliverhennigh changed the title Refactor functional architecture, interpolation, specs, and benchmarks Cleanup function spec, plus adding a few functionals Feb 26, 2026
@@ -0,0 +1,102 @@
# SPDX-FileCopyrightText: Copyright (c) 2023 - 2026 NVIDIA CORPORATION & AFFILIATES.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code in the benchmarks is still a bit junky.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants