Skip to content

fix(lmp): avoid double qe2f in DPLR efield#5732

Merged
njzjz merged 1 commit into
deepmodeling:masterfrom
Yi-FanLi:fix/lmp-dplr-efield-qe2f
Jul 4, 2026
Merged

fix(lmp): avoid double qe2f in DPLR efield#5732
njzjz merged 1 commit into
deepmodeling:masterfrom
Yi-FanLi:fix/lmp-dplr-efield-qe2f

Conversation

@Yi-FanLi

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

Copy link
Copy Markdown
Collaborator

Summary

  • remove the second qe2f multiplication when forming fix dplr efield forces
  • keep the existing conversion when storing constant and equal-style efield values
  • add real-unit regressions for constant and equal-style efield paths so qe2f != 1 is covered

Closes #5646.

Tests

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

Not run

  • Targeted LAMMPS DPLR pytest tests could not run in the local ad hoc venv: the lammps Python module is not installed there, and pytest startup segfaulted in the temporary environment before collection.

Summary by CodeRabbit

  • Bug Fixes

    • Corrected electric-field force calculations so results are accumulated consistently in real-unit simulations.
    • Fixed related force and virial contributions to match expected values.
  • Tests

    • Added coverage for electric-field behavior in real units.
    • Included checks for both constant and variable field settings to confirm force results remain accurate.

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

coderabbitai Bot commented Jul 4, 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: 77791842-bad2-4b67-8cc7-f52c08a4a7b1

📥 Commits

Reviewing files that changed from the base of the PR and between c1b9de1 and fb65689.

📒 Files selected for processing (2)
  • source/lmp/fix_dplr.cpp
  • source/lmp/tests/test_dplr.py

📝 Walkthrough

Walkthrough

The PR removes a redundant force->qe2f multiplication in FixDPLR::post_force when computing the electric-field force term, fixing double-scaling of qe2f. It also adds a lammps_real fixture and two new tests validating DPLR efield behavior under real units.

Changes

DPLR efield qe2f fix

Layer / File(s) Summary
Remove duplicate qe2f multiplication
source/lmp/fix_dplr.cpp
tmpf[dd] now uses q[ii] * efield[dd] directly instead of applying force->qe2f twice, correcting the scaling of efield force, dfele, efield_fsum, and virial contributions.
Real-units regression tests
source/lmp/tests/test_dplr.py
Adds lammps_real fixture using units="real" and two tests (test_pair_deepmd_lr_efield_constant_real, test_pair_deepmd_lr_efield_variable_real) asserting forces match expected_e_efield_constant scaled by constants.ener_metal2real for constant and variable efield configurations.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: Python, LAMMPS

Suggested reviewers: njzjz, wanghan-iapcm, iProzd

🚥 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 summarizes the main fix: preventing double application of qe2f in DPLR efield forces.
Linked Issues check ✅ Passed The code and tests address the linked issue by applying qe2f once and adding regression coverage for constant and equal-style efield cases.
Out of Scope Changes check ✅ Passed The changes stay focused on the qe2f DPLR efield fix and its regression tests, with no obvious unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

@njzjz njzjz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@njzjz njzjz enabled auto-merge July 4, 2026 14:33
@codecov

codecov Bot commented Jul 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.16%. Comparing base (c1b9de1) to head (fb65689).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5732      +/-   ##
==========================================
- Coverage   81.29%   81.16%   -0.13%     
==========================================
  Files         988      988              
  Lines      110897   110897              
  Branches     4234     4236       +2     
==========================================
- Hits        90151    90009     -142     
- Misses      19220    19360     +140     
- Partials     1526     1528       +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 added this pull request to the merge queue Jul 4, 2026
Merged via the queue into deepmodeling:master with commit ffe57a3 Jul 4, 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] Apply qe2f only once in fix dplr efield forces

2 participants