Skip to content

fix(dynamics): use inv_ex with contiguous in NPT.pre_update#43

Merged
dallasfoster merged 4 commits intoNVIDIA:mainfrom
Ryan-Reese:fix/npt-inv-consistency
Apr 6, 2026
Merged

fix(dynamics): use inv_ex with contiguous in NPT.pre_update#43
dallasfoster merged 4 commits intoNVIDIA:mainfrom
Ryan-Reese:fix/npt-inv-consistency

Conversation

@Ryan-Reese
Copy link
Copy Markdown
Contributor

ALCHEMI Toolkit Pull Request

Description

NPT.pre_update() was the only cell inversion call in the dynamics codebase using torch.linalg.inv() instead of inv_ex()[0].contiguous(). inv() returns a non-contiguous tensor (column-major strides (9, 1, 3)) which can cause incorrect results in downstream Warp kernels that expect row-major layout.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Changes Made

  • Changed npt.py:292 from torch.linalg.inv(batch.cell) to torch.linalg.inv_ex(batch.cell)[0].contiguous(), matching every other cell inversion call site (NPH, NPT.post_update, FIREVariableCell, NeighborListHook).

Testing

  • Unit tests pass locally (make pytest)
  • Linting passes (make lint)
  • Ran test_npt_nph.py (20/20 pass) and test_ops.py (80/80 pass) on CUDA

Checklist

NPT.pre_update() was the only cell inversion call in the dynamics
codebase using torch.linalg.inv() instead of inv_ex()[0].contiguous().

inv() returns a non-contiguous tensor (column-major strides) which can
cause incorrect results in downstream Warp kernels that expect
row-major layout. All other call sites (NPH, NPT.post_update,
FIREVariableCell, NeighborListHook) already use inv_ex + contiguous.
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot bot commented Apr 2, 2026

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@Ryan-Reese Ryan-Reese marked this pull request as ready for review April 2, 2026 13:56
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 2, 2026

Greptile Summary

This PR fixes a one-line inconsistency in NPT.pre_update() where torch.linalg.inv(batch.cell) was the only remaining call site not using torch.linalg.inv_ex(batch.cell)[0].contiguous(). The fix aligns it with all other cell inversions in the codebase (NPH pre/post, NPT post_update, FIREVariableCell, NeighborListHook), ensuring the result tensor is contiguous and row-major as required by downstream Warp kernels.

Important Files Changed

Filename Overview
nvalchemi/dynamics/integrators/npt.py Single-line fix in pre_update(): replaces torch.linalg.inv() with inv_ex()[0].contiguous() to match every other call site and ensure row-major layout for downstream Warp kernels.

Reviews (3): Last reviewed commit: "Merge branch 'main' into fix/npt-inv-con..." | Re-trigger Greptile

@dallasfoster dallasfoster added this pull request to the merge queue Apr 6, 2026
Merged via the queue into NVIDIA:main with commit f6c032c Apr 6, 2026
5 checks passed
@Ryan-Reese Ryan-Reese deleted the fix/npt-inv-consistency branch April 8, 2026 17:22
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