Skip to content

Commit f8a73c1

Browse files
[pre-commit.ci] pre-commit autoupdate (deepmodeling#3454)
<!--pre-commit.ci start--> updates: - [github.com/astral-sh/ruff-pre-commit: v0.2.2 → v0.3.2](astral-sh/[email protected]) - [github.com/pre-commit/mirrors-clang-format: v17.0.6 → v18.1.1](pre-commit/[email protected]) <!--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 <[email protected]>
1 parent da8f93c commit f8a73c1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+134
-226
lines changed

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ repos:
3030
exclude: ^source/3rdparty
3131
- repo: https://github.com/astral-sh/ruff-pre-commit
3232
# Ruff version.
33-
rev: v0.2.2
33+
rev: v0.3.2
3434
hooks:
3535
- id: ruff
3636
args: ["--fix"]
@@ -53,7 +53,7 @@ repos:
5353
- id: blacken-docs
5454
# C++
5555
- repo: https://github.com/pre-commit/mirrors-clang-format
56-
rev: v17.0.6
56+
rev: v18.1.1
5757
hooks:
5858
- id: clang-format
5959
exclude: ^source/3rdparty|source/lib/src/gpu/cudart/.+\.inc

backend/dp_backend.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
"""A PEP-517 backend to find TensorFlow."""
3+
34
from typing import (
45
List,
56
)

deepmd/entrypoints/freeze.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,8 @@ def _modify_model_suffix(output_graph_def, out_suffix, freeze_type):
152152
else:
153153
jdata["training"]["training_data"] = {}
154154
log.warning(
155-
"The fitting net {} has no training data in input script, resulting in "
156-
"untrained frozen model, and cannot be compressed directly! ".format(
157-
out_suffix
158-
)
155+
f"The fitting net {out_suffix} has no training data in input script, resulting in "
156+
"untrained frozen model, and cannot be compressed directly! "
159157
)
160158
# loss
161159
if "loss_dict" in jdata:

deepmd/entrypoints/ipi.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
"""Use dp_ipi inside the Python package."""
3+
34
import os
45
import subprocess
56
import sys

deepmd/entrypoints/test.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
"""Test trained DeePMD model."""
3+
34
import logging
45
from pathlib import (
56
Path,

deepmd/env.py

+6-12
Original file line numberDiff line numberDiff line change
@@ -423,20 +423,14 @@ def get_module(module_name: str) -> "ModuleType":
423423
if TF_VERSION != tf_py_version:
424424
raise RuntimeError(
425425
"The version of TensorFlow used to compile this "
426-
"deepmd-kit package is {}, but the version of TensorFlow "
427-
"runtime you are using is {}. These two versions are "
428-
"incompatible and thus an error is raised when loading {}. "
429-
"You need to install TensorFlow {}, or rebuild deepmd-kit "
430-
"against TensorFlow {}.\nIf you are using a wheel from "
426+
f"deepmd-kit package is {TF_VERSION}, but the version of TensorFlow "
427+
f"runtime you are using is {tf_py_version}. These two versions are "
428+
f"incompatible and thus an error is raised when loading {module_name}. "
429+
f"You need to install TensorFlow {TF_VERSION}, or rebuild deepmd-kit "
430+
f"against TensorFlow {tf_py_version}.\nIf you are using a wheel from "
431431
"pypi, you may consider to install deepmd-kit execuating "
432432
"`pip install deepmd-kit --no-binary deepmd-kit` "
433-
"instead.".format(
434-
TF_VERSION,
435-
tf_py_version,
436-
module_name,
437-
TF_VERSION,
438-
tf_py_version,
439-
)
433+
"instead."
440434
) from e
441435
error_message = (
442436
"This deepmd-kit package is inconsitent with TensorFlow "

deepmd/fit/ener.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -895,9 +895,7 @@ def change_energy_bias(
895895
else:
896896
raise RuntimeError("Unknown bias_shift mode: " + bias_shift)
897897
log.info(
898-
"Change energy bias of {} from {} to {}.".format(
899-
str(origin_type_map), str(old_bias), str(self.bias_atom_e[idx_type_map])
900-
)
898+
f"Change energy bias of {origin_type_map!s} from {old_bias!s} to {self.bias_atom_e[idx_type_map]!s}."
901899
)
902900

903901
def enable_mixed_precision(self, mixed_prec: Optional[dict] = None) -> None:

deepmd/infer/model_devi.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ def calc_model_devi_f(
3333
real_f: Optional[np.ndarray] = None,
3434
relative: Optional[float] = None,
3535
atomic: Literal[False] = False,
36-
) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
37-
...
36+
) -> Tuple[np.ndarray, np.ndarray, np.ndarray]: ...
3837

3938

4039
@overload
@@ -44,8 +43,7 @@ def calc_model_devi_f(
4443
relative: Optional[float] = None,
4544
*,
4645
atomic: Literal[True],
47-
) -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
48-
...
46+
) -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]: ...
4947

5048

5149
def calc_model_devi_f(

deepmd/lmp.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
"""Register entry points for lammps-wheel."""
3+
34
import os
45
import platform
56
from importlib import (

deepmd/loggers/loggers.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
"""Alias of deepmd_utils.loggers.loggers for backward compatibility."""
3+
34
from deepmd_utils.loggers.loggers import (
45
set_log_handles,
56
)

deepmd/model/model_stat.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
"""Alias for backward compatibility."""
3+
34
from deepmd_utils.utils.model_stat import (
45
_make_all_stat_ref,
56
make_stat_input,

deepmd/nvnmd/utils/argcheck.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
"""Alias for backward compatibility."""
3+
34
from deepmd_utils.utils.argcheck_nvnmd import (
45
nvnmd_args,
56
)

deepmd/op/_gelu.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22
# SPDX-License-Identifier: LGPL-3.0-or-later
33
"""First-order derivatives and second-order derivatives for gelu function."""
4+
45
import tensorflow
56
from tensorflow.python.framework import (
67
ops,

deepmd/train/trainer.py

+6-13
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,7 @@ def build(self, data=None, stop_batch=0, origin_type_map=None, suffix=""):
231231
if data[fitting_key].mixed_type:
232232
assert isinstance(
233233
self.fitting[fitting_key], EnerFitting
234-
), "Data for fitting net {} in mixed_type format must use ener fitting!".format(
235-
fitting_key
236-
)
234+
), f"Data for fitting net {fitting_key} in mixed_type format must use ener fitting!"
237235
if self.numb_fparam_dict[fitting_key] > 0:
238236
log.info(
239237
"fitting net %s training with %d frame parameter(s)"
@@ -1057,10 +1055,7 @@ def _init_from_frz_model(self):
10571055
except FileNotFoundError as e:
10581056
# throw runtime error if there's no frozen model
10591057
raise RuntimeError(
1060-
"The input frozen model {} ({}) does not exist! Please check the path of the frozen model. ".format(
1061-
self.run_opt.init_frz_model,
1062-
os.path.abspath(self.run_opt.init_frz_model),
1063-
)
1058+
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. "
10641059
) from e
10651060
# get the model type from the frozen model(self.run_opt.init_frz_model)
10661061
try:
@@ -1113,10 +1108,8 @@ def _init_from_pretrained_model(
11131108
except FileNotFoundError as e:
11141109
# throw runtime error if there's no frozen model
11151110
raise RuntimeError(
1116-
"The input frozen pretrained model {} ({}) does not exist! "
1117-
"Please check the path of the frozen pretrained model. ".format(
1118-
self.run_opt.finetune, os.path.abspath(self.run_opt.finetune)
1119-
)
1111+
f"The input frozen pretrained model {self.run_opt.finetune} ({os.path.abspath(self.run_opt.finetune)}) does not exist! "
1112+
"Please check the path of the frozen pretrained model. "
11201113
) from e
11211114
# get the model type from the frozen model(self.run_opt.finetune)
11221115
try:
@@ -1135,8 +1128,8 @@ def _init_from_pretrained_model(
11351128
), "Compressed models are not supported for finetuning!"
11361129
self.model.init_variables(graph, graph_def, model_type=self.model_type)
11371130
log.info(
1138-
"Changing energy bias in pretrained model for types {}... "
1139-
"(this step may take long time)".format(str(origin_type_map))
1131+
f"Changing energy bias in pretrained model for types {origin_type_map!s}... "
1132+
"(this step may take long time)"
11401133
)
11411134
self._change_energy_bias(
11421135
data, self.run_opt.finetune, origin_type_map, bias_shift

deepmd/utils/argcheck.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
"""Alias for backward compatibility."""
3+
34
from deepmd_utils.utils.argcheck import (
45
gen_args,
56
gen_doc,

deepmd/utils/compat.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
"""Alias for backward compatibility."""
3+
34
from deepmd_utils.utils.compat import (
45
convert_input_v0_v1,
56
convert_input_v1_v2,

deepmd/utils/data.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
"""Alias for backward compatibility."""
3+
34
from deepmd_utils.utils.data import (
45
DeepmdData,
56
)

deepmd/utils/data_system.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
"""Alias for backward compatibility."""
3+
34
from deepmd_utils.utils.data_system import (
45
DeepmdDataSystem,
56
prob_sys_size_ext,

deepmd/utils/finetune.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ def replace_model_params_with_pretrained_model(
6363
)
6464
if cur_type_map != pretrained_type_map:
6565
log.info(
66-
"Change the type_map from {} to {}.".format(
67-
str(cur_type_map), str(pretrained_type_map)
68-
)
66+
f"Change the type_map from {cur_type_map!s} to {pretrained_type_map!s}."
6967
)
7068
jdata["model"]["type_map"] = pretrained_type_map
7169

deepmd/utils/graph.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,13 @@ def get_extra_embedding_net_variables_from_graph_def(
312312
extra_embedding_net_variables = {}
313313
for i in range(1, layer_size + 1):
314314
matrix_pattern = f"filter_type_all{suffix}/matrix_{i}{extra_suffix}"
315-
extra_embedding_net_variables[
316-
matrix_pattern
317-
] = get_variables_from_graph_def_as_numpy_array(graph_def, matrix_pattern)
315+
extra_embedding_net_variables[matrix_pattern] = (
316+
get_variables_from_graph_def_as_numpy_array(graph_def, matrix_pattern)
317+
)
318318
bias_pattern = f"filter_type_all{suffix}/bias_{i}{extra_suffix}"
319-
extra_embedding_net_variables[
320-
bias_pattern
321-
] = get_variables_from_graph_def_as_numpy_array(graph_def, bias_pattern)
319+
extra_embedding_net_variables[bias_pattern] = (
320+
get_variables_from_graph_def_as_numpy_array(graph_def, bias_pattern)
321+
)
322322
return extra_embedding_net_variables
323323

324324

deepmd/utils/multi_init.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ def replace_model_params_with_frz_multi_model(
5959
)
6060
if cur_type_map != pretrained_type_map:
6161
log.info(
62-
"Change the type_map from {} to {}.".format(
63-
str(cur_type_map), str(pretrained_type_map)
64-
)
62+
f"Change the type_map from {cur_type_map!s} to {pretrained_type_map!s}."
6563
)
6664
jdata["model"]["type_map"] = pretrained_type_map
6765

deepmd/utils/pair_tab.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
"""Alias for backward compatibility."""
3+
34
from deepmd_utils.utils.pair_tab import (
45
PairTab,
56
)

deepmd/utils/path.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
"""Alias for backward compatibility."""
3+
34
from deepmd_utils.utils.path import (
45
DPH5Path,
56
DPOSPath,

deepmd/utils/plugin.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
"""Alias for backward compatibility."""
3+
34
from deepmd_utils.utils.plugin import (
45
Plugin,
56
PluginVariant,

deepmd/utils/random.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
"""Alias for backward compatibility."""
3+
34
from deepmd_utils.utils.random import (
45
choice,
56
random,

deepmd/utils/weight_avg.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
"""Alias for backward compatibility."""
3+
34
from deepmd_utils.utils.weight_avg import (
45
weighted_average,
56
)

deepmd_utils/main.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
If only printing the help message, this module does not call
55
the main DeePMD-kit module to avoid the slow import of TensorFlow.
66
"""
7+
78
import argparse
89
import logging
910
import textwrap

deepmd_utils/model_format/network.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
See issue #2982 for more information.
55
"""
6+
67
import copy
78
import itertools
89
import json

deepmd_utils/utils/argcheck.py

+9-23
Original file line numberDiff line numberDiff line change
@@ -1870,10 +1870,10 @@ def normalize_multi_task(data):
18701870
data["model"]["fitting_net_dict"].keys(), data["learning_rate_dict"]
18711871
)
18721872
elif single_learning_rate:
1873-
data[
1874-
"learning_rate_dict"
1875-
] = normalize_learning_rate_dict_with_single_learning_rate(
1876-
data["model"]["fitting_net_dict"].keys(), data["learning_rate"]
1873+
data["learning_rate_dict"] = (
1874+
normalize_learning_rate_dict_with_single_learning_rate(
1875+
data["model"]["fitting_net_dict"].keys(), data["learning_rate"]
1876+
)
18771877
)
18781878
fitting_weight = (
18791879
data["training"]["fitting_weight"] if multi_fitting_weight else None
@@ -1916,11 +1916,7 @@ def normalize_data_dict(data_dict):
19161916
def normalize_loss_dict(fitting_keys, loss_dict):
19171917
# check the loss dict
19181918
failed_loss_keys = [item for item in loss_dict if item not in fitting_keys]
1919-
assert (
1920-
not failed_loss_keys
1921-
), "Loss dict key(s) {} not have corresponding fitting keys in {}! ".format(
1922-
str(failed_loss_keys), str(list(fitting_keys))
1923-
)
1919+
assert not failed_loss_keys, f"Loss dict key(s) {failed_loss_keys!s} not have corresponding fitting keys in {list(fitting_keys)!s}! "
19241920
new_dict = {}
19251921
base = Argument("base", dict, [], [loss_variant_type_args()], doc="")
19261922
for item in loss_dict:
@@ -1935,9 +1931,7 @@ def normalize_learning_rate_dict(fitting_keys, learning_rate_dict):
19351931
failed_learning_rate_keys = [
19361932
item for item in learning_rate_dict if item not in fitting_keys
19371933
]
1938-
assert not failed_learning_rate_keys, "Learning rate dict key(s) {} not have corresponding fitting keys in {}! ".format(
1939-
str(failed_learning_rate_keys), str(list(fitting_keys))
1940-
)
1934+
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}! "
19411935
new_dict = {}
19421936
base = Argument("base", dict, [], [learning_rate_variant_type_args()], doc="")
19431937
for item in learning_rate_dict:
@@ -1960,11 +1954,7 @@ def normalize_learning_rate_dict_with_single_learning_rate(fitting_keys, learnin
19601954
def normalize_fitting_weight(fitting_keys, data_keys, fitting_weight=None):
19611955
# check the mapping
19621956
failed_data_keys = [item for item in data_keys if item not in fitting_keys]
1963-
assert (
1964-
not failed_data_keys
1965-
), "Data dict key(s) {} not have corresponding fitting keys in {}! ".format(
1966-
str(failed_data_keys), str(list(fitting_keys))
1967-
)
1957+
assert not failed_data_keys, f"Data dict key(s) {failed_data_keys!s} not have corresponding fitting keys in {list(fitting_keys)!s}! "
19681958
empty_fitting_keys = []
19691959
valid_fitting_keys = []
19701960
for item in fitting_keys:
@@ -1974,9 +1964,7 @@ def normalize_fitting_weight(fitting_keys, data_keys, fitting_weight=None):
19741964
valid_fitting_keys.append(item)
19751965
if empty_fitting_keys:
19761966
log.warning(
1977-
"Fitting net(s) {} have no data and will not be used in training.".format(
1978-
str(empty_fitting_keys)
1979-
)
1967+
f"Fitting net(s) {empty_fitting_keys!s} have no data and will not be used in training."
19801968
)
19811969
num_pair = len(valid_fitting_keys)
19821970
assert num_pair > 0, "No valid training data systems for fitting nets!"
@@ -1991,9 +1979,7 @@ def normalize_fitting_weight(fitting_keys, data_keys, fitting_weight=None):
19911979
failed_weight_keys = [
19921980
item for item in fitting_weight if item not in fitting_keys
19931981
]
1994-
assert not failed_weight_keys, "Fitting weight key(s) {} not have corresponding fitting keys in {}! ".format(
1995-
str(failed_weight_keys), str(list(fitting_keys))
1996-
)
1982+
assert not failed_weight_keys, f"Fitting weight key(s) {failed_weight_keys!s} not have corresponding fitting keys in {list(fitting_keys)!s}! "
19971983
sum_prob = 0.0
19981984
for item in fitting_keys:
19991985
if item in valid_fitting_keys:

0 commit comments

Comments
 (0)