Skip to content

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

Open

Description

@BDxka

Bug summary

When using a converted DPA4 pt_expt model with LAMMPS, pair_style deepmd/kk produces correct per-atom virials but fails to populate the global virial used by LAMMPS thermo pressure. As a result, Press, Pxx, Pyy, and Pzz contain only the kinetic contribution; at zero velocity they are exactly zero.
The same structure and model work correctly with the non-Kokkos path, pair_style deepmd.
This is important for NPT simulations: the barostat receives an incorrect pressure signal, which can cause unphysical cell evolution.

DeePMD-kit Version

Source checkout at commit 14a71f1

Backend and its version

PyTorch 2.11.0+cu126 (CUDA 12.6)

How did you download the software?

Built from source

Input Files, Running Commands, Error Log, etc.

Environment

  • LAMMPS: patch_4Jul2026 (LAMMPS (4 Jul 2026))

  • GPU: NVIDIA A40

  • CUDA: 12.6

  • DeePMD-kit was built from source at commit 14a71f13.

  • The DPA4 model was converted with:

    dp convert-backend --atomic-virial DPA4-Pro-MPtrj.pt DPA4-Pro-converted.pt2

Minimal test

The same relaxed alpha-quartz SiO2 structure was evaluated with zero velocities and run 0.
Input:

read_data quartz_dpa_relaxed.lmp
mass 1 28.0855
mass 2 15.9994
pair_style deepmd/kk DPA4-Pro-converted.pt2
pair_coeff * * Si O
compute stress all centroid/stress/atom NULL virial
thermo_style custom step temp press pxx pyy pzz
run 0

Observed behavior

With pair_style deepmd/kk, thermo output is exactly zero at zero velocity:
Press = 0
Pxx = 0
Pyy = 0
Pzz = 0

However, compute centroid/stress/atom returns nonzero per-atom virials. Their sum agrees with an independent ASE stress calculation within approximately 0.1%.
For the same structure and converted model, replacing only:
pair_style deepmd/kk DPA4-Pro-converted.pt2
with:
pair_style deepmd DPA4-Pro-converted.pt2
produces nonzero thermo pressure/stress consistent with both ASE and the summed per-atom virial.
Therefore, the issue appears specific to the Kokkos path.

Steps to Reproduce

  1. Convert a DPA4-Pro-MPtrj checkpoint to pt_expt format with:
    dp convert-backend --atomic-virial DPA4-Pro-MPtrj.pt DPA4-Pro-converted.pt2
  2. Build LAMMPS with Kokkos/CUDA support against this DeePMD-kit checkout.
  3. Run the input below (relaxed alpha-quartz SiO2, 72 atoms) with
    pair_style deepmd/kk, using:
    lmp -k on g 1 -sf kk -pk kokkos newton on neigh half -in in.lammps
  4. Observe that thermo Press/Pxx/Pyy/Pzz are exactly zero, while
    compute centroid/stress/atom still gives correct nonzero per-atom
    virials (summed, they agree with an independent ASE calculation
    within ~0.1%).
  5. Repeat step 3 with pair_style deepmd (no /kk) instead, changing
    nothing else. Thermo pressure/stress becomes correct and nonzero.

Further Information, Files, and Links

Source-level observation:

  • source/lmp/pair_deepmd.cpp performs the explicit global-virial reduction under if (vflag).
  • source/lmp/pair_deepmd_kokkos.cpp performs the corresponding reduction under if (vflag_global).
    In the failing reproduction, vflag is nonzero (10 when the per-atom virial compute is requested), whereas vflag_global = 0. Therefore, the explicit Kokkos reduction is skipped. The per-atom virial buffer is nevertheless nonzero and agrees with the non-Kokkos result; the LAMMPS global virial[] / thermo pressure remains zero.
    I have attached a zip archive containing the minimal structure, the two LAMMPS input files, the two comparison logs, and a README. The converted model is not included because it is large; it can be regenerated from the DPA4-Pro-MPtrj checkpoint using the conversion command given above.
    The DEBUG_VFLAG lines in the attached logs were added locally for diagnosis and are not part of the upstream DeePMD-kit output.

deepmd_kk_virial_bug_report.zip

Activity

  1. dosubot commented on Aug 20, 2026

    @dosubot

    Hi @BDxka! I'm Dosu and I'm helping the DeepModeling team.

    Your diagnosis is spot-on. The root cause is a guard mismatch between the two pair styles:

    • pair_deepmd.cpp accumulates the global virial under if (vflag) — the raw bitmask that is nonzero whenever any virial (global or per-atom) is requested [1].
    • pair_deepmd_kokkos.cpp guards the same reduction with if (vflag_global), which is only set when the global virial is explicitly requested [2].

    Both paths call ev_init(eflag, vflag), which derives vflag_global, vflag_atom, and cvflag_atom from the raw vflag bitmask. In your scenario, adding compute centroid/stress/atom sets cvflag_atom = 1 and makes vflag nonzero, but vflag_global can remain 0 depending on how LAMMPS's implicit pressure compute propagates back through the Kokkos pair path. The non-Kokkos path works because if (vflag) catches this case; the Kokkos path's narrower if (vflag_global) does not, so the virial[] array stays zeroed and thermo pressure reports only the kinetic contribution.

    The pair_deepmd_kokkos.cpp file was introduced in PR #5758, so this code path is quite new and this edge case likely wasn't caught.

    Suggested fix: change the Kokkos guard to match the non-Kokkos behaviour:

    // Before
    if (vflag_global) {
    
    // After
    if (vflag_either) {   // or simply: if (vflag)

    vflag_either is the idiomatic LAMMPS choice (true when either global or per-atom virial is needed). The extra work of reducing the global virial when only per-atom is requested is negligible next to model inference cost.

    Would you be able to test that one-line change locally and confirm it resolves the issue? That would strengthen a fix PR.

    To reply, just mention @dosu.


    Share context across your team and agents. Try Dosu.

    Leave Feedback Learn about deepmd-kit with Dosu Add Dosu to your team

  2. BDxka commented on Aug 20, 2026

    @BDxka
    Author

    I tested the suggested change locally.

    I changed the guard in source/lmp/pair_deepmd_kokkos.cpp from:
    if (vflag_global)
    to:
    if (vflag_either)

    After an incremental rebuild and reinstall of LAMMPS, the same pair_style deepmd/kk reproduction case now reports nonzero global thermo stress:
    Press = 159.18387 bar
    Pxx = 232.23730 bar
    Pyy = 231.30624 bar
    Pzz = 14.00809 bar

    The summed per-atom centroid virial remains unchanged and agrees with the previous non-Kokkos result. This resolves the issue in my test case. Thank you.

  3. njzjz-bot commented on Sep 26, 2026

    @njzjz-bot
    Contributor

    Thanks for testing and confirming the guard change. That is strong evidence that the Kokkos path should use vflag_either here rather than vflag_global.

    We should carry this as a code fix in source/lmp/pair_deepmd_kokkos.cpp and add a regression test that covers global thermo pressure together with per-atom/centroid virial requests, so the Kokkos and non-Kokkos paths cannot diverge again.

    Agent: ChatGPT
    Model: GPT-5.6 Sol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions