fix(pt): remap spins after null atom filtering - #5795
Conversation
Compact spin vectors with the same backward map used for coordinates and atom types in DeepSpinPT neighbor-list inference. Add strict compact-versus-padded regression coverage for NULL atoms in the middle of both float and double inputs. Coding-Agent: Codex Codex-Version: codex-cli 0.144.1 Model: gpt-5.6-sol Reasoning-Effort: xhigh
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughDeepSpinPT now remaps spin components alongside filtered real atoms using ChangesPyTorch spin remapping
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5795 +/- ##
==========================================
- Coverage 79.85% 79.57% -0.28%
==========================================
Files 1022 1022
Lines 117351 117399 +48
Branches 4313 4316 +3
==========================================
- Hits 93706 93422 -284
- Misses 22101 22418 +317
- Partials 1544 1559 +15 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
wanghan-iapcm
left a comment
There was a problem hiding this comment.
Correct fix. coord_wrapped = dcoord is compacted by select_real_atoms_coord with dcoord[ii] = coord[bkw_map[ii]], so rebuilding spin_wrapped[ii] = spin[bkw_map[ii]] gives spin exactly the same compacted ordering as coordinates and types; the old prefix of the original spin buffer was only correct when NULL atoms happened to be at the end. The regression is well designed: it uses the .pth backend explicitly (DeepSpinPT, not PTExpt), inserts a NULL atom with a distinctive spin in the middle so misalignment is observable, and -- importantly -- tightens the tolerance to 1e-10/1e-5, below the 0.015-0.09 error magnitude, since the file's default 0.1 tolerance would have masked it. It covers both float and double and checks that NULL output slots are zero. LGTM.
Dismissing to re-review through the /code-review skill per process.
wanghan-iapcm
left a comment
There was a problem hiding this comment.
Re-reviewed via the code-review skill. Correct and complete: coord_wrapped=dcoord is compacted so dcoord[ii]=coord[bkw_map[ii]], and rebuilding spin_wrapped[ii]=spin[bkw_map[ii]] gives spin the identical compacted ordering (same bkw_map gather/scatter idiom the output side already uses); the old prefix was only correct when NULLs were at the end. The incomplete-fix sweep is clean: DeepSpinPTExpt already uses bkw_map (correct since #5370) and DeepSpinTF folds spin into the coord array before filtering, so neither is affected; the no-nlist compute() overload correctly keeps the plain copy. The regression fails pre-fix (author's run: 0 passed, 2 failed) and, importantly, tightens the tolerance to 1e-10/1e-5 -- below the 0.01-0.09 error -- since the file default 0.1 would have masked it; both float and double, .pth backend, NULL-slot forces asserted zero. Bug dates to #4321. LGTM.
Summary
bkw_mapused for coordinates and atom types.pthneighbor-list regression with a NULL atom in the middle of the inputRoot cause and fix
select_real_atoms_coordremoves NULL-type atoms and returns compacted coordinates/types plus forward and backward maps. The DeepSpinPT neighbor-list path used the compacted coordinates and types, but reshaped a prefix of the original spin buffer tonall_realrows. That only preserves atom-to-spin association when all filtered NULL atoms happen to be at the end.The fix rebuilds the spin buffer in
bkw_maporder before creating the tensor. Spin is a per-atom side channel, so it now follows exactly the same compacted ordering as coordinates and atom types, including local and ghost partitions.Regression coverage
The existing tests covered ordinary neighbor-list inference, but did not place
atype = -1between real atoms. Therefore the incorrect prefix and the correct mapped spin buffers were indistinguishable in the tested layouts.The new test evaluates the same six real atoms in two representations:
It compares energy, virial, real-atom force and magnetic force, and verifies that the NULL output slots are zero. The test explicitly checks the
.pthbackend so it exercises DeepSpinPT rather than PTExpt.The file's historical float reference tolerance is
0.1. The old mapping error is smaller than that (maximum observed differences: energy0.01493, force0.02159, magnetic force0.08961, virial0.03228), so this equivalence regression uses1e-10for double and1e-5for float. With the old production line restored, both typed cases fail; with the fix, both pass.Validation performed:
runUnitTests_cc,deepmd_backend_pt, anddeepmd_op_ptwith CPU PyTorchruff format --check .ruff check .git diff --checkCloses #5619.
Coding agent: Codex
Codex version: codex-cli 0.144.1
Model: gpt-5.6-sol
Reasoning effort: xhigh
Summary by CodeRabbit
Bug Fixes
Tests