Skip to content

Commit ddc80d6

Browse files
Merge branch 'devel' into 1108_default_fparam_stat
2 parents 6f18144 + da452d7 commit ddc80d6

17 files changed

Lines changed: 225 additions & 67 deletions

.devcontainer/build_cxx.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ cmake -D ENABLE_TENSORFLOW=ON \
1313
-D ENABLE_PYTORCH=ON \
1414
-D ENABLE_PADDLE=ON \
1515
-D CMAKE_INSTALL_PREFIX=${SCRIPT_PATH}/../dp/ \
16-
-D LAMMPS_VERSION=stable_22Jul2025_update1 \
16+
-D LAMMPS_VERSION=stable_22Jul2025_update2 \
1717
-D CMAKE_BUILD_TYPE=Debug \
1818
-D BUILD_TESTING:BOOL=TRUE \
1919
-D TENSORFLOW_ROOT=${TENSORFLOW_ROOT} \

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ repos:
2929
exclude: ^source/3rdparty
3030
- repo: https://github.com/astral-sh/ruff-pre-commit
3131
# Ruff version.
32-
rev: v0.14.3
32+
rev: v0.14.5
3333
hooks:
3434
- id: ruff
3535
args: ["--fix"]
@@ -60,7 +60,7 @@ repos:
6060
- id: blacken-docs
6161
# C++
6262
- repo: https://github.com/pre-commit/mirrors-clang-format
63-
rev: v21.1.2
63+
rev: v21.1.5
6464
hooks:
6565
- id: clang-format
6666
exclude: ^(source/3rdparty|source/lib/src/gpu/cudart/.+\.inc|.+\.ipynb$|.+\.json$)
@@ -154,7 +154,7 @@ repos:
154154
exclude: .pre-commit-config.yaml|source/lmp
155155
# customized pylint rules
156156
- repo: https://github.com/pylint-dev/pylint/
157-
rev: v4.0.2
157+
rev: v4.0.3
158158
hooks:
159159
- id: pylint
160160
entry: env PYTHONPATH=source/checker pylint

deepmd/pt/infer/deep_eval.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,9 @@ def _get_request_defs(self, atomic: bool) -> list[OutputVariableDef]:
397397
The requested output definitions.
398398
"""
399399
if atomic:
400-
return list(self.output_def.var_defs.values())
400+
output_defs = list(self.output_def.var_defs.values())
401401
else:
402-
return [
402+
output_defs = [
403403
x
404404
for x in self.output_def.var_defs.values()
405405
if x.category
@@ -411,6 +411,13 @@ def _get_request_defs(self, atomic: bool) -> list[OutputVariableDef]:
411411
OutputVariableCategory.DERV_R_DERV_R,
412412
)
413413
]
414+
if not self.get_has_hessian():
415+
output_defs = [
416+
x
417+
for x in output_defs
418+
if x.category != OutputVariableCategory.DERV_R_DERV_R
419+
]
420+
return output_defs
414421

415422
def _eval_func(self, inner_func: Callable, numb_test: int, natoms: int) -> Callable:
416423
"""Wrapper method with auto batch size.

deepmd/pt/utils/tabulate.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ class DPTabulate(BaseTabulate):
4646
The excluded pairs of types which have no interaction with each other.
4747
For example, `[[0, 1]]` means no interaction between type 0 and type 1.
4848
activation_function
49-
The activation function in the embedding net. Supported options are {"tanh","gelu"} in common.ActivationFn.
49+
The activation function in the embedding net. See :class:`ActivationFn`
50+
for supported options (e.g. "tanh", "gelu", "relu", "silu").
5051
"""
5152

5253
def __init__(
@@ -84,6 +85,7 @@ def __init__(
8485
"relu6": 4,
8586
"softplus": 5,
8687
"sigmoid": 6,
88+
"silu": 7,
8789
}
8890

8991
activation = activation_fn.activation
@@ -468,6 +470,11 @@ def grad(xbar: torch.Tensor, y: torch.Tensor, functype: int) -> torch.Tensor:
468470
elif functype == 6:
469471
return y * (1 - y)
470472

473+
elif functype == 7:
474+
# silu'(x) = sigmoid(x) * (1 + x * (1 - sigmoid(x)))
475+
sig = torch.sigmoid(xbar)
476+
return sig + xbar * sig * (1 - sig)
477+
471478
else:
472479
raise ValueError(f"Unsupported function type: {functype}")
473480

@@ -495,6 +502,12 @@ def grad_grad(xbar: torch.Tensor, y: torch.Tensor, functype: int) -> torch.Tenso
495502
elif functype == 6:
496503
return y * (1 - y) * (1 - 2 * y)
497504

505+
elif functype == 7:
506+
sig = torch.sigmoid(xbar)
507+
d_sig = sig * (1 - sig)
508+
# silu''(x) = 2 * d_sig + x * d_sig * (1 - 2 * sig)
509+
return 2 * d_sig + xbar * d_sig * (1 - 2 * sig)
510+
498511
else:
499512
return -torch.ones_like(xbar)
500513

deepmd/utils/data.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from typing import (
1515
Any,
1616
Optional,
17+
Union,
1718
)
1819

1920
import numpy as np
@@ -103,13 +104,10 @@ def __init__(
103104
f"Elements {missing_elements} are not present in the provided `type_map`."
104105
)
105106
if not self.mixed_type:
106-
# Use vectorized operation for better performance with large atom counts
107-
# Create a mapping array where old_type_idx -> new_type_idx
108-
max_old_type = max(self.atom_type) + 1
109-
type_mapping = np.zeros(max_old_type, dtype=np.int32)
110-
for old_idx in range(len(self.type_map)):
111-
type_mapping[old_idx] = type_map.index(self.type_map[old_idx])
112-
self.atom_type = type_mapping[self.atom_type].astype(np.int32)
107+
old_to_new_type_idx = np.array(
108+
[type_map.index(name) for name in self.type_map], dtype=np.int32
109+
)
110+
self.atom_type = old_to_new_type_idx[self.atom_type].astype(np.int32)
113111
else:
114112
self.enforce_type_map = True
115113
sorter = np.argsort(type_map)
@@ -138,8 +136,7 @@ def __init__(
138136
self.shuffle_test = shuffle_test
139137
# set modifier
140138
self.modifier = modifier
141-
# calculate prefix sum for get_item method
142-
frames_list = [self._get_nframes(item) for item in self.dirs]
139+
frames_list = [self._get_nframes(set_name) for set_name in self.dirs]
143140
self.nframes = np.sum(frames_list)
144141
# The prefix sum stores the range of indices contained in each directory, which is needed by get_item method
145142
self.prefix_sum = np.cumsum(frames_list).tolist()
@@ -341,8 +338,10 @@ def get_numb_set(self) -> int:
341338

342339
def get_numb_batch(self, batch_size: int, set_idx: int) -> int:
343340
"""Get the number of batches in a set."""
344-
data = self._load_set(self.dirs[set_idx])
345-
ret = data["coord"].shape[0] // batch_size
341+
set_name = self.dirs[set_idx]
342+
# Directly obtain the number of frames to avoid loading the entire dataset
343+
nframes = self._get_nframes(set_name)
344+
ret = nframes // batch_size
346345
if ret == 0:
347346
ret = 1
348347
return ret
@@ -581,18 +580,27 @@ def _shuffle_data(self, data: dict[str, Any]) -> dict[str, Any]:
581580
ret[kk] = data[kk]
582581
return ret, idx
583582

584-
def _get_nframes(self, set_name: DPPath) -> int:
585-
# get nframes
583+
def _get_nframes(self, set_name: Union[DPPath, str]) -> int:
586584
if not isinstance(set_name, DPPath):
587585
set_name = DPPath(set_name)
588586
path = set_name / "coord.npy"
589-
if self.data_dict["coord"]["high_prec"]:
590-
coord = path.load_numpy().astype(GLOBAL_ENER_FLOAT_PRECISION)
587+
if isinstance(set_name, DPH5Path):
588+
nframes = path.root[path._name].shape[0]
591589
else:
592-
coord = path.load_numpy().astype(GLOBAL_NP_FLOAT_PRECISION)
593-
if coord.ndim == 1:
594-
coord = coord.reshape([1, -1])
595-
nframes = coord.shape[0]
590+
# Read only the header to get shape
591+
with open(str(path), "rb") as f:
592+
version = np.lib.format.read_magic(f)
593+
if version[0] == 1:
594+
shape, _fortran_order, _dtype = np.lib.format.read_array_header_1_0(
595+
f
596+
)
597+
elif version[0] in [2, 3]:
598+
shape, _fortran_order, _dtype = np.lib.format.read_array_header_2_0(
599+
f
600+
)
601+
else:
602+
raise ValueError(f"Unsupported .npy file version: {version}")
603+
nframes = shape[0] if len(shape) > 1 else 1
596604
return nframes
597605

598606
def reformat_data_torch(self, data: dict[str, Any]) -> dict[str, Any]:

doc/install/install-lammps.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ DeePMD-kit will generate a module called `USER-DEEPMD` in the `build` directory,
1717

1818
```bash
1919
cd /some/workspace
20-
wget https://github.com/lammps/lammps/archive/stable_22Jul2025_update1.tar.gz
21-
tar xf stable_22Jul2025_update1.tar.gz
20+
wget https://github.com/lammps/lammps/archive/stable_22Jul2025_update2.tar.gz
21+
tar xf stable_22Jul2025_update2.tar.gz
2222
```
2323

24-
The source code of LAMMPS is stored in the directory `lammps-stable_22Jul2025_update1`.
24+
The source code of LAMMPS is stored in the directory `lammps-stable_22Jul2025_update2`.
2525

2626
Then, you can [build LAMMPS](https://docs.lammps.org/Build.html) with either make or CMake.
2727

@@ -30,7 +30,7 @@ Then, you can [build LAMMPS](https://docs.lammps.org/Build.html) with either mak
3030
Now go into the LAMMPS code and copy the DeePMD-kit module like this
3131

3232
```bash
33-
cd lammps-stable_22Jul2025_update1/src/
33+
cd lammps-stable_22Jul2025_update2/src/
3434
cp -r $deepmd_source_dir/source/build/USER-DEEPMD .
3535
make yes-kspace
3636
make yes-extra-fix
@@ -60,8 +60,8 @@ make no-user-deepmd
6060
Now go into the LAMMPS directory and create a directory called `build`:
6161

6262
```bash
63-
mkdir -p lammps-stable_22Jul2025_update1/build/
64-
cd lammps-stable_22Jul2025_update1/build/
63+
mkdir -p lammps-stable_22Jul2025_update2/build/
64+
cd lammps-stable_22Jul2025_update2/build/
6565
```
6666

6767
Patch the LAMMPS `CMakeLists.txt` file:
@@ -94,15 +94,15 @@ Now download the LAMMPS code (`8Apr2021` or later), and uncompress it:
9494

9595
```bash
9696
cd /some/workspace
97-
wget https://github.com/lammps/lammps/archive/stable_22Jul2025_update1.tar.gz
98-
tar xf stable_22Jul2025_update1.tar.gz
97+
wget https://github.com/lammps/lammps/archive/stable_22Jul2025_update2.tar.gz
98+
tar xf stable_22Jul2025_update2.tar.gz
9999
```
100100

101-
The source code of LAMMPS is stored in the directory `lammps-stable_22Jul2025_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`
101+
The source code of LAMMPS is stored in the directory `lammps-stable_22Jul2025_update2`. 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`
102102

103103
```bash
104-
mkdir -p lammps-stable_22Jul2025_update1/build/
105-
cd lammps-stable_22Jul2025_update1/build/
104+
mkdir -p lammps-stable_22Jul2025_update2/build/
105+
cd lammps-stable_22Jul2025_update2/build/
106106
```
107107

108108
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.

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ docs = [
108108
"sphinx-remove-toctrees",
109109
]
110110
lmp = [
111-
"lammps[mpi]~=2025.7.22.1.0",
111+
"lammps[mpi]~=2025.7.22.2.0",
112112
]
113113
ipi = [
114114
"ipi",
@@ -242,7 +242,7 @@ repair-wheel-command = """delocate-wheel --require-archs {delocate_archs} -w {de
242242

243243
[tool.cibuildwheel.macos.environment]
244244
PIP_PREFER_BINARY = "1"
245-
DP_LAMMPS_VERSION = "stable_22Jul2025_update1"
245+
DP_LAMMPS_VERSION = "stable_22Jul2025_update2"
246246
DP_ENABLE_IPI = "1"
247247
DP_ENABLE_PYTORCH = "1"
248248
DP_ENABLE_PADDLE = "1"
@@ -278,7 +278,7 @@ before-build = [
278278
]
279279
[tool.cibuildwheel.linux.environment]
280280
PIP_PREFER_BINARY = "1"
281-
DP_LAMMPS_VERSION = "stable_22Jul2025_update1"
281+
DP_LAMMPS_VERSION = "stable_22Jul2025_update2"
282282
DP_ENABLE_IPI = "1"
283283
DP_ENABLE_PYTORCH = "1"
284284
DP_ENABLE_PADDLE = "1"

source/install/build_cc.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ cmake -D ENABLE_TENSORFLOW=ON \
2626
-D USE_TF_PYTHON_LIBS=TRUE \
2727
-D USE_PT_PYTHON_LIBS=TRUE \
2828
${CUDA_ARGS} \
29-
-D LAMMPS_VERSION=stable_22Jul2025_update1 \
29+
-D LAMMPS_VERSION=stable_22Jul2025_update2 \
3030
..
3131
cmake --build . -j${NPROC}
3232
cmake --install .

source/install/build_from_c.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ NPROC=$(nproc --all)
1313
BUILD_TMP_DIR=${SCRIPT_PATH}/../build
1414
mkdir -p ${BUILD_TMP_DIR}
1515
cd ${BUILD_TMP_DIR}
16-
cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -DDEEPMD_C_ROOT=${DEEPMD_C_ROOT} -DLAMMPS_VERSION=stable_22Jul2025_update1 ..
16+
cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -DDEEPMD_C_ROOT=${DEEPMD_C_ROOT} -DLAMMPS_VERSION=stable_22Jul2025_update2 ..
1717
cmake --build . -j${NPROC}
1818
cmake --install .
1919
cmake --build . --target=lammps

source/install/build_lammps.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ BUILD_TMP_DIR=${SCRIPT_PATH}/../build_lammps
1414
mkdir -p ${BUILD_TMP_DIR}
1515
cd ${BUILD_TMP_DIR}
1616
# download LAMMMPS
17-
LAMMPS_VERSION=stable_22Jul2025_update1
17+
LAMMPS_VERSION=stable_22Jul2025_update2
1818
if [ ! -d "lammps-${LAMMPS_VERSION}" ]; then
1919
curl -L -o lammps.tar.gz https://github.com/lammps/lammps/archive/refs/tags/${LAMMPS_VERSION}.tar.gz
2020
tar vxzf lammps.tar.gz

0 commit comments

Comments
 (0)