From da68686dfe021c92a4125840d6076eab8a1d8a6a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 13 Mar 2024 04:26:13 +0000 Subject: [PATCH] [pre-commit.ci] pre-commit autoupdate (#3454) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.2.2 → v0.3.2](https://github.com/astral-sh/ruff-pre-commit/compare/v0.2.2...v0.3.2) - [github.com/pre-commit/mirrors-clang-format: v17.0.6 → v18.1.1](https://github.com/pre-commit/mirrors-clang-format/compare/v17.0.6...v18.1.1) --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 4 +- backend/dp_backend.py | 1 + deepmd/__init__.py | 1 + deepmd/backend/__init__.py | 1 + deepmd/dpmodel/atomic_model/__init__.py | 1 - deepmd/dpmodel/utils/network.py | 1 + deepmd/dpmodel/utils/nlist.py | 2 +- deepmd/driver.py | 1 + deepmd/entrypoints/test.py | 1 + deepmd/infer/model_devi.py | 6 +- deepmd/main.py | 1 + deepmd/pt/loss/tensor.py | 6 +- deepmd/pt/model/task/fitting.py | 4 +- deepmd/pt/utils/nlist.py | 2 +- deepmd/pt/utils/plugin.py | 1 + deepmd/pt/utils/utils.py | 12 ++-- deepmd/tf/entrypoints/freeze.py | 6 +- deepmd/tf/entrypoints/ipi.py | 1 + deepmd/tf/env.py | 18 ++--- deepmd/tf/fit/fitting.py | 6 +- deepmd/tf/lmp.py | 1 + deepmd/tf/loggers/loggers.py | 1 + deepmd/tf/model/model_stat.py | 1 + deepmd/tf/model/multi.py | 6 +- deepmd/tf/nvnmd/utils/argcheck.py | 1 + deepmd/tf/op/_gelu.py | 1 + deepmd/tf/train/trainer.py | 19 ++---- deepmd/tf/utils/argcheck.py | 1 + deepmd/tf/utils/compat.py | 1 + deepmd/tf/utils/data.py | 1 + deepmd/tf/utils/data_system.py | 1 + deepmd/tf/utils/finetune.py | 4 +- deepmd/tf/utils/graph.py | 12 ++-- deepmd/tf/utils/multi_init.py | 4 +- deepmd/tf/utils/pair_tab.py | 1 + deepmd/tf/utils/path.py | 1 + deepmd/tf/utils/plugin.py | 1 + deepmd/tf/utils/random.py | 1 + deepmd/tf/utils/weight_avg.py | 1 + deepmd/utils/argcheck.py | 32 +++------ deepmd/utils/data.py | 8 +-- deepmd/utils/finetune.py | 4 +- deepmd/utils/out_stat.py | 1 + source/api_cc/src/common.cc | 13 ++-- source/api_cc/tests/test_ewald.cc | 4 +- source/ipi/driver.cc | 9 +-- source/lib/tests/test_ewald.cc | 2 +- source/lmp/tests/test_deeptensor.py | 12 +--- source/lmp/tests/test_dplr.py | 6 +- source/lmp/tests/test_lammps.py | 50 +++----------- source/lmp/tests/test_lammps_3types.py | 28 ++------ source/lmp/tests/test_lammps_faparam.py | 7 +- source/lmp/tests/test_lammps_pt.py | 44 +++--------- source/md/src/GroFileManager.cc | 9 +-- source/md/src/Poly.cpp | 12 ++-- source/nodejs/prepublish.py | 1 + source/op/dotmul_flt_nvnmd.cc | 2 +- source/op/map_flt_nvnmd.cc | 8 +-- source/op/matmul_fitnet_nvnmd.cc | 2 +- source/op/matmul_flt2fix_nvnmd.cc | 6 +- source/op/matmul_flt_nvnmd.cc | 6 +- source/op/tanh4_flt_nvnmd.cc | 4 +- source/tests/common/test_examples.py | 1 + source/tests/pt/test_multitask.py | 72 ++++++++++---------- source/tests/tf/test_init_frz_model_multi.py | 36 +++++----- source/tests/tf/test_pairwise_dprc.py | 1 + source/tests/tf/test_virtual_type.py | 1 + 67 files changed, 199 insertions(+), 317 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 041d47f0da..892962b2fe 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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"] @@ -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 diff --git a/backend/dp_backend.py b/backend/dp_backend.py index d28afdb239..2ca0ff2f93 100644 --- a/backend/dp_backend.py +++ b/backend/dp_backend.py @@ -1,5 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later """A PEP-517 backend to find TensorFlow.""" + from typing import ( List, ) diff --git a/deepmd/__init__.py b/deepmd/__init__.py index 5664c3edc6..1ce4beb723 100644 --- a/deepmd/__init__.py +++ b/deepmd/__init__.py @@ -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: diff --git a/deepmd/backend/__init__.py b/deepmd/backend/__init__.py index 8969edd480..2b3f24c5ed 100644 --- a/deepmd/backend/__init__.py +++ b/deepmd/backend/__init__.py @@ -3,6 +3,7 @@ Avoid directly importing third-party libraries in this module for performance. """ + # copy from dpdata from importlib import ( import_module, diff --git a/deepmd/dpmodel/atomic_model/__init__.py b/deepmd/dpmodel/atomic_model/__init__.py index e51ca0a65e..37f6b8bf28 100644 --- a/deepmd/dpmodel/atomic_model/__init__.py +++ b/deepmd/dpmodel/atomic_model/__init__.py @@ -14,7 +14,6 @@ """ - from .base_atomic_model import ( BaseAtomicModel, ) diff --git a/deepmd/dpmodel/utils/network.py b/deepmd/dpmodel/utils/network.py index 1747e25527..a0dcc6b706 100644 --- a/deepmd/dpmodel/utils/network.py +++ b/deepmd/dpmodel/utils/network.py @@ -3,6 +3,7 @@ See issue #2982 for more information. """ + import copy import itertools import json diff --git a/deepmd/dpmodel/utils/nlist.py b/deepmd/dpmodel/utils/nlist.py index 1aa1820495..e5631bf2e3 100644 --- a/deepmd/dpmodel/utils/nlist.py +++ b/deepmd/dpmodel/utils/nlist.py @@ -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 diff --git a/deepmd/driver.py b/deepmd/driver.py index 1e5e36c652..0b48f2ac84 100644 --- a/deepmd/driver.py +++ b/deepmd/driver.py @@ -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. diff --git a/deepmd/entrypoints/test.py b/deepmd/entrypoints/test.py index ccf8b1da1e..cad6e12d2b 100644 --- a/deepmd/entrypoints/test.py +++ b/deepmd/entrypoints/test.py @@ -1,5 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later """Test trained DeePMD model.""" + import logging from pathlib import ( Path, diff --git a/deepmd/infer/model_devi.py b/deepmd/infer/model_devi.py index cb5d79797b..c214e39e92 100644 --- a/deepmd/infer/model_devi.py +++ b/deepmd/infer/model_devi.py @@ -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]: ... @overload @@ -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]: ... def calc_model_devi_f( diff --git a/deepmd/main.py b/deepmd/main.py index 09457419e8..b503107c73 100644 --- a/deepmd/main.py +++ b/deepmd/main.py @@ -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 diff --git a/deepmd/pt/loss/tensor.py b/deepmd/pt/loss/tensor.py index 5ac0a6e37b..ec7ef0b323 100644 --- a/deepmd/pt/loss/tensor.py +++ b/deepmd/pt/loss/tensor.py @@ -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() diff --git a/deepmd/pt/model/task/fitting.py b/deepmd/pt/model/task/fitting.py index 48ffe34084..4637178318 100644 --- a/deepmd/pt/model/task/fitting.py +++ b/deepmd/pt/model/task/fitting.py @@ -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"] diff --git a/deepmd/pt/utils/nlist.py b/deepmd/pt/utils/nlist.py index d37931b65a..7e92f44e8d 100644 --- a/deepmd/pt/utils/nlist.py +++ b/deepmd/pt/utils/nlist.py @@ -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 diff --git a/deepmd/pt/utils/plugin.py b/deepmd/pt/utils/plugin.py index c24f36f574..aa901c06e8 100644 --- a/deepmd/pt/utils/plugin.py +++ b/deepmd/pt/utils/plugin.py @@ -1,5 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later """Base of plugin systems.""" + from deepmd.utils.plugin import ( Plugin, PluginVariant, diff --git a/deepmd/pt/utils/utils.py b/deepmd/pt/utils/utils.py index 10dcadadac..3337036ca9 100644 --- a/deepmd/pt/utils/utils.py +++ b/deepmd/pt/utils/utils.py @@ -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: ... @overload -def to_numpy_array(xx: None) -> None: - ... +def to_numpy_array(xx: None) -> None: ... def to_numpy_array( @@ -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: ... @overload -def to_torch_tensor(xx: None) -> None: - ... +def to_torch_tensor(xx: None) -> None: ... def to_torch_tensor( diff --git a/deepmd/tf/entrypoints/freeze.py b/deepmd/tf/entrypoints/freeze.py index c7ab1023fa..3d2a609797 100755 --- a/deepmd/tf/entrypoints/freeze.py +++ b/deepmd/tf/entrypoints/freeze.py @@ -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: diff --git a/deepmd/tf/entrypoints/ipi.py b/deepmd/tf/entrypoints/ipi.py index 49f72434f3..1631a35c2e 100644 --- a/deepmd/tf/entrypoints/ipi.py +++ b/deepmd/tf/entrypoints/ipi.py @@ -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 diff --git a/deepmd/tf/env.py b/deepmd/tf/env.py index 3127e01e97..0b16c8758a 100644 --- a/deepmd/tf/env.py +++ b/deepmd/tf/env.py @@ -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 " diff --git a/deepmd/tf/fit/fitting.py b/deepmd/tf/fit/fitting.py index 6a7398daac..0f73230bc8 100644 --- a/deepmd/tf/fit/fitting.py +++ b/deepmd/tf/fit/fitting.py @@ -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 diff --git a/deepmd/tf/lmp.py b/deepmd/tf/lmp.py index f8497bef59..b2e47308ed 100644 --- a/deepmd/tf/lmp.py +++ b/deepmd/tf/lmp.py @@ -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 ( diff --git a/deepmd/tf/loggers/loggers.py b/deepmd/tf/loggers/loggers.py index eae99f5367..be948c9858 100644 --- a/deepmd/tf/loggers/loggers.py +++ b/deepmd/tf/loggers/loggers.py @@ -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, ) diff --git a/deepmd/tf/model/model_stat.py b/deepmd/tf/model/model_stat.py index 9149c0b666..db70262d50 100644 --- a/deepmd/tf/model/model_stat.py +++ b/deepmd/tf/model/model_stat.py @@ -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, diff --git a/deepmd/tf/model/multi.py b/deepmd/tf/model/multi.py index 6280fcd2f6..8fd4b539f1 100644 --- a/deepmd/tf/model/multi.py +++ b/deepmd/tf/model/multi.py @@ -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, diff --git a/deepmd/tf/nvnmd/utils/argcheck.py b/deepmd/tf/nvnmd/utils/argcheck.py index c22d9e0cd4..1f10a1c03e 100644 --- a/deepmd/tf/nvnmd/utils/argcheck.py +++ b/deepmd/tf/nvnmd/utils/argcheck.py @@ -1,5 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later """Alias for backward compatibility.""" + from deepmd.utils.argcheck_nvnmd import ( nvnmd_args, ) diff --git a/deepmd/tf/op/_gelu.py b/deepmd/tf/op/_gelu.py index fcfd2d49fa..04ae124f70 100644 --- a/deepmd/tf/op/_gelu.py +++ b/deepmd/tf/op/_gelu.py @@ -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, diff --git a/deepmd/tf/train/trainer.py b/deepmd/tf/train/trainer.py index 27478abaa1..c8668174fd 100644 --- a/deepmd/tf/train/trainer.py +++ b/deepmd/tf/train/trainer.py @@ -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)" @@ -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: @@ -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: @@ -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 diff --git a/deepmd/tf/utils/argcheck.py b/deepmd/tf/utils/argcheck.py index c3c0ed4f22..caec33c319 100644 --- a/deepmd/tf/utils/argcheck.py +++ b/deepmd/tf/utils/argcheck.py @@ -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, diff --git a/deepmd/tf/utils/compat.py b/deepmd/tf/utils/compat.py index 6c95476ac8..e80a366b83 100644 --- a/deepmd/tf/utils/compat.py +++ b/deepmd/tf/utils/compat.py @@ -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, diff --git a/deepmd/tf/utils/data.py b/deepmd/tf/utils/data.py index 3c2eb4298d..54130c18f4 100644 --- a/deepmd/tf/utils/data.py +++ b/deepmd/tf/utils/data.py @@ -1,5 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later """Alias for backward compatibility.""" + from deepmd.utils.data import ( DeepmdData, ) diff --git a/deepmd/tf/utils/data_system.py b/deepmd/tf/utils/data_system.py index 88c38d3dd4..da0cce28e8 100644 --- a/deepmd/tf/utils/data_system.py +++ b/deepmd/tf/utils/data_system.py @@ -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, diff --git a/deepmd/tf/utils/finetune.py b/deepmd/tf/utils/finetune.py index 01b5eaaafe..38824b6954 100644 --- a/deepmd/tf/utils/finetune.py +++ b/deepmd/tf/utils/finetune.py @@ -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 diff --git a/deepmd/tf/utils/graph.py b/deepmd/tf/utils/graph.py index 8c4b0fcc84..f09250aa9f 100644 --- a/deepmd/tf/utils/graph.py +++ b/deepmd/tf/utils/graph.py @@ -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 diff --git a/deepmd/tf/utils/multi_init.py b/deepmd/tf/utils/multi_init.py index 056a6694e8..2e3c43c069 100644 --- a/deepmd/tf/utils/multi_init.py +++ b/deepmd/tf/utils/multi_init.py @@ -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 diff --git a/deepmd/tf/utils/pair_tab.py b/deepmd/tf/utils/pair_tab.py index a5f5e64aae..a9747c4367 100644 --- a/deepmd/tf/utils/pair_tab.py +++ b/deepmd/tf/utils/pair_tab.py @@ -1,5 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later """Alias for backward compatibility.""" + from deepmd.utils.pair_tab import ( PairTab, ) diff --git a/deepmd/tf/utils/path.py b/deepmd/tf/utils/path.py index 63c82b9da0..67990543ae 100644 --- a/deepmd/tf/utils/path.py +++ b/deepmd/tf/utils/path.py @@ -1,5 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later """Alias for backward compatibility.""" + from deepmd.utils.path import ( DPH5Path, DPOSPath, diff --git a/deepmd/tf/utils/plugin.py b/deepmd/tf/utils/plugin.py index 436a80a819..f2f0336691 100644 --- a/deepmd/tf/utils/plugin.py +++ b/deepmd/tf/utils/plugin.py @@ -1,5 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later """Alias for backward compatibility.""" + from deepmd.utils.plugin import ( Plugin, PluginVariant, diff --git a/deepmd/tf/utils/random.py b/deepmd/tf/utils/random.py index 6d875df224..55b8eba91e 100644 --- a/deepmd/tf/utils/random.py +++ b/deepmd/tf/utils/random.py @@ -1,5 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later """Alias for backward compatibility.""" + from deepmd.utils.random import ( choice, random, diff --git a/deepmd/tf/utils/weight_avg.py b/deepmd/tf/utils/weight_avg.py index fe162aa1ea..fb3ae27934 100644 --- a/deepmd/tf/utils/weight_avg.py +++ b/deepmd/tf/utils/weight_avg.py @@ -1,5 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later """Alias for backward compatibility.""" + from deepmd.utils.weight_avg import ( weighted_average, ) diff --git a/deepmd/utils/argcheck.py b/deepmd/utils/argcheck.py index 57f1145d55..1c2b7935b5 100644 --- a/deepmd/utils/argcheck.py +++ b/deepmd/utils/argcheck.py @@ -2385,10 +2385,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 @@ -2431,11 +2431,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: @@ -2450,9 +2446,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: @@ -2475,11 +2469,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: @@ -2489,9 +2479,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!" @@ -2506,9 +2494,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: diff --git a/deepmd/utils/data.py b/deepmd/utils/data.py index 1e1d7c2251..6ad76be3c7 100644 --- a/deepmd/utils/data.py +++ b/deepmd/utils/data.py @@ -549,9 +549,7 @@ def _load_set(self, set_name: DPPath): atom_type_mix_ = self.type_idx_map[atom_type_mix].astype(np.int32) except IndexError as e: raise IndexError( - "some types in 'real_atom_types.npy' of set {} are not contained in {} types!".format( - set_name, self.get_ntypes() - ) + f"some types in 'real_atom_types.npy' of set {set_name} are not contained in {self.get_ntypes()} types!" ) from e atom_type_mix = atom_type_mix_ real_type = atom_type_mix.reshape([nframes, self.natoms]) @@ -568,9 +566,7 @@ def _load_set(self, set_name: DPPath): ).T assert ( atom_type_nums.sum(axis=-1) + ghost_nums.sum(axis=-1) == natoms - ).all(), "some types in 'real_atom_types.npy' of set {} are not contained in {} types!".format( - set_name, self.get_ntypes() - ) + ).all(), f"some types in 'real_atom_types.npy' of set {set_name} are not contained in {self.get_ntypes()} types!" data["real_natoms_vec"] = np.concatenate( ( np.tile(np.array([natoms, natoms], dtype=np.int32), (nframes, 1)), diff --git a/deepmd/utils/finetune.py b/deepmd/utils/finetune.py index b6d04b9bc5..a454ad72ea 100644 --- a/deepmd/utils/finetune.py +++ b/deepmd/utils/finetune.py @@ -135,8 +135,6 @@ def change_energy_bias_lower( 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(bias_atom_e[idx_type_map]) - ) + f"Change energy bias of {origin_type_map!s} from {old_bias!s} to {bias_atom_e[idx_type_map]!s}." ) return bias_atom_e diff --git a/deepmd/utils/out_stat.py b/deepmd/utils/out_stat.py index 8f68e32417..3659e57305 100644 --- a/deepmd/utils/out_stat.py +++ b/deepmd/utils/out_stat.py @@ -1,5 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later """Output statistics.""" + from typing import ( Optional, Tuple, diff --git a/source/api_cc/src/common.cc b/source/api_cc/src/common.cc index f104433468..aa1e27ace1 100644 --- a/source/api_cc/src/common.cc +++ b/source/api_cc/src/common.cc @@ -329,8 +329,8 @@ void deepmd::check_status(const tensorflow::Status& status) { void throw_env_not_set_warning(std::string env_name) { std::cerr << "DeePMD-kit WARNING: Environmental variable " << env_name - << " is not set. " - << "Tune " << env_name << " for the best performance. " + << " is not set. " << "Tune " << env_name + << " for the best performance. " << "See https://deepmd.rtfd.io/parallelism/ for more information." << std::endl; } @@ -1341,14 +1341,11 @@ void deepmd::print_summary(const std::string& pre) { std::cout << pre << "source commit at: " + global_git_date << "\n"; std::cout << pre << "support model ver.: " + global_model_version << "\n"; #if defined(GOOGLE_CUDA) - std::cout << pre << "build variant: cuda" - << "\n"; + std::cout << pre << "build variant: cuda" << "\n"; #elif defined(TENSORFLOW_USE_ROCM) - std::cout << pre << "build variant: rocm" - << "\n"; + std::cout << pre << "build variant: rocm" << "\n"; #else - std::cout << pre << "build variant: cpu" - << "\n"; + std::cout << pre << "build variant: cpu" << "\n"; #endif #ifdef BUILD_TENSORFLOW std::cout << pre << "build with tf inc: " + global_tf_include_dir << "\n"; diff --git a/source/api_cc/tests/test_ewald.cc b/source/api_cc/tests/test_ewald.cc index 7eb433816d..d5aa6993a9 100644 --- a/source/api_cc/tests/test_ewald.cc +++ b/source/api_cc/tests/test_ewald.cc @@ -18,8 +18,8 @@ class TestInferEwald : public ::testing::Test { 3.51, 2.51, 2.60, 4.27, 3.22, 1.56}; std::vector charge = {-2, 1, 1, -2, 1, 1}; std::vector box = {13., 0., 0., 0., 13., 0., 0., 0., 13.}; - void SetUp() override{}; - void TearDown() override{}; + void SetUp() override {}; + void TearDown() override {}; }; TYPED_TEST_SUITE(TestInferEwald, ValueTypes); diff --git a/source/ipi/driver.cc b/source/ipi/driver.cc index 9a91a27ad3..977d76011a 100644 --- a/source/ipi/driver.cc +++ b/source/ipi/driver.cc @@ -126,20 +126,17 @@ int main(int argc, char *argv[]) { if (!isinit) { writebuffer_(&socket, msg_needinit, MSGLEN); if (b_verb) { - std::cout << "# send back " - << "NEEDINIT" << std::endl; + std::cout << "# send back " << "NEEDINIT" << std::endl; } } else if (hasdata) { writebuffer_(&socket, msg_havedata, MSGLEN); if (b_verb) { - std::cout << "# send back " - << "HAVEDATA" << std::endl; + std::cout << "# send back " << "HAVEDATA" << std::endl; } } else { writebuffer_(&socket, msg_ready, MSGLEN); if (b_verb) { - std::cout << "# send back " - << "READY" << std::endl; + std::cout << "# send back " << "READY" << std::endl; } } } else if (header_str == "INIT") { diff --git a/source/lib/tests/test_ewald.cc b/source/lib/tests/test_ewald.cc index 45c8ea7bf1..ca6f3a845e 100644 --- a/source/lib/tests/test_ewald.cc +++ b/source/lib/tests/test_ewald.cc @@ -30,7 +30,7 @@ class TestEwald : public ::testing::Test { 1.9076542856278367e+00, 1.3101841366497322e+00, 1.9794445391572657e-01, -9.8010077026955389e-01, 1.9794445391572657e-01, 1.9232614011636004e+00}; - void SetUp() override{}; + void SetUp() override {}; }; TEST_F(TestEwald, cpu) { diff --git a/source/lmp/tests/test_deeptensor.py b/source/lmp/tests/test_deeptensor.py index 3e684b386e..6df0a8617a 100644 --- a/source/lmp/tests/test_deeptensor.py +++ b/source/lmp/tests/test_deeptensor.py @@ -57,19 +57,11 @@ sp.check_output( - "{} -m deepmd convert-from pbtxt -i {} -o {}".format( - sys.executable, - pbtxt_file.resolve(), - pb_file.resolve(), - ).split() + f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file.resolve()} -o {pb_file.resolve()}".split() ) sp.check_output( - "{} -m deepmd convert-from pbtxt -i {} -o {}".format( - sys.executable, - pbtxt_file2.resolve(), - pb_file2.resolve(), - ).split() + f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file2.resolve()} -o {pb_file2.resolve()}".split() ) diff --git a/source/lmp/tests/test_dplr.py b/source/lmp/tests/test_dplr.py index 9c8f1c0d4f..2dd3531894 100644 --- a/source/lmp/tests/test_dplr.py +++ b/source/lmp/tests/test_dplr.py @@ -264,11 +264,7 @@ sp.check_output( - "{} -m deepmd convert-from pbtxt -i {} -o {}".format( - sys.executable, - pbtxt_file.resolve(), - pb_file.resolve(), - ).split() + f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file.resolve()} -o {pb_file.resolve()}".split() ) diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index 028b403abf..c495f16ffd 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -219,18 +219,10 @@ sp.check_output( - "{} -m deepmd convert-from pbtxt -i {} -o {}".format( - sys.executable, - pbtxt_file.resolve(), - pb_file.resolve(), - ).split() + f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file.resolve()} -o {pb_file.resolve()}".split() ) sp.check_output( - "{} -m deepmd convert-from pbtxt -i {} -o {}".format( - sys.executable, - pbtxt_file2.resolve(), - pb_file2.resolve(), - ).split() + f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file2.resolve()} -o {pb_file2.resolve()}".split() ) @@ -348,9 +340,7 @@ def test_pair_deepmd_virial(lammps): def test_pair_deepmd_model_devi(lammps): lammps.pair_style( - "deepmd {} {} out_file {} out_freq 1 atomic".format( - pb_file.resolve(), pb_file2.resolve(), md_file.resolve() - ) + f"deepmd {pb_file.resolve()} {pb_file2.resolve()} out_file {md_file.resolve()} out_freq 1 atomic" ) lammps.pair_coeff("* *") lammps.run(0) @@ -376,9 +366,7 @@ def test_pair_deepmd_model_devi(lammps): def test_pair_deepmd_model_devi_virial(lammps): lammps.pair_style( - "deepmd {} {} out_file {} out_freq 1 atomic".format( - pb_file.resolve(), pb_file2.resolve(), md_file.resolve() - ) + f"deepmd {pb_file.resolve()} {pb_file2.resolve()} out_file {md_file.resolve()} out_freq 1 atomic" ) lammps.pair_coeff("* *") lammps.compute("virial all centroid/stress/atom NULL pair") @@ -417,9 +405,7 @@ def test_pair_deepmd_model_devi_virial(lammps): def test_pair_deepmd_model_devi_atomic_relative(lammps): relative = 1.0 lammps.pair_style( - "deepmd {} {} out_file {} out_freq 1 atomic relative {}".format( - pb_file.resolve(), pb_file2.resolve(), md_file.resolve(), relative - ) + f"deepmd {pb_file.resolve()} {pb_file2.resolve()} out_file {md_file.resolve()} out_freq 1 atomic relative {relative}" ) lammps.pair_coeff("* *") lammps.run(0) @@ -448,9 +434,7 @@ def test_pair_deepmd_model_devi_atomic_relative(lammps): def test_pair_deepmd_model_devi_atomic_relative_v(lammps): relative = 1.0 lammps.pair_style( - "deepmd {} {} out_file {} out_freq 1 atomic relative_v {}".format( - pb_file.resolve(), pb_file2.resolve(), md_file.resolve(), relative - ) + f"deepmd {pb_file.resolve()} {pb_file2.resolve()} out_file {md_file.resolve()} out_freq 1 atomic relative_v {relative}" ) lammps.pair_coeff("* *") lammps.run(0) @@ -535,9 +519,7 @@ def test_pair_deepmd_virial_real(lammps_real): def test_pair_deepmd_model_devi_real(lammps_real): lammps_real.pair_style( - "deepmd {} {} out_file {} out_freq 1 atomic".format( - pb_file.resolve(), pb_file2.resolve(), md_file.resolve() - ) + f"deepmd {pb_file.resolve()} {pb_file2.resolve()} out_file {md_file.resolve()} out_freq 1 atomic" ) lammps_real.pair_coeff("* *") lammps_real.run(0) @@ -567,9 +549,7 @@ def test_pair_deepmd_model_devi_real(lammps_real): def test_pair_deepmd_model_devi_virial_real(lammps_real): lammps_real.pair_style( - "deepmd {} {} out_file {} out_freq 1 atomic".format( - pb_file.resolve(), pb_file2.resolve(), md_file.resolve() - ) + f"deepmd {pb_file.resolve()} {pb_file2.resolve()} out_file {md_file.resolve()} out_freq 1 atomic" ) lammps_real.pair_coeff("* *") lammps_real.compute("virial all centroid/stress/atom NULL pair") @@ -614,12 +594,7 @@ def test_pair_deepmd_model_devi_virial_real(lammps_real): def test_pair_deepmd_model_devi_atomic_relative_real(lammps_real): relative = 1.0 lammps_real.pair_style( - "deepmd {} {} out_file {} out_freq 1 atomic relative {}".format( - pb_file.resolve(), - pb_file2.resolve(), - md_file.resolve(), - relative * constants.force_metal2real, - ) + f"deepmd {pb_file.resolve()} {pb_file2.resolve()} out_file {md_file.resolve()} out_freq 1 atomic relative {relative * constants.force_metal2real}" ) lammps_real.pair_coeff("* *") lammps_real.run(0) @@ -652,12 +627,7 @@ def test_pair_deepmd_model_devi_atomic_relative_real(lammps_real): def test_pair_deepmd_model_devi_atomic_relative_v_real(lammps_real): relative = 1.0 lammps_real.pair_style( - "deepmd {} {} out_file {} out_freq 1 atomic relative_v {}".format( - pb_file.resolve(), - pb_file2.resolve(), - md_file.resolve(), - relative * constants.ener_metal2real, - ) + f"deepmd {pb_file.resolve()} {pb_file2.resolve()} out_file {md_file.resolve()} out_freq 1 atomic relative_v {relative * constants.ener_metal2real}" ) lammps_real.pair_coeff("* *") lammps_real.run(0) diff --git a/source/lmp/tests/test_lammps_3types.py b/source/lmp/tests/test_lammps_3types.py index 46e1a00c8f..e4e64d9ecf 100644 --- a/source/lmp/tests/test_lammps_3types.py +++ b/source/lmp/tests/test_lammps_3types.py @@ -245,18 +245,10 @@ nktv2p = 1.6021765e6 sp.check_output( - "{} -m deepmd convert-from pbtxt -i {} -o {}".format( - sys.executable, - pbtxt_file.resolve(), - pb_file.resolve(), - ).split() + f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file.resolve()} -o {pb_file.resolve()}".split() ) sp.check_output( - "{} -m deepmd convert-from pbtxt -i {} -o {}".format( - sys.executable, - pbtxt_file2.resolve(), - pb_file2.resolve(), - ).split() + f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file2.resolve()} -o {pb_file2.resolve()}".split() ) @@ -337,9 +329,7 @@ def test_pair_deepmd_virial(lammps): def test_pair_deepmd_model_devi(lammps): lammps.pair_style( - "deepmd {} {} out_file {} out_freq 1 atomic".format( - pb_file.resolve(), pb_file2.resolve(), md_file.resolve() - ) + f"deepmd {pb_file.resolve()} {pb_file2.resolve()} out_file {md_file.resolve()} out_freq 1 atomic" ) lammps.pair_coeff("* *") lammps.run(0) @@ -365,9 +355,7 @@ def test_pair_deepmd_model_devi(lammps): def test_pair_deepmd_model_devi_virial(lammps): lammps.pair_style( - "deepmd {} {} out_file {} out_freq 1 atomic".format( - pb_file.resolve(), pb_file2.resolve(), md_file.resolve() - ) + f"deepmd {pb_file.resolve()} {pb_file2.resolve()} out_file {md_file.resolve()} out_freq 1 atomic" ) lammps.pair_coeff("* *") lammps.compute("virial all centroid/stress/atom NULL pair") @@ -406,9 +394,7 @@ def test_pair_deepmd_model_devi_virial(lammps): def test_pair_deepmd_model_devi_atomic_relative(lammps): relative = 1.0 lammps.pair_style( - "deepmd {} {} out_file {} out_freq 1 atomic relative {}".format( - pb_file.resolve(), pb_file2.resolve(), md_file.resolve(), relative - ) + f"deepmd {pb_file.resolve()} {pb_file2.resolve()} out_file {md_file.resolve()} out_freq 1 atomic relative {relative}" ) lammps.pair_coeff("* *") lammps.run(0) @@ -437,9 +423,7 @@ def test_pair_deepmd_model_devi_atomic_relative(lammps): def test_pair_deepmd_model_devi_atomic_relative_v(lammps): relative = 1.0 lammps.pair_style( - "deepmd {} {} out_file {} out_freq 1 atomic relative_v {}".format( - pb_file.resolve(), pb_file2.resolve(), md_file.resolve(), relative - ) + f"deepmd {pb_file.resolve()} {pb_file2.resolve()} out_file {md_file.resolve()} out_freq 1 atomic relative_v {relative}" ) lammps.pair_coeff("* *") lammps.run(0) diff --git a/source/lmp/tests/test_lammps_faparam.py b/source/lmp/tests/test_lammps_faparam.py index 064928eeb1..f78639a96b 100644 --- a/source/lmp/tests/test_lammps_faparam.py +++ b/source/lmp/tests/test_lammps_faparam.py @@ -1,5 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later """Test LAMMPS fparam and aparam input.""" + import os import subprocess as sp import sys @@ -134,11 +135,7 @@ sp.check_output( - "{} -m deepmd convert-from pbtxt -i {} -o {}".format( - sys.executable, - pbtxt_file.resolve(), - pb_file.resolve(), - ).split() + f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file.resolve()} -o {pb_file.resolve()}".split() ) diff --git a/source/lmp/tests/test_lammps_pt.py b/source/lmp/tests/test_lammps_pt.py index bf1ef97e2b..55eaf4fde7 100644 --- a/source/lmp/tests/test_lammps_pt.py +++ b/source/lmp/tests/test_lammps_pt.py @@ -218,11 +218,7 @@ sp.check_output( - "{} -m deepmd convert-from pbtxt -i {} -o {}".format( - sys.executable, - pbtxt_file2.resolve(), - pb_file2.resolve(), - ).split() + f"{sys.executable} -m deepmd convert-from pbtxt -i {pbtxt_file2.resolve()} -o {pb_file2.resolve()}".split() ) @@ -340,9 +336,7 @@ def test_pair_deepmd_virial(lammps): def test_pair_deepmd_model_devi(lammps): lammps.pair_style( - "deepmd {} {} out_file {} out_freq 1 atomic".format( - pb_file.resolve(), pb_file2.resolve(), md_file.resolve() - ) + f"deepmd {pb_file.resolve()} {pb_file2.resolve()} out_file {md_file.resolve()} out_freq 1 atomic" ) lammps.pair_coeff("* *") lammps.run(0) @@ -368,9 +362,7 @@ def test_pair_deepmd_model_devi(lammps): def test_pair_deepmd_model_devi_virial(lammps): lammps.pair_style( - "deepmd {} {} out_file {} out_freq 1 atomic".format( - pb_file.resolve(), pb_file2.resolve(), md_file.resolve() - ) + f"deepmd {pb_file.resolve()} {pb_file2.resolve()} out_file {md_file.resolve()} out_freq 1 atomic" ) lammps.pair_coeff("* *") lammps.compute("virial all centroid/stress/atom NULL pair") @@ -409,9 +401,7 @@ def test_pair_deepmd_model_devi_virial(lammps): def test_pair_deepmd_model_devi_atomic_relative(lammps): relative = 1.0 lammps.pair_style( - "deepmd {} {} out_file {} out_freq 1 atomic relative {}".format( - pb_file.resolve(), pb_file2.resolve(), md_file.resolve(), relative - ) + f"deepmd {pb_file.resolve()} {pb_file2.resolve()} out_file {md_file.resolve()} out_freq 1 atomic relative {relative}" ) lammps.pair_coeff("* *") lammps.run(0) @@ -440,9 +430,7 @@ def test_pair_deepmd_model_devi_atomic_relative(lammps): def test_pair_deepmd_model_devi_atomic_relative_v(lammps): relative = 1.0 lammps.pair_style( - "deepmd {} {} out_file {} out_freq 1 atomic relative_v {}".format( - pb_file.resolve(), pb_file2.resolve(), md_file.resolve(), relative - ) + f"deepmd {pb_file.resolve()} {pb_file2.resolve()} out_file {md_file.resolve()} out_freq 1 atomic relative_v {relative}" ) lammps.pair_coeff("* *") lammps.run(0) @@ -527,9 +515,7 @@ def test_pair_deepmd_virial_real(lammps_real): def test_pair_deepmd_model_devi_real(lammps_real): lammps_real.pair_style( - "deepmd {} {} out_file {} out_freq 1 atomic".format( - pb_file.resolve(), pb_file2.resolve(), md_file.resolve() - ) + f"deepmd {pb_file.resolve()} {pb_file2.resolve()} out_file {md_file.resolve()} out_freq 1 atomic" ) lammps_real.pair_coeff("* *") lammps_real.run(0) @@ -559,9 +545,7 @@ def test_pair_deepmd_model_devi_real(lammps_real): def test_pair_deepmd_model_devi_virial_real(lammps_real): lammps_real.pair_style( - "deepmd {} {} out_file {} out_freq 1 atomic".format( - pb_file.resolve(), pb_file2.resolve(), md_file.resolve() - ) + f"deepmd {pb_file.resolve()} {pb_file2.resolve()} out_file {md_file.resolve()} out_freq 1 atomic" ) lammps_real.pair_coeff("* *") lammps_real.compute("virial all centroid/stress/atom NULL pair") @@ -606,12 +590,7 @@ def test_pair_deepmd_model_devi_virial_real(lammps_real): def test_pair_deepmd_model_devi_atomic_relative_real(lammps_real): relative = 1.0 lammps_real.pair_style( - "deepmd {} {} out_file {} out_freq 1 atomic relative {}".format( - pb_file.resolve(), - pb_file2.resolve(), - md_file.resolve(), - relative * constants.force_metal2real, - ) + f"deepmd {pb_file.resolve()} {pb_file2.resolve()} out_file {md_file.resolve()} out_freq 1 atomic relative {relative * constants.force_metal2real}" ) lammps_real.pair_coeff("* *") lammps_real.run(0) @@ -644,12 +623,7 @@ def test_pair_deepmd_model_devi_atomic_relative_real(lammps_real): def test_pair_deepmd_model_devi_atomic_relative_v_real(lammps_real): relative = 1.0 lammps_real.pair_style( - "deepmd {} {} out_file {} out_freq 1 atomic relative_v {}".format( - pb_file.resolve(), - pb_file2.resolve(), - md_file.resolve(), - relative * constants.ener_metal2real, - ) + f"deepmd {pb_file.resolve()} {pb_file2.resolve()} out_file {md_file.resolve()} out_freq 1 atomic relative_v {relative * constants.ener_metal2real}" ) lammps_real.pair_coeff("* *") lammps_real.run(0) diff --git a/source/md/src/GroFileManager.cc b/source/md/src/GroFileManager.cc index 5969168a72..d61fbb7b97 100644 --- a/source/md/src/GroFileManager.cc +++ b/source/md/src/GroFileManager.cc @@ -125,8 +125,7 @@ void GroFileManager::read(const std::string &name, std::cerr << "cannot open file " << name << std::endl; return; } - while (fgetc(fp) != '\n') - ; + while (fgetc(fp) != '\n'); int npart; fscanf(fp, "%d\n", &npart); fclose(fp); @@ -141,10 +140,8 @@ void GroFileManager::read(const std::string &name, boxsize.resize(3); fp = fopen(name.c_str(), "r"); - while (fgetc(fp) != '\n') - ; - while (fgetc(fp) != '\n') - ; + while (fgetc(fp) != '\n'); + while (fgetc(fp) != '\n'); char line[1024]; for (int i = 0; i < npart; ++i) { fgets(line, 1024, fp); diff --git a/source/md/src/Poly.cpp b/source/md/src/Poly.cpp index 49d2897f14..80db3a139f 100644 --- a/source/md/src/Poly.cpp +++ b/source/md/src/Poly.cpp @@ -38,11 +38,9 @@ double PiecewisePoly::value_periodic(const double& xx_) const { double xx(xx_); double T = x.back() - x.front(); if (xx < x.front()) { - while ((xx += T) < x.front()) - ; + while ((xx += T) < x.front()); } else if (xx >= x.back()) { - while ((xx -= T) >= x.back()) - ; + while ((xx -= T) >= x.back()); } unsigned begin = 0; unsigned end = x.size() - 1; @@ -126,11 +124,9 @@ void PiecewisePoly::value_periodic(const std::vector& r, presentStart = presentEnd; double shift = 0; if (r[presentStart] < x.front()) { - while (r[presentStart] + (shift += T) < x.front()) - ; + while (r[presentStart] + (shift += T) < x.front()); } else if (r[presentStart] >= x.back()) { - while (r[presentStart] + (shift -= T) >= x.back()) - ; + while (r[presentStart] + (shift -= T) >= x.back()); } while (presentEnd < r.size() && r[presentEnd] + shift >= x.front() && r[presentEnd] + shift < x.back()) { diff --git a/source/nodejs/prepublish.py b/source/nodejs/prepublish.py index 2f607a7d07..cb60659f02 100644 --- a/source/nodejs/prepublish.py +++ b/source/nodejs/prepublish.py @@ -4,6 +4,7 @@ The NPM package downloads the C library binary from GitHub releases. This script changes the package.json to make it work. """ + import json import shutil diff --git a/source/op/dotmul_flt_nvnmd.cc b/source/op/dotmul_flt_nvnmd.cc index fd7c831ef1..d7c2c8d3c3 100644 --- a/source/op/dotmul_flt_nvnmd.cc +++ b/source/op/dotmul_flt_nvnmd.cc @@ -159,7 +159,7 @@ class DotmulFltNvnmdOp : public OpKernel { ufi3.nint &= FLT_MASK; y[ii] = ufi3.nflt; } // loop ii - } // Compute + } // Compute }; // DotmulFltNvnmdOp diff --git a/source/op/map_flt_nvnmd.cc b/source/op/map_flt_nvnmd.cc index b23deac9c8..77b788e537 100644 --- a/source/op/map_flt_nvnmd.cc +++ b/source/op/map_flt_nvnmd.cc @@ -141,10 +141,10 @@ class MapFltNvnmdOp : public OpKernel { add_flt_nvnmd(ytmp, d, ytmp); y[ii * M + jj] = ytmp; } // jj - } // ii - } // ss - } // Compute -}; // MapFltNvnmdOp + } // ii + } // ss + } // Compute +}; // MapFltNvnmdOp #define REGISTER_CPU(T) \ REGISTER_KERNEL_BUILDER( \ diff --git a/source/op/matmul_fitnet_nvnmd.cc b/source/op/matmul_fitnet_nvnmd.cc index b5dc32a642..acc8e4b591 100644 --- a/source/op/matmul_fitnet_nvnmd.cc +++ b/source/op/matmul_fitnet_nvnmd.cc @@ -160,7 +160,7 @@ class MatmulFitnetNvnmdOp : public OpKernel { s = floor(s * prec * precx) * div_precx; y[ii * K + kk] = s; } // loop xx - } // loop kk + } // loop kk } // Compute diff --git a/source/op/matmul_flt2fix_nvnmd.cc b/source/op/matmul_flt2fix_nvnmd.cc index ab823a829d..10cfb3d3ba 100644 --- a/source/op/matmul_flt2fix_nvnmd.cc +++ b/source/op/matmul_flt2fix_nvnmd.cc @@ -138,9 +138,9 @@ class MatmulFlt2fixNvnmdOp : public OpKernel { ufi.nint &= FLT_MASK; y[hh * N * K + ii * K + kk] = ufi.nflt; } // loop jj - } // loop ii - } // loop hh - } // Compute + } // loop ii + } // loop hh + } // Compute private: int nbit; diff --git a/source/op/matmul_flt_nvnmd.cc b/source/op/matmul_flt_nvnmd.cc index 92b6375100..22ed23c0a3 100644 --- a/source/op/matmul_flt_nvnmd.cc +++ b/source/op/matmul_flt_nvnmd.cc @@ -188,9 +188,9 @@ class MatmulFltNvnmdOp : public OpKernel { ufi3.nint &= FLT_MASK; y[hh * N * K + ii * K + kk] = ufi3.nflt; } // loop kk - } // loop ii - } // loop hh - } // Compute + } // loop ii + } // loop hh + } // Compute private: int normx; diff --git a/source/op/tanh4_flt_nvnmd.cc b/source/op/tanh4_flt_nvnmd.cc index 987013a5e6..3351a366e4 100644 --- a/source/op/tanh4_flt_nvnmd.cc +++ b/source/op/tanh4_flt_nvnmd.cc @@ -117,8 +117,8 @@ class Tanh4FltNvnmdOp : public OpKernel { y = floor(y * prechi) / prechi; ys(ii, jj) = (x < 0) ? (-y) : y; } // loop jj - } // loop ii - } // Compute + } // loop ii + } // Compute //- define the private variable for calculation }; // Tanh4FltNvnmd diff --git a/source/tests/common/test_examples.py b/source/tests/common/test_examples.py index 1ec4cef3a5..91bb9c0174 100644 --- a/source/tests/common/test_examples.py +++ b/source/tests/common/test_examples.py @@ -2,6 +2,7 @@ """This module ensures input in the examples directory could pass the argument checking. """ + import unittest from pathlib import ( Path, diff --git a/source/tests/pt/test_multitask.py b/source/tests/pt/test_multitask.py index d06733b016..e959e9a128 100644 --- a/source/tests/pt/test_multitask.py +++ b/source/tests/pt/test_multitask.py @@ -73,24 +73,24 @@ def setUp(self): self.stat_files = "se_e2_a" os.makedirs(self.stat_files, exist_ok=True) self.config = multitask_se_e2_a - self.config["training"]["data_dict"]["model_1"]["training_data"][ - "systems" - ] = data_file + self.config["training"]["data_dict"]["model_1"]["training_data"]["systems"] = ( + data_file + ) self.config["training"]["data_dict"]["model_1"]["validation_data"][ "systems" ] = data_file - self.config["training"]["data_dict"]["model_1"][ - "stat_file" - ] = f"{self.stat_files}/model_1" - self.config["training"]["data_dict"]["model_2"]["training_data"][ - "systems" - ] = data_file + self.config["training"]["data_dict"]["model_1"]["stat_file"] = ( + f"{self.stat_files}/model_1" + ) + self.config["training"]["data_dict"]["model_2"]["training_data"]["systems"] = ( + data_file + ) self.config["training"]["data_dict"]["model_2"]["validation_data"][ "systems" ] = data_file - self.config["training"]["data_dict"]["model_2"][ - "stat_file" - ] = f"{self.stat_files}/model_2" + self.config["training"]["data_dict"]["model_2"]["stat_file"] = ( + f"{self.stat_files}/model_2" + ) self.config["training"]["numb_steps"] = 1 self.config["training"]["save_freq"] = 1 self.config["model"], self.shared_links = preprocess_shared_params( @@ -111,24 +111,24 @@ def setUp(self): self.stat_files = "DPA1" os.makedirs(self.stat_files, exist_ok=True) self.config = multitask_DPA1 - self.config["training"]["data_dict"]["model_1"]["training_data"][ - "systems" - ] = data_file + self.config["training"]["data_dict"]["model_1"]["training_data"]["systems"] = ( + data_file + ) self.config["training"]["data_dict"]["model_1"]["validation_data"][ "systems" ] = data_file - self.config["training"]["data_dict"]["model_1"][ - "stat_file" - ] = f"{self.stat_files}/model_1" - self.config["training"]["data_dict"]["model_2"]["training_data"][ - "systems" - ] = data_file + self.config["training"]["data_dict"]["model_1"]["stat_file"] = ( + f"{self.stat_files}/model_1" + ) + self.config["training"]["data_dict"]["model_2"]["training_data"]["systems"] = ( + data_file + ) self.config["training"]["data_dict"]["model_2"]["validation_data"][ "systems" ] = data_file - self.config["training"]["data_dict"]["model_2"][ - "stat_file" - ] = f"{self.stat_files}/model_2" + self.config["training"]["data_dict"]["model_2"]["stat_file"] = ( + f"{self.stat_files}/model_2" + ) self.config["training"]["numb_steps"] = 1 self.config["training"]["save_freq"] = 1 self.config["model"], self.shared_links = preprocess_shared_params( @@ -149,24 +149,24 @@ def setUp(self): self.stat_files = "DPA2" os.makedirs(self.stat_files, exist_ok=True) self.config = multitask_DPA2 - self.config["training"]["data_dict"]["model_1"]["training_data"][ - "systems" - ] = data_file + self.config["training"]["data_dict"]["model_1"]["training_data"]["systems"] = ( + data_file + ) self.config["training"]["data_dict"]["model_1"]["validation_data"][ "systems" ] = data_file - self.config["training"]["data_dict"]["model_1"][ - "stat_file" - ] = f"{self.stat_files}/model_1" - self.config["training"]["data_dict"]["model_2"]["training_data"][ - "systems" - ] = data_file + self.config["training"]["data_dict"]["model_1"]["stat_file"] = ( + f"{self.stat_files}/model_1" + ) + self.config["training"]["data_dict"]["model_2"]["training_data"]["systems"] = ( + data_file + ) self.config["training"]["data_dict"]["model_2"]["validation_data"][ "systems" ] = data_file - self.config["training"]["data_dict"]["model_2"][ - "stat_file" - ] = f"{self.stat_files}/model_2" + self.config["training"]["data_dict"]["model_2"]["stat_file"] = ( + f"{self.stat_files}/model_2" + ) self.config["training"]["numb_steps"] = 1 self.config["training"]["save_freq"] = 1 self.config["model"], self.shared_links = preprocess_shared_params( diff --git a/source/tests/tf/test_init_frz_model_multi.py b/source/tests/tf/test_init_frz_model_multi.py index b723134ca1..b6209a7e69 100644 --- a/source/tests/tf/test_init_frz_model_multi.py +++ b/source/tests/tf/test_init_frz_model_multi.py @@ -64,12 +64,12 @@ def _init_models(): jdata["training"]["data_dict"]["water_ener"] = {} jdata["training"]["data_dict"]["water_ener"]["training_data"] = training_data_config jdata["training"]["data_dict"]["water_ener"]["training_data"]["systems"] = data_file - jdata["training"]["data_dict"]["water_ener"][ - "validation_data" - ] = validation_data_config - jdata["training"]["data_dict"]["water_ener"]["validation_data"][ - "systems" - ] = data_file + jdata["training"]["data_dict"]["water_ener"]["validation_data"] = ( + validation_data_config + ) + jdata["training"]["data_dict"]["water_ener"]["validation_data"]["systems"] = ( + data_file + ) jdata["training"]["save_ckpt"] = ckpt jdata["model"]["fitting_net_dict"] = {} jdata["model"]["fitting_net_dict"]["water_ener"] = fitting_config @@ -98,18 +98,18 @@ def _init_models(): jdata["learning_rate_dict"]["water_ener_new"] = learning_rate_config jdata["training"]["data_dict"] = {} jdata["training"]["data_dict"]["water_ener_new"] = {} - jdata["training"]["data_dict"]["water_ener_new"][ - "training_data" - ] = training_data_config - jdata["training"]["data_dict"]["water_ener_new"]["training_data"][ - "systems" - ] = data_file - jdata["training"]["data_dict"]["water_ener_new"][ - "validation_data" - ] = validation_data_config - jdata["training"]["data_dict"]["water_ener_new"]["validation_data"][ - "systems" - ] = data_file + jdata["training"]["data_dict"]["water_ener_new"]["training_data"] = ( + training_data_config + ) + jdata["training"]["data_dict"]["water_ener_new"]["training_data"]["systems"] = ( + data_file + ) + jdata["training"]["data_dict"]["water_ener_new"]["validation_data"] = ( + validation_data_config + ) + jdata["training"]["data_dict"]["water_ener_new"]["validation_data"]["systems"] = ( + data_file + ) jdata["training"].pop("fitting_weight") jdata = replace_model_params_with_frz_multi_model(jdata, frozen_model) diff --git a/source/tests/tf/test_pairwise_dprc.py b/source/tests/tf/test_pairwise_dprc.py index afe6885542..38b8d8b775 100644 --- a/source/tests/tf/test_pairwise_dprc.py +++ b/source/tests/tf/test_pairwise_dprc.py @@ -1,5 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later """Test pairwise DPRc features.""" + import json import unittest diff --git a/source/tests/tf/test_virtual_type.py b/source/tests/tf/test_virtual_type.py index e9c675fe3a..a3e87a35ed 100644 --- a/source/tests/tf/test_virtual_type.py +++ b/source/tests/tf/test_virtual_type.py @@ -1,5 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later """Test virtual atomic type.""" + import os import unittest