Skip to content

fix(lmp): clear DPLR PPPM force cache#5744

Merged
njzjz merged 1 commit into
deepmodeling:masterfrom
Yi-FanLi:fix/lmp-dplr-clear-fele
Jul 7, 2026
Merged

fix(lmp): clear DPLR PPPM force cache#5744
njzjz merged 1 commit into
deepmodeling:masterfrom
Yi-FanLi:fix/lmp-dplr-clear-fele

Conversation

@Yi-FanLi

@Yi-FanLi Yi-FanLi commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add a small helper to resize and zero the DPLR PPPM fele cache
  • clear fele before returning from PPPMDPLR::compute when qsqsum == 0
  • reuse the same helper in init and fieldforce paths

This addresses #5647 as a defensive consistency fix. In normal DeePMD DPLR usage, atom charges are fixed and are not changed from nonzero to all-zero during a run, so this stale-cache path should not be triggered by standard DeePMD workflows. It would only matter for unusual external charge mutation or reinitialization paths where qsqsum is refreshed to zero after a previous nonzero-charge PPPM/DPLR step.

Tests

  • git diff --check
  • /tmp/deepmd-check-venv/bin/ruff check .
  • /tmp/deepmd-check-venv/bin/ruff format --check .

Summary by CodeRabbit

  • Bug Fixes

    • Improved consistency in per-atom field/force handling by clearing the accumulator before early exits and during setup.
    • Reduced the chance of stale values carrying over between calculations.
  • Refactor

    • Consolidated repeated zeroing and resizing steps into a shared internal routine, simplifying the calculation flow and making the code easier to maintain.

@dosubot dosubot Bot added the bug label Jul 6, 2026
@github-actions github-actions Bot added the LAMMPS label Jul 6, 2026
@Yi-FanLi
Yi-FanLi requested a review from njzjz July 6, 2026 17:26
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Introduces a private clear_fele() method in PPPMDPLR that resizes and zero-fills the fele accumulator. Replaces duplicated inline resize/zero logic in init(), fieldforce_ik(), and fieldforce_ad() with calls to this helper, and adds a call to it in compute()'s early-return path when qsqsum == 0.0.

Changes

fele Clearing Refactor

Layer / File(s) Summary
clear_fele helper declaration and definition
source/lmp/pppm_dplr.h, source/lmp/pppm_dplr.cpp
Adds a private clear_fele() declaration to the class and implements it to resize fele to atom->nlocal * 3 and zero-fill it.
Wiring clear_fele into init, compute, and fieldforce paths
source/lmp/pppm_dplr.cpp
Replaces inline resize/zero logic with clear_fele() calls in init(), fieldforce_ik(), and fieldforce_ad(), and adds a clear_fele() call in compute()'s qsqsum == 0.0 early-return path.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Compute as PPPMDPLR::compute
  participant Init as PPPMDPLR::init
  participant FieldforceIK as PPPMDPLR::fieldforce_ik
  participant FieldforceAD as PPPMDPLR::fieldforce_ad
  participant ClearFele as PPPMDPLR::clear_fele

  Init->>ClearFele: reset fele buffer
  Compute->>ClearFele: reset fele on qsqsum == 0.0
  FieldforceIK->>ClearFele: reset fele buffer
  FieldforceAD->>ClearFele: reset fele buffer
  ClearFele->>ClearFele: resize fele to nlocal*3 and fill with 0.0
Loading

Possibly related issues

Suggested reviewers: njzjz

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: clearing the DPLR PPPM force cache.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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

🧹 Nitpick comments (1)
source/lmp/pppm_dplr.cpp (1)

51-55: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Optional: use assign instead of resize + fill.

fele.assign(static_cast<size_t>(nlocal) * 3, 0.0); achieves the same result in one call.

♻️ Optional simplification
 void PPPMDPLR::clear_fele() {
   int nlocal = atom->nlocal;
-  fele.resize(static_cast<size_t>(nlocal) * 3);
-  fill(fele.begin(), fele.end(), 0.0);
+  fele.assign(static_cast<size_t>(nlocal) * 3, 0.0);
 }
🤖 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/pppm_dplr.cpp` around lines 51 - 55, The clear_fele() method in
PPPMDPLR currently resizes fele and then fills it with zeros in two steps;
simplify this by using fele.assign(static_cast<size_t>(nlocal) * 3, 0.0) to
initialize the buffer in one call. Keep the behavior the same and update only
the fele initialization logic inside PPPMDPLR::clear_fele().
🤖 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.

Nitpick comments:
In `@source/lmp/pppm_dplr.cpp`:
- Around line 51-55: The clear_fele() method in PPPMDPLR currently resizes fele
and then fills it with zeros in two steps; simplify this by using
fele.assign(static_cast<size_t>(nlocal) * 3, 0.0) to initialize the buffer in
one call. Keep the behavior the same and update only the fele initialization
logic inside PPPMDPLR::clear_fele().

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 585df065-3b96-4ee5-ba19-0facf93c76a9

📥 Commits

Reviewing files that changed from the base of the PR and between 3d73c67 and 0a487fc.

📒 Files selected for processing (2)
  • source/lmp/pppm_dplr.cpp
  • source/lmp/pppm_dplr.h

@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.22%. Comparing base (3d73c67) to head (0a487fc).

Files with missing lines Patch % Lines
source/lmp/pppm_dplr.cpp 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5744      +/-   ##
==========================================
- Coverage   81.36%   81.22%   -0.14%     
==========================================
  Files         991      991              
  Lines      111198   111200       +2     
  Branches     4235     4234       -1     
==========================================
- Hits        90474    90324     -150     
- Misses      19199    19349     +150     
- Partials     1525     1527       +2     

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

@njzjz njzjz linked an issue Jul 7, 2026 that may be closed by this pull request
@njzjz
njzjz added this pull request to the merge queue Jul 7, 2026
Merged via the queue into deepmodeling:master with commit 33593b1 Jul 7, 2026
60 checks passed
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.

[Code scan] Clear pppm/dplr electric forces when charges vanish

2 participants