Skip to content

Add non-periodic grid gradient boundary mode#1853

Draft
loliverhennigh wants to merge 1 commit into
mainfrom
agent/non-periodic-grid-gradients
Draft

Add non-periodic grid gradient boundary mode#1853
loliverhennigh wants to merge 1 commit into
mainfrom
agent/non-periodic-grid-gradients

Conversation

@loliverhennigh

Copy link
Copy Markdown
Collaborator

What changed

  • adds boundary="one_sided" to rectilinear_grid_gradient and uniform_grid_gradient
  • preserves boundary="periodic" as the default with the existing periodic code path unchanged
  • computes arbitrary-grid one-sided finite-difference weights for first and second derivatives
  • applies corrections across the full stencil radius, including the two edge points required by fourth-order uniform stencils
  • supports torch and Warp forward paths and autograd; Warp retains its existing kernels for interior points and composes differentiable boundary corrections
  • documents the new API and updates the changelog

Why

Periodic wrapping mixes values from opposite edges on bounded, non-periodic domains and corrupts boundary derivatives. Callers currently need to mask or replace those values themselves.

The explicit boundary mode is backward-compatible and leaves room for additional boundary treatments in the future.

Validation

  • uv run --group dev python -m pytest -q test/nn/functional/derivatives
    • 202 passed
  • uv run ruff check <changed Python files>
  • uv run ruff format --check <changed Python files>
  • verified public generated signatures include boundary: str = "periodic"

Tests cover analytic boundary derivatives, uniform/rectilinear equivalence, torch/Warp forward parity, torch/Warp backward parity, fourth-order stencil radius handling, invalid modes, and insufficient axis lengths.

Closes #1852.

@copy-pr-bot

copy-pr-bot Bot commented Jul 17, 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.

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.

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

1 participant