Skip to content

Use CMake build of NEP_CPU - #8311

Open
Growl1234 wants to merge 2 commits into
deepmodeling:developfrom
Growl1234:develop
Open

Growl1234 wants to merge 2 commits into
deepmodeling:developfrom
Growl1234:develop

Conversation

@Growl1234

Copy link
Copy Markdown
Collaborator

NEP_CPU package now supports building with CMake.

@Growl1234 Growl1234 added the Compile & CICD & Docs & Dependencies Issues related to compiling ABACUS label Nov 12, 2026
@Growl1234
Growl1234 force-pushed the develop branch 3 times, most recently from ff5a590 to 45e2fc0 Compare November 12, 2026 13:11

@ABACUS-PR-BOT ABACUS-PR-BOT 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 package update needs fixes for legacy-model compatibility, system discovery, and the OpenMP-disabled configuration.

[P2] Update system-package discovery — In toolchain/scripts/stage4/install_nep.sh:64–68, --with-nep=system still probes -lnep and the old header location. The new CMake package installs libnep_cpu and include/NEP_CPU/nep.h, so this branch rejects a valid new installation. Please discover the CMake package or update those probes.

Static review of 43177a4 against 52bc797. Whitespace and pinned governance checks passed, and the dependency archive checksum matched. No configure/build, runtime, or CI checks were run; numerical parity after model conversion remains unverified.

# NEP (Neural Evolution Potential) - CPU version
nep_ver="629ec5d"
nep_sha256="4d4d3c64211a2a39e5d5c795b77befbba987cc809786e0cd6abfa46d0f3bf8cb"
nep_ver="9fc64e5"

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.

[P1] Migrate existing NEP models with the dependency update

This pin makes the existing 101_NEP_HfO2 case terminate during NEP construction: tests/PP_ORB/nep_hfo2.txt starts with nep4_zbl, while the new parser requires nep ... and format_version 1. Please migrate the bundled model with the supported converter and document conversion for existing users, then verify energy, forces and stress against the existing case.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'm not familiar with NEP model itself... @ABACUS-PR-BOT can you propose a patch?

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.

Here is a minimal F1 proposal: convert the bundled HfO2 model with GPUMD's pinned converter, add migration guidance, and register the existing case when ENABLE_NEP=ON. The conversion retains every learned scalar with the required descriptor permutation; INPUT, STRU, and result.ref stay unchanged.

At PR head 43177a4e3d3e04440fb20b68c65754e03bc50a03, run the conversion below from the repository root, then save and apply the accompanying docs/test diff with git apply nep-f1.patch.

Reproducible model conversion
set -eu
work_dir=$(mktemp -d)
curl -fsSL --output "$work_dir/nep_model_converter.py" \
  https://raw.githubusercontent.com/brucefan1983/GPUMD/8db441f006a6b6a7cfc4ad2dc372bec012e802a4/potentials/nep/nep_model_converter.py
printf '%s  %s\n' \
  873798ecdbf3035b7c3a5efeb9a4d2a136bff21e0cf430d0162cef00d12e8318 \
  "$work_dir/nep_model_converter.py" | sha256sum -c -
printf '%s  %s\n' \
  bc341981f74632859b461a6c8fd9bd6b30aa1747f7750ac10fb66eb969ff3d65 \
  tests/PP_ORB/nep_hfo2.txt | sha256sum -c -
cp tests/PP_ORB/nep_hfo2.txt "$work_dir/nep_hfo2.legacy.txt"
python3 "$work_dir/nep_model_converter.py" \
  "$work_dir/nep_hfo2.legacy.txt" "$work_dir/nep_hfo2.converted.txt"
printf '%s  %s\n' \
  1b7ee17832d3ceff83dcd245a1941f2a54ab36e2dded35b71a7a291e2ec0871e \
  "$work_dir/nep_hfo2.converted.txt" | sha256sum -c -
cp "$work_dir/nep_hfo2.converted.txt" tests/PP_ORB/nep_hfo2.txt

The original stays in $work_dir/nep_hfo2.legacy.txt. This converter excludes NEP3/NEP5; other GPUMD families and architectures still need NEP_CPU compatibility checks.

Docs and test-registration patch
diff --git a/docs/advanced/install.md b/docs/advanced/install.md
index 95f219f6594fc758040935e3c21539d01c7f5580..b3cf3142e3655c46b39ebab433f475e21f67f8d8 100644
--- a/docs/advanced/install.md
+++ b/docs/advanced/install.md
@@ -73,6 +73,8 @@ To build ABACUS:
 cmake -B build -DENABLE_NEP=ON
 ```
 
+NEP_CPU requires the new model-file format. See the [NEP model migration instructions](md.md#nep) before using a legacy potential file.
+
 ## Build with LibRI support
 
 The new EXX implementation directly depends on [LibRI](https://github.com/abacusmodeling/LibRI) to provide RI implementation, while LibRI requires two external dependencies: [LibComm](https://github.com/abacusmodeling/LibComm) for inter-process communication, and [cereal](https://github.com/USCiLab/cereal) for serialization. Set `-DENABLE_LIBRI=ON` to build with these libraries.
diff --git a/docs/advanced/md.md b/docs/advanced/md.md
index 47778388bd26f824a31138045e648615fb173860..caaad0beb49058907dfb6d956f8d423274bc6504 100644
--- a/docs/advanced/md.md
+++ b/docs/advanced/md.md
@@ -102,6 +102,28 @@ And the filename of DP model is specified by keyword [pot_file](./input_files/in
 
 If ABACUS is compiled with the Neuroevolution Potential ([NEP](https://gpumd.org/potentials/nep.html)), MD simulations using  NEP models are enabled. To use this feature, set [esolver_type](./input_files/input-main.md#esolver_type) to `nep` and specify the potential file path with the [pot_file](./input_files/input-main.md#pot_file) keyword in your INPUT file.
 
+The toolchain's NEP_CPU revision `9fc64e5` requires model files with
+`format_version 1`. For supported legacy NEP4 files, including ordinary
+`nep4_zbl` models, use GPUMD's
+[model converter](https://github.com/brucefan1983/GPUMD/blob/8db441f006a6b6a7cfc4ad2dc372bec012e802a4/potentials/nep/nep_model_converter.py)
+from commit `8db441f006a6b6a7cfc4ad2dc372bec012e802a4`:
+
+```bash
+python3 /path/to/GPUMD/potentials/nep/nep_model_converter.py old_nep.txt new_nep.txt
+```
+
+Use different input and output paths, then set `pot_file` to `new_nep.txt`.
+Keep the original file for comparison. The converter preserves the learned
+numeric values, reorders descriptor coefficients for the new format, and adds
+zero elemental energy references. Changing only the first line leaves the
+coefficient layout incorrect. Check energy, forces, and stress against the
+original model with the previous library before adopting the converted model.
+
+This converter does not support NEP3 or NEP5. Its other GPUMD model families,
+descriptor sizes, and network architectures are not all supported by NEP_CPU;
+successful conversion alone does not establish CPU compatibility. The bundled
+`tests/04_FF/101_NEP_HfO2` case uses an ordinary, one-hidden-layer NEP4/ZBL model.
+
 ## SNAP
 
 CPU SNAP calculations use `esolver_type snap`, with the coefficient file in
diff --git a/tests/04_FF/101_NEP_HfO2/README b/tests/04_FF/101_NEP_HfO2/README
index 59471a3d63b0c276795f6703af71012e3ed644cd..93106b2cfb0c2d1f52e1a017c15b55918c3640df 100644
--- a/tests/04_FF/101_NEP_HfO2/README
+++ b/tests/04_FF/101_NEP_HfO2/README
@@ -1 +1,18 @@
-This test is for NEP potential in source_esolver
+This test exercises the NEP potential through the MDCell/LAMMPS interface.
+
+The bundled tests/PP_ORB/nep_hfo2.txt was converted from ordinary nep4_zbl
+with GPUMD potentials/nep/nep_model_converter.py at commit
+8db441f006a6b6a7cfc4ad2dc372bec012e802a4. The converter's SHA256 is
+873798ecdbf3035b7c3a5efeb9a4d2a136bff21e0cf430d0162cef00d12e8318.
+The conversion preserves all learned values, the O/Hf model type order,
+the 0.75/1.5 Angstrom ZBL radii and the energy reference. Descriptor
+coefficients are permuted into the format_version 1 type-pair layout.
+INPUT, STRU and result.ref are unchanged.
+
+With ENABLE_NEP=ON, CTest registers 04_FF_NEP_HfO2 using CASES_NEP.txt.
+To run the case directly from tests/04_FF with a NEP-enabled executable:
+
+  OMP_NUM_THREADS=1 bash ../integrate/Autotest.sh -a /path/to/abacus -n 1 -o 1 -j 1 -f CASES_NEP.txt -r '^101_NEP_HfO2$'
+
+The force and stress reference properties are sums of absolute components;
+componentwise comparisons are also needed when validating a model migration.
diff --git a/tests/04_FF/CASES_NEP.txt b/tests/04_FF/CASES_NEP.txt
new file mode 100644
index 0000000000000000000000000000000000000000..97249be36b9bcd95489bf14fc780c2ff23433774
--- /dev/null
+++ b/tests/04_FF/CASES_NEP.txt
@@ -0,0 +1 @@
+101_NEP_HfO2
diff --git a/tests/04_FF/CMakeLists.txt b/tests/04_FF/CMakeLists.txt
index 3041d6d389e7edbbfca4b8fbb9c3601764ce86bb..1ffbc802c05f0b83e9879aeeb614a24ec3a99b36 100644
--- a/tests/04_FF/CMakeLists.txt
+++ b/tests/04_FF/CMakeLists.txt
@@ -12,3 +12,18 @@ else()
     COMMAND ${BASH} ../integrate/Autotest.sh -a ${ABACUS_BIN_PATH} -n 4 -j auto
     WORKING_DIRECTORY ${ABACUS_TEST_DIR}/04_FF)
 endif()
+
+if(ENABLE_NEP)
+  set(nep_sanitize false)
+  if(ENABLE_ASAN)
+    set(nep_sanitize true)
+  endif()
+  add_test(
+    NAME 04_FF_NEP_HfO2
+    COMMAND ${BASH} ../integrate/Autotest.sh -a ${ABACUS_BIN_PATH}
+            -n 1 -o 1 -j 1 -s ${nep_sanitize}
+            -f ${ABACUS_TEST_DIR}/04_FF/CASES_NEP.txt -r "^101_NEP_HfO2$"
+    WORKING_DIRECTORY ${ABACUS_TEST_DIR}/04_FF)
+  # The integration runner shares test.sum and sanitizer output with 04_FF.
+  set_tests_properties(04_FF_NEP_HfO2 PROPERTIES RUN_SERIAL TRUE ENVIRONMENT "OMP_NUM_THREADS=1")
+endif()

Verification: an independent inverse/token audit confirmed preservation of all 2,471 learned/scaler values. Analytic, single-thread native builds of NEP_CPU 629ec5d and 9fc64e5 passed componentwise energy/force/virial comparisons through both compute and compute_for_lammps on 12 geometries (including distorted bulk and ZBL-active pairs), plus coordinate/strain finite-difference checks over 49 geometries under the fixed pre-run bounds (native component comparisons: 2e-10 + 2e-10 * abs(reference)). CMake ON/OFF/ASAN registration checks, governance, and whitespace checks passed. ABACUS integration and ASAN runtime remain unverified: both full configurations stopped at missing ELPA, and both MPI NEP-only configurations stopped at missing ScaLAPACK. Before adopting this proposal, run the unchanged HfO2 case with base/old-library and proposal/new-library executables at 1 and 2 MPI ranks (OMP_NUM_THREADS=1), retain signed componentwise outputs, and keep the existing reference and tolerances.

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 headers at 5d7645a now match format v1, but the numeric payload is still in legacy order. The new evaluator expects [type_pair,n,k] instead of [n,k,type_pair], so 516 of 520 descriptor coefficients feed different terms. For O–O n=0,k=1, it reads -2.2940616e-01 instead of 2.8657326e-01.

Use the pinned converter in the earlier proposal. The current header-edited file is no longer a legacy NEP4 input, so replace that procedure’s current-file checksum/copy steps with:

git show 43177a4e3d3e04440fb20b68c65754e03bc50a03:tests/PP_ORB/nep_hfo2.txt > "$work_dir/nep_hfo2.legacy.txt"
printf '%s  %s\n' \
  bc341981f74632859b461a6c8fd9bd6b30aa1747f7750ac10fb66eb969ff3d65 \
  "$work_dir/nep_hfo2.legacy.txt" | sha256sum -c -

Then continue with the converter and output-check/install steps already listed there. This is static source/token revalidation; the current model has not been numerically evaluated.

Comment thread CMakeLists.txt Resolved
Comment thread cmake/CollectBuildInfoVars.cmake Resolved
@ZhouXY-PKU

Copy link
Copy Markdown
Collaborator

We need to make sure that the new NEP version can run on DSP, so please do not merge now.

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

Request changes: the NEP_CPU package-discovery contract and bundled-model migration still need to be completed. Please also finish the requested DSP validation before merging.

Comment thread CMakeLists.txt
if(DEFINED NEP_DIR)
find_package(NEP REQUIRED)
if(ENABLE_NEP)
find_package(NEP_CPU CONFIG REQUIRED)

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 update the supported Toolchain discovery paths together with this CMake package migration. The installer still probes the legacy -lnep/nep.h layout, while this consumer now requires the NEP_CPU CMake package. Please make --with-nep=system and custom prefixes locate/export NEP_CPUConfig.cmake, or explicitly narrow the supported installation modes.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

That is a tricky one. It's unlikely that one can easily validate the CMake build through one or two lines of Bash logic. Maybe a helper helps, but I'm reluctant to do so as it adds complexity.

Comment thread tests/PP_ORB/nep_hfo2.txt
@@ -1,10 +1,14 @@
nep4_zbl 2 O Hf
nep 2 O Hf

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 validate the complete model migration, not only the header rewrite. This NEP_CPU revision requires a new model format, but the diff does not show descriptor-coefficient conversion or a NEP-specific regression. Please convert the bundled model and compare energy, force, and virial results before merging.

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

Compile & CICD & Docs & Dependencies Issues related to compiling ABACUS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants