From c0b71f06589307b745cd2efae91cf0829ad89b64 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 4 Aug 2025 00:01:27 +0800 Subject: [PATCH 01/36] chore: bump LAMMPS to stable_22Jul2025 --- .devcontainer/build_cxx.sh | 2 +- doc/install/install-lammps.md | 22 +++++++++++----------- pyproject.toml | 6 +++--- source/install/build_cc.sh | 2 +- source/install/build_from_c.sh | 2 +- source/install/build_lammps.sh | 2 +- source/install/test_cc.sh | 2 +- source/install/test_cc_local.sh | 2 +- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/.devcontainer/build_cxx.sh b/.devcontainer/build_cxx.sh index 007c99b9e5..432d7d32db 100755 --- a/.devcontainer/build_cxx.sh +++ b/.devcontainer/build_cxx.sh @@ -13,7 +13,7 @@ cmake -D ENABLE_TENSORFLOW=ON \ -D ENABLE_PYTORCH=ON \ -D ENABLE_PADDLE=ON \ -D CMAKE_INSTALL_PREFIX=${SCRIPT_PATH}/../dp/ \ - -D LAMMPS_VERSION=stable_29Aug2024_update1 \ + -D LAMMPS_VERSION=stable_22Jul2025 \ -D CMAKE_BUILD_TYPE=Debug \ -D BUILD_TESTING:BOOL=TRUE \ -D TENSORFLOW_ROOT=${TENSORFLOW_ROOT} \ diff --git a/doc/install/install-lammps.md b/doc/install/install-lammps.md index 00b887e9c3..91d2435066 100644 --- a/doc/install/install-lammps.md +++ b/doc/install/install-lammps.md @@ -17,11 +17,11 @@ DeePMD-kit will generate a module called `USER-DEEPMD` in the `build` directory, ```bash cd /some/workspace -wget https://github.com/lammps/lammps/archive/stable_29Aug2024_update1.tar.gz -tar xf stable_29Aug2024_update1.tar.gz +wget https://github.com/lammps/lammps/archive/stable_22Jul2025.tar.gz +tar xf stable_22Jul2025.tar.gz ``` -The source code of LAMMPS is stored in the directory `lammps-stable_29Aug2024_update1`. +The source code of LAMMPS is stored in the directory `lammps-stable_22Jul2025`. Then, you can [build LAMMPS](https://docs.lammps.org/Build.html) with either make or CMake. @@ -30,7 +30,7 @@ Then, you can [build LAMMPS](https://docs.lammps.org/Build.html) with either mak Now go into the LAMMPS code and copy the DeePMD-kit module like this ```bash -cd lammps-stable_29Aug2024_update1/src/ +cd lammps-stable_22Jul2025/src/ cp -r $deepmd_source_dir/source/build/USER-DEEPMD . make yes-kspace make yes-extra-fix @@ -60,8 +60,8 @@ make no-user-deepmd Now go into the LAMMPS directory and create a directory called `build`: ```bash -mkdir -p lammps-stable_29Aug2024_update1/build/ -cd lammps-stable_29Aug2024_update1/build/ +mkdir -p lammps-stable_22Jul2025/build/ +cd lammps-stable_22Jul2025/build/ ``` Patch the LAMMPS `CMakeLists.txt` file: @@ -94,15 +94,15 @@ Now download the LAMMPS code (`8Apr2021` or later), and uncompress it: ```bash cd /some/workspace -wget https://github.com/lammps/lammps/archive/stable_29Aug2024_update1.tar.gz -tar xf stable_29Aug2024_update1.tar.gz +wget https://github.com/lammps/lammps/archive/stable_22Jul2025.tar.gz +tar xf stable_22Jul2025.tar.gz ``` -The source code of LAMMPS is stored in the directory `lammps-stable_29Aug2024_update1`. The directory of the source code should be specified as the CMAKE argument `LAMMPS_SOURCE_ROOT` during installation of the DeePMD-kit C++ interface. Now go into the LAMMPS directory and create a directory called `build` +The source code of LAMMPS is stored in the directory `lammps-stable_22Jul2025`. The directory of the source code should be specified as the CMAKE argument `LAMMPS_SOURCE_ROOT` during installation of the DeePMD-kit C++ interface. Now go into the LAMMPS directory and create a directory called `build` ```bash -mkdir -p lammps-stable_29Aug2024_update1/build/ -cd lammps-stable_29Aug2024_update1/build/ +mkdir -p lammps-stable_22Jul2025/build/ +cd lammps-stable_22Jul2025/build/ ``` Now build LAMMPS. Note that `PLUGIN` must be enabled, and `BUILD_SHARED_LIBS` must be set to `yes`. You can install any other package you want. diff --git a/pyproject.toml b/pyproject.toml index 8af6b85cdb..e5b52a24cf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -108,7 +108,7 @@ docs = [ "sphinx-remove-toctrees", ] lmp = [ - "lammps~=2024.8.29.1.0", + "lammps~=2025.7.22.0.0", ] ipi = [ "ipi", @@ -245,7 +245,7 @@ repair-wheel-command = """delocate-wheel --require-archs {delocate_archs} -w {de [tool.cibuildwheel.macos.environment] PIP_PREFER_BINARY = "1" -DP_LAMMPS_VERSION = "stable_29Aug2024_update1" +DP_LAMMPS_VERSION = "stable_22Jul2025" DP_ENABLE_IPI = "1" DP_ENABLE_PYTORCH = "1" DP_ENABLE_PADDLE = "1" @@ -282,7 +282,7 @@ before-build = [ ] [tool.cibuildwheel.linux.environment] PIP_PREFER_BINARY = "1" -DP_LAMMPS_VERSION = "stable_29Aug2024_update1" +DP_LAMMPS_VERSION = "stable_22Jul2025" DP_ENABLE_IPI = "1" DP_ENABLE_PYTORCH = "1" DP_ENABLE_PADDLE = "1" diff --git a/source/install/build_cc.sh b/source/install/build_cc.sh index dc66343cb2..0a3b3e5903 100755 --- a/source/install/build_cc.sh +++ b/source/install/build_cc.sh @@ -26,7 +26,7 @@ cmake -D ENABLE_TENSORFLOW=ON \ -D USE_TF_PYTHON_LIBS=TRUE \ -D USE_PT_PYTHON_LIBS=TRUE \ ${CUDA_ARGS} \ - -D LAMMPS_VERSION=stable_29Aug2024_update1 \ + -D LAMMPS_VERSION=stable_22Jul2025 \ .. cmake --build . -j${NPROC} cmake --install . diff --git a/source/install/build_from_c.sh b/source/install/build_from_c.sh index 22739ec531..8122fad603 100755 --- a/source/install/build_from_c.sh +++ b/source/install/build_from_c.sh @@ -13,7 +13,7 @@ NPROC=$(nproc --all) BUILD_TMP_DIR=${SCRIPT_PATH}/../build mkdir -p ${BUILD_TMP_DIR} cd ${BUILD_TMP_DIR} -cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -DDEEPMD_C_ROOT=${DEEPMD_C_ROOT} -DLAMMPS_VERSION=stable_29Aug2024_update1 .. +cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -DDEEPMD_C_ROOT=${DEEPMD_C_ROOT} -DLAMMPS_VERSION=stable_22Jul2025 .. cmake --build . -j${NPROC} cmake --install . cmake --build . --target=lammps diff --git a/source/install/build_lammps.sh b/source/install/build_lammps.sh index d101714739..04c2d372c6 100755 --- a/source/install/build_lammps.sh +++ b/source/install/build_lammps.sh @@ -14,7 +14,7 @@ BUILD_TMP_DIR=${SCRIPT_PATH}/../build_lammps mkdir -p ${BUILD_TMP_DIR} cd ${BUILD_TMP_DIR} # download LAMMMPS -LAMMPS_VERSION=stable_29Aug2024_update1 +LAMMPS_VERSION=stable_22Jul2025 if [ ! -d "lammps-${LAMMPS_VERSION}" ]; then curl -L -o lammps.tar.gz https://github.com/lammps/lammps/archive/refs/tags/${LAMMPS_VERSION}.tar.gz tar vxzf lammps.tar.gz diff --git a/source/install/test_cc.sh b/source/install/test_cc.sh index 1626f36193..dd3e0476a9 100755 --- a/source/install/test_cc.sh +++ b/source/install/test_cc.sh @@ -17,7 +17,7 @@ INSTALL_PREFIX=${SCRIPT_PATH}/../../dp_test BUILD_TMP_DIR=${SCRIPT_PATH}/../build_tests mkdir -p ${BUILD_TMP_DIR} cd ${BUILD_TMP_DIR} -cmake -DINSTALL_TENSORFLOW=TRUE -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -DTENSORFLOW_ROOT=${INSTALL_PREFIX} -DBUILD_TESTING:BOOL=TRUE -DLAMMPS_VERSION=stable_29Aug2024_update1 ${CUDA_ARGS} .. +cmake -DINSTALL_TENSORFLOW=TRUE -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -DTENSORFLOW_ROOT=${INSTALL_PREFIX} -DBUILD_TESTING:BOOL=TRUE -DLAMMPS_VERSION=stable_22Jul2025 ${CUDA_ARGS} .. cmake --build . -j${NPROC} cmake --install . ctest --output-on-failure diff --git a/source/install/test_cc_local.sh b/source/install/test_cc_local.sh index 8152b6f1a4..776c8a70cf 100755 --- a/source/install/test_cc_local.sh +++ b/source/install/test_cc_local.sh @@ -28,7 +28,7 @@ cmake \ -D USE_PT_PYTHON_LIBS=TRUE \ -D CMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \ -D BUILD_TESTING:BOOL=TRUE \ - -D LAMMPS_VERSION=stable_29Aug2024_update1 \ + -D LAMMPS_VERSION=stable_22Jul2025 \ ${CUDA_ARGS} .. cmake --build . -j${NPROC} cmake --install . From 3cb979df6ad60f5b92cddee94fd44bfe69e2299e Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 4 Aug 2025 00:23:36 +0800 Subject: [PATCH 02/36] vendor old get_lammps_version --- source/lmp/builtin.cmake | 26 +++++++++++++++++++++++++- source/lmp/plugin/CMakeLists.txt | 29 +++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/source/lmp/builtin.cmake b/source/lmp/builtin.cmake index f29e9d3319..ad1b848924 100644 --- a/source/lmp/builtin.cmake +++ b/source/lmp/builtin.cmake @@ -5,7 +5,31 @@ # assume LAMMPS CMake file has been executed, so these target/variables exist: # lammps LAMMPS_SOURCE_DIR get_lammps_version -get_lammps_version(${LAMMPS_SOURCE_DIR}/version.h LAMMPS_VERSION_NUMBER) +# Since May 15, 2025, the output of get_lammps_version is changed. +# We vendor the old get_lammps_version +# https://github.com/lammps/lammps/commit/b3e7121535863df3db487cd3e6a68c080bf2a6b4#diff-1214db0d1c015a50103f61f8ff7896053dec7ebc1edb930d6ef8bb07282f52abR75 +function(_get_lammps_version version_header variable) + file(STRINGS ${version_header} line REGEX LAMMPS_VERSION) + set(MONTHS x Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) + string(REGEX REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" "\\1" day "${line}") + string(REGEX REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" "\\2" month "${line}") + string(REGEX REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" "\\3" year "${line}") + string(STRIP ${day} day) + string(STRIP ${month} month) + string(STRIP ${year} year) + list(FIND MONTHS "${month}" month) + string(LENGTH ${day} day_length) + string(LENGTH ${month} month_length) + if(day_length EQUAL 1) + set(day "0${day}") + endif() + if(month_length EQUAL 1) + set(month "0${month}") + endif() + set(${variable} "${year}${month}${day}" PARENT_SCOPE) +endfunction() + +_get_lammps_version(${LAMMPS_SOURCE_DIR}/version.h LAMMPS_VERSION_NUMBER) configure_file("${CMAKE_CURRENT_LIST_DIR}/deepmd_version.h.in" "${CMAKE_CURRENT_BINARY_DIR}/deepmd_version.h" @ONLY) diff --git a/source/lmp/plugin/CMakeLists.txt b/source/lmp/plugin/CMakeLists.txt index a0998b3ce9..f970b513ae 100644 --- a/source/lmp/plugin/CMakeLists.txt +++ b/source/lmp/plugin/CMakeLists.txt @@ -38,8 +38,33 @@ if(DEFINED LAMMPS_SOURCE_ROOT OR DEFINED LAMMPS_VERSION) # get_lammps_version # https://github.com/lammps/lammps/blob/c2a12f97c5f665852fb38fdd4922f7dd2e77a0a1/cmake/Modules/LAMMPSUtils.cmake#L27-L46 - include(${LAMMPS_SOURCE_ROOT}/cmake/Modules/LAMMPSUtils.cmake) - get_lammps_version(${LAMMPS_HEADER_DIR}/version.h LAMMPS_VERSION_NUMBER) + # include(${LAMMPS_SOURCE_ROOT}/cmake/Modules/LAMMPSUtils.cmake) + # Since May 15, 2025, the output of get_lammps_version is changed. + # We vendor the old get_lammps_version + # https://github.com/lammps/lammps/commit/b3e7121535863df3db487cd3e6a68c080bf2a6b4#diff-1214db0d1c015a50103f61f8ff7896053dec7ebc1edb930d6ef8bb07282f52abR75 + + function(_get_lammps_version version_header variable) + file(STRINGS ${version_header} line REGEX LAMMPS_VERSION) + set(MONTHS x Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) + string(REGEX REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" "\\1" day "${line}") + string(REGEX REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" "\\2" month "${line}") + string(REGEX REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" "\\3" year "${line}") + string(STRIP ${day} day) + string(STRIP ${month} month) + string(STRIP ${year} year) + list(FIND MONTHS "${month}" month) + string(LENGTH ${day} day_length) + string(LENGTH ${month} month_length) + if(day_length EQUAL 1) + set(day "0${day}") + endif() + if(month_length EQUAL 1) + set(month "0${month}") + endif() + set(${variable} "${year}${month}${day}" PARENT_SCOPE) + endfunction() + + _get_lammps_version_old(${LAMMPS_HEADER_DIR}/version.h LAMMPS_VERSION_NUMBER) set(LAMMPS_VERSION_NUMBER ${LAMMPS_VERSION_NUMBER} PARENT_SCOPE) From 2742eaaa169df66a03e72fd47f595dc7564faa29 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 3 Aug 2025 16:25:21 +0000 Subject: [PATCH 03/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- source/lmp/builtin.cmake | 61 +++++++++++++++++++++---------- source/lmp/plugin/CMakeLists.txt | 63 +++++++++++++++++++++----------- 2 files changed, 83 insertions(+), 41 deletions(-) diff --git a/source/lmp/builtin.cmake b/source/lmp/builtin.cmake index ad1b848924..e051e5c24a 100644 --- a/source/lmp/builtin.cmake +++ b/source/lmp/builtin.cmake @@ -5,28 +5,49 @@ # assume LAMMPS CMake file has been executed, so these target/variables exist: # lammps LAMMPS_SOURCE_DIR get_lammps_version -# Since May 15, 2025, the output of get_lammps_version is changed. -# We vendor the old get_lammps_version +# Since May 15, 2025, the output of get_lammps_version is changed. We vendor the +# old get_lammps_version # https://github.com/lammps/lammps/commit/b3e7121535863df3db487cd3e6a68c080bf2a6b4#diff-1214db0d1c015a50103f61f8ff7896053dec7ebc1edb930d6ef8bb07282f52abR75 function(_get_lammps_version version_header variable) - file(STRINGS ${version_header} line REGEX LAMMPS_VERSION) - set(MONTHS x Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) - string(REGEX REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" "\\1" day "${line}") - string(REGEX REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" "\\2" month "${line}") - string(REGEX REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" "\\3" year "${line}") - string(STRIP ${day} day) - string(STRIP ${month} month) - string(STRIP ${year} year) - list(FIND MONTHS "${month}" month) - string(LENGTH ${day} day_length) - string(LENGTH ${month} month_length) - if(day_length EQUAL 1) - set(day "0${day}") - endif() - if(month_length EQUAL 1) - set(month "0${month}") - endif() - set(${variable} "${year}${month}${day}" PARENT_SCOPE) + file(STRINGS ${version_header} line REGEX LAMMPS_VERSION) + set(MONTHS + x + Jan + Feb + Mar + Apr + May + Jun + Jul + Aug + Sep + Oct + Nov + Dec) + string(REGEX + REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" + "\\1" day "${line}") + string(REGEX + REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" + "\\2" month "${line}") + string(REGEX + REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" + "\\3" year "${line}") + string(STRIP ${day} day) + string(STRIP ${month} month) + string(STRIP ${year} year) + list(FIND MONTHS "${month}" month) + string(LENGTH ${day} day_length) + string(LENGTH ${month} month_length) + if(day_length EQUAL 1) + set(day "0${day}") + endif() + if(month_length EQUAL 1) + set(month "0${month}") + endif() + set(${variable} + "${year}${month}${day}" + PARENT_SCOPE) endfunction() _get_lammps_version(${LAMMPS_SOURCE_DIR}/version.h LAMMPS_VERSION_NUMBER) diff --git a/source/lmp/plugin/CMakeLists.txt b/source/lmp/plugin/CMakeLists.txt index f970b513ae..774542ef67 100644 --- a/source/lmp/plugin/CMakeLists.txt +++ b/source/lmp/plugin/CMakeLists.txt @@ -38,30 +38,51 @@ if(DEFINED LAMMPS_SOURCE_ROOT OR DEFINED LAMMPS_VERSION) # get_lammps_version # https://github.com/lammps/lammps/blob/c2a12f97c5f665852fb38fdd4922f7dd2e77a0a1/cmake/Modules/LAMMPSUtils.cmake#L27-L46 - # include(${LAMMPS_SOURCE_ROOT}/cmake/Modules/LAMMPSUtils.cmake) - # Since May 15, 2025, the output of get_lammps_version is changed. - # We vendor the old get_lammps_version + # include(${LAMMPS_SOURCE_ROOT}/cmake/Modules/LAMMPSUtils.cmake) Since May 15, + # 2025, the output of get_lammps_version is changed. We vendor the old + # get_lammps_version # https://github.com/lammps/lammps/commit/b3e7121535863df3db487cd3e6a68c080bf2a6b4#diff-1214db0d1c015a50103f61f8ff7896053dec7ebc1edb930d6ef8bb07282f52abR75 function(_get_lammps_version version_header variable) - file(STRINGS ${version_header} line REGEX LAMMPS_VERSION) - set(MONTHS x Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) - string(REGEX REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" "\\1" day "${line}") - string(REGEX REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" "\\2" month "${line}") - string(REGEX REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" "\\3" year "${line}") - string(STRIP ${day} day) - string(STRIP ${month} month) - string(STRIP ${year} year) - list(FIND MONTHS "${month}" month) - string(LENGTH ${day} day_length) - string(LENGTH ${month} month_length) - if(day_length EQUAL 1) - set(day "0${day}") - endif() - if(month_length EQUAL 1) - set(month "0${month}") - endif() - set(${variable} "${year}${month}${day}" PARENT_SCOPE) + file(STRINGS ${version_header} line REGEX LAMMPS_VERSION) + set(MONTHS + x + Jan + Feb + Mar + Apr + May + Jun + Jul + Aug + Sep + Oct + Nov + Dec) + string(REGEX + REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" + "\\1" day "${line}") + string(REGEX + REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" + "\\2" month "${line}") + string(REGEX + REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" + "\\3" year "${line}") + string(STRIP ${day} day) + string(STRIP ${month} month) + string(STRIP ${year} year) + list(FIND MONTHS "${month}" month) + string(LENGTH ${day} day_length) + string(LENGTH ${month} month_length) + if(day_length EQUAL 1) + set(day "0${day}") + endif() + if(month_length EQUAL 1) + set(month "0${month}") + endif() + set(${variable} + "${year}${month}${day}" + PARENT_SCOPE) endfunction() _get_lammps_version_old(${LAMMPS_HEADER_DIR}/version.h LAMMPS_VERSION_NUMBER) From 39481842e8c0508e3a930b04830b106754453f8a Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 4 Aug 2025 00:30:30 +0800 Subject: [PATCH 04/36] fix typo --- source/lmp/plugin/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/lmp/plugin/CMakeLists.txt b/source/lmp/plugin/CMakeLists.txt index 774542ef67..cf8bd88a22 100644 --- a/source/lmp/plugin/CMakeLists.txt +++ b/source/lmp/plugin/CMakeLists.txt @@ -85,7 +85,7 @@ if(DEFINED LAMMPS_SOURCE_ROOT OR DEFINED LAMMPS_VERSION) PARENT_SCOPE) endfunction() - _get_lammps_version_old(${LAMMPS_HEADER_DIR}/version.h LAMMPS_VERSION_NUMBER) + _get_lammps_version(${LAMMPS_HEADER_DIR}/version.h LAMMPS_VERSION_NUMBER) set(LAMMPS_VERSION_NUMBER ${LAMMPS_VERSION_NUMBER} PARENT_SCOPE) From fbea9128d989a4efe3180a3e1ac282106add8595 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 4 Aug 2025 01:05:02 +0800 Subject: [PATCH 05/36] update lammps version --- pyproject.toml | 2 +- source/lmp/plugin/CMakeLists.txt | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e5b52a24cf..7ed51f7c32 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -108,7 +108,7 @@ docs = [ "sphinx-remove-toctrees", ] lmp = [ - "lammps~=2025.7.22.0.0", + "lammps~=2025.7.22.0.1", ] ipi = [ "ipi", diff --git a/source/lmp/plugin/CMakeLists.txt b/source/lmp/plugin/CMakeLists.txt index cf8bd88a22..a4e7d9e430 100644 --- a/source/lmp/plugin/CMakeLists.txt +++ b/source/lmp/plugin/CMakeLists.txt @@ -121,8 +121,7 @@ if(DEFINED LAMMPS_SOURCE_ROOT OR DEFINED LAMMPS_VERSION) target_link_libraries(${libname} PUBLIC ${LIB_DEEPMD_C}) target_precompile_headers(${libname} PUBLIC [["deepmd.hpp"]]) remove_definitions(-D_GLIBCXX_USE_CXX11_ABI=${OP_CXX_ABI}) - if("$ENV{CIBUILDWHEEL}" STREQUAL "1" OR "$ENV{LMP_CXX11_ABI_0}" STREQUAL - "1") + if("$ENV{LMP_CXX11_ABI_0}" STREQUAL "1") add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) endif() else() From db0048ee0dcacb3fb94770b2db999a169f6a014c Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 4 Aug 2025 13:06:29 +0800 Subject: [PATCH 06/36] logging for debug Signed-off-by: Jinzhe Zeng --- .github/workflows/test_cc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_cc.yml b/.github/workflows/test_cc.yml index cd4eca96f7..ddf56470aa 100644 --- a/.github/workflows/test_cc.yml +++ b/.github/workflows/test_cc.yml @@ -64,7 +64,7 @@ jobs: cp ${{ github.workspace }}/source/build_tests/paddle_inference_install_dir/paddle/lib/*.so ${{ github.workspace }}/dp_test/lib/ cp ${{ github.workspace }}/source/build_tests/paddle_inference_install_dir/third_party/install/onednn/lib/* ${{ github.workspace }}/dp_test/lib/ cp ${{ github.workspace }}/source/build_tests/paddle_inference_install_dir/third_party/install/mklml/lib/* ${{ github.workspace }}/dp_test/lib/ - pytest --cov=deepmd source/ipi/tests + pytest -s --cov=deepmd source/ipi/tests env: OMP_NUM_THREADS: 1 TF_INTRA_OP_PARALLELISM_THREADS: 1 From 6a68f9d949297687424165cbdb945e8c552eb827 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 4 Aug 2025 13:23:11 +0800 Subject: [PATCH 07/36] debug lmp, not ipi Signed-off-by: Jinzhe Zeng --- .github/workflows/test_cc.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_cc.yml b/.github/workflows/test_cc.yml index ddf56470aa..3bb9a2c35f 100644 --- a/.github/workflows/test_cc.yml +++ b/.github/workflows/test_cc.yml @@ -51,7 +51,7 @@ jobs: cp ${{ github.workspace }}/source/build_tests/paddle_inference_install_dir/third_party/install/onednn/lib/* ${{ github.workspace }}/dp_test/lib/ cp ${{ github.workspace }}/source/build_tests/paddle_inference_install_dir/third_party/install/mklml/lib/* ${{ github.workspace }}/dp_test/lib/ export LD_LIBRARY_PATH=${{ github.workspace }}/dp_test/lib:$LD_LIBRARY_PATH - pytest --cov=deepmd source/lmp/tests + pytest -s --cov=deepmd source/lmp/tests env: OMP_NUM_THREADS: 1 TF_INTRA_OP_PARALLELISM_THREADS: 1 @@ -64,7 +64,7 @@ jobs: cp ${{ github.workspace }}/source/build_tests/paddle_inference_install_dir/paddle/lib/*.so ${{ github.workspace }}/dp_test/lib/ cp ${{ github.workspace }}/source/build_tests/paddle_inference_install_dir/third_party/install/onednn/lib/* ${{ github.workspace }}/dp_test/lib/ cp ${{ github.workspace }}/source/build_tests/paddle_inference_install_dir/third_party/install/mklml/lib/* ${{ github.workspace }}/dp_test/lib/ - pytest -s --cov=deepmd source/ipi/tests + pytest --cov=deepmd source/ipi/tests env: OMP_NUM_THREADS: 1 TF_INTRA_OP_PARALLELISM_THREADS: 1 From 7d651ab2a66cf05deda4bfbc6f5b94eace7ca951 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 4 Aug 2025 14:28:18 +0800 Subject: [PATCH 08/36] clean up LMP_CXX11_ABI_0 --- .devcontainer/devcontainer.json | 1 - .github/workflows/test_cc.yml | 1 - .github/workflows/test_cuda.yml | 1 - 3 files changed, 3 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 27c40bbe6a..85d67db2a9 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -11,7 +11,6 @@ "PATH": "${containerEnv:PATH}:${containerWorkspaceFolder}/.venv/bin", "DP_ENABLE_PYTORCH": "1", "DP_VARIANT": "cpu", - "LMP_CXX11_ABI_0": "1", "UV_EXTRA_INDEX_URL": "https://download.pytorch.org/whl/cpu" } } diff --git a/.github/workflows/test_cc.yml b/.github/workflows/test_cc.yml index cd4eca96f7..7d76e60ba1 100644 --- a/.github/workflows/test_cc.yml +++ b/.github/workflows/test_cc.yml @@ -41,7 +41,6 @@ jobs: OMP_NUM_THREADS: 1 TF_INTRA_OP_PARALLELISM_THREADS: 1 TF_INTER_OP_PARALLELISM_THREADS: 1 - LMP_CXX11_ABI_0: 1 CMAKE_GENERATOR: Ninja CXXFLAGS: ${{ matrix.check_memleak && '-fsanitize=leak' || '' }} LSAN_OPTIONS: suppressions=${{ github.workspace }}/.github/workflows/suppr.txt diff --git a/.github/workflows/test_cuda.yml b/.github/workflows/test_cuda.yml index 5f6b0e73ab..dce3b95ff0 100644 --- a/.github/workflows/test_cuda.yml +++ b/.github/workflows/test_cuda.yml @@ -74,7 +74,6 @@ jobs: OMP_NUM_THREADS: 1 TF_INTRA_OP_PARALLELISM_THREADS: 1 TF_INTER_OP_PARALLELISM_THREADS: 1 - LMP_CXX11_ABI_0: 1 CMAKE_GENERATOR: Ninja DP_VARIANT: cuda DP_USE_MPICH2: 1 From 77dd1a9c89cdb3b61e47c4221961e1bc78e7a119 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 4 Aug 2025 14:36:07 +0800 Subject: [PATCH 09/36] Revert "debug lmp, not ipi" This reverts commit 6a68f9d949297687424165cbdb945e8c552eb827. --- .github/workflows/test_cc.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_cc.yml b/.github/workflows/test_cc.yml index aabe4c58c3..b8f4f33f69 100644 --- a/.github/workflows/test_cc.yml +++ b/.github/workflows/test_cc.yml @@ -50,7 +50,7 @@ jobs: cp ${{ github.workspace }}/source/build_tests/paddle_inference_install_dir/third_party/install/onednn/lib/* ${{ github.workspace }}/dp_test/lib/ cp ${{ github.workspace }}/source/build_tests/paddle_inference_install_dir/third_party/install/mklml/lib/* ${{ github.workspace }}/dp_test/lib/ export LD_LIBRARY_PATH=${{ github.workspace }}/dp_test/lib:$LD_LIBRARY_PATH - pytest -s --cov=deepmd source/lmp/tests + pytest --cov=deepmd source/lmp/tests env: OMP_NUM_THREADS: 1 TF_INTRA_OP_PARALLELISM_THREADS: 1 @@ -63,7 +63,7 @@ jobs: cp ${{ github.workspace }}/source/build_tests/paddle_inference_install_dir/paddle/lib/*.so ${{ github.workspace }}/dp_test/lib/ cp ${{ github.workspace }}/source/build_tests/paddle_inference_install_dir/third_party/install/onednn/lib/* ${{ github.workspace }}/dp_test/lib/ cp ${{ github.workspace }}/source/build_tests/paddle_inference_install_dir/third_party/install/mklml/lib/* ${{ github.workspace }}/dp_test/lib/ - pytest --cov=deepmd source/ipi/tests + pytest -s --cov=deepmd source/ipi/tests env: OMP_NUM_THREADS: 1 TF_INTRA_OP_PARALLELISM_THREADS: 1 From c17c7134b07c15f933785e1f9f38fda35448dba0 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 4 Aug 2025 14:36:12 +0800 Subject: [PATCH 10/36] Revert "logging for debug" This reverts commit db0048ee0dcacb3fb94770b2db999a169f6a014c. --- .github/workflows/test_cc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_cc.yml b/.github/workflows/test_cc.yml index b8f4f33f69..7d76e60ba1 100644 --- a/.github/workflows/test_cc.yml +++ b/.github/workflows/test_cc.yml @@ -63,7 +63,7 @@ jobs: cp ${{ github.workspace }}/source/build_tests/paddle_inference_install_dir/paddle/lib/*.so ${{ github.workspace }}/dp_test/lib/ cp ${{ github.workspace }}/source/build_tests/paddle_inference_install_dir/third_party/install/onednn/lib/* ${{ github.workspace }}/dp_test/lib/ cp ${{ github.workspace }}/source/build_tests/paddle_inference_install_dir/third_party/install/mklml/lib/* ${{ github.workspace }}/dp_test/lib/ - pytest -s --cov=deepmd source/ipi/tests + pytest --cov=deepmd source/ipi/tests env: OMP_NUM_THREADS: 1 TF_INTRA_OP_PARALLELISM_THREADS: 1 From 67979085c5d3b133f9ade20483acfc86bb57f69b Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 4 Aug 2025 22:32:43 +0800 Subject: [PATCH 11/36] disable the MPI tests --- .github/workflows/test_cc.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test_cc.yml b/.github/workflows/test_cc.yml index 7d76e60ba1..d995566641 100644 --- a/.github/workflows/test_cc.yml +++ b/.github/workflows/test_cc.yml @@ -27,7 +27,9 @@ jobs: run: | source/install/uv_with_retry.sh pip install --system tensorflow-cpu~=2.18.0 jax==0.5.0 export TENSORFLOW_ROOT=$(python -c 'import importlib,pathlib;print(pathlib.Path(importlib.util.find_spec("tensorflow").origin).parent)') - source/install/uv_with_retry.sh pip install --system -e .[cpu,test,lmp,jax] mpi4py mpich + # 20250804: disable the MPI tests since mpi4py MPI is conflict with LAMMPS MPI + # TODO: recover the MPI tests after the conflict is resolved + source/install/uv_with_retry.sh pip install --system -e .[cpu,test,lmp,jax] # mpi4py mpich source/install/uv_with_retry.sh pip install --system 'torch==2.7' --index-url https://download.pytorch.org/whl/cpu - name: Convert models run: source/tests/infer/convert-models.sh From 7cd3e7d76c4d90fa24c78a775694d328a44b7cec Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 5 Aug 2025 14:47:49 +0800 Subject: [PATCH 12/36] mpich is still required Signed-off-by: Jinzhe Zeng --- .github/workflows/test_cc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_cc.yml b/.github/workflows/test_cc.yml index d995566641..734966a089 100644 --- a/.github/workflows/test_cc.yml +++ b/.github/workflows/test_cc.yml @@ -29,7 +29,7 @@ jobs: export TENSORFLOW_ROOT=$(python -c 'import importlib,pathlib;print(pathlib.Path(importlib.util.find_spec("tensorflow").origin).parent)') # 20250804: disable the MPI tests since mpi4py MPI is conflict with LAMMPS MPI # TODO: recover the MPI tests after the conflict is resolved - source/install/uv_with_retry.sh pip install --system -e .[cpu,test,lmp,jax] # mpi4py mpich + source/install/uv_with_retry.sh pip install --system -e .[cpu,test,lmp,jax] mpich # mpi4py source/install/uv_with_retry.sh pip install --system 'torch==2.7' --index-url https://download.pytorch.org/whl/cpu - name: Convert models run: source/tests/infer/convert-models.sh From 00c8bc7ed34b99fb2e3f2f330303bb72cce32d57 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 5 Aug 2025 19:59:35 +0800 Subject: [PATCH 13/36] fix idx_map Signed-off-by: Jinzhe Zeng --- source/lmp/tests/test_deeptensor.py | 2 +- source/lmp/tests/test_dplr.py | 8 ++++---- source/lmp/tests/test_lammps.py | 4 ++-- source/lmp/tests/test_lammps_3types.py | 4 ++-- source/lmp/tests/test_lammps_dpa_jax.py | 4 ++-- source/lmp/tests/test_lammps_dpa_pt.py | 4 ++-- source/lmp/tests/test_lammps_dpa_pt_nopbc.py | 4 ++-- source/lmp/tests/test_lammps_dpa_sel_pt.py | 4 ++-- source/lmp/tests/test_lammps_faparam.py | 2 +- source/lmp/tests/test_lammps_jax.py | 4 ++-- source/lmp/tests/test_lammps_pd.py | 4 ++-- source/lmp/tests/test_lammps_pt.py | 4 ++-- source/lmp/tests/test_lammps_spin.py | 2 +- source/lmp/tests/test_lammps_spin_pt.py | 2 +- 14 files changed, 26 insertions(+), 26 deletions(-) diff --git a/source/lmp/tests/test_deeptensor.py b/source/lmp/tests/test_deeptensor.py index 6fb7cde746..38f887186a 100644 --- a/source/lmp/tests/test_deeptensor.py +++ b/source/lmp/tests/test_deeptensor.py @@ -142,7 +142,7 @@ def test_compute_deeptensor_atom(lammps) -> None: lammps.variable("tensor atom c_tensor[1]") lammps.dump("1 all custom 1 dump id c_tensor[1]") lammps.run(0) - idx_map = lammps.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 assert np.array(lammps.variables["tensor"].value) == pytest.approx( expected_d[idx_map] ) diff --git a/source/lmp/tests/test_dplr.py b/source/lmp/tests/test_dplr.py index 21d1f18658..51cb57a8eb 100644 --- a/source/lmp/tests/test_dplr.py +++ b/source/lmp/tests/test_dplr.py @@ -357,7 +357,7 @@ def test_pair_deepmd_sr(lammps) -> None: lammps.pair_coeff("* *") lammps.run(0) assert lammps.eval("pe") == pytest.approx(expected_e_sr) - id_list = lammps.lmp.numpy.extract_atom("id") + id_list = lammps.lmp.numpy.extract_atom("id")[:6] for ii in range(6): assert lammps.atoms[np.where(id_list == (ii + 1))[0][0]].force == pytest.approx( expected_f_sr[ii] @@ -378,7 +378,7 @@ def test_pair_deepmd_sr_virial(lammps) -> None: ) lammps.dump_modify("1 sort id") lammps.run(0) - id_list = lammps.lmp.numpy.extract_atom("id") + id_list = lammps.lmp.numpy.extract_atom("id")[:6] idx_list = [np.where(id_list == i)[0][0] for i in range(1, 7)] assert lammps.eval("pe") == pytest.approx(expected_e_sr) for ii in range(6): @@ -445,7 +445,7 @@ def test_pair_deepmd_lr_efield_constant(lammps) -> None: ) lammps.fix_modify("0 energy yes virial yes") lammps.run(0) - id_list = lammps.lmp.numpy.extract_atom("id") + id_list = lammps.lmp.numpy.extract_atom("id")[:6] assert lammps.eval("evdwl") == pytest.approx(expected_evdwl_lr_efield_constant) assert lammps.eval("f_0") == pytest.approx(expected_e_efield_constant) assert lammps.eval("pe") == pytest.approx(expected_e_lr_efield_constant) @@ -481,7 +481,7 @@ def test_pair_deepmd_lr_efield_variable(lammps) -> None: ) lammps.fix_modify("0 energy yes virial yes") lammps.run(0) - id_list = lammps.lmp.numpy.extract_atom("id") + id_list = lammps.lmp.numpy.extract_atom("id")[:6] assert lammps.eval("evdwl") == pytest.approx(expected_evdwl_lr_efield_variable) assert lammps.eval("f_0") == pytest.approx(expected_e_efield_variable) assert lammps.eval("pe") == pytest.approx(expected_e_lr_efield_variable) diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index ad8f8cdaac..fba629b276 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -340,7 +340,7 @@ def test_pair_deepmd_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 assert np.array(lammps.variables["eatom"].value) == pytest.approx( expected_ae[idx_map] ) @@ -408,7 +408,7 @@ def test_pair_deepmd_model_devi_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 assert np.array(lammps.variables["eatom"].value) == pytest.approx( expected_ae[idx_map] ) diff --git a/source/lmp/tests/test_lammps_3types.py b/source/lmp/tests/test_lammps_3types.py index f0cbe19ddf..ac5185ac04 100644 --- a/source/lmp/tests/test_lammps_3types.py +++ b/source/lmp/tests/test_lammps_3types.py @@ -320,7 +320,7 @@ def test_pair_deepmd_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value @@ -371,7 +371,7 @@ def test_pair_deepmd_model_devi_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value diff --git a/source/lmp/tests/test_lammps_dpa_jax.py b/source/lmp/tests/test_lammps_dpa_jax.py index 4867b5f84e..5105c18e16 100644 --- a/source/lmp/tests/test_lammps_dpa_jax.py +++ b/source/lmp/tests/test_lammps_dpa_jax.py @@ -334,7 +334,7 @@ def test_pair_deepmd_virial(lammps): assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value @@ -385,7 +385,7 @@ def test_pair_deepmd_model_devi_virial(lammps): assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value diff --git a/source/lmp/tests/test_lammps_dpa_pt.py b/source/lmp/tests/test_lammps_dpa_pt.py index e66b93e09e..6f397a60ba 100644 --- a/source/lmp/tests/test_lammps_dpa_pt.py +++ b/source/lmp/tests/test_lammps_dpa_pt.py @@ -330,7 +330,7 @@ def test_pair_deepmd_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value @@ -381,7 +381,7 @@ def test_pair_deepmd_model_devi_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value diff --git a/source/lmp/tests/test_lammps_dpa_pt_nopbc.py b/source/lmp/tests/test_lammps_dpa_pt_nopbc.py index 563650c714..5e72473186 100644 --- a/source/lmp/tests/test_lammps_dpa_pt_nopbc.py +++ b/source/lmp/tests/test_lammps_dpa_pt_nopbc.py @@ -328,7 +328,7 @@ def test_pair_deepmd_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value @@ -379,7 +379,7 @@ def test_pair_deepmd_model_devi_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value diff --git a/source/lmp/tests/test_lammps_dpa_sel_pt.py b/source/lmp/tests/test_lammps_dpa_sel_pt.py index 9ff2883fc1..d7f9c588a9 100644 --- a/source/lmp/tests/test_lammps_dpa_sel_pt.py +++ b/source/lmp/tests/test_lammps_dpa_sel_pt.py @@ -333,7 +333,7 @@ def test_pair_deepmd_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value @@ -384,7 +384,7 @@ def test_pair_deepmd_model_devi_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value diff --git a/source/lmp/tests/test_lammps_faparam.py b/source/lmp/tests/test_lammps_faparam.py index 4206aa68fb..5e4dd09db9 100644 --- a/source/lmp/tests/test_lammps_faparam.py +++ b/source/lmp/tests/test_lammps_faparam.py @@ -213,7 +213,7 @@ def test_pair_deepmd_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value diff --git a/source/lmp/tests/test_lammps_jax.py b/source/lmp/tests/test_lammps_jax.py index 5d88cfca12..cbd4d53d0b 100644 --- a/source/lmp/tests/test_lammps_jax.py +++ b/source/lmp/tests/test_lammps_jax.py @@ -332,7 +332,7 @@ def test_pair_deepmd_virial(lammps): assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value @@ -383,7 +383,7 @@ def test_pair_deepmd_model_devi_virial(lammps): assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value diff --git a/source/lmp/tests/test_lammps_pd.py b/source/lmp/tests/test_lammps_pd.py index 31ee2e482a..9463ded353 100644 --- a/source/lmp/tests/test_lammps_pd.py +++ b/source/lmp/tests/test_lammps_pd.py @@ -333,7 +333,7 @@ def test_pair_deepmd_virial(lammps): assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value @@ -384,7 +384,7 @@ def test_pair_deepmd_model_devi_virial(lammps): assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1], RTOL, ATOL ) - idx_map = lammps.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value diff --git a/source/lmp/tests/test_lammps_pt.py b/source/lmp/tests/test_lammps_pt.py index 9aed014b62..789cdaf7a7 100644 --- a/source/lmp/tests/test_lammps_pt.py +++ b/source/lmp/tests/test_lammps_pt.py @@ -330,7 +330,7 @@ def test_pair_deepmd_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value @@ -381,7 +381,7 @@ def test_pair_deepmd_model_devi_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value diff --git a/source/lmp/tests/test_lammps_spin.py b/source/lmp/tests/test_lammps_spin.py index 39e12b03fc..073572b7bc 100644 --- a/source/lmp/tests/test_lammps_spin.py +++ b/source/lmp/tests/test_lammps_spin.py @@ -172,7 +172,7 @@ def test_pair_deepmd_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 assert np.array(lammps.variables["eatom"].value) == pytest.approx( expected_ae[idx_map] ) diff --git a/source/lmp/tests/test_lammps_spin_pt.py b/source/lmp/tests/test_lammps_spin_pt.py index e15a10ee72..ff0a6fc26c 100644 --- a/source/lmp/tests/test_lammps_spin_pt.py +++ b/source/lmp/tests/test_lammps_spin_pt.py @@ -168,7 +168,7 @@ def test_pair_deepmd_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 assert np.array(lammps.variables["eatom"].value) == pytest.approx( expected_ae[idx_map] ) From b897686deeb37acf11c63649f0e44dbebf181502 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 5 Aug 2025 21:16:51 +0800 Subject: [PATCH 14/36] bump lammps to 2025.7.22.0.2 Signed-off-by: Jinzhe Zeng --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index e2eb85530e..ad4a189326 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -108,7 +108,7 @@ docs = [ "sphinx-remove-toctrees", ] lmp = [ - "lammps~=2025.7.22.0.1", + "lammps~=2025.7.22.0.2", ] ipi = [ "ipi", From 1a3aac585683695f3212e1165a757fbfffaaf94b Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 5 Aug 2025 21:18:01 +0800 Subject: [PATCH 15/36] Revert "mpich is still required" This reverts commit 7cd3e7d76c4d90fa24c78a775694d328a44b7cec. --- .github/workflows/test_cc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_cc.yml b/.github/workflows/test_cc.yml index 734966a089..d995566641 100644 --- a/.github/workflows/test_cc.yml +++ b/.github/workflows/test_cc.yml @@ -29,7 +29,7 @@ jobs: export TENSORFLOW_ROOT=$(python -c 'import importlib,pathlib;print(pathlib.Path(importlib.util.find_spec("tensorflow").origin).parent)') # 20250804: disable the MPI tests since mpi4py MPI is conflict with LAMMPS MPI # TODO: recover the MPI tests after the conflict is resolved - source/install/uv_with_retry.sh pip install --system -e .[cpu,test,lmp,jax] mpich # mpi4py + source/install/uv_with_retry.sh pip install --system -e .[cpu,test,lmp,jax] # mpi4py mpich source/install/uv_with_retry.sh pip install --system 'torch==2.7' --index-url https://download.pytorch.org/whl/cpu - name: Convert models run: source/tests/infer/convert-models.sh From b649db65f8caaebb5c2d033588b64f62cda777dc Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 5 Aug 2025 21:18:02 +0800 Subject: [PATCH 16/36] Revert "disable the MPI tests" This reverts commit 67979085c5d3b133f9ade20483acfc86bb57f69b. --- .github/workflows/test_cc.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/test_cc.yml b/.github/workflows/test_cc.yml index d995566641..7d76e60ba1 100644 --- a/.github/workflows/test_cc.yml +++ b/.github/workflows/test_cc.yml @@ -27,9 +27,7 @@ jobs: run: | source/install/uv_with_retry.sh pip install --system tensorflow-cpu~=2.18.0 jax==0.5.0 export TENSORFLOW_ROOT=$(python -c 'import importlib,pathlib;print(pathlib.Path(importlib.util.find_spec("tensorflow").origin).parent)') - # 20250804: disable the MPI tests since mpi4py MPI is conflict with LAMMPS MPI - # TODO: recover the MPI tests after the conflict is resolved - source/install/uv_with_retry.sh pip install --system -e .[cpu,test,lmp,jax] # mpi4py mpich + source/install/uv_with_retry.sh pip install --system -e .[cpu,test,lmp,jax] mpi4py mpich source/install/uv_with_retry.sh pip install --system 'torch==2.7' --index-url https://download.pytorch.org/whl/cpu - name: Convert models run: source/tests/infer/convert-models.sh From 9e3ca792ae07857ab5a8ff4adacee789522b221c Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 5 Aug 2025 23:07:12 +0800 Subject: [PATCH 17/36] install mpich Signed-off-by: Jinzhe Zeng --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index ad4a189326..acf0d593d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -230,6 +230,9 @@ test-command = [ "pytest {project}/source/tests/common/test_lammps.py" ] test-extras = ["cpu", "test", "lmp", "ipi", "torch", "paddle"] +test-requires = [ + "mpich", +] build = ["cp311-*"] skip = ["*-win32", "*-manylinux_i686", "*-musllinux*"] # TODO: uncomment to use the latest image when CUDA 11 is deprecated From e9f548c99a028d483374d5c72ec7eb20321cb04d Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 5 Aug 2025 23:07:49 +0800 Subject: [PATCH 18/36] Revert "Revert "disable the MPI tests"" This reverts commit b649db65f8caaebb5c2d033588b64f62cda777dc. --- .github/workflows/test_cc.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test_cc.yml b/.github/workflows/test_cc.yml index 7d76e60ba1..d995566641 100644 --- a/.github/workflows/test_cc.yml +++ b/.github/workflows/test_cc.yml @@ -27,7 +27,9 @@ jobs: run: | source/install/uv_with_retry.sh pip install --system tensorflow-cpu~=2.18.0 jax==0.5.0 export TENSORFLOW_ROOT=$(python -c 'import importlib,pathlib;print(pathlib.Path(importlib.util.find_spec("tensorflow").origin).parent)') - source/install/uv_with_retry.sh pip install --system -e .[cpu,test,lmp,jax] mpi4py mpich + # 20250804: disable the MPI tests since mpi4py MPI is conflict with LAMMPS MPI + # TODO: recover the MPI tests after the conflict is resolved + source/install/uv_with_retry.sh pip install --system -e .[cpu,test,lmp,jax] # mpi4py mpich source/install/uv_with_retry.sh pip install --system 'torch==2.7' --index-url https://download.pytorch.org/whl/cpu - name: Convert models run: source/tests/infer/convert-models.sh From 51c5eefe26fc556f817d69c1c694147ddf614c45 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 5 Aug 2025 23:07:50 +0800 Subject: [PATCH 19/36] Revert "Revert "mpich is still required"" This reverts commit 1a3aac585683695f3212e1165a757fbfffaaf94b. --- .github/workflows/test_cc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_cc.yml b/.github/workflows/test_cc.yml index d995566641..734966a089 100644 --- a/.github/workflows/test_cc.yml +++ b/.github/workflows/test_cc.yml @@ -29,7 +29,7 @@ jobs: export TENSORFLOW_ROOT=$(python -c 'import importlib,pathlib;print(pathlib.Path(importlib.util.find_spec("tensorflow").origin).parent)') # 20250804: disable the MPI tests since mpi4py MPI is conflict with LAMMPS MPI # TODO: recover the MPI tests after the conflict is resolved - source/install/uv_with_retry.sh pip install --system -e .[cpu,test,lmp,jax] # mpi4py mpich + source/install/uv_with_retry.sh pip install --system -e .[cpu,test,lmp,jax] mpich # mpi4py source/install/uv_with_retry.sh pip install --system 'torch==2.7' --index-url https://download.pytorch.org/whl/cpu - name: Convert models run: source/tests/infer/convert-models.sh From 705bb524d2b884389e173df93ccd6f950496b968 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 5 Aug 2025 23:49:37 +0800 Subject: [PATCH 20/36] fix idx_map Signed-off-by: Jinzhe Zeng --- source/lmp/tests/test_deeptensor.py | 2 +- source/lmp/tests/test_lammps.py | 4 ++-- source/lmp/tests/test_lammps_dpa_jax.py | 4 ++-- source/lmp/tests/test_lammps_dpa_pt_nopbc.py | 4 ++-- source/lmp/tests/test_lammps_dpa_sel_pt.py | 4 ++-- source/lmp/tests/test_lammps_jax.py | 4 ++-- source/lmp/tests/test_lammps_pd.py | 4 ++-- source/lmp/tests/test_lammps_pt.py | 4 ++-- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/source/lmp/tests/test_deeptensor.py b/source/lmp/tests/test_deeptensor.py index 38f887186a..902a7294ee 100644 --- a/source/lmp/tests/test_deeptensor.py +++ b/source/lmp/tests/test_deeptensor.py @@ -155,7 +155,7 @@ def test_compute_deeptensor_atom_si(lammps_si) -> None: lammps_si.variable("tensor atom c_tensor[1]") lammps_si.dump("1 all custom 1 dump id c_tensor[1]") lammps_si.run(0) - idx_map = lammps_si.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps_si.lmp.numpy.extract_atom("id")[:6] - 1 assert np.array(lammps_si.variables["tensor"].value) == pytest.approx( expected_d[idx_map] * constants.dist_metal2si ) diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index fba629b276..193d18a123 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -545,7 +545,7 @@ def test_pair_deepmd_virial_real(lammps_real) -> None: assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value @@ -604,7 +604,7 @@ def test_pair_deepmd_model_devi_virial_real(lammps_real) -> None: assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value diff --git a/source/lmp/tests/test_lammps_dpa_jax.py b/source/lmp/tests/test_lammps_dpa_jax.py index 5105c18e16..273fec48af 100644 --- a/source/lmp/tests/test_lammps_dpa_jax.py +++ b/source/lmp/tests/test_lammps_dpa_jax.py @@ -511,7 +511,7 @@ def test_pair_deepmd_virial_real(lammps_real): assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value @@ -570,7 +570,7 @@ def test_pair_deepmd_model_devi_virial_real(lammps_real): assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value diff --git a/source/lmp/tests/test_lammps_dpa_pt_nopbc.py b/source/lmp/tests/test_lammps_dpa_pt_nopbc.py index 5e72473186..76db80cb44 100644 --- a/source/lmp/tests/test_lammps_dpa_pt_nopbc.py +++ b/source/lmp/tests/test_lammps_dpa_pt_nopbc.py @@ -505,7 +505,7 @@ def test_pair_deepmd_virial_real(lammps_real) -> None: assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value @@ -564,7 +564,7 @@ def test_pair_deepmd_model_devi_virial_real(lammps_real) -> None: assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value diff --git a/source/lmp/tests/test_lammps_dpa_sel_pt.py b/source/lmp/tests/test_lammps_dpa_sel_pt.py index d7f9c588a9..e30f6e6343 100644 --- a/source/lmp/tests/test_lammps_dpa_sel_pt.py +++ b/source/lmp/tests/test_lammps_dpa_sel_pt.py @@ -510,7 +510,7 @@ def test_pair_deepmd_virial_real(lammps_real) -> None: assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value @@ -569,7 +569,7 @@ def test_pair_deepmd_model_devi_virial_real(lammps_real) -> None: assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value diff --git a/source/lmp/tests/test_lammps_jax.py b/source/lmp/tests/test_lammps_jax.py index cbd4d53d0b..4fcfdf8ca5 100644 --- a/source/lmp/tests/test_lammps_jax.py +++ b/source/lmp/tests/test_lammps_jax.py @@ -509,7 +509,7 @@ def test_pair_deepmd_virial_real(lammps_real): assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value @@ -568,7 +568,7 @@ def test_pair_deepmd_model_devi_virial_real(lammps_real): assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value diff --git a/source/lmp/tests/test_lammps_pd.py b/source/lmp/tests/test_lammps_pd.py index 9463ded353..038d2786d0 100644 --- a/source/lmp/tests/test_lammps_pd.py +++ b/source/lmp/tests/test_lammps_pd.py @@ -516,7 +516,7 @@ def test_pair_deepmd_virial_real(lammps_real): RTOL, ATOL, ) - idx_map = lammps_real.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value @@ -581,7 +581,7 @@ def test_pair_deepmd_model_devi_virial_real(lammps_real): RTOL, ATOL, ) - idx_map = lammps_real.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value diff --git a/source/lmp/tests/test_lammps_pt.py b/source/lmp/tests/test_lammps_pt.py index 789cdaf7a7..ef2617d1a0 100644 --- a/source/lmp/tests/test_lammps_pt.py +++ b/source/lmp/tests/test_lammps_pt.py @@ -507,7 +507,7 @@ def test_pair_deepmd_virial_real(lammps_real) -> None: assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value @@ -566,7 +566,7 @@ def test_pair_deepmd_model_devi_virial_real(lammps_real) -> None: assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value From ae8d2c572370ec266b849b0737104c17eb11bee8 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 5 Aug 2025 23:54:53 +0800 Subject: [PATCH 21/36] move mpich deps to metadata Signed-off-by: Jinzhe Zeng --- backend/dp_backend.py | 7 +++++++ pyproject.toml | 8 -------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/backend/dp_backend.py b/backend/dp_backend.py index 81c3f20f19..e32d5db38b 100644 --- a/backend/dp_backend.py +++ b/backend/dp_backend.py @@ -1,6 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later """A PEP-517 backend to find TensorFlow.""" +import os + from scikit_build_core import build as _orig from .find_pytorch import ( @@ -39,10 +41,15 @@ def __dir__() -> list[str]: def get_requires_for_build_wheel( config_settings: dict, ) -> list[str]: + if os.environ.get("CIBUILDWHEEL", "0") == "1": + cibw_deps = ["mpich"] + else: + cibw_deps = [] return ( _orig.get_requires_for_build_wheel(config_settings) + find_tensorflow()[1] + find_pytorch()[1] + + cibw_deps ) diff --git a/pyproject.toml b/pyproject.toml index acf0d593d5..16d4046cc5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -241,9 +241,6 @@ manylinux-x86_64-image = "quay.io/pypa/manylinux_2_28_x86_64:2022-11-19-1b19e81" manylinux-aarch64-image = "manylinux_2_28" [tool.cibuildwheel.macos] -before-all = [ - '''pip install mpich''', -] repair-wheel-command = """delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel} --ignore-missing-dependencies""" [tool.cibuildwheel.macos.environment] @@ -275,7 +272,6 @@ before-all = [ # https://almalinux.org/blog/2023-12-20-almalinux-8-key-update/ """rpm --import https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux""", """{ if [ "$(uname -m)" = "x86_64" ] ; then yum config-manager --add-repo http://developer.download.nvidia.com/compute/cuda/repos/rhel8/x86_64/cuda-rhel8.repo && yum install -y cuda-nvcc-${CUDA_VERSION/./-} cuda-cudart-devel-${CUDA_VERSION/./-}; fi }""", - '''/opt/python/cp311-cp311/bin/python -m pip install mpich''', # uv is not available in the old manylinux image """{ if [ "$(uname -m)" = "x86_64" ] ; then pipx install uv; fi }""", ] @@ -289,14 +285,10 @@ DP_LAMMPS_VERSION = "stable_22Jul2025" DP_ENABLE_IPI = "1" DP_ENABLE_PYTORCH = "1" DP_ENABLE_PADDLE = "1" -MPI_HOME = "/usr/lib64/mpich" -PATH = "/usr/lib64/mpich/bin:$PATH" # use CPU version of torch for building, which should also work for GPU # note: uv has different behavior from pip on extra index url # https://github.com/astral-sh/uv/blob/main/PIP_COMPATIBILITY.md#packages-that-exist-on-multiple-indexes UV_EXTRA_INDEX_URL = "https://download.pytorch.org/whl/cpu" -# trick to find the correction version of mpich -CMAKE_PREFIX_PATH="/opt/python/cp311-cp311/" [tool.cibuildwheel.windows] test-extras = ["cpu", "torch", "paddle"] From 839063fcbc4215c54be04e607fe660aeea2257df Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 5 Aug 2025 18:03:05 +0000 Subject: [PATCH 22/36] Update pyproject.toml Signed-off-by: Jinzhe Zeng --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 16d4046cc5..9e2c319c83 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -259,7 +259,7 @@ inherit.environment = "append" environment.MACOSX_DEPLOYMENT_TARGET = "11.0" [tool.cibuildwheel.linux] -repair-wheel-command = "auditwheel repair --exclude libtensorflow_framework.so.2 --exclude libtensorflow_framework.so.1 --exclude libtensorflow_framework.so --exclude _pywrap_tensorflow_internal.so --exclude libtensorflow_cc.so.2 --exclude libc10.so --exclude libtorch.so --exclude libtorch_cpu.so -w {dest_dir} {wheel}" +repair-wheel-command = "auditwheel repair --exclude libtensorflow_framework.so.2 --exclude libtensorflow_framework.so.1 --exclude libtensorflow_framework.so --exclude _pywrap_tensorflow_internal.so --exclude libtensorflow_cc.so.2 --exclude libc10.so --exclude libtorch.so --exclude libtorch_cpu.so -e libmpi.so.12 -w {dest_dir} {wheel}" environment-pass = [ "CIBW_BUILD", "DP_VARIANT", From 27fd43a381db78a52dba7317eb234a5a8715a013 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 6 Aug 2025 02:33:38 +0800 Subject: [PATCH 23/36] Update pyproject.toml Signed-off-by: Jinzhe Zeng --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 9e2c319c83..15cd65db59 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -259,7 +259,7 @@ inherit.environment = "append" environment.MACOSX_DEPLOYMENT_TARGET = "11.0" [tool.cibuildwheel.linux] -repair-wheel-command = "auditwheel repair --exclude libtensorflow_framework.so.2 --exclude libtensorflow_framework.so.1 --exclude libtensorflow_framework.so --exclude _pywrap_tensorflow_internal.so --exclude libtensorflow_cc.so.2 --exclude libc10.so --exclude libtorch.so --exclude libtorch_cpu.so -e libmpi.so.12 -w {dest_dir} {wheel}" +repair-wheel-command = "auditwheel repair --exclude libtensorflow_framework.so.2 --exclude libtensorflow_framework.so.1 --exclude libtensorflow_framework.so --exclude _pywrap_tensorflow_internal.so --exclude libtensorflow_cc.so.2 --exclude libc10.so --exclude libtorch.so --exclude libtorch_cpu.so --exclude libmpi.so.12 -w {dest_dir} {wheel}" environment-pass = [ "CIBW_BUILD", "DP_VARIANT", From 0111e9658f40c3a2fefaa4b818a5dedcd1612918 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 6 Aug 2025 04:59:10 +0800 Subject: [PATCH 24/36] load mpi --- backend/read_env.py | 1 + deepmd/lmp.py | 205 ++++++++++++++++++----------------- deepmd/pt/cxx_op.py | 29 +++++ source/config/run_config.ini | 2 + 4 files changed, 140 insertions(+), 97 deletions(-) diff --git a/backend/read_env.py b/backend/read_env.py index f28e2917f3..482f9766a0 100644 --- a/backend/read_env.py +++ b/backend/read_env.py @@ -119,6 +119,7 @@ def get_argument_from_env() -> tuple[str, list, list, dict, str, str]: cmake_args = [ "-DBUILD_PY_IF:BOOL=TRUE", + f"-DCIBUILDWHEEL={os.environ.get('CIBUILDWHEEL', '0')}", *cmake_args, ] return ( diff --git a/deepmd/lmp.py b/deepmd/lmp.py index 15959cf243..2bd0caef0f 100644 --- a/deepmd/lmp.py +++ b/deepmd/lmp.py @@ -13,119 +13,130 @@ Optional, ) -import torch # noqa: TID253 -from packaging.version import ( - Version, -) - from deepmd.env import ( - SHARED_LIB_DIR, -) -from deepmd.tf.env import ( # noqa: TID253 - TF_VERSION, - tf, + GLOBAL_CONFIG, ) -if Version(TF_VERSION) < Version("2.12"): - from find_libpython import ( - find_libpython, - ) +if GLOBAL_CONFIG.get("LAMMPS_VERSION", "") == "": + def get_op_dir() -> str: + """Get the directory of the deepmd-kit OP library.""" + # empty + return "" else: - find_libpython = None - - -def get_env(paths: list[Optional[str]]) -> str: - """Get the environment variable from given paths.""" - return ":".join(p for p in paths if p is not None) - -def get_library_path(module: str, filename: str) -> list[str]: - """Get library path from a module. + import torch # noqa: TID253 + from packaging.version import ( + Version, + ) - Parameters - ---------- - module : str - The module name. - filename : str - The library filename pattern. + from deepmd.env import ( + SHARED_LIB_DIR, + ) + from deepmd.tf.env import ( # noqa: TID253 + TF_VERSION, + tf, + ) - Returns - ------- - list[str] - The library path. - """ - try: - m = import_module(module) - except ModuleNotFoundError: - return [] + if Version(TF_VERSION) < Version("2.12"): + from find_libpython import ( + find_libpython, + ) else: - libs = sorted(Path(m.__path__[0]).glob(filename)) - return [str(lib) for lib in libs] - - -if platform.system() == "Linux": - lib_env = "LD_LIBRARY_PATH" -elif platform.system() == "Darwin": - lib_env = "DYLD_FALLBACK_LIBRARY_PATH" -else: - raise RuntimeError("Unsupported platform") - -if platform.system() == "Linux": - preload_env = "LD_PRELOAD" -elif platform.system() == "Darwin": - preload_env = "DYLD_INSERT_LIBRARIES" -else: - raise RuntimeError("Unsupported platform") - -tf_dir = tf.sysconfig.get_lib() -pt_dir = os.path.join(torch.__path__[0], "lib") -op_dir = str(SHARED_LIB_DIR) + find_libpython = None + + + def get_env(paths: list[Optional[str]]) -> str: + """Get the environment variable from given paths.""" + return ":".join(p for p in paths if p is not None) + + + def get_library_path(module: str, filename: str) -> list[str]: + """Get library path from a module. + + Parameters + ---------- + module : str + The module name. + filename : str + The library filename pattern. + + Returns + ------- + list[str] + The library path. + """ + try: + m = import_module(module) + except ModuleNotFoundError: + return [] + else: + libs = sorted(Path(m.__path__[0]).glob(filename)) + return [str(lib) for lib in libs] + + + if platform.system() == "Linux": + lib_env = "LD_LIBRARY_PATH" + elif platform.system() == "Darwin": + lib_env = "DYLD_FALLBACK_LIBRARY_PATH" + else: + raise RuntimeError("Unsupported platform") + if platform.system() == "Linux": + preload_env = "LD_PRELOAD" + elif platform.system() == "Darwin": + preload_env = "DYLD_INSERT_LIBRARIES" + else: + raise RuntimeError("Unsupported platform") + + tf_dir = tf.sysconfig.get_lib() + pt_dir = os.path.join(torch.__path__[0], "lib") + op_dir = str(SHARED_LIB_DIR) + + + cuda_library_paths = [] + if platform.system() == "Linux": + cuda_library_paths.extend( + [ + *get_library_path("nvidia.cuda_runtime.lib", "libcudart.so*"), + *get_library_path("nvidia.cublas.lib", "libcublasLt.so*"), + *get_library_path("nvidia.cublas.lib", "libcublas.so*"), + *get_library_path("nvidia.cufft.lib", "libcufft.so*"), + *get_library_path("nvidia.curand.lib", "libcurand.so*"), + *get_library_path("nvidia.cusolver.lib", "libcusolver.so*"), + *get_library_path("nvidia.cusparse.lib", "libcusparse.so*"), + *get_library_path("nvidia.cudnn.lib", "libcudnn.so*"), + ] + ) -cuda_library_paths = [] -if platform.system() == "Linux": - cuda_library_paths.extend( + os.environ[preload_env] = get_env( [ - *get_library_path("nvidia.cuda_runtime.lib", "libcudart.so*"), - *get_library_path("nvidia.cublas.lib", "libcublasLt.so*"), - *get_library_path("nvidia.cublas.lib", "libcublas.so*"), - *get_library_path("nvidia.cufft.lib", "libcufft.so*"), - *get_library_path("nvidia.curand.lib", "libcurand.so*"), - *get_library_path("nvidia.cusolver.lib", "libcusolver.so*"), - *get_library_path("nvidia.cusparse.lib", "libcusparse.so*"), - *get_library_path("nvidia.cudnn.lib", "libcudnn.so*"), + os.environ.get(preload_env), + *cuda_library_paths, ] ) -os.environ[preload_env] = get_env( - [ - os.environ.get(preload_env), - *cuda_library_paths, - ] -) - -# set LD_LIBRARY_PATH -os.environ[lib_env] = get_env( - [ - os.environ.get(lib_env), - tf_dir, - os.path.join(tf_dir, "python"), - pt_dir, - op_dir, - ] -) - -# preload python library, only for TF<2.12 -if find_libpython is not None: - libpython = find_libpython() - os.environ[preload_env] = get_env( + # set LD_LIBRARY_PATH + os.environ[lib_env] = get_env( [ - os.environ.get(preload_env), - libpython, + os.environ.get(lib_env), + tf_dir, + os.path.join(tf_dir, "python"), + pt_dir, + op_dir, ] ) + # preload python library, only for TF<2.12 + if find_libpython is not None: + libpython = find_libpython() + os.environ[preload_env] = get_env( + [ + os.environ.get(preload_env), + libpython, + ] + ) + -def get_op_dir() -> str: - """Get the directory of the deepmd-kit OP library.""" - return op_dir + def get_op_dir() -> str: + """Get the directory of the deepmd-kit OP library.""" + return op_dir diff --git a/deepmd/pt/cxx_op.py b/deepmd/pt/cxx_op.py index f7922a5c52..c3272f99c6 100644 --- a/deepmd/pt/cxx_op.py +++ b/deepmd/pt/cxx_op.py @@ -87,6 +87,35 @@ def load_library(module_name: str) -> bool: return False +if GLOBAL_CONFIG.get("CIBUILDWHEEL", "0") == "1": + if platform.system() == "Linux": + lib_env = "LD_LIBRARY_PATH" + extension = ".so" + elif platform.system() == "Darwin": + lib_env = "DYLD_FALLBACK_LIBRARY_PATH" + exition = ".dylib" + else: + # windows + pass + + if platform.system() in ("Linux", "Darwin"): + # try to find MPI directory and add to LD_LIBRARY_PATH + try: + MPI_ROOT = ( + [p for p in metadata.files("mpich") if f"libmpi{extension}" in str(p)][0] + .locate() + .parent + ) + # insert MPI_ROOT to LD_LIBRARY_PATH + current_ld_path = os.environ.get(lib_env, "") + if current_ld_path: + os.environ[lib_env] = f"{current_ld_path}:{MPI_ROOT}" + else: + os.environ[lib_env] = str(MPI_ROOT) + except Exception: + # MPI not found or not available, continue without it + pass + ENABLE_CUSTOMIZED_OP = load_library("deepmd_op_pt") __all__ = [ diff --git a/source/config/run_config.ini b/source/config/run_config.ini index 7bb6041af9..596be911db 100644 --- a/source/config/run_config.ini +++ b/source/config/run_config.ini @@ -18,3 +18,5 @@ PD_VERSION = @PADDLE_VERSION@ PD_INFERENCE_DIR = @PADDLE_INFERENCE_DIR@ MODEL_VERSION=@MODEL_VERSION@ DP_VARIANT=@DP_VARIANT@ +LAMMPS_VERSION = @LAMMPS_VERSION@ +CIBUILDWHEEL = @CIBUILDWHEEL@ From fe1aa569de1f192ad0c2184e3e836a0451e65229 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 5 Aug 2025 21:02:16 +0000 Subject: [PATCH 25/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- deepmd/lmp.py | 11 +++-------- deepmd/pt/cxx_op.py | 4 +++- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/deepmd/lmp.py b/deepmd/lmp.py index 2bd0caef0f..d97861709c 100644 --- a/deepmd/lmp.py +++ b/deepmd/lmp.py @@ -18,13 +18,13 @@ ) if GLOBAL_CONFIG.get("LAMMPS_VERSION", "") == "": + def get_op_dir() -> str: """Get the directory of the deepmd-kit OP library.""" # empty return "" else: - - import torch # noqa: TID253 + import torch from packaging.version import ( Version, ) @@ -32,7 +32,7 @@ def get_op_dir() -> str: from deepmd.env import ( SHARED_LIB_DIR, ) - from deepmd.tf.env import ( # noqa: TID253 + from deepmd.tf.env import ( TF_VERSION, tf, ) @@ -44,12 +44,10 @@ def get_op_dir() -> str: else: find_libpython = None - def get_env(paths: list[Optional[str]]) -> str: """Get the environment variable from given paths.""" return ":".join(p for p in paths if p is not None) - def get_library_path(module: str, filename: str) -> list[str]: """Get library path from a module. @@ -73,7 +71,6 @@ def get_library_path(module: str, filename: str) -> list[str]: libs = sorted(Path(m.__path__[0]).glob(filename)) return [str(lib) for lib in libs] - if platform.system() == "Linux": lib_env = "LD_LIBRARY_PATH" elif platform.system() == "Darwin": @@ -92,7 +89,6 @@ def get_library_path(module: str, filename: str) -> list[str]: pt_dir = os.path.join(torch.__path__[0], "lib") op_dir = str(SHARED_LIB_DIR) - cuda_library_paths = [] if platform.system() == "Linux": cuda_library_paths.extend( @@ -136,7 +132,6 @@ def get_library_path(module: str, filename: str) -> list[str]: ] ) - def get_op_dir() -> str: """Get the directory of the deepmd-kit OP library.""" return op_dir diff --git a/deepmd/pt/cxx_op.py b/deepmd/pt/cxx_op.py index c3272f99c6..810132e39d 100644 --- a/deepmd/pt/cxx_op.py +++ b/deepmd/pt/cxx_op.py @@ -102,7 +102,9 @@ def load_library(module_name: str) -> bool: # try to find MPI directory and add to LD_LIBRARY_PATH try: MPI_ROOT = ( - [p for p in metadata.files("mpich") if f"libmpi{extension}" in str(p)][0] + [p for p in metadata.files("mpich") if f"libmpi{extension}" in str(p)][ + 0 + ] .locate() .parent ) From 5a288bdd60a664d47f77eb4e07951a3eccf6b271 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 6 Aug 2025 14:30:42 +0800 Subject: [PATCH 26/36] fix errors --- deepmd/lmp.py | 2 +- deepmd/pt/cxx_op.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/deepmd/lmp.py b/deepmd/lmp.py index d97861709c..5b836f6311 100644 --- a/deepmd/lmp.py +++ b/deepmd/lmp.py @@ -17,7 +17,7 @@ GLOBAL_CONFIG, ) -if GLOBAL_CONFIG.get("LAMMPS_VERSION", "") == "": +if GLOBAL_CONFIG.get("lammps_version", "") == "": def get_op_dir() -> str: """Get the directory of the deepmd-kit OP library.""" diff --git a/deepmd/pt/cxx_op.py b/deepmd/pt/cxx_op.py index 810132e39d..7bb6d0d30c 100644 --- a/deepmd/pt/cxx_op.py +++ b/deepmd/pt/cxx_op.py @@ -1,5 +1,9 @@ # SPDX-License-Identifier: LGPL-3.0-or-later +import os import platform +from importlib import ( + metadata, +) import torch from packaging.version import ( @@ -87,13 +91,13 @@ def load_library(module_name: str) -> bool: return False -if GLOBAL_CONFIG.get("CIBUILDWHEEL", "0") == "1": +if GLOBAL_CONFIG.get("cibuildwheel", "0") == "1": if platform.system() == "Linux": lib_env = "LD_LIBRARY_PATH" extension = ".so" elif platform.system() == "Darwin": lib_env = "DYLD_FALLBACK_LIBRARY_PATH" - exition = ".dylib" + extension = ".dylib" else: # windows pass @@ -102,9 +106,9 @@ def load_library(module_name: str) -> bool: # try to find MPI directory and add to LD_LIBRARY_PATH try: MPI_ROOT = ( - [p for p in metadata.files("mpich") if f"libmpi{extension}" in str(p)][ - 0 - ] + next( + p for p in metadata.files("mpich") if f"libmpi{extension}" in str(p) + ) .locate() .parent ) From 36db848275d3c183504c749bfb8807ff2aabdf73 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 6 Aug 2025 14:36:28 +0800 Subject: [PATCH 27/36] fix slice --- source/lmp/tests/test_deeptensor.py | 4 ++-- source/lmp/tests/test_dplr.py | 8 ++++---- source/lmp/tests/test_lammps.py | 8 ++++---- source/lmp/tests/test_lammps_3types.py | 4 ++-- source/lmp/tests/test_lammps_dpa_jax.py | 8 ++++---- source/lmp/tests/test_lammps_dpa_pt.py | 4 ++-- source/lmp/tests/test_lammps_dpa_pt_nopbc.py | 8 ++++---- source/lmp/tests/test_lammps_dpa_sel_pt.py | 8 ++++---- source/lmp/tests/test_lammps_faparam.py | 2 +- source/lmp/tests/test_lammps_jax.py | 8 ++++---- source/lmp/tests/test_lammps_pd.py | 8 ++++---- source/lmp/tests/test_lammps_pt.py | 8 ++++---- source/lmp/tests/test_lammps_spin.py | 2 +- source/lmp/tests/test_lammps_spin_pt.py | 2 +- 14 files changed, 41 insertions(+), 41 deletions(-) diff --git a/source/lmp/tests/test_deeptensor.py b/source/lmp/tests/test_deeptensor.py index 902a7294ee..41d1c10ed6 100644 --- a/source/lmp/tests/test_deeptensor.py +++ b/source/lmp/tests/test_deeptensor.py @@ -142,7 +142,7 @@ def test_compute_deeptensor_atom(lammps) -> None: lammps.variable("tensor atom c_tensor[1]") lammps.dump("1 all custom 1 dump id c_tensor[1]") lammps.run(0) - idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 assert np.array(lammps.variables["tensor"].value) == pytest.approx( expected_d[idx_map] ) @@ -155,7 +155,7 @@ def test_compute_deeptensor_atom_si(lammps_si) -> None: lammps_si.variable("tensor atom c_tensor[1]") lammps_si.dump("1 all custom 1 dump id c_tensor[1]") lammps_si.run(0) - idx_map = lammps_si.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps_si.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 assert np.array(lammps_si.variables["tensor"].value) == pytest.approx( expected_d[idx_map] * constants.dist_metal2si ) diff --git a/source/lmp/tests/test_dplr.py b/source/lmp/tests/test_dplr.py index 51cb57a8eb..bf8783f233 100644 --- a/source/lmp/tests/test_dplr.py +++ b/source/lmp/tests/test_dplr.py @@ -357,7 +357,7 @@ def test_pair_deepmd_sr(lammps) -> None: lammps.pair_coeff("* *") lammps.run(0) assert lammps.eval("pe") == pytest.approx(expected_e_sr) - id_list = lammps.lmp.numpy.extract_atom("id")[:6] + id_list = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] for ii in range(6): assert lammps.atoms[np.where(id_list == (ii + 1))[0][0]].force == pytest.approx( expected_f_sr[ii] @@ -378,7 +378,7 @@ def test_pair_deepmd_sr_virial(lammps) -> None: ) lammps.dump_modify("1 sort id") lammps.run(0) - id_list = lammps.lmp.numpy.extract_atom("id")[:6] + id_list = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] idx_list = [np.where(id_list == i)[0][0] for i in range(1, 7)] assert lammps.eval("pe") == pytest.approx(expected_e_sr) for ii in range(6): @@ -445,7 +445,7 @@ def test_pair_deepmd_lr_efield_constant(lammps) -> None: ) lammps.fix_modify("0 energy yes virial yes") lammps.run(0) - id_list = lammps.lmp.numpy.extract_atom("id")[:6] + id_list = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] assert lammps.eval("evdwl") == pytest.approx(expected_evdwl_lr_efield_constant) assert lammps.eval("f_0") == pytest.approx(expected_e_efield_constant) assert lammps.eval("pe") == pytest.approx(expected_e_lr_efield_constant) @@ -481,7 +481,7 @@ def test_pair_deepmd_lr_efield_variable(lammps) -> None: ) lammps.fix_modify("0 energy yes virial yes") lammps.run(0) - id_list = lammps.lmp.numpy.extract_atom("id")[:6] + id_list = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] assert lammps.eval("evdwl") == pytest.approx(expected_evdwl_lr_efield_variable) assert lammps.eval("f_0") == pytest.approx(expected_e_efield_variable) assert lammps.eval("pe") == pytest.approx(expected_e_lr_efield_variable) diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index 193d18a123..c24f032cf6 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -340,7 +340,7 @@ def test_pair_deepmd_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 assert np.array(lammps.variables["eatom"].value) == pytest.approx( expected_ae[idx_map] ) @@ -408,7 +408,7 @@ def test_pair_deepmd_model_devi_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 assert np.array(lammps.variables["eatom"].value) == pytest.approx( expected_ae[idx_map] ) @@ -545,7 +545,7 @@ def test_pair_deepmd_virial_real(lammps_real) -> None: assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value @@ -604,7 +604,7 @@ def test_pair_deepmd_model_devi_virial_real(lammps_real) -> None: assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value diff --git a/source/lmp/tests/test_lammps_3types.py b/source/lmp/tests/test_lammps_3types.py index ac5185ac04..a99a83b758 100644 --- a/source/lmp/tests/test_lammps_3types.py +++ b/source/lmp/tests/test_lammps_3types.py @@ -320,7 +320,7 @@ def test_pair_deepmd_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value @@ -371,7 +371,7 @@ def test_pair_deepmd_model_devi_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value diff --git a/source/lmp/tests/test_lammps_dpa_jax.py b/source/lmp/tests/test_lammps_dpa_jax.py index 273fec48af..65991b9732 100644 --- a/source/lmp/tests/test_lammps_dpa_jax.py +++ b/source/lmp/tests/test_lammps_dpa_jax.py @@ -334,7 +334,7 @@ def test_pair_deepmd_virial(lammps): assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value @@ -385,7 +385,7 @@ def test_pair_deepmd_model_devi_virial(lammps): assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value @@ -511,7 +511,7 @@ def test_pair_deepmd_virial_real(lammps_real): assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value @@ -570,7 +570,7 @@ def test_pair_deepmd_model_devi_virial_real(lammps_real): assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value diff --git a/source/lmp/tests/test_lammps_dpa_pt.py b/source/lmp/tests/test_lammps_dpa_pt.py index 6f397a60ba..9e15263ecb 100644 --- a/source/lmp/tests/test_lammps_dpa_pt.py +++ b/source/lmp/tests/test_lammps_dpa_pt.py @@ -330,7 +330,7 @@ def test_pair_deepmd_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value @@ -381,7 +381,7 @@ def test_pair_deepmd_model_devi_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value diff --git a/source/lmp/tests/test_lammps_dpa_pt_nopbc.py b/source/lmp/tests/test_lammps_dpa_pt_nopbc.py index 76db80cb44..1c2e145c84 100644 --- a/source/lmp/tests/test_lammps_dpa_pt_nopbc.py +++ b/source/lmp/tests/test_lammps_dpa_pt_nopbc.py @@ -328,7 +328,7 @@ def test_pair_deepmd_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value @@ -379,7 +379,7 @@ def test_pair_deepmd_model_devi_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value @@ -505,7 +505,7 @@ def test_pair_deepmd_virial_real(lammps_real) -> None: assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value @@ -564,7 +564,7 @@ def test_pair_deepmd_model_devi_virial_real(lammps_real) -> None: assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value diff --git a/source/lmp/tests/test_lammps_dpa_sel_pt.py b/source/lmp/tests/test_lammps_dpa_sel_pt.py index e30f6e6343..e758251f18 100644 --- a/source/lmp/tests/test_lammps_dpa_sel_pt.py +++ b/source/lmp/tests/test_lammps_dpa_sel_pt.py @@ -333,7 +333,7 @@ def test_pair_deepmd_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value @@ -384,7 +384,7 @@ def test_pair_deepmd_model_devi_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value @@ -510,7 +510,7 @@ def test_pair_deepmd_virial_real(lammps_real) -> None: assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value @@ -569,7 +569,7 @@ def test_pair_deepmd_model_devi_virial_real(lammps_real) -> None: assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value diff --git a/source/lmp/tests/test_lammps_faparam.py b/source/lmp/tests/test_lammps_faparam.py index 5e4dd09db9..4f744119b6 100644 --- a/source/lmp/tests/test_lammps_faparam.py +++ b/source/lmp/tests/test_lammps_faparam.py @@ -213,7 +213,7 @@ def test_pair_deepmd_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value diff --git a/source/lmp/tests/test_lammps_jax.py b/source/lmp/tests/test_lammps_jax.py index 4fcfdf8ca5..0c488cd1bc 100644 --- a/source/lmp/tests/test_lammps_jax.py +++ b/source/lmp/tests/test_lammps_jax.py @@ -332,7 +332,7 @@ def test_pair_deepmd_virial(lammps): assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value @@ -383,7 +383,7 @@ def test_pair_deepmd_model_devi_virial(lammps): assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value @@ -509,7 +509,7 @@ def test_pair_deepmd_virial_real(lammps_real): assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value @@ -568,7 +568,7 @@ def test_pair_deepmd_model_devi_virial_real(lammps_real): assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value diff --git a/source/lmp/tests/test_lammps_pd.py b/source/lmp/tests/test_lammps_pd.py index 038d2786d0..92b00aba29 100644 --- a/source/lmp/tests/test_lammps_pd.py +++ b/source/lmp/tests/test_lammps_pd.py @@ -333,7 +333,7 @@ def test_pair_deepmd_virial(lammps): assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value @@ -384,7 +384,7 @@ def test_pair_deepmd_model_devi_virial(lammps): assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1], RTOL, ATOL ) - idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value @@ -516,7 +516,7 @@ def test_pair_deepmd_virial_real(lammps_real): RTOL, ATOL, ) - idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value @@ -581,7 +581,7 @@ def test_pair_deepmd_model_devi_virial_real(lammps_real): RTOL, ATOL, ) - idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value diff --git a/source/lmp/tests/test_lammps_pt.py b/source/lmp/tests/test_lammps_pt.py index ef2617d1a0..f675b2b671 100644 --- a/source/lmp/tests/test_lammps_pt.py +++ b/source/lmp/tests/test_lammps_pt.py @@ -330,7 +330,7 @@ def test_pair_deepmd_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value @@ -381,7 +381,7 @@ def test_pair_deepmd_model_devi_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value @@ -507,7 +507,7 @@ def test_pair_deepmd_virial_real(lammps_real) -> None: assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value @@ -566,7 +566,7 @@ def test_pair_deepmd_model_devi_virial_real(lammps_real) -> None: assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value diff --git a/source/lmp/tests/test_lammps_spin.py b/source/lmp/tests/test_lammps_spin.py index 073572b7bc..9ab7271f5f 100644 --- a/source/lmp/tests/test_lammps_spin.py +++ b/source/lmp/tests/test_lammps_spin.py @@ -172,7 +172,7 @@ def test_pair_deepmd_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 assert np.array(lammps.variables["eatom"].value) == pytest.approx( expected_ae[idx_map] ) diff --git a/source/lmp/tests/test_lammps_spin_pt.py b/source/lmp/tests/test_lammps_spin_pt.py index ff0a6fc26c..9a0771d047 100644 --- a/source/lmp/tests/test_lammps_spin_pt.py +++ b/source/lmp/tests/test_lammps_spin_pt.py @@ -168,7 +168,7 @@ def test_pair_deepmd_virial(lammps) -> None: assert lammps.atoms[ii].force == pytest.approx( expected_f[lammps.atoms[ii].id - 1] ) - idx_map = lammps.lmp.numpy.extract_atom("id")[:6] - 1 + idx_map = lammps.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 assert np.array(lammps.variables["eatom"].value) == pytest.approx( expected_ae[idx_map] ) From 31b541bd55a10a3e976362519153ea3f1c927fbd Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 6 Aug 2025 14:40:06 +0800 Subject: [PATCH 28/36] fix --- source/lmp/tests/test_lammps_dpa_pt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/lmp/tests/test_lammps_dpa_pt.py b/source/lmp/tests/test_lammps_dpa_pt.py index 9e15263ecb..2768332c71 100644 --- a/source/lmp/tests/test_lammps_dpa_pt.py +++ b/source/lmp/tests/test_lammps_dpa_pt.py @@ -507,7 +507,7 @@ def test_pair_deepmd_virial_real(lammps_real) -> None: assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value @@ -566,7 +566,7 @@ def test_pair_deepmd_model_devi_virial_real(lammps_real) -> None: assert lammps_real.atoms[ii].force == pytest.approx( expected_f[lammps_real.atoms[ii].id - 1] * constants.force_metal2real ) - idx_map = lammps_real.lmp.numpy.extract_atom("id") - 1 + idx_map = lammps_real.lmp.numpy.extract_atom("id")[: coord.shape[0]] - 1 for ii in range(9): assert np.array( lammps_real.variables[f"virial{ii}"].value From 2dde1b7ceda64003fcbfc096d4b0e007da9d6233 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 6 Aug 2025 14:40:27 +0800 Subject: [PATCH 29/36] Revert "Revert "Revert "mpich is still required""" This reverts commit 51c5eefe26fc556f817d69c1c694147ddf614c45. --- .github/workflows/test_cc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_cc.yml b/.github/workflows/test_cc.yml index 734966a089..d995566641 100644 --- a/.github/workflows/test_cc.yml +++ b/.github/workflows/test_cc.yml @@ -29,7 +29,7 @@ jobs: export TENSORFLOW_ROOT=$(python -c 'import importlib,pathlib;print(pathlib.Path(importlib.util.find_spec("tensorflow").origin).parent)') # 20250804: disable the MPI tests since mpi4py MPI is conflict with LAMMPS MPI # TODO: recover the MPI tests after the conflict is resolved - source/install/uv_with_retry.sh pip install --system -e .[cpu,test,lmp,jax] mpich # mpi4py + source/install/uv_with_retry.sh pip install --system -e .[cpu,test,lmp,jax] # mpi4py mpich source/install/uv_with_retry.sh pip install --system 'torch==2.7' --index-url https://download.pytorch.org/whl/cpu - name: Convert models run: source/tests/infer/convert-models.sh From 4036f0aaff81e8620207d3077c6592672ef0d35f Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 6 Aug 2025 14:40:29 +0800 Subject: [PATCH 30/36] Revert "Revert "Revert "disable the MPI tests""" This reverts commit e9f548c99a028d483374d5c72ec7eb20321cb04d. --- .github/workflows/test_cc.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/test_cc.yml b/.github/workflows/test_cc.yml index d995566641..7d76e60ba1 100644 --- a/.github/workflows/test_cc.yml +++ b/.github/workflows/test_cc.yml @@ -27,9 +27,7 @@ jobs: run: | source/install/uv_with_retry.sh pip install --system tensorflow-cpu~=2.18.0 jax==0.5.0 export TENSORFLOW_ROOT=$(python -c 'import importlib,pathlib;print(pathlib.Path(importlib.util.find_spec("tensorflow").origin).parent)') - # 20250804: disable the MPI tests since mpi4py MPI is conflict with LAMMPS MPI - # TODO: recover the MPI tests after the conflict is resolved - source/install/uv_with_retry.sh pip install --system -e .[cpu,test,lmp,jax] # mpi4py mpich + source/install/uv_with_retry.sh pip install --system -e .[cpu,test,lmp,jax] mpi4py mpich source/install/uv_with_retry.sh pip install --system 'torch==2.7' --index-url https://download.pytorch.org/whl/cpu - name: Convert models run: source/tests/infer/convert-models.sh From 7a9ac5f6d3cd9a7a1af1f0bcc8fdf945ee451309 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 6 Aug 2025 15:00:00 +0800 Subject: [PATCH 31/36] add mpich to dependencies --- backend/find_pytorch.py | 8 +++++++- doc/install/easy-install.md | 2 +- pyproject.toml | 5 +---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/backend/find_pytorch.py b/backend/find_pytorch.py index c51c8905b8..2a40fc40e6 100644 --- a/backend/find_pytorch.py +++ b/backend/find_pytorch.py @@ -124,6 +124,11 @@ def get_pt_requirement(pt_version: str = "") -> dict: raise RuntimeError("Unsupported CUDA version") from None if pt_version == "": pt_version = os.environ.get("PYTORCH_VERSION", "") + if os.environ.get("CIBUILDWHEEL", "0") == "1": + # PyTorch OP library is built against mpich + mpi_requirement = ["mpich"] + else: + mpi_requirement = [] return { "torch": [ @@ -134,7 +139,8 @@ def get_pt_requirement(pt_version: str = "") -> dict: f"torch=={Version(pt_version).base_version}.*" if pt_version != "" # https://github.com/pytorch/pytorch/commit/7e0c26d4d80d6602aed95cb680dfc09c9ce533bc - else "torch>=2.1.0" + else "torch>=2.1.0", + *mpi_requirement, ], } diff --git a/doc/install/easy-install.md b/doc/install/easy-install.md index d28c0d0773..bbf8d9b1d9 100644 --- a/doc/install/easy-install.md +++ b/doc/install/easy-install.md @@ -227,4 +227,4 @@ If your platform is not supported, or you want to build against the installed ba pip install deepmd-kit[gpu,cu12,lmp,ipi] ``` -MPICH is required for parallel running. +MPICH will be installed automatically - you do not need to install a MPI library by yourself. diff --git a/pyproject.toml b/pyproject.toml index 15cd65db59..e9832816d3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -108,7 +108,7 @@ docs = [ "sphinx-remove-toctrees", ] lmp = [ - "lammps~=2025.7.22.0.2", + "lammps[mpi]~=2025.7.22.0.2", ] ipi = [ "ipi", @@ -230,9 +230,6 @@ test-command = [ "pytest {project}/source/tests/common/test_lammps.py" ] test-extras = ["cpu", "test", "lmp", "ipi", "torch", "paddle"] -test-requires = [ - "mpich", -] build = ["cp311-*"] skip = ["*-win32", "*-manylinux_i686", "*-musllinux*"] # TODO: uncomment to use the latest image when CUDA 11 is deprecated From aca113c33bd5ce4da765e3db8c583ca2e4208856 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 6 Aug 2025 15:50:29 +0800 Subject: [PATCH 32/36] use cdll --- deepmd/pt/cxx_op.py | 47 +++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/deepmd/pt/cxx_op.py b/deepmd/pt/cxx_op.py index 7bb6d0d30c..eaa8fbe980 100644 --- a/deepmd/pt/cxx_op.py +++ b/deepmd/pt/cxx_op.py @@ -1,6 +1,9 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import os import platform +from ctypes import ( + CDLL, + RTLD_GLOBAL, +) from importlib import ( metadata, ) @@ -91,36 +94,30 @@ def load_library(module_name: str) -> bool: return False -if GLOBAL_CONFIG.get("cibuildwheel", "0") == "1": +def load_mpi_library() -> None: + """Load MPI library. + + When building with cibuildwheel, the link to the MPI library is lost + after the wheel is repaired. + """ if platform.system() == "Linux": - lib_env = "LD_LIBRARY_PATH" extension = ".so" elif platform.system() == "Darwin": - lib_env = "DYLD_FALLBACK_LIBRARY_PATH" extension = ".dylib" else: - # windows - pass + raise RuntimeError("Unsupported platform") + MPI_LIB = next( + p for p in metadata.files("mpich") if f"libmpi{extension}" in str(p) + ).locate() + # use CDLL to load the library + CDLL(MPI_LIB, mode=RTLD_GLOBAL) - if platform.system() in ("Linux", "Darwin"): - # try to find MPI directory and add to LD_LIBRARY_PATH - try: - MPI_ROOT = ( - next( - p for p in metadata.files("mpich") if f"libmpi{extension}" in str(p) - ) - .locate() - .parent - ) - # insert MPI_ROOT to LD_LIBRARY_PATH - current_ld_path = os.environ.get(lib_env, "") - if current_ld_path: - os.environ[lib_env] = f"{current_ld_path}:{MPI_ROOT}" - else: - os.environ[lib_env] = str(MPI_ROOT) - except Exception: - # MPI not found or not available, continue without it - pass + +if GLOBAL_CONFIG.get("cibuildwheel", "0") == "1" and platform.system() in ( + "Linux", + "Darwin", +): + load_mpi_library() ENABLE_CUSTOMIZED_OP = load_library("deepmd_op_pt") From 7a1dd60882751509de2c84e4012761600ec0c9d1 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 6 Aug 2025 15:57:18 +0800 Subject: [PATCH 33/36] move check build out of lmp.py --- deepmd/lmp.py | 203 ++++++++++++++++++-------------------- deepmd/lmp_check_build.py | 19 ++++ pyproject.toml | 2 +- 3 files changed, 118 insertions(+), 106 deletions(-) create mode 100644 deepmd/lmp_check_build.py diff --git a/deepmd/lmp.py b/deepmd/lmp.py index 5b836f6311..7ac1570f0f 100644 --- a/deepmd/lmp.py +++ b/deepmd/lmp.py @@ -13,125 +13,118 @@ Optional, ) -from deepmd.env import ( - GLOBAL_CONFIG, +import torch # noqa: TID253 +from packaging.version import ( + Version, ) -if GLOBAL_CONFIG.get("lammps_version", "") == "": +from deepmd.env import ( + SHARED_LIB_DIR, +) +from deepmd.tf.env import ( # noqa: TID253 + TF_VERSION, + tf, +) - def get_op_dir() -> str: - """Get the directory of the deepmd-kit OP library.""" - # empty - return "" -else: - import torch - from packaging.version import ( - Version, +if Version(TF_VERSION) < Version("2.12"): + from find_libpython import ( + find_libpython, ) +else: + find_libpython = None - from deepmd.env import ( - SHARED_LIB_DIR, - ) - from deepmd.tf.env import ( - TF_VERSION, - tf, - ) - if Version(TF_VERSION) < Version("2.12"): - from find_libpython import ( - find_libpython, - ) - else: - find_libpython = None - - def get_env(paths: list[Optional[str]]) -> str: - """Get the environment variable from given paths.""" - return ":".join(p for p in paths if p is not None) - - def get_library_path(module: str, filename: str) -> list[str]: - """Get library path from a module. - - Parameters - ---------- - module : str - The module name. - filename : str - The library filename pattern. - - Returns - ------- - list[str] - The library path. - """ - try: - m = import_module(module) - except ModuleNotFoundError: - return [] - else: - libs = sorted(Path(m.__path__[0]).glob(filename)) - return [str(lib) for lib in libs] - - if platform.system() == "Linux": - lib_env = "LD_LIBRARY_PATH" - elif platform.system() == "Darwin": - lib_env = "DYLD_FALLBACK_LIBRARY_PATH" - else: - raise RuntimeError("Unsupported platform") +def get_env(paths: list[Optional[str]]) -> str: + """Get the environment variable from given paths.""" + return ":".join(p for p in paths if p is not None) + - if platform.system() == "Linux": - preload_env = "LD_PRELOAD" - elif platform.system() == "Darwin": - preload_env = "DYLD_INSERT_LIBRARIES" +def get_library_path(module: str, filename: str) -> list[str]: + """Get library path from a module. + + Parameters + ---------- + module : str + The module name. + filename : str + The library filename pattern. + + Returns + ------- + list[str] + The library path. + """ + try: + m = import_module(module) + except ModuleNotFoundError: + return [] else: - raise RuntimeError("Unsupported platform") - - tf_dir = tf.sysconfig.get_lib() - pt_dir = os.path.join(torch.__path__[0], "lib") - op_dir = str(SHARED_LIB_DIR) - - cuda_library_paths = [] - if platform.system() == "Linux": - cuda_library_paths.extend( - [ - *get_library_path("nvidia.cuda_runtime.lib", "libcudart.so*"), - *get_library_path("nvidia.cublas.lib", "libcublasLt.so*"), - *get_library_path("nvidia.cublas.lib", "libcublas.so*"), - *get_library_path("nvidia.cufft.lib", "libcufft.so*"), - *get_library_path("nvidia.curand.lib", "libcurand.so*"), - *get_library_path("nvidia.cusolver.lib", "libcusolver.so*"), - *get_library_path("nvidia.cusparse.lib", "libcusparse.so*"), - *get_library_path("nvidia.cudnn.lib", "libcudnn.so*"), - ] - ) + libs = sorted(Path(m.__path__[0]).glob(filename)) + return [str(lib) for lib in libs] - os.environ[preload_env] = get_env( + +if platform.system() == "Linux": + lib_env = "LD_LIBRARY_PATH" +elif platform.system() == "Darwin": + lib_env = "DYLD_FALLBACK_LIBRARY_PATH" +else: + raise RuntimeError("Unsupported platform") + +if platform.system() == "Linux": + preload_env = "LD_PRELOAD" +elif platform.system() == "Darwin": + preload_env = "DYLD_INSERT_LIBRARIES" +else: + raise RuntimeError("Unsupported platform") + +tf_dir = tf.sysconfig.get_lib() +pt_dir = os.path.join(torch.__path__[0], "lib") +op_dir = str(SHARED_LIB_DIR) + +cuda_library_paths = [] +if platform.system() == "Linux": + cuda_library_paths.extend( [ - os.environ.get(preload_env), - *cuda_library_paths, + *get_library_path("nvidia.cuda_runtime.lib", "libcudart.so*"), + *get_library_path("nvidia.cublas.lib", "libcublasLt.so*"), + *get_library_path("nvidia.cublas.lib", "libcublas.so*"), + *get_library_path("nvidia.cufft.lib", "libcufft.so*"), + *get_library_path("nvidia.curand.lib", "libcurand.so*"), + *get_library_path("nvidia.cusolver.lib", "libcusolver.so*"), + *get_library_path("nvidia.cusparse.lib", "libcusparse.so*"), + *get_library_path("nvidia.cudnn.lib", "libcudnn.so*"), ] ) - # set LD_LIBRARY_PATH - os.environ[lib_env] = get_env( +os.environ[preload_env] = get_env( + [ + os.environ.get(preload_env), + *cuda_library_paths, + ] +) + +# set LD_LIBRARY_PATH +os.environ[lib_env] = get_env( + [ + os.environ.get(lib_env), + tf_dir, + os.path.join(tf_dir, "python"), + pt_dir, + op_dir, + ] +) + +# preload python library, only for TF<2.12 +if find_libpython is not None: + libpython = find_libpython() + os.environ[preload_env] = get_env( [ - os.environ.get(lib_env), - tf_dir, - os.path.join(tf_dir, "python"), - pt_dir, - op_dir, + os.environ.get(preload_env), + libpython, ] ) - # preload python library, only for TF<2.12 - if find_libpython is not None: - libpython = find_libpython() - os.environ[preload_env] = get_env( - [ - os.environ.get(preload_env), - libpython, - ] - ) - - def get_op_dir() -> str: - """Get the directory of the deepmd-kit OP library.""" - return op_dir + +def get_op_dir() -> str: + """Get the directory of the deepmd-kit OP library.""" + return op_dir diff --git a/deepmd/lmp_check_build.py b/deepmd/lmp_check_build.py new file mode 100644 index 0000000000..dc81a31d8e --- /dev/null +++ b/deepmd/lmp_check_build.py @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: LGPL-3.0-or-later +from deepmd.env import ( + GLOBAL_CONFIG, +) + +if GLOBAL_CONFIG.get("lammps_version", "") == "": + + def get_op_dir() -> str: + """Get the directory of the deepmd-kit OP library.""" + # empty + return "" +else: + from deepmd.lmp import ( + get_op_dir, + ) + +__all__ = [ + "get_op_dir", +] diff --git a/pyproject.toml b/pyproject.toml index e9832816d3..a877ea5a8c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,7 +58,7 @@ requires-python = ">=3.9" keywords = ["deepmd"] [project.entry-points."lammps.plugins"] -deepmd = "deepmd.lmp:get_op_dir" +deepmd = "deepmd.lmp_check_build:get_op_dir" [project.entry-points."dpgui"] "DeePMD-kit" = "deepmd.utils.argcheck:gen_args" From af448339abfb542b4eebcf9604d9b3d0b26cb63d Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 6 Aug 2025 15:59:35 +0800 Subject: [PATCH 34/36] avoid load symlink --- deepmd/pt/cxx_op.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deepmd/pt/cxx_op.py b/deepmd/pt/cxx_op.py index eaa8fbe980..f00f055e15 100644 --- a/deepmd/pt/cxx_op.py +++ b/deepmd/pt/cxx_op.py @@ -107,7 +107,7 @@ def load_mpi_library() -> None: else: raise RuntimeError("Unsupported platform") MPI_LIB = next( - p for p in metadata.files("mpich") if f"libmpi{extension}" in str(p) + p for p in metadata.files("mpich") if f"libmpi{extension}." in str(p) ).locate() # use CDLL to load the library CDLL(MPI_LIB, mode=RTLD_GLOBAL) From a987430d1be9a2e83a3a019ff16cc5d8dbaf8a9b Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 6 Aug 2025 16:03:23 +0800 Subject: [PATCH 35/36] fix match --- deepmd/pt/cxx_op.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/deepmd/pt/cxx_op.py b/deepmd/pt/cxx_op.py index f00f055e15..1106a8887f 100644 --- a/deepmd/pt/cxx_op.py +++ b/deepmd/pt/cxx_op.py @@ -101,14 +101,12 @@ def load_mpi_library() -> None: after the wheel is repaired. """ if platform.system() == "Linux": - extension = ".so" + libname = "libmpi.so.*" elif platform.system() == "Darwin": - extension = ".dylib" + libname = "libmpi.*.dylib" else: raise RuntimeError("Unsupported platform") - MPI_LIB = next( - p for p in metadata.files("mpich") if f"libmpi{extension}." in str(p) - ).locate() + MPI_LIB = next(p for p in metadata.files("mpich") if p.match(libname)).locate() # use CDLL to load the library CDLL(MPI_LIB, mode=RTLD_GLOBAL) From 20c3b27bea42acb0c5737777ef2e8d910915da61 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 7 Aug 2025 14:47:50 +0800 Subject: [PATCH 36/36] remove conflict mpi in test_cuda --- .github/workflows/test_cuda.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/test_cuda.yml b/.github/workflows/test_cuda.yml index dce3b95ff0..14c051123c 100644 --- a/.github/workflows/test_cuda.yml +++ b/.github/workflows/test_cuda.yml @@ -30,10 +30,6 @@ jobs: with: python-version: '3.11' # cache: 'pip' - - name: Setup MPI - uses: mpi4py/setup-mpi@v1 - with: - mpi: mpich - name: Install wget and unzip run: apt-get update && apt-get install -y wget unzip - uses: lukka/get-cmake@latest