Skip to content

refactor(lmp): share test infrastructure#5770

Open
njzjz-bot wants to merge 4 commits into
deepmodeling:masterfrom
njzjz-bot:codex/refactor-lmp-tests
Open

refactor(lmp): share test infrastructure#5770
njzjz-bot wants to merge 4 commits into
deepmodeling:masterfrom
njzjz-bot:codex/refactor-lmp-tests

Conversation

@njzjz-bot

@njzjz-bot njzjz-bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Summary:

  • add lammps_test_utils.py as the shared infrastructure layer for LAMMPS Python tests
  • centralize atomic and spin LAMMPS construction across backend, model-format, periodic/non-periodic, graph, fparam/aparam, and DeepTensor suites
  • support configurable boundaries, atom maps, unit systems, and one/two/three-type mass tables without duplicating command sequences
  • share backend gating, water data variants, generated-file cleanup, two-model MPI invocation, and DPA3 atomic/spin MPI output parsing
  • keep the atomic and spin model-deviation entry points thin through the existing shared mpi_pair_deepmd.py runner

Reduction:

  • latest update changes 27 files with 494 additions and 1,063 deletions
  • existing pytest test names and node IDs remain unchanged

Compatibility preserved:

  • unchanged LAMMPS units, boundaries, atom styles, neighbor settings, masses, timesteps, fixes, atom-map behavior, pair styles, processor grids, and runner arguments
  • atom_map="no" continues to omit the unsupported atom_modify map no command
  • periodic and non-periodic MPI flags remain scenario-specific
  • DPA3 failure-path subprocesses still return raw status/stdout/stderr, while successful runs retain the same parsed energy/force/virial contracts

Validation:

  • ruff check . — passed
  • ruff format . — 1,599 files left unchanged
  • pre-commit hooks — passed
  • git diff --check — passed
  • python -m compileall -q source/lmp/tests — passed
  • pytest --collect-only -q source/lmp/tests — 244 tests collected
  • fake-LAMMPS compatibility harness — passed atomic/spin setup, periodic boundaries, atom-map omission, SI units, one/two/three-type mass tables, MPI output parsing, and failure capture
  • real numerical tests were attempted, but the installed LAMMPS reported loading 0 plugins from the existing build and therefore did not recognize deepmd/deepspin; this environment issue is outside the refactor

Coding agent: Codex
Codex version: codex-cli 0.144.1
Model: gpt-5.6-sol
Reasoning effort: xhigh

Summary by CodeRabbit

  • Refactor
    • Consolidated DeepMD/DeepSpin two-rank MPI model-deviation execution into shared, parameterized runners.
    • Replaced DeepMD/DeepSpin MPI launcher scripts with lightweight entrypoints using scenario-specific defaults.
    • Centralized LAMMPS test setup, generated water-data variants, backend gating, cleanup, and MPI result parsing; updated multiple LAMMPS-related tests to use the shared helpers.
  • Bug Fixes
    • Improved MPI shutdown handling to ensure LAMMPS resources are released cleanly before MPI finalization.

njzjz-bot and others added 2 commits July 12, 2026 09:35
Consolidate the common pair_deepmd and pair_deepspin MPI setup while preserving their existing script entry points and model-specific configuration.

Authored by OpenClaw (model: gpt-5.6-sol)

Coding-Agent: Codex
Codex-Version: codex-cli 0.144.1
Model: gpt-5.6-sol
Reasoning-Effort: xhigh
@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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: f953924a-ea57-4692-8b08-174a6974b208

📥 Commits

Reviewing files that changed from the base of the PR and between c5b2ad0 and 2fde99e.

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

📝 Walkthrough

Walkthrough

Introduces shared LAMMPS test utilities and a configurable MPI pair-test runner for DeepMD and DeepSpin. Existing tests delegate simulation setup, fixture handling, MPI execution, output parsing, backend gating, and cleanup to the shared infrastructure.

Changes

Shared LAMMPS test infrastructure

Layer / File(s) Summary
Configurable MPI pair-test runner
source/lmp/tests/mpi_pair_deepmd.py, source/lmp/tests/run_mpi_pair_deepmd*.py
Adds PairStyleConfig, centralizes MPI/LAMMPS execution, and reduces DeepMD and DeepSpin scripts to fixed-configuration entrypoints.
Shared test utilities
source/lmp/tests/lammps_test_utils.py
Adds backend gating, fixture generation and cleanup, standardized atomic/spin LAMMPS construction, MPI command execution, and output parsing.
Test migration
source/lmp/tests/test_lammps*.py, source/lmp/tests/test_deeptensor.py
Replaces duplicated LAMMPS setup and subprocess-based MPI orchestration with shared utility calls across the test suite.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Test
  participant SharedUtilities
  participant MPI
  participant PyLammps
  participant Output
  Test->>SharedUtilities: Request LAMMPS setup or MPI run
  SharedUtilities->>MPI: Launch configured runner
  MPI->>PyLammps: Configure and execute simulation
  PyLammps->>Output: Write energy and per-atom results
  SharedUtilities->>Test: Parse and return structured results
Loading

Possibly related PRs

Suggested labels: enhancement, Python

Suggested reviewers: njzjz, wanghan-iapcm, OutisLi

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 19.23% 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 title accurately summarizes the main change: shared LMP test infrastructure was refactored and centralized.
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.
✨ 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.

@codecov

codecov Bot commented Jul 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.56%. Comparing base (7c362d7) to head (2fde99e).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5770      +/-   ##
==========================================
- Coverage   79.65%   79.56%   -0.10%     
==========================================
  Files        1015     1020       +5     
  Lines      115781   116359     +578     
  Branches     4272     4303      +31     
==========================================
+ Hits        92229    92577     +348     
- Misses      22008    22227     +219     
- Partials     1544     1555      +11     

☔ View full report in Codecov by Harness.
📢 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.

Centralize atomic and spin LAMMPS construction, common water fixture lifecycle, and MPI subprocess parsing across backend and model-format tests.

Coding-Agent: Codex
Codex-Version: codex-cli 0.144.1
Model: gpt-5.6-sol
Reasoning-Effort: xhigh
@njzjz-bot njzjz-bot changed the title refactor(lmp): share MPI pair test driver refactor(lmp): share test infrastructure Jul 12, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
source/lmp/tests/lammps_test_utils.py (1)

128-193: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Docstring omits the capture=True return contract.

The docstring only describes the parsed {"pe", "forces", "virials", ...} shape; when capture=True the function instead returns {"returncode", "stdout", "stderr"}. Worth a one-line mention since this is a shared utility other test files rely on.

📝 Suggested docstring addition
     """Invoke a DPA MPI runner and parse its energy/per-atom output.

     The runner output contract is one energy line followed by a rectangular
     per-atom table. ``output_columns`` names and slices that table while each
     model-specific wrapper retains its own defaults and explanatory docstring.
+
+    If ``capture`` is True, the parsed result is skipped and the function
+    instead returns ``{"returncode": int, "stdout": str, "stderr": str}``
+    from the raw subprocess invocation.
     """
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@source/lmp/tests/lammps_test_utils.py` around lines 128 - 193, Update the
docstring of run_mpi_pair_runner to document that capture=True returns a
dictionary containing returncode, stdout, and stderr instead of the parsed
energy and per-atom output fields; leave the existing parsing behavior and
parameters unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@source/lmp/tests/test_lammps_spin_nopbc_pt.py`:
- Around line 205-213: Update test_pair_deepmd_mpi to append "--nopbc" to the
existing balance_args when invoking run_mpi_model_deviation, matching the
argument handling in test_lammps_spin_nopbc.py so the MPI runner uses
non-periodic boundaries.

---

Nitpick comments:
In `@source/lmp/tests/lammps_test_utils.py`:
- Around line 128-193: Update the docstring of run_mpi_pair_runner to document
that capture=True returns a dictionary containing returncode, stdout, and stderr
instead of the parsed energy and per-atom output fields; leave the existing
parsing behavior and parameters unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 445af8d4-f2d5-41ac-b91a-917da076ea17

📥 Commits

Reviewing files that changed from the base of the PR and between cbe6ae8 and c5b2ad0.

📒 Files selected for processing (27)
  • source/lmp/tests/lammps_test_utils.py
  • source/lmp/tests/test_deeptensor.py
  • source/lmp/tests/test_lammps.py
  • source/lmp/tests/test_lammps_3types.py
  • source/lmp/tests/test_lammps_dpa1_graph_pt2.py
  • source/lmp/tests/test_lammps_dpa2_pt.py
  • source/lmp/tests/test_lammps_dpa2_pt_nopbc.py
  • source/lmp/tests/test_lammps_dpa3_pt2.py
  • source/lmp/tests/test_lammps_dpa3_pt2_nopbc.py
  • source/lmp/tests/test_lammps_dpa4_pt2.py
  • source/lmp/tests/test_lammps_dpa_jax.py
  • source/lmp/tests/test_lammps_faparam.py
  • source/lmp/tests/test_lammps_faparam_pt.py
  • source/lmp/tests/test_lammps_faparam_pt2.py
  • source/lmp/tests/test_lammps_fparam_from_fix_dedn.py
  • source/lmp/tests/test_lammps_jax.py
  • source/lmp/tests/test_lammps_model_devi_pt2.py
  • source/lmp/tests/test_lammps_pd.py
  • source/lmp/tests/test_lammps_pt.py
  • source/lmp/tests/test_lammps_pt2.py
  • source/lmp/tests/test_lammps_spin.py
  • source/lmp/tests/test_lammps_spin_dpa3_pt2.py
  • source/lmp/tests/test_lammps_spin_nopbc.py
  • source/lmp/tests/test_lammps_spin_nopbc_pt.py
  • source/lmp/tests/test_lammps_spin_nopbc_pt2.py
  • source/lmp/tests/test_lammps_spin_pt.py
  • source/lmp/tests/test_lammps_spin_pt2.py

Comment thread source/lmp/tests/test_lammps_spin_nopbc_pt.py
@njzjz njzjz requested a review from wanghan-iapcm July 12, 2026 12:36
Document the capture-mode return contract for the shared MPI runner.

Coding-Agent: Codex
Codex-Version: codex-cli 0.144.1
Model: gpt-5.6-sol
Reasoning-Effort: xhigh

@wanghan-iapcm wanghan-iapcm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Faithful test-infrastructure extraction. Verified no expected-value arrays, tolerances, assertions, or skip markers were altered, and per-test special-casing (masses, atom_map, boundary="f f f", the 15-column spin-dpa3 MPI output layout) is preserved as explicit call-site arguments. The --nopbc addition in test_lammps_spin_nopbc_pt.py::test_pair_deepmd_mpi is a correct fix (commit 2fde99e) that makes the MPI test consistent with the serial nopbc tests in the same file.

Non-blocking: test_lammps_dpa1_graph_pt2.py still keeps a hand-rolled MPI runner instead of delegating to the new run_mpi_pair_runner helper like test_lammps_dpa3_pt2.py and test_lammps_spin_dpa3_pt2.py do; consolidating it would complete the stated goal.

lammps.timestep(0.0005)
lammps.fix("1 all nve")
return lammps
return make_atomic_lammps(data_file, units, atom_map=atom_map)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Non-blocking: this file adopts make_atomic_lammps here, but its MPI path (_run_mpi_subprocess, ~L180) still hand-rolls the mpirun argv building and output parsing, whereas the sibling GNN tests test_lammps_dpa3_pt2.py and test_lammps_spin_dpa3_pt2.py now delegate to the new run_mpi_pair_runner in lammps_test_utils.py. Consolidating this one too would complete the PR's stated goal of sharing the MPI pair-test driver across formats. Not required for merge.

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.

2 participants