From 49d6e7b4760e915cc5634b44ae69799bb51ae087 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sun, 27 Oct 2024 05:05:11 +0000 Subject: [PATCH 1/5] add devcontainer directory Signed-off-by: GitHub --- .devcontainer/Dockerfile | 3 +++ .devcontainer/build_cxx.sh | 20 ++++++++++++++++++++ .devcontainer/build_py.sh | 8 ++++++++ .devcontainer/devcontainer.json | 14 ++++++++++++++ .devcontainer/download_libtorch.sh | 8 ++++++++ .devcontainer/gdb_lmp | 9 +++++++++ .devcontainer/lmp | 9 +++++++++ .gitignore | 3 +++ pyproject.toml | 20 ++++++++++++++++++++ 9 files changed, 94 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100755 .devcontainer/build_cxx.sh create mode 100755 .devcontainer/build_py.sh create mode 100644 .devcontainer/devcontainer.json create mode 100755 .devcontainer/download_libtorch.sh create mode 100755 .devcontainer/gdb_lmp create mode 100755 .devcontainer/lmp diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000000..18a2acda7f --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,3 @@ +FROM mcr.microsoft.com/devcontainers/cpp:1-ubuntu-24.04 + +COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ diff --git a/.devcontainer/build_cxx.sh b/.devcontainer/build_cxx.sh new file mode 100755 index 0000000000..cffac9d5fd --- /dev/null +++ b/.devcontainer/build_cxx.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -ev + +NPROC=$(nproc --all) +SCRIPT_PATH=$(dirname $(realpath -s $0)) + +export CMAKE_PREFIX_PATH=${SCRIPT_PATH}/../libtorch +TENSORFLOW_ROOT=$(python -c 'import importlib,pathlib;print(pathlib.Path(importlib.util.find_spec("tensorflow").origin).parent)') + +mkdir -p ${SCRIPT_PATH}/../buildcxx/ +cd ${SCRIPT_PATH}/../buildcxx/ +cmake -D ENABLE_TENSORFLOW=ON \ + -D ENABLE_PYTORCH=ON \ + -D CMAKE_INSTALL_PREFIX=${SCRIPT_PATH}/../dp/ \ + -D LAMMPS_VERSION=stable_29Aug2024_update1 \ + -D CMAKE_BUILD_TYPE=Debug \ + -D TENSORFLOW_ROOT=${TENSORFLOW_ROOT} \ + ${SCRIPT_PATH}/../source +cmake --build . -j${NPROC} +cmake --install . diff --git a/.devcontainer/build_py.sh b/.devcontainer/build_py.sh new file mode 100755 index 0000000000..8e9a006a4f --- /dev/null +++ b/.devcontainer/build_py.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -ev + +SCRIPT_PATH=$(dirname $(realpath -s $0)) +cd ${SCRIPT_PATH}/.. + +uv sync --dev --python 3.12 --extra cpu --extra torch --extra jax --extra lmp --extra test --extra docs +pre-commit install diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..46b410b7bf --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,14 @@ +{ + "name": "DeePMD-kit", + "build": { + "dockerfile": "Dockerfile" + }, + "postCreateCommand": ".devcontainer/build_py.sh && .devcontainer/download_libtorch.sh && .devcontainer/build_cxx.sh && pre-commit install-hooks", + "remoteEnv": { + "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/.devcontainer/download_libtorch.sh b/.devcontainer/download_libtorch.sh new file mode 100755 index 0000000000..d78b559997 --- /dev/null +++ b/.devcontainer/download_libtorch.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -ev + +SCRIPT_PATH=$(dirname $(realpath -s $0)) +cd ${SCRIPT_PATH}/.. + +wget https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-2.5.0%2Bcpu.zip -O ~/libtorch.zip +unzip ~/libtorch.zip diff --git a/.devcontainer/gdb_lmp b/.devcontainer/gdb_lmp new file mode 100755 index 0000000000..33e883780b --- /dev/null +++ b/.devcontainer/gdb_lmp @@ -0,0 +1,9 @@ +#!/bin/bash +SCRIPT_PATH=$(dirname $(realpath -s $0)) + +export CMAKE_PREFIX_PATH=${SCRIPT_PATH}/../libtorch +TENSORFLOW_ROOT=$(python -c 'import importlib,pathlib;print(pathlib.Path(importlib.util.find_spec("tensorflow").origin).parent)') + +env LAMMPS_PLUGIN_PATH=${SCRIPT_PATH}/../dp/lib/deepmd_lmp \ + LD_LIBRARY_PATH=${SCRIPT_PATH}/../dp/lib:${CMAKE_PREFIX_PATH}/lib:${TENSORFLOW_ROOT} \ + gdb ${SCRIPT_PATH}/../.venv/lib/python3.12/site-packages/lammps/lmp "$@" diff --git a/.devcontainer/lmp b/.devcontainer/lmp new file mode 100755 index 0000000000..c8e781aa57 --- /dev/null +++ b/.devcontainer/lmp @@ -0,0 +1,9 @@ +#!/bin/bash +SCRIPT_PATH=$(dirname $(realpath -s $0)) + +export CMAKE_PREFIX_PATH=${SCRIPT_PATH}/../libtorch +TENSORFLOW_ROOT=$(python -c 'import importlib,pathlib;print(pathlib.Path(importlib.util.find_spec("tensorflow").origin).parent)') + +env LAMMPS_PLUGIN_PATH=${SCRIPT_PATH}/../dp/lib/deepmd_lmp \ + LD_LIBRARY_PATH=${SCRIPT_PATH}/../dp/lib:${CMAKE_PREFIX_PATH}/lib:${TENSORFLOW_ROOT} \ + ${SCRIPT_PATH}/../.venv/bin/lmp "$@" diff --git a/.gitignore b/.gitignore index c531a76177..a293e3e8d1 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,6 @@ build_c_tests build_c/ libdeepmd_c/ .uv/ +libtorch/ +uv.lock +buildcxx/ diff --git a/pyproject.toml b/pyproject.toml index 6f0404174d..0a1b2e6731 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -136,9 +136,14 @@ cu12 = [ "nvidia-cuda-nvcc-cu12", ] jax = [ + # below is a funny workaround for + # https://github.com/astral-sh/uv/issues/8601 'jax>=0.4.33;python_version>="3.10"', + 'jax>=0.4.33;python_version>="3.10"', + 'flax>=0.10.0;python_version>="3.10"', 'flax>=0.10.0;python_version>="3.10"', 'orbax-checkpoint;python_version>="3.10"', + 'orbax-checkpoint;python_version>="3.10"', # The pinning of ml_dtypes may conflict with TF # 'jax-ai-stack;python_version>="3.10"', ] @@ -146,6 +151,13 @@ jax = [ [tool.deepmd_build_backend.scripts] dp = "deepmd.main:main" +[dependency-groups] +dev = [ + "pre-commit", + "cmake", + "mpich", +] + [tool.setuptools_scm] [tool.scikit-build] @@ -428,3 +440,11 @@ select = [ "TOR1", "TOR2", ] + +[tool.uv.sources] +mpich = { index = "mpi4py" } + +[[tool.uv.index]] +name = "mpi4py" +url = "https://pypi.anaconda.org/mpi4py/simple" +explicit = true From 4cace3a0823f937894ffb05e59f84e3eb9892dba Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sun, 27 Oct 2024 05:06:37 +0000 Subject: [PATCH 2/5] need github cli Signed-off-by: GitHub --- .devcontainer/devcontainer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 46b410b7bf..27c40bbe6a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,6 +3,9 @@ "build": { "dockerfile": "Dockerfile" }, + "features": { + "ghcr.io/devcontainers/features/github-cli:1": {} + }, "postCreateCommand": ".devcontainer/build_py.sh && .devcontainer/download_libtorch.sh && .devcontainer/build_cxx.sh && pre-commit install-hooks", "remoteEnv": { "PATH": "${containerEnv:PATH}:${containerWorkspaceFolder}/.venv/bin", From 06f58107e9459a8f4d12fa216dc36d70f8558494 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sun, 27 Oct 2024 05:32:35 +0000 Subject: [PATCH 3/5] add readme Signed-off-by: Jinzhe Zeng --- .devcontainer/READMD.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .devcontainer/READMD.md diff --git a/.devcontainer/READMD.md b/.devcontainer/READMD.md new file mode 100644 index 0000000000..8e600a143f --- /dev/null +++ b/.devcontainer/READMD.md @@ -0,0 +1,35 @@ +# DeePMD-kit devcontainer environment + +This [devcontainer](https://vscode.js.cn/docs/devcontainers/devcontainer-cli) environment setups Python and C++ environment to develop DeePMD-kit. +One can setup locally or use [GitHub Codespaces](https://docs.github.com/en/codespaces) by clicking the Code button on the DeePMD-kit repository page. +The whole setup process requires about 10 minutes, so one needs to be patient. + +## Python environment + +The following packages are installed into the Python environment `.venv`: + +- DeePMD-kit (in edit mode) +- Backends including TensorFlow, PyTorch, JAX +- LAMMPS +- MPICH +- CMake +- pre-commit (including hooks) +- Test packages including pytest +- Doc packages including sphinx + +## C++ interface + +The C++ interface with TensorFlow and PyTorch support is installed into `dp` directory. + +When calling and debuging LAMMPS with DeePMD-kit, use the following scripts instead of the regular `lmp`: + +- `.devcontainer/lmp` +- `.devcontainer/gdb_lmp` + +## Rebuild + +Usually the Python package does not need to reinstall. +But when one wants to recompile the C++ code, the following scripts can be executed. + +- `.devcontainer/build_cxx.sh` +- `.devcontainer/build_py.sh` From 56ef285d35d6af37ba740bf05a3726dea6f3043c Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sun, 27 Oct 2024 05:34:31 +0000 Subject: [PATCH 4/5] add more to .gitignore Signed-off-by: Jinzhe Zeng --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index a293e3e8d1..c574da757a 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,5 @@ libdeepmd_c/ libtorch/ uv.lock buildcxx/ +node_modules/ +*.bib.original From 0b87f7a1832671890f4b1e264218b6acf441019a Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sun, 27 Oct 2024 05:50:07 +0000 Subject: [PATCH 5/5] set BUILD_TESTING to true Signed-off-by: Jinzhe Zeng --- .devcontainer/build_cxx.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.devcontainer/build_cxx.sh b/.devcontainer/build_cxx.sh index cffac9d5fd..442539301e 100755 --- a/.devcontainer/build_cxx.sh +++ b/.devcontainer/build_cxx.sh @@ -14,6 +14,7 @@ cmake -D ENABLE_TENSORFLOW=ON \ -D CMAKE_INSTALL_PREFIX=${SCRIPT_PATH}/../dp/ \ -D LAMMPS_VERSION=stable_29Aug2024_update1 \ -D CMAKE_BUILD_TYPE=Debug \ + -D BUILD_TESTING:BOOL=TRUE \ -D TENSORFLOW_ROOT=${TENSORFLOW_ROOT} \ ${SCRIPT_PATH}/../source cmake --build . -j${NPROC}