Skip to content

test(infer,lmp): drop stale DPA2 .pth fixtures, repoint tests to deeppot_dpa2#5446

Open
wanghan-iapcm wants to merge 4 commits into
deepmodeling:masterfrom
wanghan-iapcm:fix-stale-dpa-pth-fixtures
Open

test(infer,lmp): drop stale DPA2 .pth fixtures, repoint tests to deeppot_dpa2#5446
wanghan-iapcm wants to merge 4 commits into
deepmodeling:masterfrom
wanghan-iapcm:fix-stale-dpa-pth-fixtures

Conversation

@wanghan-iapcm
Copy link
Copy Markdown
Collaborator

@wanghan-iapcm wanghan-iapcm commented May 18, 2026

Summary

  • Drop the stale pre-committed deeppot_dpa.pth and deeppot_dpa_sel.pth fixtures and the redundant C++ test test_deeppot_dpa_pt.cc. Both .pth files predate the g1_out_mlp / g1_out_conv repformer features, so they could be loaded only via the baked-in TorchScript IR (torch.jit.load) — they could not be round-tripped through get_model() + load_state_dict() and therefore could not be converted to .pt2. This was the blocker recorded in memory/project_stale_dpa2_pth.md and the master plan's "LAMMPS .pt2 DPA tests" planned item.
  • Repoint the three LAMMPS PyTorch-backend tests at the current-arch deeppot_dpa2.pth and load reference values from deeppot_dpa2.expected via read_expected_ref (already used by test_lammps_dpa3_pt2.py). This replaces ~150 hard-coded reference floats per file with a 5-line try / except block, and the .expected file is regenerated at CI time by source/tests/infer/gen_dpa2.py.
  • Rename test_lammps_dpa_pt.pytest_lammps_dpa2_pt.py and test_lammps_dpa_pt_nopbc.pytest_lammps_dpa2_pt_nopbc.py so the descriptor is visible from the filename (matching test_lammps_dpa2_pt2.py / test_lammps_dpa3_* convention). Delete test_lammps_dpa_sel_pt.py outright — once both fixtures collapse onto deeppot_dpa2.pth it becomes a pure duplicate of the PBC variant. The small-sel-specific semantics of the old deeppot_dpa_sel.pth are not preserved; if that coverage is wanted back, the right path is a separate deeppot_dpa2_sel.pth fixture written by an extended gen_dpa2.py.
  • Deletion of test_deeppot_dpa_pt.cc: once migrated to deeppot_dpa2.pth + expected_ref.h, this file is byte-for-byte equivalent to the existing test_deeppot_dpa2_pt.cc (same backend, same fixture, same geometry, same five test cases). Keeping both would be pure duplication.

Net diff: 9 files changed, +61 insertions, −1369 deletions.

The JAX path (source/lmp/tests/test_lammps_dpa_jax.py, source/api_cc/tests/test_deeppot_dpa_jax.cc, and the deeppot_dpa.yamldeeppot_dpa.savedmodel conversion in convert-models.sh) is intentionally left untouched. The deeppot_dpa.yaml has the current architecture (the .pth files diverged from it at some point), so the JAX tests continue to work; renaming them for consistency would be a separate cleanup.

Test plan

  • pytest --collect-only on the two renamed Python tests collects 33 tests (PBC 17 + NoPBC 16). No ModuleNotFoundError, read_expected_ref resolves the .expected file at import time.
  • Live DeepPot(deeppot_dpa2.pth).eval(...) output matches every value in deeppot_dpa2.expected for both PBC and NoPBC sections (atol=1e-12, rtol=0).
  • C++ ctest filter *Dpa2Pt*:*Dpa2PtNoPbc* from build_pt2_test/: 28 / 28 PASSED in 69.4 s. Covers all .pth cases that the deleted test_deeppot_dpa_pt.cc would have run (TestInferDeepPotDpa2Pt, TestInferDeepPotDpa2PtNoPbc, double + float), plus the existing .pt2 AOTI suites.
  • Full LAMMPS pair_deepmd run (not exercised locally — depends on built LAMMPS-with-deepmd integration; CI will cover).
  • Confirm CI convert-models.sh still produces deeppot_dpa.savedmodel cleanly for the JAX tests (the yaml is unchanged, but worth watching the first CI run).

Closes the "Stale DPA2 .pth files" limitation and the "LAMMPS .pt2 DPA tests" planned item in the pt_expt master plan.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • DPA2 LAMMPS tests now load expected references from external files (with graceful fallback when reference files are unavailable).
    • Added tests to validate per-atom energy/virial outputs when periodic boundaries are disabled.
    • Removed several deprecated DeepPot test modules to streamline and reduce redundant test coverage.

Review Change Stack

Han Wang added 2 commits May 18, 2026 20:02
…eeppot_dpa2

The pre-committed deeppot_dpa.pth and deeppot_dpa_sel.pth predate the
g1_out_mlp / g1_out_conv repformer features, so they cannot be loaded
via get_model() + load_state_dict() and therefore can't be converted
to .pt2. LAMMPS .pth tests still passed only because torch.jit.load
restores the baked-in TorchScript IR.

Drop both stale fixtures and point the three LAMMPS .pth tests
(test_lammps_dpa_pt.py, _nopbc.py, _sel_pt.py) at the current-arch
deeppot_dpa2.pth, loading reference values from deeppot_dpa2.expected
via read_expected_ref instead of ~150 hard-coded floats per file.
Also delete test_deeppot_dpa_pt.cc — fully redundant with
test_deeppot_dpa2_pt.cc, which already exercises the C++ .pth backend
on the fresh fixture via expected_ref.h.

The small-sel-specific semantics of the deleted deeppot_dpa_sel.pth
are not preserved; test_lammps_dpa_sel_pt.py now exercises the same
model as the PBC variant. .pt2 LAMMPS coverage for DPA2 is already
provided by test_lammps_dpa2_pt2.py, so the original blocker for
"LAMMPS .pt2 DPA tests" is closed by this cleanup.
…2_*, drop sel duplicate

These three tests target the DPA2 descriptor (not generic DPA);
align with the existing test_lammps_dpa2_pt2.py / test_lammps_dpa3_*
naming so the descriptor is visible from the filename.

test_lammps_dpa_sel_pt.py becomes pure duplicate of the renamed
test_lammps_dpa2_pt.py once both point at deeppot_dpa2.pth — drop it
rather than carry a misleading "sel" name with no small-sel-specific
fixture behind it.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d745bb36-8ea8-4800-8025-7300affa0f29

📥 Commits

Reviewing files that changed from the base of the PR and between 0605c7c and ff1264b.

📒 Files selected for processing (2)
  • source/lmp/tests/test_lammps_dpa2_pt.py
  • source/lmp/tests/test_lammps_dpa2_pt_nopbc.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • source/lmp/tests/test_lammps_dpa2_pt.py
  • source/lmp/tests/test_lammps_dpa2_pt_nopbc.py

📝 Walkthrough

Walkthrough

This PR externalizes DPA2 LAMMPS test expectations to .expected sidecar files and adds two C++ typed tests for atomic per-atom outputs in the DPA2 no-PBC code paths; it also deletes two obsolete test modules.

Changes

Test Reference Data Externalization

Layer / File(s) Summary
test_lammps_dpa2_pt.py reference externalization
source/lmp/tests/test_lammps_dpa2_pt.py
Imports read_expected_ref, loads expected energies/forces from deeppot_dpa2.expected["pbc"], and reads expected virial tensor (reshaped and sign-inverted); falls back to None on missing file/key.
test_lammps_dpa2_pt_nopbc.py reference externalization
source/lmp/tests/test_lammps_dpa2_pt_nopbc.py
Imports read_expected_ref, uses deeppot_dpa2.pth/deeppot_dpa2.expected["nopbc"] to populate expected energies/forces and virial (reshape and negation); sets to None when reference data is unavailable.

C++ DeepPot DPA2 atomic-output tests

Layer / File(s) Summary
Add atomic-output typed tests
source/api_cc/tests/test_deeppot_dpa2_pt.cc
Adds TYPED_TEST(TestInferDeepPotDpa2PtNoPbc, cpu_build_nlist_atomic) and TYPED_TEST(TestInferDeepPotDpa2PtNoPbc, cpu_lmp_nlist_atomic) that call dp.compute with atom_ener/atom_vir, assert output sizes, and validate per-atom and total energy/forces/virial against test references.

Test File Removals

Layer / File(s) Summary
C++ DPA test removal
source/api_cc/tests/test_deeppot_dpa_pt.cc
Entire file deleted, removing prior GoogleTest suites and DeepPot inference verification for DPA/PT CPU/nlist and atomic variants.
LAMMPS DPA-sel test removal
source/lmp/tests/test_lammps_dpa_sel_pt.py
Entire file deleted, removing LAMMPS setup helpers, fixtures, and a large set of parametrized DeepMD/LAMMPS tests (multiple variants and MPI-based run).

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • njzjz
  • iProzd
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly summarizes the main change: dropping stale DPA2 .pth fixtures and repointing tests to deeppot_dpa2, which aligns with the core objective.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread source/lmp/tests/test_lammps_dpa2_pt.py Fixed
Comment thread source/lmp/tests/test_lammps_dpa2_pt_nopbc.py Fixed
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0e9bb240a0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread source/api_cc/tests/test_deeppot_dpa_pt.cc
@wanghan-iapcm wanghan-iapcm requested a review from iProzd May 18, 2026 13:51
Han Wang added 2 commits May 18, 2026 22:31
…ot_dpa_pt.cc

The previous commit deleted test_deeppot_dpa_pt.cc on the basis that
test_deeppot_dpa2_pt.cc already covered the same backend / fixture.
That's true for the PBC suite, but the NoPbc suite in the kept file
only had cpu_build_nlist and cpu_lmp_nlist — the atomic variants
(cpu_build_nlist_atomic, cpu_lmp_nlist_atomic) that the deleted file
exercised for NoPbc were silently lost, leaving per-atom energy and
virial behavior on the no-PBC .pth path uncovered.

Add both atomic NoPbc cases back in test_deeppot_dpa2_pt.cc, mirroring
the existing PBC atomic test and the deleted NoPbc atomic bodies.
Local ctest with --gtest_filter=*Dpa2PtNoPbc* now reports 8/8 PASSED
(double and float x build_nlist{,_atomic} and lmp_nlist{,_atomic}).

Flagged by Codex review on PR deepmodeling#5446.
CodeQL flagged the migrated read_expected_ref blocks for an unused
module-level expected_ae variable (test_lammps_dpa2_pt.py:47 and
test_lammps_dpa2_pt_nopbc.py:43). The pre-migration files exposed
expected_ae for symmetry with similar TF/PT tests, but the LAMMPS
test bodies only consume expected_e / expected_f / expected_v —
nothing inside the test functions references expected_ae directly.

Inline the np.sum over the atomic-energy array and remove the
expected_ae binding from both the try and the except branches.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

❌ Patch coverage is 68.96552% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.48%. Comparing base (36ba4ff) to head (ff1264b).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
source/api_cc/tests/test_deeppot_dpa2_pt.cc 68.96% 18 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master    #5446    +/-   ##
========================================
  Coverage   82.48%   82.48%            
========================================
  Files         830      829     -1     
  Lines       88514    88402   -112     
  Branches     4232     4216    -16     
========================================
- Hits        73010    72919    -91     
+ Misses      14218    14195    -23     
- Partials     1286     1288     +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@iProzd iProzd added this pull request to the merge queue May 19, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 19, 2026
@wanghan-iapcm wanghan-iapcm added this pull request to the merge queue May 20, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants