Skip to content

Mesh: fix padding for discrete data and cached centroids#1784

Merged
peterdsharpe merged 1 commit into
NVIDIA:mainfrom
peterdsharpe:codex/mesh-padding-edge-cases
Jul 2, 2026
Merged

Mesh: fix padding for discrete data and cached centroids#1784
peterdsharpe merged 1 commit into
NVIDIA:mainfrom
peterdsharpe:codex/mesh-padding-edge-cases

Conversation

@peterdsharpe

Copy link
Copy Markdown
Collaborator

PhysicsNeMo Pull Request

Description

Mesh.pad() previously failed on integer and boolean data with its default NaN fill. A previously cached cell centroid could also disagree with the geometry of a padded cell, making the result depend on whether the cache had already been populated.

This PR:

  • Uses zero for default padding of fields that cannot represent NaN, preserving their dtype.
  • Supports empty-mesh padding and rejects the impossible case of creating cells without any point.
  • Keeps cached padded-cell centroids consistent with their repeated point.
  • Adds regression coverage for discrete fields, empty meshes, cached centroids, and the low-level tiling helper.

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.

@copy-pr-bot

copy-pr-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@peterdsharpe

Copy link
Copy Markdown
Collaborator Author

/ok to test 7c46948

@peterdsharpe peterdsharpe marked this pull request as ready for review July 2, 2026 11:55
@peterdsharpe peterdsharpe requested a review from melo-gonzo July 2, 2026 11:56
@greptile-apps

greptile-apps Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes two bugs in Mesh.pad(): integer and boolean data fields previously raised an error when padded with the default NaN fill value, and a previously cached cell centroid could disagree with the geometry of padded degenerate cells. It also extends padding to support empty meshes and guards against the impossible case of creating cells with no points.

  • Dtype-safe padding: _pad_data now checks is_floating_point() / is_complex() and substitutes 0 for NaN on discrete tensors, preserving their dtype without breaking the public API.
  • Centroid cache consistency: After the standard zero-fill apply() populates padded_cell_cache, centroids are overridden with self.points[-1:] (or zeros for an empty mesh), matching the actual point each degenerate cell references.
  • Empty-mesh support: _pad_by_tiling_last short-circuits to new_zeros when the source tensor is empty, and pad() rejects the logically impossible target_n_cells > 0 + target_n_points == 0 combination.

Important Files Changed

Filename Overview
physicsnemo/mesh/mesh.py Fixes pad() to use 0 instead of NaN for integer/boolean fields, validates the empty-point + non-zero-cell case, and overrides the 0-padded cached centroids with the geometrically correct last-point value.
physicsnemo/mesh/utilities/_padding.py Adds an early-return guard in _pad_by_tiling_last for empty tensors; returns zero-filled rows instead of attempting tensor[-1:] on a 0-row tensor.
test/mesh/mesh/test_padding.py Adds regression tests for discrete field dtype preservation, empty mesh padding, cached centroid consistency, and the impossible case of creating cells on a zero-point mesh.
test/mesh/utilities/test_utilities.py Adds a unit test for _pad_by_tiling_last with an empty input tensor, confirming zero-row output.

Reviews (1): Last reviewed commit: "fix(mesh): handle padding edge cases" | Re-trigger Greptile

@melo-gonzo melo-gonzo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

@peterdsharpe peterdsharpe added this pull request to the merge queue Jul 2, 2026
Merged via the queue into NVIDIA:main with commit 5f4b834 Jul 2, 2026
7 checks passed
@peterdsharpe peterdsharpe deleted the codex/mesh-padding-edge-cases branch July 3, 2026 02:38
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