Repository navigation
feat(lammps): support Cartesian native-spin magnetic forces - #6084
Conversation
Preserve the default precession convention and expose Cartesian -dE/dS for native-spin integrators. Replace algebra-only checks with mandatory LAMMPS adapter finite differences, zero/tiny-moment, scaling and parser regressions. Scope the PyTorch CPU SIMD workaround to the test fixture. Based on the implementation in deepmodeling#6078. Co-authored-by: OutisLi-Bot <44916828+OutisLi-Bot@users.noreply.github.com>
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
Add a separate compressed canonical fixture and explicit /kk integration coverage for zero, tiny and finite moments, one/two MPI ranks, scaling and overlay accumulation. Build matching CUDA Kokkos LAMMPS/plugin in the opt-in CUDA job and require all test prerequisites. Keep the repository's one-shot CUDA label trigger unchanged. GPU runtime and finite-difference acceptance remain for the CUDA runner.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6084 +/- ##
==========================================
+ Coverage 77.79% 77.83% +0.03%
==========================================
Files 1171 1171
Lines 141562 141607 +45
Branches 5066 5078 +12
==========================================
+ Hits 110135 110214 +79
+ Misses 29550 29455 -95
- Partials 1877 1938 +61 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
njzjz-bot
left a comment
There was a problem hiding this comment.
Agent: dot
Source review LGTM for exact head aa3bb2928546b0bdd09a8f78e89df4d21cbd9fb2.
I rechecked the host/Kokkos convention selection and accumulation, default-precession compatibility, Cartesian metal-unit restriction, scalar extraction, host plugin registration, and the regression/CI integration. I found no remaining actionable defect in this scope. The delta from 210536990c3df8444da4296908d20e9cdcbd4f32 adds only the 22-line model-independent plugin-registration test; production code and workflows are unchanged. Four exact-test control-flow checks with doubles cover automatic/explicit loading, missing-style failure, quoted paths and context cleanup.
Validation scope:
- The actual CUDA run succeeded on
210536990c3df8444da4296908d20e9cdcbd4f32: all 6 dedicated Kokkos tests passed with 0 skips, including genuine two-rank MPI; ordinary LAMMPS 295 passed/24 skipped; i-PI 8 passed; CUDA Python 14,070 passed/8,709 skipped. These are CI executions, not local GPU runs by this review. - That evidence remains attributed to the earlier SHA. At this submission, current-head C++ and Python tests are still running; the current CUDA workflow's actual C++/Python jobs are skipped.
- Local checks of the latest test used doubles, not a real LAMMPS runtime. No new GPU finite-difference, GPU mutation, CUDA-aware-MPI or large-system communication-stress validation is claimed.
This is source approval; the remaining current-head checks still need to complete.
iProzd
left a comment
There was a problem hiding this comment.
Reviewed the exact head and the LAMMPS stable communication contract. AtomVecSpin already reverse-communicates fm/fm_long for the host path; the pair-specific comm_reverse=6 is correctly confined to the Kokkos device path. Cartesian scaling, unit validation, extraction, host/plugin coverage, and one-/two-rank Kokkos tests are covered. All current checks are green; I found no blocking issue.
Summary
Implements #6077, fixes #6075, and supersedes #6078. This revision builds on the original implementation by @OutisLi-Bot (credited in the commit), rebases it onto current master, and replaces the weak/optional regression checks with tests of the actual LAMMPS adapter.
magnetic_force precessionremains the default and preserves the existing moment/hbarconversion.magnetic_force cartesianstores-dE/dSwith the energy-per-model-spin conversion, including zero moments; currently requiresunits metal.Pair::extract("fm_cartesian_force", dim)exposes a scalar integer (dim == 0, precession = 0, Cartesian = 1).Regression coverage and CI repair
The model-independent
test_lammps_plugin.pychecks unsuffixeddpa4spinavailability without loading a model or gating on an inference backend. It supports the CILAMMPS_PLUGIN_PATHautoload path and explicitDEEPMD_TEST_PLUGINloading. The host factory and registration are outsideLMP_KOKKOS; this closes #6075 without changing magnetic-force conventions or Kokkos aliases.The new adapter tests check all three Cartesian components against energy finite differences at zero, tiny (
1e-8), and finite moments; default/explicit precession equivalence; nonmagnetic atoms; unchanged mechanical force/energy; pair scaling and repeated compute; extraction; invalid/missing/duplicate options; and non-metal rejection. PyTorch-enabled LAMMPS CI explicitly requires the model fixture, bindings, and plugin registration instead of silently skipping them.The previous C++ CI failure was reproduced with PyTorch 2.11 and
OMP_NUM_THREADS=1: CPU SIMD gather codegen references an undeclaredtmp42. Disabling loop-tail vectorization still fails. A scopedcpp.simdlen=1context around this small test-fixture export only avoids the defect. Production export settings and CUDA device selection are unchanged, and the setting is restored afterward.CUDA Kokkos regression
The CUDA C++ job uses the same Python-prefix MPICH distribution for mpi4py, DeePMD, LAMMPS, plugins, and launcher. Ubuntu 24.04's MPICH package can start independent singleton worlds (upstream report); avoiding it also removes its leaked host-LTO compiler flags, so the earlier job-local NVCC workaround is no longer needed. An early two-rank probe checks communicator size, rank gathering, and actual MPI library paths before the long model/build stages. The integration runner also checks the requested rank count against both mpi4py and native LAMMPS.
The CUDA job now separately builds matching Kokkos-enabled LAMMPS and plugin libraries, exports a compressed float32 canonical native-spin archive, and runs explicit
atom_style spin/kk,pair_style dpa4spin/kk, andrun_style verlet/kkwith Kokkos enabled. The required test mode fails on missing CUDA, MPI, fixture, or plugin prerequisites. The ordinary host test suite does not silently substitute for this test.The new regression compares the same canonical archive through the host adapter and one-/two-rank GPU adapters: all atom-ID-ordered magnetic forces, mechanical forces, and total energy; convention extraction; default/explicit precession; zero, tiny, and finite moments; repeated compute, pair scaling, and two-style hybrid/overlay accumulation. The two-rank system has interacting atoms on both sides of its domain boundary. Tiny-moment precession is normalized before comparison, and a live zero-moment Cartesian gradient makes a forced-precession kernel fail. Communication is host-staged, so this does not require or claim CUDA-aware MPI coverage.
Validation
stable_22Jul2025_update2built with SPIN/KSPACE/EXTRA-FIX/MOLECULE/PLUGIN.pytest -q source/lmp/tests/test_dpa4spin_magnetic_force_convention.py: 10 passed, using the default generated artifact and mandatory-test mode; independently rerun.hybrid/overlaycontributions add correctly in both conventions.c985896e.21053699, the actual C++ CUDA job passed: the unified MPICH 5.0.2 two-rank/library-path preflight; CUDA Kokkos LAMMPS/plugin build and canonical fixture export; all 6/kkintegration tests, covering zero/tiny/finite moments, genuine one-/two-rank convention comparisons, and overlay accumulation; all C++ ctests; the ordinary LAMMPS suite (295 passed, 24 skipped); and i-PI (8 passed). The runner explicitly verifiesverlet/kkand both mpi4py/native-LAMMPS rank counts.21053699: 14,070 passed, 8,709 skipped (5:01:19).21053699: 54 successful, 2 skipped (the PyPI publishing jobs), with no failed or pending checks. One unchanged CPU LMDB training test initially failed with an already-open-environment error; rerunning only that failed job succeeded, without code changes or restarting CUDA jobs.git diff --checkpassed.Model-independent registration validation (
aa3bb292)ALLOW_NO_BACKEND=ON, all inference backends disabled) and matching LAMMPSstable_22Jul2025_update2builds passed the new test both without Kokkos and with Kokkos Serial. Explicit plugin loading and CI-style autoloading each passed in fresh Python processes, with no model fixture./kkaliases were available.git diff --checkpassed. This follow-up adds only the standalone regression test; production code and CI workflows are unchanged. No new CUDA run or full-CI result is claimed for this test-only commit.Coverage limits
This development environment has no GPU and cannot run two-rank communication; the real one-/two-rank CUDA Kokkos validation above was executed in GitHub CI on
21053699. GPU energy finite differences are not claimed by the new adapter-equivalence tests, and no actual GPU mutation run is claimed. Communication is host-staged rather than CUDA-aware MPI. The six-atom MPI regression is not a large-system communication-buffer stress test. The full GPU Python suite and the remaining CPU/static checks also passed on21053699.Fixes #6077
Fixes #6075
Summary by CodeRabbit
dpa4spinhost and Kokkos pair styles support an optionalmagnetic_force cartesiansetting, which uses the raw energy gradient with respect to spin. Cartesian mode requiresunits metal; precession remains the default.fm_cartesian_forceextraction value.dpa4spinpair style is available as a LAMMPS runtime plugin.