Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (deepmodeling#3454)
Browse files Browse the repository at this point in the history
<!--pre-commit.ci start-->
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.2.2 →
v0.3.2](astral-sh/ruff-pre-commit@v0.2.2...v0.3.2)
- [github.com/pre-commit/mirrors-clang-format: v17.0.6 →
v18.1.1](pre-commit/mirrors-clang-format@v17.0.6...v18.1.1)
<!--pre-commit.ci end-->

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
(cherry picked from commit da68686)
Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
  • Loading branch information
njzjz and pre-commit-ci[bot] committed Apr 6, 2024
1 parent da8f93c commit f8a73c1
Show file tree
Hide file tree
Showing 53 changed files with 134 additions and 226 deletions.
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
6 changes: 2 additions & 4 deletions deepmd/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/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
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
18 changes: 6 additions & 12 deletions deepmd/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,20 +423,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
4 changes: 1 addition & 3 deletions deepmd/fit/ener.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,9 +895,7 @@ def change_energy_bias(
else:
raise RuntimeError("Unknown bias_shift mode: " + bias_shift)
log.info(
"Change energy bias of {} from {} to {}.".format(
str(origin_type_map), str(old_bias), str(self.bias_atom_e[idx_type_map])
)
f"Change energy bias of {origin_type_map!s} from {old_bias!s} to {self.bias_atom_e[idx_type_map]!s}."
)

def enable_mixed_precision(self, mixed_prec: Optional[dict] = None) -> None:
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 @@ -33,8 +33,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]: ...


@overload
Expand All @@ -44,8 +43,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]: ...


def calc_model_devi_f(
Expand Down
1 change: 1 addition & 0 deletions deepmd/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/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_utils.loggers.loggers for backward compatibility."""

from deepmd_utils.loggers.loggers import (
set_log_handles,
)
Expand Down
1 change: 1 addition & 0 deletions deepmd/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.utils.model_stat import (
_make_all_stat_ref,
make_stat_input,
Expand Down
1 change: 1 addition & 0 deletions deepmd/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.utils.argcheck_nvnmd import (
nvnmd_args,
)
Expand Down
1 change: 1 addition & 0 deletions deepmd/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/train/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,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 @@ -1057,10 +1055,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 @@ -1113,10 +1108,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 @@ -1135,8 +1128,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/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.utils.argcheck import (
gen_args,
gen_doc,
Expand Down
1 change: 1 addition & 0 deletions deepmd/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.utils.compat import (
convert_input_v0_v1,
convert_input_v1_v2,
Expand Down
1 change: 1 addition & 0 deletions deepmd/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.utils.data import (
DeepmdData,
)
Expand Down
1 change: 1 addition & 0 deletions deepmd/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.utils.data_system import (
DeepmdDataSystem,
prob_sys_size_ext,
Expand Down
4 changes: 1 addition & 3 deletions deepmd/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/utils/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,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
4 changes: 1 addition & 3 deletions deepmd/utils/multi_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def replace_model_params_with_frz_multi_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
1 change: 1 addition & 0 deletions deepmd/utils/pair_tab.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.utils.pair_tab import (
PairTab,
)
Expand Down
1 change: 1 addition & 0 deletions deepmd/utils/path.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.utils.path import (
DPH5Path,
DPOSPath,
Expand Down
1 change: 1 addition & 0 deletions deepmd/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
"""Alias for backward compatibility."""

from deepmd_utils.utils.plugin import (
Plugin,
PluginVariant,
Expand Down
1 change: 1 addition & 0 deletions deepmd/utils/random.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.utils.random import (
choice,
random,
Expand Down
1 change: 1 addition & 0 deletions deepmd/utils/weight_avg.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.utils.weight_avg import (
weighted_average,
)
Expand Down
1 change: 1 addition & 0 deletions deepmd_utils/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 textwrap
Expand Down
1 change: 1 addition & 0 deletions deepmd_utils/model_format/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
32 changes: 9 additions & 23 deletions deepmd_utils/utils/argcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -1870,10 +1870,10 @@ def normalize_multi_task(data):
data["model"]["fitting_net_dict"].keys(), data["learning_rate_dict"]
)
elif single_learning_rate:
data[
"learning_rate_dict"
] = normalize_learning_rate_dict_with_single_learning_rate(
data["model"]["fitting_net_dict"].keys(), data["learning_rate"]
data["learning_rate_dict"] = (
normalize_learning_rate_dict_with_single_learning_rate(
data["model"]["fitting_net_dict"].keys(), data["learning_rate"]
)
)
fitting_weight = (
data["training"]["fitting_weight"] if multi_fitting_weight else None
Expand Down Expand Up @@ -1916,11 +1916,7 @@ def normalize_data_dict(data_dict):
def normalize_loss_dict(fitting_keys, loss_dict):
# check the loss dict
failed_loss_keys = [item for item in loss_dict if item not in fitting_keys]
assert (
not failed_loss_keys
), "Loss dict key(s) {} not have corresponding fitting keys in {}! ".format(
str(failed_loss_keys), str(list(fitting_keys))
)
assert not failed_loss_keys, f"Loss dict key(s) {failed_loss_keys!s} not have corresponding fitting keys in {list(fitting_keys)!s}! "
new_dict = {}
base = Argument("base", dict, [], [loss_variant_type_args()], doc="")
for item in loss_dict:
Expand All @@ -1935,9 +1931,7 @@ def normalize_learning_rate_dict(fitting_keys, learning_rate_dict):
failed_learning_rate_keys = [
item for item in learning_rate_dict if item not in fitting_keys
]
assert not failed_learning_rate_keys, "Learning rate dict key(s) {} not have corresponding fitting keys in {}! ".format(
str(failed_learning_rate_keys), str(list(fitting_keys))
)
assert not failed_learning_rate_keys, f"Learning rate dict key(s) {failed_learning_rate_keys!s} not have corresponding fitting keys in {list(fitting_keys)!s}! "
new_dict = {}
base = Argument("base", dict, [], [learning_rate_variant_type_args()], doc="")
for item in learning_rate_dict:
Expand All @@ -1960,11 +1954,7 @@ def normalize_learning_rate_dict_with_single_learning_rate(fitting_keys, learnin
def normalize_fitting_weight(fitting_keys, data_keys, fitting_weight=None):
# check the mapping
failed_data_keys = [item for item in data_keys if item not in fitting_keys]
assert (
not failed_data_keys
), "Data dict key(s) {} not have corresponding fitting keys in {}! ".format(
str(failed_data_keys), str(list(fitting_keys))
)
assert not failed_data_keys, f"Data dict key(s) {failed_data_keys!s} not have corresponding fitting keys in {list(fitting_keys)!s}! "
empty_fitting_keys = []
valid_fitting_keys = []
for item in fitting_keys:
Expand All @@ -1974,9 +1964,7 @@ def normalize_fitting_weight(fitting_keys, data_keys, fitting_weight=None):
valid_fitting_keys.append(item)
if empty_fitting_keys:
log.warning(
"Fitting net(s) {} have no data and will not be used in training.".format(
str(empty_fitting_keys)
)
f"Fitting net(s) {empty_fitting_keys!s} have no data and will not be used in training."
)
num_pair = len(valid_fitting_keys)
assert num_pair > 0, "No valid training data systems for fitting nets!"
Expand All @@ -1991,9 +1979,7 @@ def normalize_fitting_weight(fitting_keys, data_keys, fitting_weight=None):
failed_weight_keys = [
item for item in fitting_weight if item not in fitting_keys
]
assert not failed_weight_keys, "Fitting weight key(s) {} not have corresponding fitting keys in {}! ".format(
str(failed_weight_keys), str(list(fitting_keys))
)
assert not failed_weight_keys, f"Fitting weight key(s) {failed_weight_keys!s} not have corresponding fitting keys in {list(fitting_keys)!s}! "
sum_prob = 0.0
for item in fitting_keys:
if item in valid_fitting_keys:
Expand Down
Loading

0 comments on commit f8a73c1

Please sign in to comment.