Skip to content

fix(lammps): tally the global virial in deepmd/kk - #6153

Open
Miller10101010 wants to merge 3 commits into
deepmodeling:masterfrom
Miller10101010:fix-kokkos-global-virial
Open

Miller10101010 wants to merge 3 commits into
deepmodeling:masterfrom
Miller10101010:fix-kokkos-global-virial

Conversation

@Miller10101010

@Miller10101010 Miller10101010 commented Nov 24, 2026 •

Copy link
Copy Markdown

Kokkos can request a global virial through the force–position tally when Newton pair is enabled. Tell LAMMPS that this style tallies the model virial explicitly so that thermo pressure uses the model output.

Compared deepmd/kk with deepmd on the same DPA4 configuration on an NVIDIA A800. Energy and diagonal pressure agreed for Newton on/off, with and without per-atom stress output (eight runs across both pair styles).

Closes #5983.

Summary by CodeRabbit

  • Bug Fixes
    • Virial calculations for FDOTR requests now use explicit model-virial tallying, aligning reported virial values with the selected calculation method.
  • Tests
    • Added regression coverage for pressure calculations across Kokkos settings, helping verify results against the standard calculation method.

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The PairDeepMDKokkos constructor sets no_virial_fdotr_compute to 1. An opt-in regression test compares Kokkos pressure with the regular deepmd reference across Newton and per-atom-stress settings.

Changes: Kokkos virial tally

Layer / File(s) Summary
Set the FDOTR virial flag
source/lmp/pair_deepmd_kokkos.cpp
The constructor sets no_virial_fdotr_compute to 1.
Run Kokkos pressure comparisons
source/lmp/tests/test_kokkos_pressure.py, source/install/test_lammps_kokkos.sh
The opt-in test compares pressure components from deepmd/kk with the deepmd reference for Newton on/off and per-atom stress disabled/enabled. The Kokkos test script adds the test to its first pytest session.

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: wanghan-iapcm

Merge Risk: Minimal · up to 8f186

This change makes pair_style deepmd/kk report the model's global virial so thermo pressure matches the regular deepmd style. It is a one-line, easily reverted constructor change with a regression test covering both Newton settings and per-atom stress. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title 'fix(lammps): tally the global virial in deepmd/kk' matches the main change. The raw summary says the PairDeepMDKokkos constructor now sets no_virial_fdotr_compute to 1, so the global virial…
Linked Issues check Passed [#5983] requires correct global virial and thermo pressure for pair_style deepmd/kk with a DPA4 pt_expt model, matching the non-Kokkos deepmd path. The reported cause is that the explicit global-viria…
Out of Scope Changes check Passed The whole-PR change set has three files. The constructor change in source/lmp/pair_deepmd_kokkos.cpp (+2/-0) directly implements the global-virial objective of [#5983]. The one-line addition in source…
Full details: Title check

Explanation

The title 'fix(lammps): tally the global virial in deepmd/kk' matches the main change. The raw summary says the PairDeepMDKokkos constructor now sets no_virial_fdotr_compute to 1, so the global virial is tallied explicitly from the model output. The objectives confirm this addresses linked issue #5983, where deepmd/kk did not populate the global virial used for thermo pressure. The title is specific and identifies the primary fix. The test additions are secondary and need not appear in the title.

Full details: Linked Issues check

Explanation

[#5983] requires correct global virial and thermo pressure for pair_style deepmd/kk with a DPA4 pt_expt model, matching the non-Kokkos deepmd path. The reported cause is that the explicit global-virial reduction in source/lmp/pair_deepmd_kokkos.cpp runs only under vflag_global, which stays 0 when LAMMPS uses the force-position (FDOTR) tally. The whole-PR diff (merge base to head) adds no_virial_fdotr_compute = 1; with a comment in the PairDeepMDKokkos constructor. This makes LAMMPS request the explicit tally, so the existing vflag_global reduction fills virial[] used by thermo pressure. Per-atom virial code is unchanged. The change since the previous reviewed head adds only the regression test file source/lmp/tests/test_kokkos_pressure.py and its registration in source/install/test_lammps_kokkos.sh. That test compares deepmd/kk pressure with deepmd for Newton on/off and per-atom stress on/off, which covers the automated-test part of the issue. The eight-run A800 comparison in the PR description is author-reported and was not re-run here. The test skips unless DPA4SPIN_KOKKOS_REQUIRED=1 and lmp is present, so its pass status depends on the CUDA Kokkos environment.

Full details: Out of Scope Changes check

Explanation

The whole-PR change set has three files. The constructor change in source/lmp/pair_deepmd_kokkos.cpp (+2/-0) directly implements the global-virial objective of [#5983]. The one-line addition in source/install/test_lammps_kokkos.sh registers the new pressure test in the Kokkos test run. The new file source/lmp/tests/test_kokkos_pressure.py (+87) is a regression test for the same objective. No unrelated change was found.

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: 0c7e67fd-5655-48e0-a950-11780d5ff838
Commits

Reviewing files that changed from the base of the PR and between 209b8d1 and 8f18664.

Files selected for processing: 2

  • source/install/test_lammps_kokkos.sh
  • source/lmp/tests/test_kokkos_pressure.py

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

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

The FDOTR flag is the right fix. Please pin the pressure that the integrator actually sees with a regression test.

reverse_used_host(false) {
respa_enable = 0;
// This style tallies the model virial explicitly, also for FDOTR requests.
no_virial_fdotr_compute = 1;

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.

Please add a Newton-pair-on pressure regression to the CUDA Kokkos suite. Use zero velocities and a geometry with nonzero model stress, then compare the six thermo pressure components against ordinary deepmd or a model oracle. Cover a pure global-pressure request and a request that also needs per-atom virial; a Newton-off control would retain the existing behavior. The test should fail before this change and pass with it. The reported A800 run is useful, but without a regression this silent failure can return in NPT.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated in c29de72.

Added a CUDA Kokkos regression that compares all six thermo pressure components to ordinary deepmd at zero velocity. It covers Newton pair on and off, with both a global-only request and a simultaneous per-atom centroid virial request. On an AISI A800 the regression passed with the fix. As a negative control, the adapter without the fix returned zero for all six components under Newton on; the reference included pxx = −2.644664 and pyy = 11.162216 bar.

@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6153      +/-   ##
==========================================
- Coverage   78.09%   77.85%   -0.24%     
==========================================
  Files        1214     1214              
  Lines      147782   147782              
  Branches     5246     5246              
==========================================
- Hits       115410   115059     -351     
- Misses      30392    30744     +352     
+ Partials     1980     1979       -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.

@OutisLi
OutisLi self-requested a review November 26, 2026 01:28

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.

pair_style deepmd/kk does not populate global virial / thermo pressure for a DPA4 pt_expt model

2 participants