Skip to content

Commit 3384efb

Browse files
wanghan-iapcmHan Wang
andauthored
test(infer,lmp): drop stale DPA2 .pth fixtures, repoint tests to deeppot_dpa2 (#5446)
## 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.py` → `test_lammps_dpa2_pt.py` and `test_lammps_dpa_pt_nopbc.py` → `test_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.yaml` → `deeppot_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 - [x] `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. - [x] 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). - [x] 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](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## 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_stack_entry_start --> [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/deepmodeling/deepmd-kit/pull/5446?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Han Wang <wang_han@iapcm.ac.cn>
1 parent e7108b6 commit 3384efb

7 files changed

Lines changed: 121 additions & 1350 deletions

File tree

source/api_cc/tests/test_deeppot_dpa2_pt.cc

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,42 @@ TYPED_TEST(TestInferDeepPotDpa2PtNoPbc, cpu_build_nlist) {
209209
}
210210
}
211211

212+
TYPED_TEST(TestInferDeepPotDpa2PtNoPbc, cpu_build_nlist_atomic) {
213+
using VALUETYPE = TypeParam;
214+
std::vector<VALUETYPE>& coord = this->coord;
215+
std::vector<int>& atype = this->atype;
216+
std::vector<VALUETYPE>& box = this->box;
217+
std::vector<VALUETYPE>& expected_e = this->expected_e;
218+
std::vector<VALUETYPE>& expected_f = this->expected_f;
219+
std::vector<VALUETYPE>& expected_v = this->expected_v;
220+
int& natoms = this->natoms;
221+
double& expected_tot_e = this->expected_tot_e;
222+
std::vector<VALUETYPE>& expected_tot_v = this->expected_tot_v;
223+
deepmd::DeepPot& dp = this->dp;
224+
double ener;
225+
std::vector<VALUETYPE> force, virial, atom_ener, atom_vir;
226+
dp.compute(ener, force, virial, atom_ener, atom_vir, coord, atype, box);
227+
228+
EXPECT_EQ(force.size(), natoms * 3);
229+
EXPECT_EQ(virial.size(), 9);
230+
EXPECT_EQ(atom_ener.size(), natoms);
231+
EXPECT_EQ(atom_vir.size(), natoms * 9);
232+
233+
EXPECT_LT(fabs(ener - expected_tot_e), EPSILON);
234+
for (int ii = 0; ii < natoms * 3; ++ii) {
235+
EXPECT_LT(fabs(force[ii] - expected_f[ii]), EPSILON);
236+
}
237+
for (int ii = 0; ii < 3 * 3; ++ii) {
238+
EXPECT_LT(fabs(virial[ii] - expected_tot_v[ii]), EPSILON);
239+
}
240+
for (int ii = 0; ii < natoms; ++ii) {
241+
EXPECT_LT(fabs(atom_ener[ii] - expected_e[ii]), EPSILON);
242+
}
243+
for (int ii = 0; ii < natoms * 9; ++ii) {
244+
EXPECT_LT(fabs(atom_vir[ii] - expected_v[ii]), EPSILON);
245+
}
246+
}
247+
212248
TYPED_TEST(TestInferDeepPotDpa2PtNoPbc, cpu_lmp_nlist) {
213249
using VALUETYPE = TypeParam;
214250
std::vector<VALUETYPE>& coord = this->coord;
@@ -242,3 +278,48 @@ TYPED_TEST(TestInferDeepPotDpa2PtNoPbc, cpu_lmp_nlist) {
242278
EXPECT_LT(fabs(virial[ii] - expected_tot_v[ii]), EPSILON);
243279
}
244280
}
281+
282+
TYPED_TEST(TestInferDeepPotDpa2PtNoPbc, cpu_lmp_nlist_atomic) {
283+
using VALUETYPE = TypeParam;
284+
std::vector<VALUETYPE>& coord = this->coord;
285+
std::vector<int>& atype = this->atype;
286+
std::vector<VALUETYPE>& box = this->box;
287+
std::vector<VALUETYPE>& expected_e = this->expected_e;
288+
std::vector<VALUETYPE>& expected_f = this->expected_f;
289+
std::vector<VALUETYPE>& expected_v = this->expected_v;
290+
int& natoms = this->natoms;
291+
double& expected_tot_e = this->expected_tot_e;
292+
std::vector<VALUETYPE>& expected_tot_v = this->expected_tot_v;
293+
deepmd::DeepPot& dp = this->dp;
294+
double ener;
295+
std::vector<VALUETYPE> force, virial, atom_ener, atom_vir;
296+
297+
std::vector<std::vector<int> > nlist_data = {
298+
{1, 2, 3, 4, 5}, {0, 2, 3, 4, 5}, {0, 1, 3, 4, 5},
299+
{0, 1, 2, 4, 5}, {0, 1, 2, 3, 5}, {0, 1, 2, 3, 4}};
300+
std::vector<int> ilist(natoms), numneigh(natoms);
301+
std::vector<int*> firstneigh(natoms);
302+
deepmd::InputNlist inlist(natoms, &ilist[0], &numneigh[0], &firstneigh[0]);
303+
convert_nlist(inlist, nlist_data);
304+
dp.compute(ener, force, virial, atom_ener, atom_vir, coord, atype, box, 0,
305+
inlist, 0);
306+
307+
EXPECT_EQ(force.size(), natoms * 3);
308+
EXPECT_EQ(virial.size(), 9);
309+
EXPECT_EQ(atom_ener.size(), natoms);
310+
EXPECT_EQ(atom_vir.size(), natoms * 9);
311+
312+
EXPECT_LT(fabs(ener - expected_tot_e), EPSILON);
313+
for (int ii = 0; ii < natoms * 3; ++ii) {
314+
EXPECT_LT(fabs(force[ii] - expected_f[ii]), EPSILON);
315+
}
316+
for (int ii = 0; ii < 3 * 3; ++ii) {
317+
EXPECT_LT(fabs(virial[ii] - expected_tot_v[ii]), EPSILON);
318+
}
319+
for (int ii = 0; ii < natoms; ++ii) {
320+
EXPECT_LT(fabs(atom_ener[ii] - expected_e[ii]), EPSILON);
321+
}
322+
for (int ii = 0; ii < natoms * 9; ++ii) {
323+
EXPECT_LT(fabs(atom_vir[ii] - expected_v[ii]), EPSILON);
324+
}
325+
}

0 commit comments

Comments
 (0)