-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate Python build backend to scikit-build-core (#2798)
This PR migrates the Python build backend from scikit-build to [scikit-build-core](https://github.com/scikit-build/scikit-build-core), which is being actively developed. There are no breaking changes to users; all tests should be passed without modification. The behavior for editable installation (`pip install -e .`) is changed. Before, the compiled binary libraries (e.g. `libdeepmd_op.sp`) are installed into the source directory. In this PR, the library files are installed into `site-packages` separately, while the Python files are still in the source code and can be modified for development. --------- Signed-off-by: Jinzhe Zeng <[email protected]>
- Loading branch information
Showing
46 changed files
with
300 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ _skbuild | |
deepmd_kit.egg-info/ | ||
dist | ||
.eggs | ||
_version.py | ||
/deepmd/_version.py | ||
venv* | ||
.vscode/** | ||
_build | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
from typing import ( | ||
Dict, | ||
List, | ||
Optional, | ||
) | ||
|
||
from .find_tensorflow import ( | ||
get_tf_requirement, | ||
) | ||
from .read_env import ( | ||
get_argument_from_env, | ||
) | ||
|
||
__all__ = ["dynamic_metadata"] | ||
|
||
|
||
def __dir__() -> List[str]: | ||
return __all__ | ||
|
||
|
||
def dynamic_metadata( | ||
field: str, | ||
settings: Optional[Dict[str, object]] = None, | ||
) -> str: | ||
assert field in ["optional-dependencies", "entry-points", "scripts"] | ||
_, _, find_libpython_requires, extra_scripts, tf_version = get_argument_from_env() | ||
if field == "scripts": | ||
return { | ||
"dp": "deepmd_cli.main:main", | ||
**extra_scripts, | ||
} | ||
elif field == "optional-dependencies": | ||
return { | ||
"test": [ | ||
"dpdata>=0.1.9", | ||
"ase", | ||
"pytest", | ||
"pytest-cov", | ||
"pytest-sugar", | ||
], | ||
"docs": [ | ||
"sphinx>=3.1.1", | ||
"sphinx_rtd_theme>=1.0.0rc1", | ||
"sphinx_markdown_tables", | ||
"myst-nb", | ||
"breathe", | ||
"exhale", | ||
"numpydoc", | ||
"ase", | ||
"deepmodeling-sphinx>=0.1.0", | ||
"dargs>=0.3.4", | ||
"sphinx-argparse", | ||
"pygments-lammps", | ||
"sphinxcontrib-bibtex", | ||
], | ||
"lmp": [ | ||
"lammps~=2023.8.2.0.0; platform_system=='Linux'", | ||
"lammps~=2023.8.2.0.0; platform_system!='Linux'", | ||
*find_libpython_requires, | ||
], | ||
"ipi": [ | ||
"i-PI", | ||
*find_libpython_requires, | ||
], | ||
**get_tf_requirement(tf_version), | ||
"cu11": [ | ||
"nvidia-cuda-runtime-cu11", | ||
"nvidia-cublas-cu11", | ||
"nvidia-cufft-cu11", | ||
"nvidia-curand-cu11", | ||
"nvidia-cusolver-cu11", | ||
"nvidia-cusparse-cu11", | ||
"nvidia-cudnn-cu11", | ||
"nvidia-cuda-nvcc-cu11", | ||
], | ||
"cu12": [ | ||
"nvidia-cuda-runtime-cu12", | ||
"nvidia-cublas-cu12", | ||
"nvidia-cufft-cu12", | ||
"nvidia-curand-cu12", | ||
"nvidia-cusolver-cu12", | ||
"nvidia-cusparse-cu12", | ||
"nvidia-cudnn-cu12", | ||
"nvidia-cuda-nvcc-cu12", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
"""Read environment variables to configure the build.""" | ||
|
||
import os | ||
from functools import ( | ||
lru_cache, | ||
) | ||
from typing import ( | ||
Tuple, | ||
) | ||
|
||
from packaging.version import ( | ||
Version, | ||
) | ||
|
||
from .find_tensorflow import ( | ||
find_tensorflow, | ||
get_tf_version, | ||
) | ||
|
||
|
||
@lru_cache() | ||
def get_argument_from_env() -> Tuple[str, list, list, dict, str]: | ||
"""Get the arguments from environment variables. | ||
The environment variables are assumed to be not changed during the build. | ||
Returns | ||
------- | ||
str | ||
The minimum required CMake version. | ||
list of str | ||
The CMake arguments. | ||
list of str | ||
The requirements for the build. | ||
dict | ||
The extra scripts to be installed. | ||
str | ||
The TensorFlow version. | ||
""" | ||
cmake_args = [] | ||
extra_scripts = {} | ||
# get variant option from the environment varibles, available: cpu, cuda, rocm | ||
dp_variant = os.environ.get("DP_VARIANT", "cpu").lower() | ||
if dp_variant == "cpu" or dp_variant == "": | ||
cmake_minimum_required_version = "3.16" | ||
elif dp_variant == "cuda": | ||
cmake_minimum_required_version = "3.23" | ||
cmake_args.append("-DUSE_CUDA_TOOLKIT:BOOL=TRUE") | ||
cuda_root = os.environ.get("CUDAToolkit_ROOT") | ||
if cuda_root: | ||
cmake_args.append(f"-DCUDAToolkit_ROOT:STRING={cuda_root}") | ||
elif dp_variant == "rocm": | ||
cmake_minimum_required_version = "3.21" | ||
cmake_args.append("-DUSE_ROCM_TOOLKIT:BOOL=TRUE") | ||
rocm_root = os.environ.get("ROCM_ROOT") | ||
if rocm_root: | ||
cmake_args.append(f"-DCMAKE_HIP_COMPILER_ROCM_ROOT:STRING={rocm_root}") | ||
hipcc_flags = os.environ.get("HIP_HIPCC_FLAGS") | ||
if hipcc_flags: | ||
cmake_args.append(f"-DHIP_HIPCC_FLAGS:STRING={hipcc_flags}") | ||
else: | ||
raise RuntimeError("Unsupported DP_VARIANT option: %s" % dp_variant) | ||
|
||
if os.environ.get("DP_BUILD_TESTING", "0") == "1": | ||
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", "") | ||
dp_ipi = os.environ.get("DP_ENABLE_IPI", "0") | ||
if dp_lammps_version != "" or dp_ipi == "1": | ||
cmake_args.append("-DBUILD_CPP_IF:BOOL=TRUE") | ||
cmake_args.append("-DUSE_TF_PYTHON_LIBS:BOOL=TRUE") | ||
else: | ||
cmake_args.append("-DBUILD_CPP_IF:BOOL=FALSE") | ||
|
||
if dp_lammps_version != "": | ||
cmake_args.append(f"-DLAMMPS_VERSION={dp_lammps_version}") | ||
if dp_ipi == "1": | ||
cmake_args.append("-DENABLE_IPI:BOOL=TRUE") | ||
extra_scripts["dp_ipi"] = "deepmd.entrypoints.ipi:dp_ipi" | ||
|
||
tf_install_dir, _ = find_tensorflow() | ||
tf_version = get_tf_version(tf_install_dir) | ||
if tf_version == "" or Version(tf_version) >= Version("2.12"): | ||
find_libpython_requires = [] | ||
else: | ||
find_libpython_requires = ["find_libpython"] | ||
cmake_args.append(f"-DTENSORFLOW_VERSION={tf_version}") | ||
|
||
cmake_args = [ | ||
f"-DTENSORFLOW_ROOT:PATH={tf_install_dir}", | ||
"-DBUILD_PY_IF:BOOL=TRUE", | ||
*cmake_args, | ||
] | ||
return ( | ||
cmake_minimum_required_version, | ||
cmake_args, | ||
find_libpython_requires, | ||
extra_scripts, | ||
tf_version, | ||
) | ||
|
||
|
||
def set_scikit_build_env(): | ||
"""Set scikit-build environment variables before executing scikit-build.""" | ||
cmake_minimum_required_version, cmake_args, _, _, _ = get_argument_from_env() | ||
os.environ["SKBUILD_CMAKE_MINIMUM_VERSION"] = cmake_minimum_required_version | ||
os.environ["SKBUILD_CMAKE_ARGS"] = ";".join(cmake_args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
op/_*.py | ||
pkg_config | ||
run_config.ini | ||
!op/__init__.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.