fix(tf): preserve non-PBC ASE neighbor semantics - #5859
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe change preserves open-boundary semantics for TensorFlow inference with ASE neighbor lists, separates placeholder cells from boundary cells, updates neighbor-list annotations and documentation, and adds regression tests for DeepEval and DeepDipole. ChangesNon-PBC neighbor-list inference
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant DeepEval
participant ASENeighborList
participant TensorFlow
Caller->>DeepEval: Evaluate with box=None
DeepEval->>ASENeighborList: Build neighbors with neighbor_cell=None
ASENeighborList-->>DeepEval: Return non-periodic neighbor data
DeepEval->>TensorFlow: Feed placeholder cell separately
TensorFlow-->>Caller: Return inference results
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 |
Keep the original open-boundary decision separate from the identity box required by TensorFlow feeds, and let both ASE builders handle a missing cell without creating periodic ghosts. Add collected DeepPotential and DeepTensor regressions for non-periodic external neighbor-list inference. Coding-Agent: Codex Codex-Version: codex-cli 0.144.4 Model: gpt-5.6-sol Reasoning-Effort: xhigh
9212126 to
f75ab0b
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5859 +/- ##
==========================================
+ Coverage 78.58% 78.89% +0.31%
==========================================
Files 1050 1067 +17
Lines 120637 123808 +3171
Branches 4356 4515 +159
==========================================
+ Hits 94801 97681 +2880
- Misses 24278 24518 +240
- Partials 1558 1609 +51 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Possible reviewers based on changed lines, exact file history, and exact-file review history:
No review request was made automatically. Coding agent: Codex |
Coding-Agent: Codex Codex-Version: codex-cli 0.144.6 Model: gpt-5.6-sol Reasoning-Effort: xhigh
wanghan-iapcm
left a comment
There was a problem hiding this comment.
The diagnosis and the fix are both right. _prepare_feed_dict overwrote cells with a 1 Angstrom identity box to satisfy the TF box placeholder, after which the call site's cells if cells is not None else None could never be None, so build_neighbor_list re-derived pbc from cell is not None and ASE generated periodic images of a 1 Angstrom cell for a system with no cell. Threading the real boundary condition through a separate neighbor_cell is the correct separation, and substituting a zero 3x3 only where ASE needs an array - after pbc has already been computed - matches what deepmd/pt_expt/infer/deep_eval.py has done since #5284, so this converges TF with the existing reference rather than adding a third convention.
I checked the parts most likely to break rather than assuming them: the periodic path is a literal identity (neighbor_cell = cells if pbc else None reduces to the old expression when pbc is true); multi-frame is guarded by NotImplementedError at all three call sites, so no [nframes, 9] array reaches reshape(3, 3); a zero cell is safe for ASE's NewPrimitiveNeighborList with pbc=False (no ghosts, no divide-by-zero, fine down to one atom); the empty-ghost bookkeeping degenerates to a no-op; and the corrected 6-tuple return annotation matches what both copies of build_neighbor_list actually return.
The regression test is the strongest part. Run against the base commit it fails with 18/18 force components wrong, max absolute difference 3.54 and max relative difference around 4800x - exactly the signature of the spurious ghosts - and passes at the head. That is a real bug with a real test, not a test that merely accompanies a fix.
Two non-blocking notes:
-
The
deepmd/tf/infer/deep_tensor.pyhunks are not exercised by anything in this PR.source/tests/tf/test_deepdipole.pyimportsDeepDipolefromdeepmd.tf.infer, which re-exports the genericdeepmd.infer.deep_dipole.DeepDipole; its MRO runs throughdeepmd.infer.deep_tensor.DeepTensorand intodeepmd/tf/infer/deep_eval.py, never through the TF-specificdeep_tensor.py. Patching onlydeep_tensor.pyleaves that test failing (max difference 1.34); patching onlydeep_eval.pymakes it pass. The change itself is correct and mirrors thedeep_eval.pyfix, but the PR description's "focused DeepTensor eval/eval_full no-PBC regression: passed" is attributed to the wrong file - worth correcting so the claim is not taken at face value later. The only subclass of the TFDeepTensorisDeepDipoleOld, whose sole consumer never passes aneighbor_list, so the code is currently unreachable rather than wrong. -
The comment correctly identifies why
TestDeepPotNeighborListinherits nothing -parameterized()rebinds the decorated name toobject- and works around it with a standalone function. That is a fair call for this PR, but the underlying breakage dates to #4028 and means the class has contributed zero assertions since 2024-08-04, which is why this bug survived. Worth a follow-up to repair the class rather than leaving the next contributor to rediscover it.
Also minor: the substituted zero cell uses dtype=coords.dtype, so integer coordinates would yield an integer cell. It has no observable effect here (the branch only runs with pbc=False, where the offsets are all zero, and ASE upcasts internally), but the pt_expt equivalent hardcodes np.float64 and it would be nice to match.
Restore the parameterized ASE neighbor-list test inheritance, exercise the legacy TF DeepTensor path directly, and align open-boundary fallback cell precision with the reference implementation. Coding-Agent: Codex Codex-Version: codex-cli 0.144.6 Model: gpt-5.6-sol Reasoning-Effort: xhigh
|
Addressed the review follow-ups in commit 9dd4210:
Validation:
Coding agent: Codex |
Closes #5668.
Summary
Why existing tests missed this
Validation
Coding agent: Codex
Codex version: codex-cli 0.144.4
Model: gpt-5.6-sol
Reasoning effort: xhigh
Summary by CodeRabbit
Bug Fixes
Tests