Skip to content

fix(lammps): support current Modify and style registration APIs - #6149

Open
Zhang-pchao wants to merge 3 commits into
deepmodeling:masterfrom
Zhang-pchao:pimdbias/modify-accessors
Open

Zhang-pchao wants to merge 3 commits into
deepmodeling:masterfrom
Zhang-pchao:pimdbias/modify-accessors

Conversation

@Zhang-pchao

@Zhang-pchao Zhang-pchao commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Current LAMMPS development headers no longer expose the internal Modify fix and compute arrays used by the DeePMD integration. The built-in integration also needs to regenerate the new style-registration source files; otherwise it compiles but LAMMPS does not recognize pair_style deepmd.

This patch adds a small compatibility helper that uses the public by-ID accessors when the LAMMPS headers provide them and falls back to the legacy lookup otherwise. It updates the affected pair and parameter-derivative code paths, including TTM fix lookup. The built-in CMake integration regenerates style sources when LAMMPS provides that command.

The parameter tests now use the supported LAMMPS Python interface. Five cases cover default and explicit parameters, fix/compute parameter sources, atomic parameters, and finite-difference checks of parameter derivatives. Python PyTorch is initialized before native inference in the test setup.

This change is based directly on master and does not require #6053, #6054 or #6055. It does not change Kokkos header discovery addressed in #6054.

Validation:

  • C++ syntax checks against current LAMMPS and stable_22Jul2025 headers.
  • Ruff lint/format, clang-format and cmake-format checks.
  • Built the adapter into official LAMMPS develop 06428256f980b63d014d81b9ad973a6141976a1b using the documented built-in integration, without the PIMD coupling patch.
  • All five parameter tests passed without skips. A separate local guard verified that the Python wrapper loaded the newly built LAMMPS library.
  • The build reused qualified DeePMD core/Python libraries whose corresponding sources are unchanged from this PR's master baseline; the LAMMPS adapter was rebuilt from this patch. The runtime check used CPU PyTorch. Older LAMMPS validation was compile-only; TTM and Kokkos were not exercised by this focused runtime test.

Summary by CodeRabbit

  • Bug Fixes
    • Improved compatibility across LAMMPS versions when retrieving computes and fixes used for model parameters.
    • Missing compute or fix sources are handled more clearly, while parameter validation and retrieval behavior remains unchanged.
  • Build
    • Style source generation now runs when supported by the available build tools.

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The CMake configuration conditionally generates LAMMPS style sources. Compute and fix lookups use compatibility helpers that select available lookup methods. Updated tests cover parameter sources, energy, forces, and applicable energy-derivative checks.

Changes: Style Source Generation

Layer / File(s) Summary
Conditional style-source generation
source/lmp/builtin.cmake
The CMake file calls generatestylesources with the style headers directory when the command is available.

Compute and Fix Lookup Compatibility

Layer / File(s) Summary
Version-specific lookup accessors
source/lmp/lammps_modify_compat.h
The new accessors use by-ID methods when available. Otherwise, they find the ID and return the matching legacy array entry or nullptr.
Compute and fix lookup call sites
source/lmp/compute_deepmd_fparam_dedn.cpp, source/lmp/pair_base.cpp
The derivative compute and pair helpers use the compatibility accessors. Missing compute lookups in pair helpers report “not found.”
Parameter-source tests
source/lmp/tests/test_lammps_faparam_pt.py
The tests use the direct LAMMPS API and cover default and explicit parameters, compute and fix sources, and finite-difference derivative checks where applicable.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: njzjz, outisli

Merge Risk: Minimal · up to 1e12f

This change makes the LAMMPS integration work with current LAMMPS style-registration and Modify APIs while keeping the older lookup path. No merge-blocking risk was found. TTM and Kokkos were not exercised at runtime.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a fix to the LAMMPS integration that supports the current Modify API and style registration. The changeset adds a compatibility helper (lammps_modify_compat.h) that us…
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.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the main change: a fix to the LAMMPS integration that supports the current Modify API and style registration. The changeset adds a compatibility helper (lammps_modify_compat.h) that uses public Modify accessors for newer LAMMPS and keeps the legacy lookup for older headers. It also regenerates style sources in builtin.cmake. The title is specific and matches the changes, so it passes. The 'fix(lammps)' prefix follows conventional commit style.

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: a1bfd4de-268d-479a-bd4d-436391b9640a
Commits

Reviewing files that changed from the base of the PR and between cd3a524 and 1e12f26.

Files selected for processing: 1

  • source/lmp/lammps_modify_compat.h

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

@njzjz-bot njzjz-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.

Found one build-compatibility gap in the Modify feature guard between the tested releases.

Agent: dot

Comment thread source/lmp/lammps_modify_compat.h Outdated

// LAMMPS 13 Nov 2026 removed the public fix and compute arrays.
inline LAMMPS_NS::Compute* get_compute(LAMMPS_NS::Modify* modify,
const std::string& id) {

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.

This date is later than the API transition on upstream develop. At the Oct 29 upstream merge, version.h still says 30 Sep 2026, but Modify already exposes only the new lookup interface. This helper selects the fallback and references missing find_compute/find_fix and compute/fix members. The 12 Nov release-candidate checkout dcbe0b58fccf has the same mismatch. The by-ID accessors also exist on stable_22Jul2025; could we select them by API availability (keeping the fallback only for genuinely older headers) and compile one transition snapshot?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this. In 1e12f26 the helper uses the by-ID accessors whenever the headers provide them. I reproduced the failure on 5f0288a and dcbe0b58fccf, then checked that both affected source files compile against both snapshots with the fix. I also verified that stable_29Sep2021 still selects the legacy lookup.

@codecov

codecov Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.25000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.81%. Comparing base (ed85942) to head (1e12f26).

Files with missing lines Patch % Lines
source/lmp/pair_base.cpp 71.42% 2 Missing ⚠️
source/lmp/lammps_modify_compat.h 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6149      +/-   ##
==========================================
- Coverage   78.09%   77.81%   -0.28%     
==========================================
  Files        1214     1215       +1     
  Lines      147782   147766      -16     
  Branches     5246     5234      -12     
==========================================
- Hits       115410   114988     -422     
- Misses      30392    30797     +405     
- Partials     1980     1981       +1     

☔ 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.

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.

2 participants