diff --git a/deepmd/env.py b/deepmd/env.py index 97424e0ea1..9fcde6fd05 100644 --- a/deepmd/env.py +++ b/deepmd/env.py @@ -376,7 +376,7 @@ def _get_package_constants( TF_VERSION = GLOBAL_CONFIG["tf_version"] TF_CXX11_ABI_FLAG = int(GLOBAL_CONFIG["tf_cxx11_abi_flag"]) -op_module = get_module("op_abi") +op_module = get_module("deepmd_op") op_grads_module = get_module("op_grads") # FLOAT_PREC diff --git a/deepmd/lmp.py b/deepmd/lmp.py new file mode 100644 index 0000000000..1fa2db9e44 --- /dev/null +++ b/deepmd/lmp.py @@ -0,0 +1,49 @@ +"""Register entry points for lammps-wheel.""" +import os +import platform +from pathlib import Path +from typing import List, Optional + +from find_libpython import find_libpython + +from deepmd.env import tf + + +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": + lib_env = "LD_LIBRARY_PATH" +elif platform.system() == "Darwin": + lib_env = "DYLD_FALLBACK_LIBRARY_PATH" +else: + raise RuntimeError("Unsupported platform") + +tf_dir = tf.sysconfig.get_lib() +op_dir = str((Path(__file__).parent / "op").absolute()) +# set LD_LIBRARY_PATH +os.environ[lib_env] = get_env([ + os.environ.get(lib_env), + tf_dir, + os.path.join(tf_dir, "python"), + op_dir, +]) + +# preload python library +libpython = find_libpython() +if platform.system() == "Linux": + preload_env = "LD_PRELOAD" +elif platform.system() == "Darwin": + preload_env = "DYLD_INSERT_LIBRARIES" +else: + raise RuntimeError("Unsupported platform") +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 diff --git a/doc/install/easy-install.md b/doc/install/easy-install.md index 97bc0aa223..9e5e955332 100644 --- a/doc/install/easy-install.md +++ b/doc/install/easy-install.md @@ -84,7 +84,7 @@ docker pull deepmodeling/dpmdkit-rocm:dp2.0.3-rocm4.5.2-tf2.6-lmp29Sep2021 ## Install Python interface with pip -If you only want to install the Python interface and have no existing TensorFlow installed, you can use `pip` to install the pre-built package of the Python interface with CUDA 11 supported: +If you have no existing TensorFlow installed, you can use `pip` to install the pre-built package of the Python interface with CUDA 11 supported: ```bash pip install deepmd-kit[gpu] @@ -95,6 +95,13 @@ Or install the CPU version without CUDA supported: pip install deepmd-kit[cpu] ``` +[LAMMPS module](../third-party/lammps-command.md) is only provided on Linux and macOS. To enable it, add `lmp` to extras: +```bash +pip install deepmd-kit[gpu,lmp] +``` +MPICH is required for parallel running. + +It is suggested to install the package into an isolated environment. The supported platform includes Linux x86-64 and aarch64 with GNU C Library 2.28 or above, macOS x86-64, and Windows x86-64. A specific version of TensorFlow which is compatible with DeePMD-kit will be also installed. diff --git a/pyproject.toml b/pyproject.toml index 46d88afc67..f377b80036 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,8 +49,10 @@ repository = "https://github.com/deepmodeling/deepmd-kit" write_to = "deepmd/_version.py" [tool.cibuildwheel] -test-command = "dp -h" -test-requires = "tensorflow" +test-command = [ + "dp -h", +] +test-extras = ["cpu"] build = ["cp310-*"] skip = ["*-win32", "*-manylinux_i686", "*-musllinux*"] # TODO: bump to "latest" tag when CUDA supports GCC 12 @@ -58,16 +60,24 @@ manylinux-x86_64-image = "quay.io/pypa/manylinux_2_28_x86_64:2022-11-19-1b19e81" manylinux-aarch64-image = "quay.io/pypa/manylinux_2_28_aarch64:2022-11-19-1b19e81" [tool.cibuildwheel.macos] +environment = { DP_LAMMPS_VERSION="stable_23Jun2022_update2" } +before-all = ["brew install mpich"] repair-wheel-command = "delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel} --ignore-missing-dependencies" +test-extras = ["cpu", "test", "lmp"] +test-command = [ + "dp -h", + "pytest {project}/source/tests/test_lammps.py" +] [tool.cibuildwheel.linux] -repair-wheel-command = "auditwheel repair --exclude libtensorflow_framework.so.2 --exclude libtensorflow_framework.so.1 --exclude libtensorflow_framework.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 -w {dest_dir} {wheel}" environment-pass = ["CIBW_BUILD", "DP_VARIANT"] -before-all = """ -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-11-8 -fi -""" +environment = { DP_VARIANT="cuda", DP_LAMMPS_VERSION="stable_23Jun2022_update2", MPI_HOME="/usr/lib64/mpich", PATH="/usr/lib64/mpich/bin:$PATH" } +before-all = [ + """{ 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-11-8; fi }""", + "yum install -y mpich-devel", +] + # selectively turn of lintner warnings, always include reasoning why any warning should # be silenced diff --git a/setup.py b/setup.py index 387ce9e6f9..76b2cbafd5 100644 --- a/setup.py +++ b/setup.py @@ -34,6 +34,13 @@ cmake_args.append("-DBUILD_TESTING:BOOL=TRUE") if os.environ.get("DP_ENABLE_NATIVE_OPTIMIZATION", "0") == "1": cmake_args.append("-DENABLE_NATIVE_OPTIMIZATION:BOOL=TRUE") +dp_lammps_version = os.environ.get("DP_LAMMPS_VERSION", "") +if dp_lammps_version != "": + cmake_args.append("-DBUILD_CPP_IF:BOOL=TRUE") + cmake_args.append("-DUSE_TF_PYTHON_LIBS:BOOL=TRUE") + cmake_args.append(f"-DLAMMPS_VERSION={dp_lammps_version}") +else: + cmake_args.append("-DBUILD_CPP_IF:BOOL=FALSE") tf_install_dir, _ = find_tensorflow() tf_version = get_tf_version(tf_install_dir) @@ -73,7 +80,6 @@ def get_tag(self): cmake_args=[ f"-DTENSORFLOW_ROOT:PATH={tf_install_dir}", "-DBUILD_PY_IF:BOOL=TRUE", - "-DBUILD_CPP_IF:BOOL=FALSE", *cmake_args, ], cmake_source_dir="source", @@ -95,9 +101,17 @@ def get_tag(self): "sphinx-argparse", "pygments-lammps", ], + "lmp": [ + "lammps-manylinux-2-28~=2022.6.23.2.2; platform_system=='Linux'", + "lammps~=2022.6.23.2.2; platform_system!='Linux'", + "find_libpython", + ], **get_tf_requirement(tf_version), }, - entry_points={"console_scripts": ["dp = deepmd.entrypoints.main:main"]}, + entry_points={ + "console_scripts": ["dp = deepmd.entrypoints.main:main"], + "lammps.plugins": ["deepmd = deepmd.lmp:get_op_dir"], + }, cmdclass = { "bdist_wheel": bdist_wheel_abi3, }, diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 1d69f88f24..84648c169a 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -112,7 +112,11 @@ set(DEEPMD_SOURCE_DIR ${PROJECT_SOURCE_DIR}/..) # setup tensorflow libraries by python if (USE_TF_PYTHON_LIBS) - find_package (Python COMPONENTS Interpreter Development REQUIRED) + if(NOT $ENV{CIBUILDWHEEL} STREQUAL "1") + find_package (Python COMPONENTS Interpreter Development REQUIRED) + else() + set(Python_LIBRARIES ${Python_LIBRARY}) + endif() endif(USE_TF_PYTHON_LIBS) # find tensorflow, I need tf abi info @@ -149,8 +153,8 @@ endif() # define names of libs set (LIB_DEEPMD "deepmd") +set (LIB_DEEPMD_OP "deepmd_op") if (BUILD_CPP_IF) - set (LIB_DEEPMD_OP "deepmd_op") set (LIB_DEEPMD_CC "deepmd_cc") set (LIB_DEEPMD_C "deepmd_c") if (USE_CUDA_TOOLKIT) @@ -181,8 +185,10 @@ if (BUILD_CPP_IF) add_subdirectory (lmp/) if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8) # add_subdirectory (md/) + if(NOT BUILD_PY_IF) add_subdirectory (ipi/) add_subdirectory (gmx/) + endif() endif () endif (BUILD_CPP_IF) @@ -205,7 +211,7 @@ add_custom_target(lammps COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_lammps.cmake) # add configure file -if(BUILD_CPP_IF) +if(BUILD_CPP_IF AND NOT BUILD_PY_IF) include(CMakePackageConfigHelpers) set(targets_export_name ${CMAKE_PROJECT_NAME}Targets CACHE INTERNAL "") set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated" CACHE INTERNAL "") @@ -220,4 +226,4 @@ if(BUILD_CPP_IF) "${config_file}" INSTALL_DESTINATION ${cmake_files_install_dir}) install(FILES ${version_file} ${config_file} DESTINATION ${cmake_files_install_dir}) -endif(BUILD_CPP_IF) +endif(BUILD_CPP_IF AND NOT BUILD_PY_IF) diff --git a/source/api_c/CMakeLists.txt b/source/api_c/CMakeLists.txt index c8ffd4e0a3..75e785a341 100644 --- a/source/api_c/CMakeLists.txt +++ b/source/api_c/CMakeLists.txt @@ -23,6 +23,12 @@ if (CMAKE_TESTING_ENABLED) target_link_libraries(${libname} PRIVATE coverage_config) endif() +if(BUILD_PY_IF) + install( + TARGETS ${libname} + DESTINATION deepmd/op/ + ) +else(BUILD_PY_IF) install( TARGETS ${libname} EXPORT ${CMAKE_PROJECT_NAME}Targets @@ -33,6 +39,7 @@ install( FILES ${INC_SRC} DESTINATION include/deepmd ) +endif(BUILD_PY_IF) if (PACKAGE_C) MESSAGE(STATUS "Packaging C API library") diff --git a/source/api_cc/CMakeLists.txt b/source/api_cc/CMakeLists.txt index 57c28d674c..1ee043a45b 100644 --- a/source/api_cc/CMakeLists.txt +++ b/source/api_cc/CMakeLists.txt @@ -42,6 +42,12 @@ if (CMAKE_TESTING_ENABLED) endif() target_compile_features(${libname} PUBLIC cxx_std_11) +if(BUILD_PY_IF) + install( + TARGETS ${libname} + DESTINATION deepmd/op/ + ) +else(BUILD_PY_IF) install( TARGETS ${libname} EXPORT ${CMAKE_PROJECT_NAME}Targets @@ -64,3 +70,4 @@ ${CMAKE_INSTALL_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}${libname}${LOW_PREC_V if (CMAKE_TESTING_ENABLED) add_subdirectory(tests) endif() +endif(BUILD_PY_IF) \ No newline at end of file diff --git a/source/api_cc/src/DeepPot.cc b/source/api_cc/src/DeepPot.cc index f3b8d1f82a..08c425badd 100644 --- a/source/api_cc/src/DeepPot.cc +++ b/source/api_cc/src/DeepPot.cc @@ -87,7 +87,7 @@ run_model (ENERGYTYPE & dener, Session * session, const std::vector> & input_tensors, const AtomMap& atommap, - const int nghost = 0); + const int nghost); template void @@ -97,7 +97,7 @@ run_model (ENERGYTYPE & dener, Session * session, const std::vector> & input_tensors, const AtomMap& atommap, - const int nghost = 0); + const int nghost); template void @@ -107,7 +107,7 @@ run_model (ENERGYTYPE & dener, Session * session, const std::vector> & input_tensors, const AtomMap& atommap, - const int nghost = 0); + const int nghost); template void @@ -117,7 +117,7 @@ run_model (ENERGYTYPE & dener, Session * session, const std::vector> & input_tensors, const AtomMap& atommap, - const int nghost = 0); + const int nghost); template static void run_model (ENERGYTYPE & dener, @@ -210,7 +210,7 @@ void run_model (ENERGYTYPE & dener, Session* session, const std::vector> & input_tensors, const deepmd::AtomMap & atommap, - const int& nghost = 0); + const int& nghost); template void run_model (ENERGYTYPE & dener, @@ -221,7 +221,7 @@ void run_model (ENERGYTYPE & dener, Session* session, const std::vector> & input_tensors, const deepmd::AtomMap & atommap, - const int& nghost = 0); + const int& nghost); template void run_model (ENERGYTYPE & dener, @@ -232,7 +232,7 @@ void run_model (ENERGYTYPE & dener, Session* session, const std::vector> & input_tensors, const deepmd::AtomMap & atommap, - const int& nghost = 0); + const int& nghost); template void run_model (ENERGYTYPE & dener, @@ -243,7 +243,7 @@ void run_model (ENERGYTYPE & dener, Session* session, const std::vector> & input_tensors, const deepmd::AtomMap & atommap, - const int& nghost = 0); + const int& nghost); DeepPot:: DeepPot () diff --git a/source/api_cc/src/common.cc b/source/api_cc/src/common.cc index 021c97667e..3ec4f0f7eb 100644 --- a/source/api_cc/src/common.cc +++ b/source/api_cc/src/common.cc @@ -1,8 +1,22 @@ #include "common.h" #include "AtomMap.h" #include "device.h" -#include #include +#if defined(_WIN32) +#if defined(_WIN32_WINNT) +#undef _WIN32_WINNT +#endif + +// target Windows version is windows 7 and later +#define _WIN32_WINNT _WIN32_WINNT_WIN7 +#define PSAPI_VERSION 2 +#include +#include +#define O_RDONLY _O_RDONLY +#else +// not windows +#include +#endif #include "google/protobuf/text_format.h" #include "google/protobuf/io/zero_copy_stream_impl.h" @@ -299,10 +313,11 @@ deepmd:: load_op_library() { tensorflow::Env* env = tensorflow::Env::Default(); - std::string dso_path = env->FormatLibraryFileName("deepmd_op", ""); #if defined(_WIN32) + std::string dso_path = "deepmd_op.dll"; void* dso_handle = LoadLibrary(dso_path.c_str()); #else + std::string dso_path = "libdeepmd_op.so"; void* dso_handle = dlopen(dso_path.c_str(), RTLD_NOW | RTLD_LOCAL); #endif if (!dso_handle) { diff --git a/source/cmake/Findtensorflow.cmake b/source/cmake/Findtensorflow.cmake index c9f209c738..35137db664 100644 --- a/source/cmake/Findtensorflow.cmake +++ b/source/cmake/Findtensorflow.cmake @@ -150,7 +150,11 @@ endforeach () # find _pywrap_tensorflow_internal and set it as tensorflow_cc if (BUILD_CPP_IF AND USE_TF_PYTHON_LIBS) set(TF_SUFFIX python) - set(TensorFlow_FIND_COMPONENTS _pywrap_tensorflow_internal${CMAKE_SHARED_LIBRARY_SUFFIX}) + if(WIN32) + set(TensorFlow_FIND_COMPONENTS _pywrap_tensorflow_internal.lib) + else () + set(TensorFlow_FIND_COMPONENTS _pywrap_tensorflow_internal${CMAKE_SHARED_MODULE_SUFFIX}) + endif() foreach (module ${TensorFlow_FIND_COMPONENTS}) find_library(TensorFlow_LIBRARY_${module} NAMES ${module} @@ -338,7 +342,11 @@ add_definitions(-D_GLIBCXX_USE_CXX11_ABI=${OP_CXX_ABI}) add_library(TensorFlow::tensorflow_framework SHARED IMPORTED GLOBAL) if(WIN32) - string(REGEX REPLACE "[.]lib" ".dll" _DLL_FILE ${TensorFlowFramework_LIBRARY}) + if(USE_TF_PYTHON_LIBS) + string(REGEX REPLACE "[.]lib" ".pyd" _DLL_FILE ${TensorFlowFramework_LIBRARY}) + else() + string(REGEX REPLACE "[.]lib" ".dll" _DLL_FILE ${TensorFlowFramework_LIBRARY}) + endif() set_target_properties(TensorFlow::tensorflow_framework PROPERTIES IMPORTED_IMPLIB ${TensorFlowFramework_LIBRARY} IMPORTED_LOCATION ${_DLL_FILE}) @@ -356,7 +364,11 @@ target_compile_definitions(TensorFlow::tensorflow_framework INTERFACE if(BUILD_CPP_IF) add_library(TensorFlow::tensorflow_cc SHARED IMPORTED GLOBAL) if(WIN32) - string(REGEX REPLACE "[.]lib" ".dll" _DLL_FILE ${TensorFlow_LIBRARY_tensorflow_cc}) + if(USE_TF_PYTHON_LIBS) + string(REGEX REPLACE "[.]lib" ".pyd" _DLL_FILE ${TensorFlow_LIBRARY_tensorflow_cc}) + else() + string(REGEX REPLACE "[.]lib" ".dll" _DLL_FILE ${TensorFlow_LIBRARY_tensorflow_cc}) + endif() set_target_properties(TensorFlow::tensorflow_cc PROPERTIES IMPORTED_IMPLIB ${TensorFlow_LIBRARY_tensorflow_cc} IMPORTED_LOCATION ${_DLL_FILE}) diff --git a/source/ipi/CMakeLists.txt b/source/ipi/CMakeLists.txt index 542dec8379..e31e5ddce0 100644 --- a/source/ipi/CMakeLists.txt +++ b/source/ipi/CMakeLists.txt @@ -33,6 +33,7 @@ set_target_properties( ) endif() +if(BUILD_PY_IF) install( TARGETS ${libipiname} DESTINATION lib/ @@ -41,6 +42,16 @@ install( TARGETS ${ipiname} DESTINATION bin/ ) +else(BUILD_PY_IF) + install( + TARGETS ${libipiname} + DESTINATION deepmd/op/ + ) + install( + TARGETS ${ipiname} + DESTINATION deepmd/op/ + ) +endif(BUILD_PY_IF) endfunction() _add_ipi_variant("${HIGH_PREC_VARIANT}" "${HIGH_PREC_DEF}") _add_ipi_variant("${LOW_PREC_VARIANT}" "${LOW_PREC_DEF}") \ No newline at end of file diff --git a/source/lib/CMakeLists.txt b/source/lib/CMakeLists.txt index 8b5af10186..5902b78a61 100644 --- a/source/lib/CMakeLists.txt +++ b/source/lib/CMakeLists.txt @@ -45,8 +45,7 @@ endif() if(BUILD_PY_IF) install(TARGETS ${libname} DESTINATION deepmd/op/) -endif(BUILD_PY_IF) -if(BUILD_CPP_IF) +else(BUILD_PY_IF) install( TARGETS ${libname} @@ -56,7 +55,7 @@ if(BUILD_CPP_IF) FILES ${INC_SRC} DESTINATION include/deepmd ) -endif(BUILD_CPP_IF) +endif(BUILD_PY_IF) if (BUILD_CPP_IF AND CMAKE_TESTING_ENABLED) add_subdirectory(tests) diff --git a/source/lmp/plugin/CMakeLists.txt b/source/lmp/plugin/CMakeLists.txt index 6ebf6df7b2..ca42a7267b 100644 --- a/source/lmp/plugin/CMakeLists.txt +++ b/source/lmp/plugin/CMakeLists.txt @@ -22,7 +22,9 @@ if (DEFINED LAMMPS_SOURCE_ROOT OR DEFINED LAMMPS_VERSION) find_package(MPI) if(MPI_FOUND) set(LAMMPS_MPI_INCLUDE_DIRS ${MPI_CXX_INCLUDE_DIRS}) - target_link_libraries(lammps_interface INTERFACE MPI::MPI_CXX) + # LAMMPS has linked MPI; do not link twice + # target_link_libraries(lammps_interface INTERFACE MPI::MPI_CXX) + target_include_directories(lammps_interface INTERFACE ${LAMMPS_MPI_INCLUDE_DIRS}) else() # Use LAMMPS serial mpi.h header target_include_directories(lammps_interface INTERFACE "${LAMMPS_HEADER_DIR}/STUBS") @@ -69,14 +71,14 @@ if (DEFINED LAMMPS_SOURCE_ROOT OR DEFINED LAMMPS_VERSION) endif() if(CMAKE_SYSTEM_NAME STREQUAL Darwin) set_target_properties(${libname} PROPERTIES LINK_FLAGS "-Wl,-undefined,dynamic_lookup") - endif() - + else() set_target_properties( ${libname} PROPERTIES INSTALL_RPATH "$ORIGIN;${TensorFlow_LIBRARY_PATH}" LINK_FLAGS "-rdynamic" ) + endif() target_compile_definitions(${libname} PUBLIC ${prec_def} PRIVATE "LMPPLUGIN" # fix header path @@ -87,6 +89,9 @@ if (DEFINED LAMMPS_SOURCE_ROOT OR DEFINED LAMMPS_VERSION) target_link_libraries(${libname} PRIVATE coverage_config) endif() + if(BUILD_PY_IF) + install(TARGETS ${libname} DESTINATION deepmd/op/) + else(BUILD_PY_IF) install(TARGETS ${libname} DESTINATION lib/) if (${LAMMPS_VERSION_NUMBER} GREATER_EQUAL 20220324) @@ -103,10 +108,15 @@ if (DEFINED LAMMPS_SOURCE_ROOT OR DEFINED LAMMPS_VERSION) )" ) endif() + endif(BUILD_PY_IF) endfunction() + if(BUILD_PY_IF) + _add_lmp_plugin_variant("plugin" "${HIGH_PREC_DEF}") + else(BUILD_PY_IF) _add_lmp_plugin_variant("${HIGH_PREC_VARIANT}" "${HIGH_PREC_DEF}") _add_lmp_plugin_variant("${LOW_PREC_VARIANT}" "${LOW_PREC_DEF}") + endif() else() message(STATUS "disable LAMMPS plugin mode") diff --git a/source/op/CMakeLists.txt b/source/op/CMakeLists.txt index af14c9d7c4..f2b0e72247 100644 --- a/source/op/CMakeLists.txt +++ b/source/op/CMakeLists.txt @@ -5,51 +5,34 @@ file(GLOB OP_GRADS_SRC custom_op.cc prod_force_grad.cc prod_force_grad_multi_dev file(GLOB OP_PY *.py) file(GLOB OP_REMAPPER_SRC optimizer/parallel.cc) -if (BUILD_CPP_IF) - add_library(${LIB_DEEPMD_OP} MODULE ${OP_SRC}) - # link: libdeepmd libtensorflow_cc libtensorflow_framework - target_link_libraries (${LIB_DEEPMD_OP} PRIVATE TensorFlow::tensorflow_cc TensorFlow::tensorflow_framework) - target_link_libraries (${LIB_DEEPMD_OP} PRIVATE ${LIB_DEEPMD}) +add_library(${LIB_DEEPMD_OP} MODULE ${OP_SRC} ${OP_REMAPPER_SRC}) +# link: libdeepmd libtensorflow_cc libtensorflow_framework +target_link_libraries (${LIB_DEEPMD_OP} PRIVATE TensorFlow::tensorflow_framework) +target_link_libraries (${LIB_DEEPMD_OP} PRIVATE ${LIB_DEEPMD}) +if(APPLE) + set_target_properties(${LIB_DEEPMD_OP} PROPERTIES INSTALL_RPATH "@loader_path;${TensorFlow_LIBRARY_PATH}") +else() set_target_properties(${LIB_DEEPMD_OP} PROPERTIES INSTALL_RPATH "$ORIGIN;${TensorFlow_LIBRARY_PATH}") - if (CMAKE_TESTING_ENABLED) - target_link_libraries(${LIB_DEEPMD_OP} PRIVATE coverage_config) - endif() - target_precompile_headers(${LIB_DEEPMD_OP} PRIVATE custom_op.h) -endif (BUILD_CPP_IF) +endif() +if (CMAKE_TESTING_ENABLED) + target_link_libraries(${LIB_DEEPMD_OP} PRIVATE coverage_config) +endif() +target_precompile_headers(${LIB_DEEPMD_OP} PRIVATE custom_op.h) if (BUILD_PY_IF) - add_library(op_abi MODULE ${OP_SRC} ${OP_REMAPPER_SRC}) add_library(op_grads MODULE ${OP_GRADS_SRC}) - # link: libdeepmd libtensorflow_framework - target_link_libraries(op_abi PRIVATE ${LIB_DEEPMD}) target_link_libraries(op_grads PRIVATE ${LIB_DEEPMD}) - target_link_libraries( - op_abi PRIVATE TensorFlow::tensorflow_framework - ) target_link_libraries( op_grads PRIVATE TensorFlow::tensorflow_framework ) - if(Protobuf_LIBRARY) - target_link_libraries(op_abi PRIVATE ${Protobuf_LIBRARY}) - endif() - if (APPLE) - set_target_properties( - op_abi - PROPERTIES - INSTALL_RPATH @loader_path - ) + if(APPLE) set_target_properties( op_grads PROPERTIES INSTALL_RPATH @loader_path ) else() - set_target_properties( - op_abi - PROPERTIES - INSTALL_RPATH $ORIGIN - ) set_target_properties( op_grads PROPERTIES @@ -57,19 +40,16 @@ if (BUILD_PY_IF) ) endif () if (CMAKE_TESTING_ENABLED) - target_link_libraries(op_abi PRIVATE coverage_config) target_link_libraries(op_grads PRIVATE coverage_config) endif() - target_precompile_headers(op_abi PRIVATE custom_op.h) target_precompile_headers(op_grads PRIVATE custom_op.h) endif (BUILD_PY_IF) -if (BUILD_CPP_IF) - install(TARGETS ${LIB_DEEPMD_OP} DESTINATION lib/) -endif (BUILD_CPP_IF) if (BUILD_PY_IF) - install(TARGETS op_abi DESTINATION deepmd/op/) + install(TARGETS ${LIB_DEEPMD_OP} DESTINATION deepmd/op/) install(TARGETS op_grads DESTINATION deepmd/op/) install(FILES ${OP_PY} DESTINATION deepmd/op/) +else(BUILD_PY_IF) + install(TARGETS ${LIB_DEEPMD_OP} DESTINATION lib/) endif (BUILD_PY_IF) diff --git a/source/tests/infer/in.test b/source/tests/infer/in.test new file mode 100644 index 0000000000..f647c1b132 --- /dev/null +++ b/source/tests/infer/in.test @@ -0,0 +1,22 @@ +# test cibuildwheel + +units metal +boundary p p p +atom_style atomic + +neighbor 2.0 bin +neigh_modify every 10 delay 0 check no + +read_data ../../../examples/water/lmp/water.lmp +mass 1 16 +mass 2 2 + +pair_style deepmd deep_pot.pb +pair_coeff * * + +velocity all create 330.0 23456789 + +fix 1 all nve +timestep 0.0005 + +run 1 diff --git a/source/tests/test_lammps.py b/source/tests/test_lammps.py new file mode 100644 index 0000000000..098ab55d5d --- /dev/null +++ b/source/tests/test_lammps.py @@ -0,0 +1,22 @@ +import unittest +import os +import subprocess + +from pathlib import Path +from deepmd.utils.convert import convert_pbtxt_to_pb + +@unittest.skipIf(os.environ.get("CIBUILDWHEEL", "0") != "1", "Only test under cibuildwheel environment") +class TestLAMMPS(unittest.TestCase): + """Test LAMMPS in cibuildwheel environment.""" + @classmethod + def setUpClass(cls): + cls.work_dir = (Path(__file__).parent / "infer").absolute() + + convert_pbtxt_to_pb( + str(cls.work_dir / "deeppot.pbtxt"), + str(cls.work_dir / "deep_pot.pb") + ) + + def test_lmp(self): + in_file = (self.work_dir / "in.test").absolute() + subprocess.check_call(["lmp", "-in", str(in_file)], cwd=str(self.work_dir))