Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
- name: Install external tools from toolchain
run: |
cd toolchain
./install_abacus_toolchain_new.sh --with-dftd4=install --dry-run -j8
./install_abacus_toolchain_new.sh --with-dftd4 --with-nep --dry-run -j8
./scripts/stage4/install_stage4.sh
cd ..

Expand Down Expand Up @@ -131,6 +131,7 @@ jobs:
-DENABLE_FLOAT_FFTW=ON \
-DENABLE_DFTD4=ON \
-DENABLE_PEXSI=ON \
-DENABLE_NEP=ON \
-Werror=dev

- name: Build
Expand Down
77 changes: 11 additions & 66 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ option(ENABLE_DFTD4 "Enable DFT-D4 dispersion correction" OFF)
option(ENABLE_PLUMED "Enable using the PLUMED enhanced-sampling library" OFF)
option(ENABLE_JSON "Enable JSON output" OFF)
option(ENABLE_CNPY "Enable cnpy usage" OFF)
option(ENABLE_NEP "Enable NEP_CPU" OFF)
option(ENABLE_DEEPMD "Enable DeePMD-kit" OFF)

option(DEBUG_INFO "Print message to debug" OFF)
option(COMMIT_INFO "Print commit information in log" ON)
Expand Down Expand Up @@ -509,78 +511,24 @@ if(ENABLE_ASAN)
endif()

if(ENABLE_MLALGO)
find_path(libnpy_SOURCE_DIR npy.hpp HINTS ${libnpy_INCLUDE_DIR})
if(NOT libnpy_SOURCE_DIR)
include(FetchContent)
FetchContent_Declare(
libnpy
GIT_REPOSITORY https://github.com/llohse/libnpy.git
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE)
FetchContent_MakeAvailable(libnpy)
else()

endif()
endif()

# Torch uses outdated components to detect CUDA arch, causing failure on
# latest CUDA kits. Set CMake variable TORCH_CUDA_ARCH_LIST in the form of
# "major.minor" if required.
if(ENABLE_MLALGO OR DEFINED Torch_DIR)
find_package(Libnpy REQUIRED)
# Torch's CUDA architecture detection may need TORCH_CUDA_ARCH_LIST on
# recent CUDA toolkits.
find_package(Torch REQUIRED)
if(NOT Torch_VERSION VERSION_LESS "2.1.0")
set_if_higher(CMAKE_CXX_STANDARD 17)
elseif(NOT Torch_VERSION VERSION_LESS "1.5.0")
set_if_higher(CMAKE_CXX_STANDARD 14)
endif()
set(ABACUS_TORCH_CXX_FLAGS "${TORCH_CXX_FLAGS}")
endif()

if(ENABLE_CNPY)
find_path(cnpy_SOURCE_DIR cnpy.h HINTS ${libnpy_INCLUDE_DIR})
if(NOT cnpy_SOURCE_DIR)
include(FetchContent)
FetchContent_Declare(
cnpy
GIT_REPOSITORY https://github.com/rogersce/cnpy.git
GIT_PROGRESS TRUE)
FetchContent_MakeAvailable(cnpy)
else()

endif()

# find ZLIB and link
find_package(ZLIB REQUIRED)
find_package(CNPY REQUIRED)
endif()

function(git_submodule_update)
if(GIT_SUBMOD_RESULT EQUAL "0")
message(DEBUG "Submodule init'ed")
else()
find_package(Git REQUIRED)
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/.git")
message(FATAL_ERROR "Not a git repository; cannot update submodules")
endif()

message(STATUS "Updating submodules")
execute_process(
COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(
FATAL_ERROR
"git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}."
)
endif()
endif()
endfunction()

if(ENABLE_LIBRI)
set_if_higher(CMAKE_CXX_STANDARD 14)
find_package(LibRI REQUIRED)
find_package(LibComm REQUIRED)
find_package(cereal REQUIRED CONFIG)
endif()

if(ENABLE_LIBXC)
Expand All @@ -591,16 +539,13 @@ if(ENABLE_LIBXC)
endif()
endif()

if(DEFINED DeePMD_DIR)
find_package(DeePMD REQUIRED)
endif()

if(DEFINED NEP_DIR)
find_package(NEP REQUIRED)
if(ENABLE_DEEPMD)
find_package(DeePMD CONFIG REQUIRED)
include(SetupDeePMD)
endif()

if(DEFINED TensorFlow_DIR)
find_package(TensorFlow REQUIRED)
if(ENABLE_NEP)
find_package(NEP_CPU CONFIG REQUIRED)
endif()

if(ENABLE_PLUMED)
Expand Down
44 changes: 10 additions & 34 deletions cmake/CollectBuildInfoVars.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -324,52 +324,28 @@ else()
set(ABACUS_MLALGO "Disabled")
endif()

if((DEFINED Torch_DIR OR ENABLE_MLALGO) AND Torch_VERSION)
if(ENABLE_MLALGO AND Torch_VERSION)
set(ABACUS_LIBTORCH_VERSION "yes (v${Torch_VERSION})")
elseif(DEFINED Torch_DIR OR ENABLE_MLALGO)
elseif(ENABLE_MLALGO)
set(ABACUS_LIBTORCH_VERSION "yes (path: ${Torch_DIR})")
else()
set(ABACUS_LIBTORCH_VERSION "no")
endif()

if(DEFINED DeePMD_DIR)
set(ABACUS_DEEPMD_VERSION "yes (version unknown)")
set(DEEPMD_VERSION_HEADER "${DeePMD_DIR}/include/deepmd/version.h")
if(EXISTS ${DEEPMD_VERSION_HEADER})
file(STRINGS "${DEEPMD_VERSION_HEADER}" DEEPMD_VERSION_LINE
REGEX "global_install_prefix")
if(DEEPMD_VERSION_LINE)
string(
REGEX
MATCH
"global_install_prefix=\".*deepmd-kit-([0-9]+\\.[0-9]+\\.[0-9]+)\"" _
"${DEEPMD_VERSION_LINE}")
if(CMAKE_MATCH_1)
set(ABACUS_DEEPMD_VERSION "yes (v${CMAKE_MATCH_1})")
endif()
endif()
endif()
if(ABACUS_DEEPMD_VERSION STREQUAL "yes (version unknown)")
set(ABACUS_DEEPMD_VERSION "yes (path: ${DeePMD_DIR})")
endif()
if(ENABLE_DEEPMD AND DeePMD_VERSION MATCHES "^[0-9]+\\.[0-9]+")
set(ABACUS_DEEPMD_VERSION "yes (v${DeePMD_VERSION})")
elseif(ENABLE_DEEPMD)
set(ABACUS_DEEPMD_VERSION "yes (path: ${DeePMD_DIR})")
else()
set(ABACUS_DEEPMD_VERSION "no")
endif()

if(DEFINED NEP_DIR AND NEP_VERSION)
set(ABACUS_NEP_VERSION "yes (v${NEP_VERSION})")
elseif(DEFINED NEP_DIR)
set(ABACUS_NEP_VERSION "yes (path: ${NEP_DIR})")
if(ENABLE_NEP)
set(ABACUS_NEP_VERSION "yes")
else()
set(ABACUS_NEP_VERSION "no")
endif()

if(DEFINED TensorFlow_DIR)
set(ABACUS_TENSORFLOW_VERSION "yes (path: ${TensorFlow_DIR})")
else()
set(ABACUS_TENSORFLOW_VERSION "no")
endif()

# Testing & Other Libraries
if(BUILD_TESTING)
set(ABACUS_GTEST_VERSION "yes (from git origin/main)")
Expand All @@ -392,7 +368,7 @@ else()
endif()

if(ENABLE_MLALGO)
set(ABACUS_LIBNPY_VERSION "yes (path: ${libnpy_SOURCE_DIR})")
set(ABACUS_LIBNPY_VERSION "yes (path: ${libnpy_INCLUDE_DIR})")
else()
set(ABACUS_LIBNPY_VERSION "no")
endif()
Expand All @@ -404,7 +380,7 @@ else()
endif()

if(ENABLE_CNPY)
set(ABACUS_CNPY_VERSION "yes (path: ${cnpy_SOURCE_DIR})")
set(ABACUS_CNPY_VERSION "yes (path: ${CNPY_INCLUDE_DIR})")
else()
set(ABACUS_CNPY_VERSION "no")
endif()
Expand Down
35 changes: 35 additions & 0 deletions cmake/modules/FindCNPY.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
find_package(ZLIB REQUIRED)

find_path(
CNPY_INCLUDE_DIR cnpy.h
HINTS ${CNPY_DIR} ${cnpy_SOURCE_DIR}
PATH_SUFFIXES include)
find_library(
CNPY_LIBRARY
NAMES cnpy
HINTS ${CNPY_DIR} "${CNPY_INCLUDE_DIR}/.."
PATH_SUFFIXES lib lib64)

if(NOT CNPY_INCLUDE_DIR OR NOT CNPY_LIBRARY)
include(FetchContent)
FetchContent_Declare(
cnpy
GIT_REPOSITORY https://github.com/rogersce/cnpy.git
GIT_PROGRESS TRUE)
FetchContent_MakeAvailable(cnpy)
set(CNPY_INCLUDE_DIR "${cnpy_SOURCE_DIR}")
set(CNPY_LIBRARY cnpy)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CNPY DEFAULT_MSG CNPY_INCLUDE_DIR
CNPY_LIBRARY)

if(CNPY_FOUND AND NOT TARGET CNPY::cnpy)
add_library(CNPY::cnpy INTERFACE IMPORTED)
set_target_properties(
CNPY::cnpy PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CNPY_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${CNPY_LIBRARY};ZLIB::ZLIB")
endif()

mark_as_advanced(CNPY_INCLUDE_DIR CNPY_LIBRARY)
Loading
Loading