Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ repos:
exclude: ^source/3rdparty
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.2.2
rev: v0.3.2
hooks:
- id: ruff
args: ["--fix"]
Expand All @@ -53,7 +53,7 @@ repos:
- id: blacken-docs
# C++
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v17.0.6
rev: v18.1.1
hooks:
- id: clang-format
exclude: ^source/3rdparty|source/lib/src/gpu/cudart/.+\.inc
Expand Down
1 change: 1 addition & 0 deletions backend/dp_backend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
"""A PEP-517 backend to find TensorFlow."""

from typing import (
List,
)
Expand Down
1 change: 1 addition & 0 deletions deepmd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
The top module (deepmd.__init__) should not import any third-party
modules for performance.
"""

try:
from deepmd._version import version as __version__
except ImportError:
Expand Down
1 change: 1 addition & 0 deletions deepmd/backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

Avoid directly importing third-party libraries in this module for performance.
"""

# copy from dpdata
from importlib import (
import_module,
Expand Down
1 change: 0 additions & 1 deletion deepmd/dpmodel/atomic_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

"""


from .base_atomic_model import (
BaseAtomicModel,
)
Expand Down
1 change: 1 addition & 0 deletions deepmd/dpmodel/utils/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

See issue #2982 for more information.
"""

import copy
import itertools
import json
Expand Down
2 changes: 1 addition & 1 deletion deepmd/dpmodel/utils/nlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def build_multiple_neighbor_list(
ret = {}
for rc, ns in zip(rcuts[::-1], nsels[::-1]):
tnlist_1 = np.copy(nlist0[:, :, :ns])
tnlist_1[rr[:, :, :ns] > rc] = int(-1)
tnlist_1[rr[:, :, :ns] > rc] = -1
ret[get_multiple_nlist_key(rc, ns)] = tnlist_1
return ret

Expand Down
1 change: 1 addition & 0 deletions deepmd/driver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
"""dpdata driver."""

# Derived from https://github.com/deepmodeling/dpdata/blob/18a0ed5ebced8b1f6887038883d46f31ae9990a4/dpdata/plugins/deepmd.py#L361-L443
# under LGPL-3.0-or-later license.
# The original deepmd driver maintained in the dpdata package will be overriden.
Expand Down
1 change: 1 addition & 0 deletions deepmd/entrypoints/test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
"""Test trained DeePMD model."""

import logging
from pathlib import (
Path,
Expand Down
6 changes: 2 additions & 4 deletions deepmd/infer/model_devi.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ def calc_model_devi_f(
real_f: Optional[np.ndarray] = None,
relative: Optional[float] = None,
atomic: Literal[False] = False,
) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
...
) -> Tuple[np.ndarray, np.ndarray, np.ndarray]: ...

Check notice

Code scanning / CodeQL

Statement has no effect

This statement has no effect.


@overload
Expand All @@ -40,8 +39,7 @@ def calc_model_devi_f(
relative: Optional[float] = None,
*,
atomic: Literal[True],
) -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
...
) -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]: ...

Check notice

Code scanning / CodeQL

Statement has no effect

This statement has no effect.


def calc_model_devi_f(
Expand Down
1 change: 1 addition & 0 deletions deepmd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
If only printing the help message, this module does not call
the main DeePMD-kit module to avoid the slow import of TensorFlow.
"""

import argparse
import logging
import os
Expand Down
6 changes: 3 additions & 3 deletions deepmd/pt/loss/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ def forward(self, model_pred, label, natoms, learning_rate=0.0, mae=False):
atom_num = natoms
l2_global_loss = torch.mean(torch.square(diff))
if not self.inference:
more_loss[
f"l2_global_{self.tensor_name}_loss"
] = l2_global_loss.detach()
more_loss[f"l2_global_{self.tensor_name}_loss"] = (
l2_global_loss.detach()
)
loss += self.global_weight * l2_global_loss
rmse_global = l2_global_loss.sqrt() / atom_num
more_loss[f"rmse_global_{self.tensor_name}"] = rmse_global.detach()
Expand Down
4 changes: 2 additions & 2 deletions deepmd/pt/model/task/fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def change_energy_bias(
The number of test samples in a system to change the energy bias.
"""
log.info(
"Changing energy bias in pretrained model for types {}... "
"(this step may take long time)".format(str(new_type_map))
f"Changing energy bias in pretrained model for types {new_type_map!s}... "
"(this step may take long time)"
)
# data
systems = config["training"]["training_data"]["systems"]
Expand Down
2 changes: 1 addition & 1 deletion deepmd/pt/utils/nlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def build_multiple_neighbor_list(
nlist0 = nlist
ret = {}
for rc, ns in zip(rcuts[::-1], nsels[::-1]):
nlist0 = nlist0[:, :, :ns].masked_fill(rr[:, :, :ns] > rc, int(-1))
nlist0 = nlist0[:, :, :ns].masked_fill(rr[:, :, :ns] > rc, -1)
ret[get_multiple_nlist_key(rc, ns)] = nlist0
return ret

Expand Down
1 change: 1 addition & 0 deletions deepmd/pt/utils/plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
"""Base of plugin systems."""

from deepmd.utils.plugin import (
Plugin,
PluginVariant,
Expand Down
12 changes: 4 additions & 8 deletions deepmd/pt/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,11 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:


@overload
def to_numpy_array(xx: torch.Tensor) -> np.ndarray:
...
def to_numpy_array(xx: torch.Tensor) -> np.ndarray: ...

Check notice

Code scanning / CodeQL

Statement has no effect

This statement has no effect.


@overload
def to_numpy_array(xx: None) -> None:
...
def to_numpy_array(xx: None) -> None: ...

Check notice

Code scanning / CodeQL

Statement has no effect

This statement has no effect.


def to_numpy_array(
Expand All @@ -91,13 +89,11 @@ def to_numpy_array(


@overload
def to_torch_tensor(xx: np.ndarray) -> torch.Tensor:
...
def to_torch_tensor(xx: np.ndarray) -> torch.Tensor: ...

Check notice

Code scanning / CodeQL

Statement has no effect

This statement has no effect.


@overload
def to_torch_tensor(xx: None) -> None:
...
def to_torch_tensor(xx: None) -> None: ...

Check notice

Code scanning / CodeQL

Statement has no effect

This statement has no effect.


def to_torch_tensor(
Expand Down
6 changes: 2 additions & 4 deletions deepmd/tf/entrypoints/freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,8 @@ def _modify_model_suffix(output_graph_def, out_suffix, freeze_type):
else:
jdata["training"]["training_data"] = {}
log.warning(
"The fitting net {} has no training data in input script, resulting in "
"untrained frozen model, and cannot be compressed directly! ".format(
out_suffix
)
f"The fitting net {out_suffix} has no training data in input script, resulting in "
"untrained frozen model, and cannot be compressed directly! "
)
# loss
if "loss_dict" in jdata:
Expand Down
1 change: 1 addition & 0 deletions deepmd/tf/entrypoints/ipi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
"""Use dp_ipi inside the Python package."""

import os
import subprocess
import sys
Expand Down
18 changes: 6 additions & 12 deletions deepmd/tf/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,20 +376,14 @@ def get_module(module_name: str) -> "ModuleType":
if TF_VERSION != tf_py_version:
raise RuntimeError(
"The version of TensorFlow used to compile this "
"deepmd-kit package is {}, but the version of TensorFlow "
"runtime you are using is {}. These two versions are "
"incompatible and thus an error is raised when loading {}. "
"You need to install TensorFlow {}, or rebuild deepmd-kit "
"against TensorFlow {}.\nIf you are using a wheel from "
f"deepmd-kit package is {TF_VERSION}, but the version of TensorFlow "
f"runtime you are using is {tf_py_version}. These two versions are "
f"incompatible and thus an error is raised when loading {module_name}. "
f"You need to install TensorFlow {TF_VERSION}, or rebuild deepmd-kit "
f"against TensorFlow {tf_py_version}.\nIf you are using a wheel from "
"pypi, you may consider to install deepmd-kit execuating "
"`pip install deepmd-kit --no-binary deepmd-kit` "
"instead.".format(
TF_VERSION,
tf_py_version,
module_name,
TF_VERSION,
tf_py_version,
)
"instead."
) from e
error_message = (
"This deepmd-kit package is inconsitent with TensorFlow "
Expand Down
6 changes: 3 additions & 3 deletions deepmd/tf/fit/fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ def deserialize_network(cls, data: dict, suffix: str = "") -> dict:
fitting_net_variables[f"{layer_name}{key}{suffix}/matrix"] = layer.w
fitting_net_variables[f"{layer_name}{key}{suffix}/bias"] = layer.b
if layer.idt is not None:
fitting_net_variables[
f"{layer_name}{key}{suffix}/idt"
] = layer.idt.reshape(1, -1)
fitting_net_variables[f"{layer_name}{key}{suffix}/idt"] = (
layer.idt.reshape(1, -1)
)
else:
# prevent keyError
fitting_net_variables[f"{layer_name}{key}{suffix}/idt"] = 0.0
Expand Down
1 change: 1 addition & 0 deletions deepmd/tf/lmp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
"""Register entry points for lammps-wheel."""

import os
import platform
from importlib import (
Expand Down
1 change: 1 addition & 0 deletions deepmd/tf/loggers/loggers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
"""Alias of deepmd.loggers.loggers for backward compatibility."""

from deepmd.loggers.loggers import (
set_log_handles,
)
Expand Down
1 change: 1 addition & 0 deletions deepmd/tf/model/model_stat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
"""Alias for backward compatibility."""

from deepmd.utils.model_stat import (
_make_all_stat_ref,
make_stat_input,
Expand Down
6 changes: 3 additions & 3 deletions deepmd/tf/model/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ def __init__(
fitting_dict[item] = item_fitting_param
else:
if item_fitting_param["type"] in ["dipole", "polar"]:
item_fitting_param[
"embedding_width"
] = self.descrpt.get_dim_rot_mat_1()
item_fitting_param["embedding_width"] = (
self.descrpt.get_dim_rot_mat_1()
)
fitting_dict[item] = Fitting(
**item_fitting_param,
descrpt=self.descrpt,
Expand Down
1 change: 1 addition & 0 deletions deepmd/tf/nvnmd/utils/argcheck.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
"""Alias for backward compatibility."""

from deepmd.utils.argcheck_nvnmd import (
nvnmd_args,
)
Expand Down
1 change: 1 addition & 0 deletions deepmd/tf/op/_gelu.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: LGPL-3.0-or-later
"""First-order derivatives and second-order derivatives for gelu function."""

import tensorflow
from tensorflow.python.framework import (
ops,
Expand Down
19 changes: 6 additions & 13 deletions deepmd/tf/train/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,7 @@ def build(self, data=None, stop_batch=0, origin_type_map=None, suffix=""):
if data[fitting_key].mixed_type:
assert isinstance(
self.fitting[fitting_key], EnerFitting
), "Data for fitting net {} in mixed_type format must use ener fitting!".format(
fitting_key
)
), f"Data for fitting net {fitting_key} in mixed_type format must use ener fitting!"
if self.numb_fparam_dict[fitting_key] > 0:
log.info(
"fitting net %s training with %d frame parameter(s)"
Expand Down Expand Up @@ -1086,10 +1084,7 @@ def _init_from_frz_model(self):
except FileNotFoundError as e:
# throw runtime error if there's no frozen model
raise RuntimeError(
"The input frozen model {} ({}) does not exist! Please check the path of the frozen model. ".format(
self.run_opt.init_frz_model,
os.path.abspath(self.run_opt.init_frz_model),
)
f"The input frozen model {self.run_opt.init_frz_model} ({os.path.abspath(self.run_opt.init_frz_model)}) does not exist! Please check the path of the frozen model. "
) from e
# get the model type from the frozen model(self.run_opt.init_frz_model)
try:
Expand Down Expand Up @@ -1142,10 +1137,8 @@ def _init_from_pretrained_model(
except FileNotFoundError as e:
# throw runtime error if there's no frozen model
raise RuntimeError(
"The input frozen pretrained model {} ({}) does not exist! "
"Please check the path of the frozen pretrained model. ".format(
self.run_opt.finetune, os.path.abspath(self.run_opt.finetune)
)
f"The input frozen pretrained model {self.run_opt.finetune} ({os.path.abspath(self.run_opt.finetune)}) does not exist! "
"Please check the path of the frozen pretrained model. "
) from e
# get the model type from the frozen model(self.run_opt.finetune)
try:
Expand All @@ -1164,8 +1157,8 @@ def _init_from_pretrained_model(
), "Compressed models are not supported for finetuning!"
self.model.init_variables(graph, graph_def, model_type=self.model_type)
log.info(
"Changing energy bias in pretrained model for types {}... "
"(this step may take long time)".format(str(origin_type_map))
f"Changing energy bias in pretrained model for types {origin_type_map!s}... "
"(this step may take long time)"
)
self._change_energy_bias(
data, self.run_opt.finetune, origin_type_map, bias_shift
Expand Down
1 change: 1 addition & 0 deletions deepmd/tf/utils/argcheck.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
"""Alias for backward compatibility."""

from deepmd.utils.argcheck import (
gen_args,
gen_doc,
Expand Down
1 change: 1 addition & 0 deletions deepmd/tf/utils/compat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
"""Alias for backward compatibility."""

from deepmd.utils.compat import (
convert_input_v0_v1,
convert_input_v1_v2,
Expand Down
1 change: 1 addition & 0 deletions deepmd/tf/utils/data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
"""Alias for backward compatibility."""

from deepmd.utils.data import (
DeepmdData,
)
Expand Down
1 change: 1 addition & 0 deletions deepmd/tf/utils/data_system.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
"""Alias for backward compatibility."""

from deepmd.utils.data_system import (
DeepmdDataSystem,
prob_sys_size_ext,
Expand Down
4 changes: 1 addition & 3 deletions deepmd/tf/utils/finetune.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ def replace_model_params_with_pretrained_model(
)
if cur_type_map != pretrained_type_map:
log.info(
"Change the type_map from {} to {}.".format(
str(cur_type_map), str(pretrained_type_map)
)
f"Change the type_map from {cur_type_map!s} to {pretrained_type_map!s}."
)
jdata["model"]["type_map"] = pretrained_type_map

Expand Down
12 changes: 6 additions & 6 deletions deepmd/tf/utils/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,13 @@ def get_extra_embedding_net_variables_from_graph_def(
extra_embedding_net_variables = {}
for i in range(1, layer_size + 1):
matrix_pattern = f"filter_type_all{suffix}/matrix_{i}{extra_suffix}"
extra_embedding_net_variables[
matrix_pattern
] = get_variables_from_graph_def_as_numpy_array(graph_def, matrix_pattern)
extra_embedding_net_variables[matrix_pattern] = (
get_variables_from_graph_def_as_numpy_array(graph_def, matrix_pattern)
)
bias_pattern = f"filter_type_all{suffix}/bias_{i}{extra_suffix}"
extra_embedding_net_variables[
bias_pattern
] = get_variables_from_graph_def_as_numpy_array(graph_def, bias_pattern)
extra_embedding_net_variables[bias_pattern] = (
get_variables_from_graph_def_as_numpy_array(graph_def, bias_pattern)
)
return extra_embedding_net_variables


Expand Down
Loading