Skip to content

fix(pt-expt): allow DPZBL inference without ghost atoms - #6155

Open
Miller10101010 wants to merge 2 commits into
deepmodeling:masterfrom
Miller10101010:fix-pairtab-no-ghosts
Open

Miller10101010 wants to merge 2 commits into
deepmodeling:masterfrom
Miller10101010:fix-pairtab-no-ghosts

Conversation

@Miller10101010

@Miller10101010 Miller10101010 commented Nov 24, 2026 •

Copy link
Copy Markdown

Select local atoms in the tabulated pair potential without introducing an export constraint that requires the extended atom count to differ from the local atom count. Add coverage for the equal-count case.

Compared frozen and eager energy, forces and virial for a nonperiodic system and two periodic box sizes. The maximum absolute difference was below 6e-14. All 16 targeted PairTab and DPZBL tests passed.

Closes #6087.

Summary by CodeRabbit

  • Bug Fixes
    • Updated local atom selection in pairwise calculations for more consistent handling of local atoms.
  • Tests
    • Added coverage confirming that frozen DP ZBL models without ghost atoms produce energy, force, and virial results consistent with eager model evaluation.

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The pair-table model now selects local atom types and coordinates with indexed operations. A new test compares eager DP ZBL outputs with frozen-model inference without a cell.

Changes: Pair-table local atom selection

Layer / File(s) Summary
Indexed local atom selection
deepmd/dpmodel/atomic_model/pairtab_atomic_model.py
forward_atomic and _get_pairwise_dist select local atom types and coordinates with device-aware indices and xp.take instead of prefix slicing.
Frozen inference regression test
source/tests/pt_expt/model/test_dp_zbl_model.py
The test exports a DP ZBL model with lower_kind="nlist", evaluates it without a cell, and compares energy, force, and virial with eager-model outputs.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: wanghan-iapcm

Merge Risk: Minimal · up to b150c

This change lets exported DPZBL models run inference when the extended atom count equals the local atom count, such as for nonperiodic inputs. The change is small and localized, a regression test covers the reported case, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the fix (DPZBL inference without ghost atoms) in the pt-expt backend. The raw summary confirms the PairTab atomic model change selects local atoms by explicit indices instead of prefix…
Linked Issues check Passed [#6087] The issue requires successful pt_expt .pt2 inference of a DPZBL model (nlist lower) when nall == nloc. The reviewed head of deepmd/dpmodel/atomic_model/pairtab_atomic_model.py removes the pref…
Out of Scope Changes check Passed The PR changes two files. deepmd/dpmodel/atomic_model/pairtab_atomic_model.py replaces prefix slicing with explicit local-index selection in forward_atomic and _get_pairwise_dist. This is the fix for …
Full details: Title check

Explanation

The title names the fix (DPZBL inference without ghost atoms) in the pt-expt backend. The raw summary confirms the PairTab atomic model change selects local atoms by explicit indices instead of prefix slicing. This removes the need for nall to differ from nloc, which the linked issue #6087 reports as a runtime assertion failure. The added test covers the frozen-versus-eager comparison without a cell input. The title matches the main change and is specific enough for history scanning.

Full details: Linked Issues check

Explanation

[#6087] The issue requires successful pt_expt .pt2 inference of a DPZBL model (nlist lower) when nall == nloc. The reviewed head of deepmd/dpmodel/atomic_model/pairtab_atomic_model.py removes the prefix slice that specialized the exported graph. forward_atomic builds local_indices = xp.arange(nloc) and selects atom types with xp.take(extended_atype, local_indices, axis=1). _get_pairwise_dist selects local coordinates with xp.take(coords, local_indices, axis=1). The neighbor gather uses masked_nlist and does not depend on a prefix of nall. This targets the nall != nloc guard named in the issue. The test test_frozen_no_ghosts in source/tests/pt_expt/model/test_dp_zbl_model.py freezes with lower_kind="nlist", evaluates input without a cell through DeepPot, and compares energy, force and virial with the eager model. This covers the equal-count case. Change since the previous reviewed head (579ae4c) could not be read as a diff because changed blobs are missing from the checkout. The head file content matches the PR summary. Limits: the exported graph was not run, so absence of the Ne(s54, s96) assertion is not directly verified. The reported test results (16 PairTab and DPZBL tests, max difference below 6e-14) were not independently reproduced.

Full details: Out of Scope Changes check

Explanation

The PR changes two files. deepmd/dpmodel/atomic_model/pairtab_atomic_model.py replaces prefix slicing with explicit local-index selection in forward_atomic and _get_pairwise_dist. This is the fix for the export guard in #6087. source/tests/pt_expt/model/test_dp_zbl_model.py adds test_frozen_no_ghosts, a regression test for the same case. No unrelated files or behavior changes appear in the summary or in the head file content. Limit: the base-to-head and previous-to-head diffs were unavailable, so the file list comes from the PR summary and the head file, not from a diff.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a2febb76-e67e-4b05-8119-00fa15c6b5a4
Commits

Reviewing files that changed from the base of the PR and between 579ae4c and b150ca5.

Files selected for processing: 1

  • source/tests/pt_expt/model/test_dp_zbl_model.py
Files skipped from review as they are similar to previous changes: 1

  • source/tests/pt_expt/model/test_dp_zbl_model.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] pt_expt .pt2 of a DPZBL model (nlist lower) rejects inputs without ghost atoms: Expected Ne(s54, s96)

1 participant