Skip to content

Mesh Caching Improvements#1429

Merged
peterdsharpe merged 7 commits intoNVIDIA:mainfrom
peterdsharpe:psharpe/mesh-caching-improvements
Feb 19, 2026
Merged

Mesh Caching Improvements#1429
peterdsharpe merged 7 commits intoNVIDIA:mainfrom
peterdsharpe:psharpe/mesh-caching-improvements

Conversation

@peterdsharpe
Copy link
Collaborator

@peterdsharpe peterdsharpe commented Feb 18, 2026

PhysicsNeMo Pull Request

Description

Switches from Mesh.point_data["_cache"] subkey to a proper dedicated Mesh._cache TensorDict. This properly isolates public and private methods, and greatly simplifies downstream callers - now, they no longer need to filter out .exclude(CACHE_KEY) at point of use, since point_data and cell_data are "pure" user-supplied data.

For reviewers: the main change to review is in the main Mesh data structure in ./physicsnemo/mesh/mesh.py; everything else is just a downstream change of that.

Checklist

Dependencies

Review Process

All PRs are reviewed by the PhysicsNeMo team before merging.

Depending on which files are changed, GitHub may automatically assign a maintainer for review.

We are also testing AI-based code review tools (e.g., Greptile), which may add automated comments with a confidence score.
This score reflects the AI’s assessment of merge readiness and is not a qualitative judgment of your work, nor is
it an indication that the PR will be accepted / rejected.

AI-generated feedback should be reviewed critically for usefulness.
You are not required to respond to every AI comment, but they are intended to help both authors and reviewers.
Please react to Greptile comments with 👍 or 👎 to provide feedback on their accuracy.

@peterdsharpe
Copy link
Collaborator Author

/blossom-ci

@peterdsharpe peterdsharpe marked this pull request as ready for review February 18, 2026 21:28
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 18, 2026

Greptile Summary

This PR migrates the Mesh caching mechanism from storing cached computed values (centroids, areas, normals, curvatures) inside point_data["_cache"] and cell_data["_cache"] sub-TensorDicts to a dedicated top-level Mesh._cache TensorDict field with "cell" and "point" sub-TensorDicts. This cleanly separates internal cached geometry from user-supplied data and eliminates the need for .exclude(CACHE_KEY) filtering at every call site.

  • Core change: Added _cache: TensorDict field to Mesh class (with shadow=True on @tensorclass to support underscore-prefixed fields) and a keyword-only _cache constructor parameter that defaults to an empty nested TensorDict
  • Deleted physicsnemo/mesh/utilities/_cache.py (containing CACHE_KEY, get_cached, set_cached) — all 12+ downstream files updated to use mesh._cache directly
  • Cache propagation in transform() and translate() now explicitly builds fresh _cache TensorDicts and selectively carries forward applicable cached values (areas, normals, centroids)
  • Cell slicing (__getitem__) properly slices cell cache entries while preserving point cache entries
  • Downstream simplification: all .exclude(CACHE_KEY) calls removed from facet extraction, calculus, projections, repair, sampling, subdivision, and repr utilities — point_data and cell_data are now "pure" user data
  • Minor: exclude_cache parameter in mesh_repr.py is now a no-op (both branches produce identical results) and a docstring in _transform_tensordict still references "cache already stripped"

Important Files Changed

Filename Overview
physicsnemo/mesh/mesh.py Core change: replaces CACHE_KEY-based caching in point_data/cell_data with a dedicated _cache TensorDict field. Cache initialization, property access, and cell slicing all correctly updated.
physicsnemo/mesh/utilities/_cache.py Deleted: CACHE_KEY, get_cached, and set_cached are no longer needed since caching moved to Mesh._cache TensorDict. All imports removed elsewhere.
physicsnemo/mesh/transformations/geometric.py Transform/translate functions updated to build fresh _cache TensorDicts and propagate cache entries explicitly. Has a stale docstring referencing "cache already stripped".
physicsnemo/mesh/utilities/mesh_repr.py Removed CACHE_KEY usage but left the exclude_cache parameter as a no-op (both branches produce identical results). Functionally correct since the parameter is always called with False.
physicsnemo/mesh/boundaries/_facet_extraction.py Removed CACHE_KEY import and .exclude(CACHE_KEY) calls. Clean since point_data/cell_data no longer contain cache entries.
physicsnemo/mesh/geometry/dual_meshes.py Updated get_or_compute_dual_volumes_0 and get_or_compute_circumcenters to use mesh._cache directly instead of get_cached/set_cached helpers.
test/mesh/utilities/test_cache.py Rewritten from testing standalone get_cached/set_cached functions to testing Mesh._cache TensorDict behavior. Good coverage of empty cache, property population, custom overrides, cell/point separation, and device handling.

Last reviewed commit: 877eec1

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.

29 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 18, 2026

Additional Comments (1)

physicsnemo/mesh/transformations/geometric.py
Stale docstring: "cache already stripped"

This docstring still says "TensorDict with cache already stripped", but cache is no longer stored in point_data/cell_data — it's in the separate _cache field. The description is now misleading. Consider updating to something like "TensorDict containing user data fields."

        TensorDict containing user data fields to transform.

Copy link
Collaborator

@coreyjadams coreyjadams left a comment

Choose a reason for hiding this comment

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

I think this caching mechanism is significantly cleaner, easier to maintain, and less error prone than the previous version. Nice!

@peterdsharpe
Copy link
Collaborator Author

/blossom-ci

@peterdsharpe
Copy link
Collaborator Author

/blossom-ci

@peterdsharpe peterdsharpe added this pull request to the merge queue Feb 19, 2026
Merged via the queue into NVIDIA:main with commit 3ea8146 Feb 19, 2026
3 of 4 checks passed
@peterdsharpe peterdsharpe deleted the psharpe/mesh-caching-improvements branch February 19, 2026 14:50
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