NVIDIA / NVIDIA/physicsnemo

🚀[FEA]: Add non-periodic boundary mode to grid-gradient operators

Open
#1,852 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

? - Needs Triage enhancement
Dominant language
Python
Stars
3.3k
Forks
787
Avg merge
2d 21h
Merged PRs (30d)
27

Description

Is this a new feature, an improvement, or a change to existing functionality?

Improvement

How would you describe the priority of this feature request?

Medium

Please provide a clear description of the problem you would like to solve.

physicsnemo.nn.functional.derivatives.rectilinear_grid_gradient and uniform_grid_gradient currently use periodic wrapping (for example, via torch.roll) at domain boundaries. On bounded, non-periodic domains this mixes values from opposite edges and produces incorrect boundary-row gradients.

Add an opt-in non-periodic boundary mode that:

  • preserves the existing 3-point non-uniform central stencil in the interior;
  • uses appropriate one-sided stencils only at the lower and upper boundaries;
  • is implemented consistently in the torch and Warp backends, including forward and backward paths; and
  • keeps periodic behavior as the default, so existing callers see no behavior change.

A suggested API is:

boundary: Literal["periodic", "one_sided"] = "periodic"

An explicit boundary mode is preferable to periodic: bool because it is self-documenting and leaves room for other boundary treatments later.

Suggested validation and acceptance criteria:

  • analytic checks for both interior and boundary derivatives;
  • equivalence between rectilinear and uniform-grid implementations on uniform coordinates;
  • parity between torch and Warp backends;
  • autograd coverage;
  • documentation for the new argument; and
  • a CHANGELOG entry.

This would make the gradient helpers reusable for bounded-domain problems without requiring each caller to mask or replace corrupted boundary values.

Describe any alternatives you have considered

Callers can currently ignore or mask the boundary rows, or implement separate one-sided differences outside PhysicsNeMo. That duplicates numerical logic across applications and still requires special handling around the existing operator. Changing the current behavior globally is not viable because it would break callers that depend on periodic wrapping.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with physicsnemo.nn.functional.derivatives.rectilinear_grid_gradient and uniform_grid_gradient, then trace their torch and Warp forward and backward paths. Add the opt-in boundary mode while preserving periodic defaults, and verify analytic interior and boundary derivatives, uniform-grid equivalence, backend parity, autograd coverage, documentation, and the CHANGELOG entry.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
backend, machine-learning
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.