diff --git a/backend/dp_backend.py b/backend/dp_backend.py index 6fc5676c01..97fa1578c7 100644 --- a/backend/dp_backend.py +++ b/backend/dp_backend.py @@ -1,7 +1,11 @@ """A PEP-517 backend to find TensorFlow.""" -from typing import List +from typing import ( + List, +) -from find_tensorflow import find_tensorflow +from find_tensorflow import ( + find_tensorflow, +) # TODO: switch to scikit_build_core after it is available from setuptools import build_meta as _orig diff --git a/backend/find_tensorflow.py b/backend/find_tensorflow.py index 163f91d798..52c7fc5286 100644 --- a/backend/find_tensorflow.py +++ b/backend/find_tensorflow.py @@ -1,15 +1,27 @@ import os import site -from importlib.machinery import FileFinder -from importlib.util import find_spec -from pathlib import Path -from sysconfig import get_path -from typing import List -from typing import Optional -from typing import Tuple -from typing import Union - -from packaging.specifiers import SpecifierSet +from importlib.machinery import ( + FileFinder, +) +from importlib.util import ( + find_spec, +) +from pathlib import ( + Path, +) +from sysconfig import ( + get_path, +) +from typing import ( + List, + Optional, + Tuple, + Union, +) + +from packaging.specifiers import ( + SpecifierSet, +) def find_tensorflow() -> Tuple[Optional[str], List[str]]: diff --git a/data/json/json2yaml.py b/data/json/json2yaml.py index 5568d7196a..6c97771bec 100644 --- a/data/json/json2yaml.py +++ b/data/json/json2yaml.py @@ -2,8 +2,12 @@ import argparse import json -from pathlib import Path -from warnings import warn +from pathlib import ( + Path, +) +from warnings import ( + warn, +) import yaml diff --git a/deepmd/__init__.py b/deepmd/__init__.py index a9138c5642..d96d7eb4a4 100644 --- a/deepmd/__init__.py +++ b/deepmd/__init__.py @@ -1,29 +1,41 @@ """Root of the deepmd package, exposes all public classes and submodules.""" try: - from importlib import metadata + from importlib import ( + metadata, + ) except ImportError: # for Python<3.8 import importlib_metadata as metadata import deepmd.utils.network as network -from . import cluster -from . import descriptor -from . import fit -from . import loss -from . import nvnmd -from . import utils -from .env import set_mkl -from .infer import DeepEval -from .infer import DeepPotential -from .infer.data_modifier import DipoleChargeModifier +from . import ( + cluster, + descriptor, + fit, + loss, + nvnmd, + utils, +) +from .env import ( + set_mkl, +) +from .infer import ( + DeepEval, + DeepPotential, +) +from .infer.data_modifier import ( + DipoleChargeModifier, +) set_mkl() try: from ._version import version as __version__ except ImportError: - from .__about__ import __version__ + from .__about__ import ( + __version__, + ) # load third-party plugins try: diff --git a/deepmd/__main__.py b/deepmd/__main__.py index 09e38228fd..8e3011bc7b 100644 --- a/deepmd/__main__.py +++ b/deepmd/__main__.py @@ -1,6 +1,8 @@ """Package dp entry point.""" -from .entrypoints.main import main +from .entrypoints.main import ( + main, +) if __name__ == "__main__": main() diff --git a/deepmd/calculator.py b/deepmd/calculator.py index d878266468..4777bc80bc 100644 --- a/deepmd/calculator.py +++ b/deepmd/calculator.py @@ -1,20 +1,30 @@ """ASE calculator interface module.""" -from pathlib import Path -from typing import TYPE_CHECKING -from typing import Dict -from typing import List -from typing import Optional -from typing import Union - -from ase.calculators.calculator import Calculator -from ase.calculators.calculator import PropertyNotImplementedError -from ase.calculators.calculator import all_changes - -from deepmd import DeepPotential +from pathlib import ( + Path, +) +from typing import ( + TYPE_CHECKING, + Dict, + List, + Optional, + Union, +) + +from ase.calculators.calculator import ( + Calculator, + PropertyNotImplementedError, + all_changes, +) + +from deepmd import ( + DeepPotential, +) if TYPE_CHECKING: - from ase import Atoms + from ase import ( + Atoms, + ) __all__ = ["DP"] diff --git a/deepmd/cluster/__init__.py b/deepmd/cluster/__init__.py index c9865ac429..4cba0c10b9 100644 --- a/deepmd/cluster/__init__.py +++ b/deepmd/cluster/__init__.py @@ -1,9 +1,11 @@ """Module that reads node resources, auto detects if running local or on SLURM.""" import os -from typing import List -from typing import Optional -from typing import Tuple +from typing import ( + List, + Optional, + Tuple, +) from .local import get_resource as get_local_res from .slurm import get_resource as get_slurm_res diff --git a/deepmd/cluster/local.py b/deepmd/cluster/local.py index 37379b9739..8ad9a83659 100644 --- a/deepmd/cluster/local.py +++ b/deepmd/cluster/local.py @@ -3,11 +3,15 @@ import socket import subprocess as sp import sys -from typing import List -from typing import Optional -from typing import Tuple - -from deepmd.env import tf +from typing import ( + List, + Optional, + Tuple, +) + +from deepmd.env import ( + tf, +) __all__ = ["get_gpus", "get_resource"] diff --git a/deepmd/cluster/slurm.py b/deepmd/cluster/slurm.py index 60e7b68a9e..2be6b438f2 100644 --- a/deepmd/cluster/slurm.py +++ b/deepmd/cluster/slurm.py @@ -6,13 +6,17 @@ """ import os -from typing import List -from typing import Optional -from typing import Tuple +from typing import ( + List, + Optional, + Tuple, +) import hostlist -from deepmd.cluster import local +from deepmd.cluster import ( + local, +) __all__ = ["get_resource"] diff --git a/deepmd/common.py b/deepmd/common.py index 2f8334f9f5..99e121c990 100644 --- a/deepmd/common.py +++ b/deepmd/common.py @@ -2,29 +2,41 @@ import json import warnings -from functools import wraps -from pathlib import Path -from typing import TYPE_CHECKING -from typing import Any -from typing import Callable -from typing import Dict -from typing import List -from typing import Optional -from typing import TypeVar -from typing import Union +from functools import ( + wraps, +) +from pathlib import ( + Path, +) +from typing import ( + TYPE_CHECKING, + Any, + Callable, + Dict, + List, + Optional, + TypeVar, + Union, +) import numpy as np import tensorflow import yaml -from tensorflow.python.framework import tensor_util - -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import GLOBAL_PD_FLOAT_PRECISION -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import op_module -from deepmd.env import paddle -from deepmd.env import tf -from deepmd.utils.path import DPPath +from tensorflow.python.framework import ( + tensor_util, +) + +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + GLOBAL_PD_FLOAT_PRECISION, + GLOBAL_TF_FLOAT_PRECISION, + op_module, + paddle, + tf, +) +from deepmd.utils.path import ( + DPPath, +) if TYPE_CHECKING: _DICT_VAL = TypeVar("_DICT_VAL") diff --git a/deepmd/descriptor/__init__.py b/deepmd/descriptor/__init__.py index 9a14bdb185..3b55a4f97a 100644 --- a/deepmd/descriptor/__init__.py +++ b/deepmd/descriptor/__init__.py @@ -1,14 +1,34 @@ -from .descriptor import Descriptor -from .hybrid import DescrptHybrid -from .loc_frame import DescrptLocFrame -from .se_a import DescrptSeA -from .se_a_ebd import DescrptSeAEbd -from .se_a_ef import DescrptSeAEf -from .se_a_ef import DescrptSeAEfLower -from .se_a_mask import DescrptSeAMask -from .se_atten import DescrptSeAtten -from .se_r import DescrptSeR -from .se_t import DescrptSeT +from .descriptor import ( + Descriptor, +) +from .hybrid import ( + DescrptHybrid, +) +from .loc_frame import ( + DescrptLocFrame, +) +from .se_a import ( + DescrptSeA, +) +from .se_a_ebd import ( + DescrptSeAEbd, +) +from .se_a_ef import ( + DescrptSeAEf, + DescrptSeAEfLower, +) +from .se_a_mask import ( + DescrptSeAMask, +) +from .se_atten import ( + DescrptSeAtten, +) +from .se_r import ( + DescrptSeR, +) +from .se_t import ( + DescrptSeT, +) __all__ = [ "Descriptor", diff --git a/deepmd/descriptor/descriptor.py b/deepmd/descriptor/descriptor.py index 59188a9ce0..3542918cb3 100644 --- a/deepmd/descriptor/descriptor.py +++ b/deepmd/descriptor/descriptor.py @@ -1,17 +1,25 @@ -from abc import abstractmethod -from typing import Any -from typing import Callable -from typing import Dict -from typing import List -from typing import Optional -from typing import Tuple +from abc import ( + abstractmethod, +) +from typing import ( + Any, + Callable, + Dict, + List, + Optional, + Tuple, +) import numpy as np -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import tf -from deepmd.utils import Plugin -from deepmd.utils import PluginVariant +from deepmd.env import ( + GLOBAL_TF_FLOAT_PRECISION, + tf, +) +from deepmd.utils import ( + Plugin, + PluginVariant, +) class Descriptor(PluginVariant): diff --git a/deepmd/descriptor/hybrid.py b/deepmd/descriptor/hybrid.py index c89ceb5c44..e1ddf5f2e9 100644 --- a/deepmd/descriptor/hybrid.py +++ b/deepmd/descriptor/hybrid.py @@ -1,12 +1,18 @@ -from typing import List -from typing import Optional -from typing import Tuple +from typing import ( + List, + Optional, + Tuple, +) import numpy as np -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import tf -from deepmd.utils.spin import Spin +from deepmd.env import ( + GLOBAL_TF_FLOAT_PRECISION, + tf, +) +from deepmd.utils.spin import ( + Spin, +) # from deepmd.descriptor import DescrptLocFrame # from deepmd.descriptor import DescrptSeA @@ -14,7 +20,9 @@ # from deepmd.descriptor import DescrptSeAEbd # from deepmd.descriptor import DescrptSeAEf # from deepmd.descriptor import DescrptSeR -from .descriptor import Descriptor +from .descriptor import ( + Descriptor, +) @Descriptor.register("hybrid") diff --git a/deepmd/descriptor/loc_frame.py b/deepmd/descriptor/loc_frame.py index f268208416..dd99f7fb57 100644 --- a/deepmd/descriptor/loc_frame.py +++ b/deepmd/descriptor/loc_frame.py @@ -1,18 +1,28 @@ -from typing import List -from typing import Optional -from typing import Tuple +from typing import ( + List, + Optional, + Tuple, +) import numpy as np -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import default_tf_session_config -from deepmd.env import op_module -from deepmd.env import tf -from deepmd.utils.graph import get_tensor_by_name_from_graph -from deepmd.utils.sess import run_sess +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + GLOBAL_TF_FLOAT_PRECISION, + default_tf_session_config, + op_module, + tf, +) +from deepmd.utils.graph import ( + get_tensor_by_name_from_graph, +) +from deepmd.utils.sess import ( + run_sess, +) -from .descriptor import Descriptor +from .descriptor import ( + Descriptor, +) @Descriptor.register("loc_frame") diff --git a/deepmd/descriptor/se.py b/deepmd/descriptor/se.py index 26dcc4d5f1..242ee5425d 100644 --- a/deepmd/descriptor/se.py +++ b/deepmd/descriptor/se.py @@ -1,10 +1,18 @@ -from typing import Tuple - -from deepmd.env import tf -from deepmd.utils.graph import get_embedding_net_variables_from_graph_def -from deepmd.utils.graph import get_tensor_by_name_from_graph - -from .descriptor import Descriptor +from typing import ( + Tuple, +) + +from deepmd.env import ( + tf, +) +from deepmd.utils.graph import ( + get_embedding_net_variables_from_graph_def, + get_tensor_by_name_from_graph, +) + +from .descriptor import ( + Descriptor, +) class DescrptSe(Descriptor): diff --git a/deepmd/descriptor/se_a.py b/deepmd/descriptor/se_a.py index 3e70516417..e1205d8593 100644 --- a/deepmd/descriptor/se_a.py +++ b/deepmd/descriptor/se_a.py @@ -1,37 +1,41 @@ -from typing import List -from typing import Optional -from typing import Tuple +from typing import ( + List, + Optional, + Tuple, +) import numpy as np -from deepmd.common import cast_precision -from deepmd.common import get_activation_func -from deepmd.common import get_precision -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import GLOBAL_PD_FLOAT_PRECISION -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import default_tf_session_config -from deepmd.env import op_module -from deepmd.env import paddle -from deepmd.env import tf -from deepmd.nvnmd.descriptor.se_a import build_davg_dstd -from deepmd.nvnmd.descriptor.se_a import build_op_descriptor -from deepmd.nvnmd.descriptor.se_a import check_switch_range -from deepmd.nvnmd.descriptor.se_a import descrpt2r4 -from deepmd.nvnmd.descriptor.se_a import filter_GR2D -from deepmd.nvnmd.descriptor.se_a import filter_lower_R42GR -from deepmd.nvnmd.utils.config import nvnmd_cfg -from deepmd.utils.errors import GraphWithoutTensorError -from deepmd.utils.graph import get_tensor_by_name_from_graph +from deepmd.common import ( + get_activation_func, + get_precision, +) +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + GLOBAL_PD_FLOAT_PRECISION, + op_module, + paddle, + tf, +) +from deepmd.utils.errors import ( + GraphWithoutTensorError, +) +from deepmd.utils.graph import ( + get_tensor_by_name_from_graph, +) from deepmd.utils.network import EmbeddingNet # embedding_net, -from deepmd.utils.network import embedding_net_rand_seed_shift -from deepmd.utils.sess import run_sess -from deepmd.utils.spin import Spin -from deepmd.utils.tabulate import DPTabulate -from deepmd.utils.type_embed import embed_atom_type - -from .descriptor import Descriptor -from .se import DescrptSe +from deepmd.utils.network import ( + embedding_net_rand_seed_shift, +) +from deepmd.utils.spin import ( + Spin, +) +from deepmd.utils.tabulate import ( + DPTabulate, +) +from deepmd.utils.type_embed import ( + embed_atom_type, +) # @Descriptor.register("se_e2_a") @@ -729,17 +733,26 @@ def _pass_filter( ): """pass_filter. - Args: - inputs (_type_): _description_ - atype (_type_): _description_ - natoms (_type_): _description_ - input_dict (_type_): _description_ - reuse (_type_, optional): _description_. Defaults to None. - suffix (str, optional): _description_. Defaults to "". - trainable (bool, optional): _description_. Defaults to True. - - Returns: - Tuple[Tensor, Tensor]: output: [1, all_atom, M1*M2], output_qmat: [1, all_atom, M1*3] + Parameters + ---------- + inputs : paddle.Tensor + Inputs tensor. + atype : paddle.Tensor + Atom type Tensor. + natoms : paddle.Tensor + Number of atoms vector + input_dict : Dict[str, paddle.Tensor] + Input data dict. + reuse : bool, optional + Whether reuse variables. Defaults to None. + suffix : str, optional + Variable suffix. Defaults to "". + trainable : bool, optional + Whether make subnetwork traninable. Defaults to True. + + Returns + ------- + Tuple[Tensor, Tensor]: output: [1, all_atom, M1*M2], output_qmat: [1, all_atom, M1*3] """ # natoms = [192, 192, 64 , 128] if input_dict is not None: @@ -1107,21 +1120,34 @@ def _filter( reuse=None, trainable=True, ): - """_filter - - Args: - inputs (paddle.Tensor): _description_ - natoms (_type_): _description_ - type_embedding (_type_, optional): _description_. Defaults to None. - activation_fn (_type_, optional): _description_. Defaults to paddle.nn.functional.tanh. - stddev (float, optional): _description_. Defaults to 1.0. - bavg (float, optional): _description_. Defaults to 0.0. - name (str, optional): _description_. Defaults to "linear". - reuse (_type_, optional): _description_. Defaults to None. - trainable (bool, optional): _description_. Defaults to True. - - Returns: - Tuple[Tensor, Tensor]: result: [64/128, M1*M2], qmat: [64/128, M1, 3] + """_filter. + + Parameters + ---------- + inputs : paddle.Tensor + Inputs tensor. + type_input : int + Type of input. + natoms : paddle.Tensor + Number of atoms, a vector. + type_embedding : paddle.Tensor + Type embedding. Defaults to None. + activation_fn : Callable + Activation function. Defaults to paddle.nn.functional.tanh. + stddev : float, optional + Stddev for parameters initialization. Defaults to 1.0. + bavg : float, optional + Bavg for parameters initialization . Defaults to 0.0. + name : str, optional + Name for subnetwork. Defaults to "linear". + reuse : bool, optional + Whether reuse variables. Defaults to None. + trainable : bool, optional + Whether make subnetwork trainable. Defaults to True. + + Returns + ------- + Tuple[Tensor, Tensor]: result: [64/128, M1*M2], qmat: [64/128, M1, 3] """ # nframes = paddle.shape(paddle.reshape(inputs, [-1, natoms[0], self.ndescrpt]))[0] # 上述 nframes的计算代码是错误的,reshape前后numel根本不相等,会导致程序报错,tf不会报错是因为tf计算图 diff --git a/deepmd/descriptor/se_a_ebd.py b/deepmd/descriptor/se_a_ebd.py index 0b009af24d..e0684403e1 100644 --- a/deepmd/descriptor/se_a_ebd.py +++ b/deepmd/descriptor/se_a_ebd.py @@ -1,17 +1,29 @@ -from typing import List -from typing import Optional +from typing import ( + List, + Optional, +) import numpy as np -from deepmd.common import add_data_requirement -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import op_module -from deepmd.env import tf -from deepmd.utils.network import embedding_net -from deepmd.utils.network import one_layer +from deepmd.common import ( + add_data_requirement, +) +from deepmd.env import ( + GLOBAL_TF_FLOAT_PRECISION, + op_module, + tf, +) +from deepmd.utils.network import ( + embedding_net, + one_layer, +) -from .descriptor import Descriptor -from .se_a import DescrptSeA +from .descriptor import ( + Descriptor, +) +from .se_a import ( + DescrptSeA, +) @Descriptor.register("se_a_tpe") diff --git a/deepmd/descriptor/se_a_ef.py b/deepmd/descriptor/se_a_ef.py index d050966175..0dbad403f4 100644 --- a/deepmd/descriptor/se_a_ef.py +++ b/deepmd/descriptor/se_a_ef.py @@ -1,19 +1,31 @@ -from typing import List -from typing import Optional -from typing import Tuple +from typing import ( + List, + Optional, + Tuple, +) import numpy as np -from deepmd.common import add_data_requirement -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import default_tf_session_config -from deepmd.env import op_module -from deepmd.env import tf -from deepmd.utils.sess import run_sess - -from .descriptor import Descriptor -from .se_a import DescrptSeA +from deepmd.common import ( + add_data_requirement, +) +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + GLOBAL_TF_FLOAT_PRECISION, + default_tf_session_config, + op_module, + tf, +) +from deepmd.utils.sess import ( + run_sess, +) + +from .descriptor import ( + Descriptor, +) +from .se_a import ( + DescrptSeA, +) @Descriptor.register("se_a_ef") diff --git a/deepmd/descriptor/se_a_mask.py b/deepmd/descriptor/se_a_mask.py index e1f88629e4..93256e3910 100644 --- a/deepmd/descriptor/se_a_mask.py +++ b/deepmd/descriptor/se_a_mask.py @@ -1,23 +1,35 @@ import warnings -from typing import Any -from typing import Dict -from typing import List -from typing import Optional -from typing import Tuple +from typing import ( + Any, + Dict, + List, + Optional, + Tuple, +) import numpy as np -from deepmd.common import get_activation_func -from deepmd.common import get_precision -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import default_tf_session_config -from deepmd.env import op_module -from deepmd.env import tf -from deepmd.utils.network import embedding_net_rand_seed_shift - -from .descriptor import Descriptor -from .se_a import DescrptSeA +from deepmd.common import ( + get_activation_func, + get_precision, +) +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + GLOBAL_TF_FLOAT_PRECISION, + default_tf_session_config, + op_module, + tf, +) +from deepmd.utils.network import ( + embedding_net_rand_seed_shift, +) + +from .descriptor import ( + Descriptor, +) +from .se_a import ( + DescrptSeA, +) @Descriptor.register("se_a_mask") diff --git a/deepmd/descriptor/se_atten.py b/deepmd/descriptor/se_atten.py index 2643467f83..b113e5c994 100644 --- a/deepmd/descriptor/se_atten.py +++ b/deepmd/descriptor/se_atten.py @@ -1,25 +1,43 @@ import warnings -from typing import List -from typing import Optional -from typing import Tuple +from typing import ( + List, + Optional, + Tuple, +) import numpy as np -from packaging.version import Version +from packaging.version import ( + Version, +) -from deepmd.common import cast_precision -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import TF_VERSION -from deepmd.env import default_tf_session_config -from deepmd.env import op_module -from deepmd.env import tf -from deepmd.utils.graph import get_attention_layer_variables_from_graph_def -from deepmd.utils.network import embedding_net -from deepmd.utils.network import one_layer -from deepmd.utils.sess import run_sess +from deepmd.common import ( + cast_precision, +) +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + GLOBAL_TF_FLOAT_PRECISION, + TF_VERSION, + default_tf_session_config, + op_module, + tf, +) +from deepmd.utils.graph import ( + get_attention_layer_variables_from_graph_def, +) +from deepmd.utils.network import ( + embedding_net, + one_layer, +) +from deepmd.utils.sess import ( + run_sess, +) -from .descriptor import Descriptor -from .se_a import DescrptSeA +from .descriptor import ( + Descriptor, +) +from .se_a import ( + DescrptSeA, +) @Descriptor.register("se_atten") diff --git a/deepmd/descriptor/se_r.py b/deepmd/descriptor/se_r.py index b2afe76be1..7ef5f47347 100644 --- a/deepmd/descriptor/se_r.py +++ b/deepmd/descriptor/se_r.py @@ -1,26 +1,46 @@ -from typing import List -from typing import Optional -from typing import Tuple +from typing import ( + List, + Optional, + Tuple, +) import numpy as np -from deepmd.common import cast_precision -from deepmd.common import get_activation_func -from deepmd.common import get_precision -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import default_tf_session_config -from deepmd.env import op_module -from deepmd.env import tf -from deepmd.utils.graph import get_tensor_by_name_from_graph -from deepmd.utils.network import embedding_net -from deepmd.utils.network import embedding_net_rand_seed_shift -from deepmd.utils.sess import run_sess -from deepmd.utils.spin import Spin -from deepmd.utils.tabulate import DPTabulate - -from .descriptor import Descriptor -from .se import DescrptSe +from deepmd.common import ( + cast_precision, + get_activation_func, + get_precision, +) +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + GLOBAL_TF_FLOAT_PRECISION, + default_tf_session_config, + op_module, + tf, +) +from deepmd.utils.graph import ( + get_tensor_by_name_from_graph, +) +from deepmd.utils.network import ( + embedding_net, + embedding_net_rand_seed_shift, +) +from deepmd.utils.sess import ( + run_sess, +) +from deepmd.utils.spin import ( + Spin, +) +from deepmd.utils.tabulate import ( + DPTabulate, +) + +from .descriptor import ( + Descriptor, +) +from .se import ( + DescrptSe, +) @Descriptor.register("se_e2_r") diff --git a/deepmd/descriptor/se_t.py b/deepmd/descriptor/se_t.py index d35b68894f..7615275a82 100644 --- a/deepmd/descriptor/se_t.py +++ b/deepmd/descriptor/se_t.py @@ -1,25 +1,43 @@ -from typing import List -from typing import Optional -from typing import Tuple +from typing import ( + List, + Optional, + Tuple, +) import numpy as np -from deepmd.common import cast_precision -from deepmd.common import get_activation_func -from deepmd.common import get_precision -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import default_tf_session_config -from deepmd.env import op_module -from deepmd.env import tf -from deepmd.utils.graph import get_tensor_by_name_from_graph -from deepmd.utils.network import embedding_net -from deepmd.utils.network import embedding_net_rand_seed_shift -from deepmd.utils.sess import run_sess -from deepmd.utils.tabulate import DPTabulate - -from .descriptor import Descriptor -from .se import DescrptSe +from deepmd.common import ( + cast_precision, + get_activation_func, + get_precision, +) +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + GLOBAL_TF_FLOAT_PRECISION, + default_tf_session_config, + op_module, + tf, +) +from deepmd.utils.graph import ( + get_tensor_by_name_from_graph, +) +from deepmd.utils.network import ( + embedding_net, + embedding_net_rand_seed_shift, +) +from deepmd.utils.sess import ( + run_sess, +) +from deepmd.utils.tabulate import ( + DPTabulate, +) + +from .descriptor import ( + Descriptor, +) +from .se import ( + DescrptSe, +) @Descriptor.register("se_e3") diff --git a/deepmd/entrypoints/__init__.py b/deepmd/entrypoints/__init__.py index 66405f0e0d..fc690daf14 100644 --- a/deepmd/entrypoints/__init__.py +++ b/deepmd/entrypoints/__init__.py @@ -1,17 +1,33 @@ """Submodule that contains all the DeePMD-Kit entry point scripts.""" -from ..infer.model_devi import make_model_devi -from .compress import compress -from .convert import convert -from .doc import doc_train_input -from .freeze import freeze -from .neighbor_stat import neighbor_stat -from .test import test +from ..infer.model_devi import ( + make_model_devi, +) +from .compress import ( + compress, +) +from .convert import ( + convert, +) +from .doc import ( + doc_train_input, +) +from .freeze import ( + freeze, +) +from .neighbor_stat import ( + neighbor_stat, +) +from .test import ( + test, +) # import `train` as `train_dp` to avoid the conflict of the # module name `train` and the function name `train` from .train import train as train_dp -from .transfer import transfer +from .transfer import ( + transfer, +) __all__ = [ "doc_train_input", diff --git a/deepmd/entrypoints/compress.py b/deepmd/entrypoints/compress.py index ee5ce3a1e2..a198127d12 100644 --- a/deepmd/entrypoints/compress.py +++ b/deepmd/entrypoints/compress.py @@ -3,22 +3,40 @@ import json import logging import os -from typing import Optional - -from deepmd.common import j_loader -from deepmd.env import GLOBAL_ENER_FLOAT_PRECISION -from deepmd.env import tf -from deepmd.utils.argcheck import normalize -from deepmd.utils.compat import update_deepmd_input -from deepmd.utils.errors import GraphTooLargeError -from deepmd.utils.errors import GraphWithoutTensorError -from deepmd.utils.graph import get_tensor_by_name_from_graph -from deepmd.utils.graph import load_graph_def - -from .freeze import freeze -from .train import get_min_nbor_dist -from .train import get_rcut -from .train import train +from typing import ( + Optional, +) + +from deepmd.common import ( + j_loader, +) +from deepmd.env import ( + GLOBAL_ENER_FLOAT_PRECISION, + tf, +) +from deepmd.utils.argcheck import ( + normalize, +) +from deepmd.utils.compat import ( + update_deepmd_input, +) +from deepmd.utils.errors import ( + GraphTooLargeError, + GraphWithoutTensorError, +) +from deepmd.utils.graph import ( + get_tensor_by_name_from_graph, + load_graph_def, +) + +from .freeze import ( + freeze, +) +from .train import ( + get_min_nbor_dist, + get_rcut, + train, +) __all__ = ["compress"] diff --git a/deepmd/entrypoints/convert.py b/deepmd/entrypoints/convert.py index dfd12bf4b7..b97c137104 100644 --- a/deepmd/entrypoints/convert.py +++ b/deepmd/entrypoints/convert.py @@ -1,10 +1,12 @@ -from deepmd.utils.convert import convert_10_to_21 -from deepmd.utils.convert import convert_012_to_21 -from deepmd.utils.convert import convert_12_to_21 -from deepmd.utils.convert import convert_13_to_21 -from deepmd.utils.convert import convert_20_to_21 -from deepmd.utils.convert import convert_pbtxt_to_pb -from deepmd.utils.convert import convert_to_21 +from deepmd.utils.convert import ( + convert_10_to_21, + convert_012_to_21, + convert_12_to_21, + convert_13_to_21, + convert_20_to_21, + convert_pbtxt_to_pb, + convert_to_21, +) def convert( diff --git a/deepmd/entrypoints/doc.py b/deepmd/entrypoints/doc.py index 42fcca983c..b439c17409 100644 --- a/deepmd/entrypoints/doc.py +++ b/deepmd/entrypoints/doc.py @@ -1,7 +1,9 @@ """Module that prints train input arguments docstrings.""" -from deepmd.utils.argcheck import gen_doc -from deepmd.utils.argcheck import gen_json +from deepmd.utils.argcheck import ( + gen_doc, + gen_json, +) __all__ = ["doc_train_input"] diff --git a/deepmd/entrypoints/freeze.py b/deepmd/entrypoints/freeze.py index d82e464c8a..566cff19b1 100755 --- a/deepmd/entrypoints/freeze.py +++ b/deepmd/entrypoints/freeze.py @@ -8,22 +8,25 @@ import json import logging -from os.path import abspath -from typing import List -from typing import Optional -from typing import Union - -import google.protobuf.message +from typing import ( + List, + Optional, + Union, +) # load grad of force module import deepmd.op # noqa: F401 -from deepmd.env import FITTING_NET_PATTERN -from deepmd.env import REMOVE_SUFFIX_DICT -from deepmd.env import tf -from deepmd.nvnmd.entrypoints.freeze import save_weight -from deepmd.utils.errors import GraphTooLargeError -from deepmd.utils.graph import get_pattern_nodes_from_graph_def -from deepmd.utils.sess import run_sess +from deepmd.env import ( + FITTING_NET_PATTERN, + REMOVE_SUFFIX_DICT, + tf, +) +from deepmd.utils.graph import ( + get_pattern_nodes_from_graph_def, +) +from deepmd.utils.sess import ( + run_sess, +) __all__ = ["freeze"] @@ -321,26 +324,16 @@ def freeze_graph( Parameters ---------- - sess : tf.Session - The default session. - input_graph : tf.GraphDef - The input graph_def stored from the checkpoint. - input_node : List[str] - The expected nodes to freeze. - freeze_type : str - The model type to freeze. - modifier : Optional[str], optional - Modifier type if any, by default None. - out_graph_name : str - The output graph. - node_names : Optional[str], optional - Names of nodes to output, by default None. - out_suffix : str - The chosen suffix to freeze in the input_graph. + model_file : str + Location of the *.pdparams file + output : str + output file name """ import paddle - from deepmd.infer import DeepPot + from deepmd.infer import ( + DeepPot, + ) dp = DeepPot( model_file, @@ -348,7 +341,9 @@ def freeze_graph( default_tf_graph=False, ) dp.model.eval() - from paddle.static import InputSpec + from paddle.static import ( + InputSpec, + ) st_model = paddle.jit.to_static( dp.model, @@ -492,16 +487,10 @@ def freeze( Parameters ---------- - checkpoint_folder : str - location of the folder with model + input_file : str + location of the *.pdparams file output : str output file name - node_names : Optional[str], optional - names of nodes to output, by default None - nvnmd_weight : Optional[str], optional - nvnmd weight file - united_model : bool - when in multi-task mode, freeze all nodes into one unit model **kwargs other arguments """ diff --git a/deepmd/entrypoints/ipi.py b/deepmd/entrypoints/ipi.py index 55378975cd..4208e7f56d 100644 --- a/deepmd/entrypoints/ipi.py +++ b/deepmd/entrypoints/ipi.py @@ -2,9 +2,13 @@ import os import subprocess import sys -from typing import List +from typing import ( + List, +) -from deepmd.lmp import get_op_dir +from deepmd.lmp import ( + get_op_dir, +) ROOT_DIR = get_op_dir() diff --git a/deepmd/entrypoints/main.py b/deepmd/entrypoints/main.py index 33a7ad56b8..baa96bd7a1 100644 --- a/deepmd/entrypoints/main.py +++ b/deepmd/entrypoints/main.py @@ -3,23 +3,37 @@ import argparse import logging import textwrap -from pathlib import Path -from typing import List -from typing import Optional - -from deepmd import __version__ -from deepmd.common import clear_session -from deepmd.entrypoints import compress -from deepmd.entrypoints import convert -from deepmd.entrypoints import doc_train_input -from deepmd.entrypoints import freeze -from deepmd.entrypoints import make_model_devi -from deepmd.entrypoints import neighbor_stat -from deepmd.entrypoints import test -from deepmd.entrypoints import train_dp -from deepmd.entrypoints import transfer -from deepmd.loggers import set_log_handles -from deepmd.nvnmd.entrypoints.train import train_nvnmd +from pathlib import ( + Path, +) +from typing import ( + List, + Optional, +) + +from deepmd import ( + __version__, +) +from deepmd.common import ( + clear_session, +) +from deepmd.entrypoints import ( + compress, + convert, + doc_train_input, + freeze, + make_model_devi, + neighbor_stat, + test, + train_dp, + transfer, +) +from deepmd.loggers import ( + set_log_handles, +) +from deepmd.nvnmd.entrypoints.train import ( + train_nvnmd, +) __all__ = ["main", "parse_args", "get_ll", "main_parser"] diff --git a/deepmd/entrypoints/neighbor_stat.py b/deepmd/entrypoints/neighbor_stat.py index bfc17fdea6..226f312621 100644 --- a/deepmd/entrypoints/neighbor_stat.py +++ b/deepmd/entrypoints/neighbor_stat.py @@ -1,9 +1,17 @@ import logging -from typing import List +from typing import ( + List, +) -from deepmd.common import expand_sys_str -from deepmd.utils.data_system import DeepmdDataSystem -from deepmd.utils.neighbor_stat import NeighborStat +from deepmd.common import ( + expand_sys_str, +) +from deepmd.utils.data_system import ( + DeepmdDataSystem, +) +from deepmd.utils.neighbor_stat import ( + NeighborStat, +) log = logging.getLogger(__name__) diff --git a/deepmd/entrypoints/test.py b/deepmd/entrypoints/test.py index 761862c330..ecab32aefb 100644 --- a/deepmd/entrypoints/test.py +++ b/deepmd/entrypoints/test.py @@ -1,27 +1,43 @@ """Test trained DeePMD model.""" import logging -from pathlib import Path -from typing import TYPE_CHECKING -from typing import Dict -from typing import List -from typing import Optional -from typing import Tuple +from pathlib import ( + Path, +) +from typing import ( + TYPE_CHECKING, + Dict, + List, + Optional, + Tuple, +) import numpy as np -from deepmd import DeepPotential -from deepmd.common import expand_sys_str +from deepmd import ( + DeepPotential, +) +from deepmd.common import ( + expand_sys_str, +) from deepmd.utils import random as dp_random -from deepmd.utils.data import DeepmdData -from deepmd.utils.weight_avg import weighted_average +from deepmd.utils.data import ( + DeepmdData, +) +from deepmd.utils.weight_avg import ( + weighted_average, +) if TYPE_CHECKING: - from deepmd.infer import DeepDipole - from deepmd.infer import DeepDOS - from deepmd.infer import DeepPolar - from deepmd.infer import DeepPot - from deepmd.infer import DeepWFC - from deepmd.infer.deep_tensor import DeepTensor + from deepmd.infer import ( + DeepDipole, + DeepDOS, + DeepPolar, + DeepPot, + DeepWFC, + ) + from deepmd.infer.deep_tensor import ( + DeepTensor, + ) __all__ = ["test"] diff --git a/deepmd/entrypoints/train.py b/deepmd/entrypoints/train.py index 9be8dc2895..472136a08e 100755 --- a/deepmd/entrypoints/train.py +++ b/deepmd/entrypoints/train.py @@ -6,31 +6,56 @@ import json import logging import time -from typing import Any -from typing import Dict -from typing import Optional - -from deepmd.common import data_requirement -from deepmd.common import expand_sys_str -from deepmd.common import j_loader -from deepmd.common import j_must_have -from deepmd.env import GLOBAL_ENER_FLOAT_PRECISION -from deepmd.env import reset_default_tf_session_config -from deepmd.env import tf -from deepmd.infer.data_modifier import DipoleChargeModifier -from deepmd.train.run_options import BUILD -from deepmd.train.run_options import CITATION -from deepmd.train.run_options import WELCOME -from deepmd.train.run_options import RunOptions -from deepmd.train.trainer import DPTrainer +from typing import ( + Any, + Dict, + Optional, +) + +from deepmd.common import ( + data_requirement, + expand_sys_str, + j_loader, + j_must_have, +) +from deepmd.env import ( + reset_default_tf_session_config, + tf, +) +from deepmd.infer.data_modifier import ( + DipoleChargeModifier, +) +from deepmd.train.run_options import ( + BUILD, + CITATION, + WELCOME, + RunOptions, +) +from deepmd.train.trainer import ( + DPTrainer, +) from deepmd.utils import random as dp_random -from deepmd.utils.argcheck import normalize -from deepmd.utils.compat import update_deepmd_input -from deepmd.utils.data_system import DeepmdDataSystem -from deepmd.utils.finetune import replace_model_params_with_pretrained_model -from deepmd.utils.multi_init import replace_model_params_with_frz_multi_model -from deepmd.utils.neighbor_stat import NeighborStat -from deepmd.utils.path import DPPath +from deepmd.utils.argcheck import ( + normalize, +) +from deepmd.utils.compat import ( + update_deepmd_input, +) +from deepmd.utils.data_system import ( + DeepmdDataSystem, +) +from deepmd.utils.finetune import ( + replace_model_params_with_pretrained_model, +) +from deepmd.utils.multi_init import ( + replace_model_params_with_frz_multi_model, +) +from deepmd.utils.neighbor_stat import ( + NeighborStat, +) +from deepmd.utils.path import ( + DPPath, +) __all__ = ["train"] diff --git a/deepmd/entrypoints/transfer.py b/deepmd/entrypoints/transfer.py index a067353e2c..8eeeb10653 100644 --- a/deepmd/entrypoints/transfer.py +++ b/deepmd/entrypoints/transfer.py @@ -2,14 +2,18 @@ import logging import re -from typing import Dict -from typing import Optional -from typing import Sequence +from typing import ( + Dict, + Optional, + Sequence, +) import numpy as np -from deepmd.env import TRANSFER_PATTERN -from deepmd.env import tf +from deepmd.env import ( + TRANSFER_PATTERN, + tf, +) __all__ = ["transfer"] diff --git a/deepmd/env.py b/deepmd/env.py index 78c48df19f..9eb7e1e6a8 100644 --- a/deepmd/env.py +++ b/deepmd/env.py @@ -4,20 +4,32 @@ import logging import os import platform -from configparser import ConfigParser -from importlib import import_module -from importlib import reload -from pathlib import Path -from typing import TYPE_CHECKING -from typing import Any -from typing import Dict -from typing import Tuple +from configparser import ( + ConfigParser, +) +from importlib import ( + import_module, + reload, +) +from pathlib import ( + Path, +) +from typing import ( + TYPE_CHECKING, + Any, + Dict, + Tuple, +) import numpy as np -from packaging.version import Version +from packaging.version import ( + Version, +) if TYPE_CHECKING: - from types import ModuleType + from types import ( + ModuleType, + ) def dlopen_library(module: str, filename: str): @@ -362,7 +374,6 @@ def get_module(module_name: str) -> "ModuleType": try: # module = tf.load_op_library(str(module_file)) import paddle_deepmd_lib - from paddle.utils import cpp_extension module = paddle_deepmd_lib diff --git a/deepmd/fit/__init__.py b/deepmd/fit/__init__.py index d5529c80e6..875c67cd5d 100644 --- a/deepmd/fit/__init__.py +++ b/deepmd/fit/__init__.py @@ -1,9 +1,19 @@ -from .dipole import DipoleFittingSeA -from .dos import DOSFitting -from .ener import EnerFitting -from .fitting import Fitting -from .polar import GlobalPolarFittingSeA -from .polar import PolarFittingSeA +from .dipole import ( + DipoleFittingSeA, +) +from .dos import ( + DOSFitting, +) +from .ener import ( + EnerFitting, +) +from .fitting import ( + Fitting, +) +from .polar import ( + GlobalPolarFittingSeA, + PolarFittingSeA, +) __all__ = [ "DipoleFittingSeA", diff --git a/deepmd/fit/dipole.py b/deepmd/fit/dipole.py index 52d68af480..9f497584ae 100644 --- a/deepmd/fit/dipole.py +++ b/deepmd/fit/dipole.py @@ -1,16 +1,28 @@ -from typing import List -from typing import Optional +from typing import ( + List, + Optional, +) import numpy as np -from deepmd.common import cast_precision -from deepmd.common import get_activation_func -from deepmd.common import get_precision -from deepmd.env import tf -from deepmd.fit.fitting import Fitting -from deepmd.utils.graph import get_fitting_net_variables_from_graph_def -from deepmd.utils.network import one_layer -from deepmd.utils.network import one_layer_rand_seed_shift +from deepmd.common import ( + cast_precision, + get_activation_func, + get_precision, +) +from deepmd.env import ( + tf, +) +from deepmd.fit.fitting import ( + Fitting, +) +from deepmd.utils.graph import ( + get_fitting_net_variables_from_graph_def, +) +from deepmd.utils.network import ( + one_layer, + one_layer_rand_seed_shift, +) @Fitting.register("dipole") diff --git a/deepmd/fit/dos.py b/deepmd/fit/dos.py index fa43634c16..4bb1838af1 100644 --- a/deepmd/fit/dos.py +++ b/deepmd/fit/dos.py @@ -1,23 +1,41 @@ import logging -from typing import List -from typing import Optional +from typing import ( + List, + Optional, +) import numpy as np -from deepmd.common import add_data_requirement -from deepmd.common import cast_precision -from deepmd.common import get_activation_func -from deepmd.common import get_precision -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import tf -from deepmd.fit.fitting import Fitting -from deepmd.nvnmd.fit.ener import one_layer_nvnmd -from deepmd.nvnmd.utils.config import nvnmd_cfg -from deepmd.utils.errors import GraphWithoutTensorError -from deepmd.utils.graph import get_fitting_net_variables_from_graph_def -from deepmd.utils.graph import get_tensor_by_name_from_graph +from deepmd.common import ( + add_data_requirement, + cast_precision, + get_activation_func, + get_precision, +) +from deepmd.env import ( + GLOBAL_TF_FLOAT_PRECISION, + tf, +) +from deepmd.fit.fitting import ( + Fitting, +) +from deepmd.nvnmd.fit.ener import ( + one_layer_nvnmd, +) +from deepmd.nvnmd.utils.config import ( + nvnmd_cfg, +) +from deepmd.utils.errors import ( + GraphWithoutTensorError, +) +from deepmd.utils.graph import ( + get_fitting_net_variables_from_graph_def, + get_tensor_by_name_from_graph, +) from deepmd.utils.network import one_layer as one_layer_deepmd -from deepmd.utils.network import one_layer_rand_seed_shift +from deepmd.utils.network import ( + one_layer_rand_seed_shift, +) log = logging.getLogger(__name__) diff --git a/deepmd/fit/ener.py b/deepmd/fit/ener.py index 959907a12a..eaac525c04 100644 --- a/deepmd/fit/ener.py +++ b/deepmd/fit/ener.py @@ -1,31 +1,42 @@ import logging -from typing import List -from typing import Optional +from typing import ( + List, + Optional, +) import numpy as np -from paddle import nn - -from deepmd.common import add_data_requirement -from deepmd.common import cast_precision -from deepmd.common import get_activation_func -from deepmd.common import get_precision -from deepmd.env import GLOBAL_PD_FLOAT_PRECISION -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import global_cvt_2_pd_float -from deepmd.env import global_cvt_2_tf_float -from deepmd.env import paddle -from deepmd.env import tf -from deepmd.fit.fitting import Fitting -from deepmd.infer import DeepPotential -from deepmd.nvnmd.fit.ener import one_layer_nvnmd -from deepmd.nvnmd.utils.config import nvnmd_cfg -from deepmd.utils.errors import GraphWithoutTensorError -from deepmd.utils.graph import get_fitting_net_variables_from_graph_def -from deepmd.utils.graph import get_tensor_by_name_from_graph +from paddle import ( + nn, +) + +from deepmd.common import ( + add_data_requirement, + get_activation_func, + get_precision, +) +from deepmd.env import ( + GLOBAL_PD_FLOAT_PRECISION, + global_cvt_2_pd_float, + paddle, + tf, +) +from deepmd.infer import ( + DeepPotential, +) +from deepmd.utils.errors import ( + GraphWithoutTensorError, +) +from deepmd.utils.graph import ( + get_fitting_net_variables_from_graph_def, + get_tensor_by_name_from_graph, +) from deepmd.utils.network import OneLayer as OneLayer_deepmd -from deepmd.utils.network import one_layer as one_layer_deepmd -from deepmd.utils.network import one_layer_rand_seed_shift -from deepmd.utils.spin import Spin +from deepmd.utils.network import ( + one_layer_rand_seed_shift, +) +from deepmd.utils.spin import ( + Spin, +) log = logging.getLogger(__name__) @@ -376,7 +387,6 @@ def compute_input_stats(self, all_stat: dict, protection: float = 1e-2) -> None: protection Divided-by-zero protection """ - # stat fparam if self.numb_fparam > 0: cat_data = np.concatenate(all_stat["fparam"], axis=0) diff --git a/deepmd/fit/ener_tf.py b/deepmd/fit/ener_tf.py index 1f77d2fdb6..aacdf5b67f 100644 --- a/deepmd/fit/ener_tf.py +++ b/deepmd/fit/ener_tf.py @@ -1,31 +1,57 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import logging -from typing import List -from typing import Optional +from typing import ( + List, + Optional, +) import numpy as np -from deepmd.common import add_data_requirement -from deepmd.common import cast_precision -from deepmd.common import get_activation_func -from deepmd.common import get_precision -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import global_cvt_2_tf_float -from deepmd.env import tf -from deepmd.fit.fitting import Fitting -from deepmd.infer import DeepPotential -from deepmd.loss.ener import EnerDipoleLoss -from deepmd.loss.ener import EnerSpinLoss -from deepmd.loss.ener import EnerStdLoss -from deepmd.loss.loss import Loss -from deepmd.nvnmd.fit.ener import one_layer_nvnmd -from deepmd.nvnmd.utils.config import nvnmd_cfg -from deepmd.utils.errors import GraphWithoutTensorError -from deepmd.utils.graph import get_fitting_net_variables_from_graph_def -from deepmd.utils.graph import get_tensor_by_name_from_graph +from deepmd.common import ( + add_data_requirement, + cast_precision, + get_activation_func, + get_precision, +) +from deepmd.env import ( + GLOBAL_TF_FLOAT_PRECISION, + global_cvt_2_tf_float, + tf, +) +from deepmd.fit.fitting import ( + Fitting, +) +from deepmd.infer import ( + DeepPotential, +) +from deepmd.loss.ener import ( + EnerDipoleLoss, + EnerSpinLoss, + EnerStdLoss, +) +from deepmd.loss.loss import ( + Loss, +) +from deepmd.nvnmd.fit.ener import ( + one_layer_nvnmd, +) +from deepmd.nvnmd.utils.config import ( + nvnmd_cfg, +) +from deepmd.utils.errors import ( + GraphWithoutTensorError, +) +from deepmd.utils.graph import ( + get_fitting_net_variables_from_graph_def, + get_tensor_by_name_from_graph, +) from deepmd.utils.network import one_layer as one_layer_deepmd -from deepmd.utils.network import one_layer_rand_seed_shift -from deepmd.utils.spin import Spin +from deepmd.utils.network import ( + one_layer_rand_seed_shift, +) +from deepmd.utils.spin import ( + Spin, +) log = logging.getLogger(__name__) diff --git a/deepmd/fit/fitting.py b/deepmd/fit/fitting.py index a2fd225c9c..b0a9efe3be 100644 --- a/deepmd/fit/fitting.py +++ b/deepmd/fit/fitting.py @@ -1,8 +1,14 @@ -from typing import Callable +from typing import ( + Callable, +) -from deepmd.env import tf -from deepmd.utils import Plugin -from deepmd.utils import PluginVariant +from deepmd.env import ( + tf, +) +from deepmd.utils import ( + Plugin, + PluginVariant, +) class Fitting(PluginVariant): diff --git a/deepmd/fit/polar.py b/deepmd/fit/polar.py index 8a36aa4ea5..42b8d155f5 100644 --- a/deepmd/fit/polar.py +++ b/deepmd/fit/polar.py @@ -1,18 +1,32 @@ import warnings -from typing import List -from typing import Optional +from typing import ( + List, + Optional, +) import numpy as np -from deepmd.common import cast_precision -from deepmd.common import get_activation_func -from deepmd.common import get_precision -from deepmd.descriptor import DescrptSeA -from deepmd.env import tf -from deepmd.fit.fitting import Fitting -from deepmd.utils.graph import get_fitting_net_variables_from_graph_def -from deepmd.utils.network import one_layer -from deepmd.utils.network import one_layer_rand_seed_shift +from deepmd.common import ( + cast_precision, + get_activation_func, + get_precision, +) +from deepmd.descriptor import ( + DescrptSeA, +) +from deepmd.env import ( + tf, +) +from deepmd.fit.fitting import ( + Fitting, +) +from deepmd.utils.graph import ( + get_fitting_net_variables_from_graph_def, +) +from deepmd.utils.network import ( + one_layer, + one_layer_rand_seed_shift, +) @Fitting.register("polar") diff --git a/deepmd/infer/__init__.py b/deepmd/infer/__init__.py index e974411ed9..f87541c889 100644 --- a/deepmd/infer/__init__.py +++ b/deepmd/infer/__init__.py @@ -1,18 +1,40 @@ """Submodule containing all the implemented potentials.""" -from pathlib import Path -from typing import Union +from pathlib import ( + Path, +) +from typing import ( + Union, +) -from .data_modifier import DipoleChargeModifier -from .deep_dipole import DeepDipole -from .deep_dos import DeepDOS -from .deep_eval import DeepEval -from .deep_polar import DeepGlobalPolar -from .deep_polar import DeepPolar -from .deep_pot import DeepPot -from .deep_wfc import DeepWFC -from .ewald_recp import EwaldRecp -from .model_devi import calc_model_devi +from .data_modifier import ( + DipoleChargeModifier, +) +from .deep_dipole import ( + DeepDipole, +) +from .deep_dos import ( + DeepDOS, +) +from .deep_eval import ( + DeepEval, +) +from .deep_polar import ( + DeepGlobalPolar, + DeepPolar, +) +from .deep_pot import ( + DeepPot, +) +from .deep_wfc import ( + DeepWFC, +) +from .ewald_recp import ( + EwaldRecp, +) +from .model_devi import ( + calc_model_devi, +) __all__ = [ "DeepPotential", diff --git a/deepmd/infer/data_modifier.py b/deepmd/infer/data_modifier.py index a552cc5b16..2da80c572b 100644 --- a/deepmd/infer/data_modifier.py +++ b/deepmd/infer/data_modifier.py @@ -1,18 +1,32 @@ import os -from typing import List -from typing import Tuple +from typing import ( + List, + Tuple, +) import numpy as np -from deepmd.common import make_default_mesh -from deepmd.common import select_idx_map -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import op_module -from deepmd.env import tf -from deepmd.infer.deep_dipole import DeepDipole -from deepmd.infer.ewald_recp import EwaldRecp -from deepmd.utils.data import DeepmdData -from deepmd.utils.sess import run_sess +from deepmd.common import ( + make_default_mesh, + select_idx_map, +) +from deepmd.env import ( + GLOBAL_TF_FLOAT_PRECISION, + op_module, + tf, +) +from deepmd.infer.deep_dipole import ( + DeepDipole, +) +from deepmd.infer.ewald_recp import ( + EwaldRecp, +) +from deepmd.utils.data import ( + DeepmdData, +) +from deepmd.utils.sess import ( + run_sess, +) class DipoleChargeModifier(DeepDipole): diff --git a/deepmd/infer/deep_dipole.py b/deepmd/infer/deep_dipole.py index 4b2384a152..e7eb1061de 100644 --- a/deepmd/infer/deep_dipole.py +++ b/deepmd/infer/deep_dipole.py @@ -1,9 +1,15 @@ -from typing import TYPE_CHECKING +from typing import ( + TYPE_CHECKING, +) -from deepmd.infer.deep_tensor import DeepTensor +from deepmd.infer.deep_tensor import ( + DeepTensor, +) if TYPE_CHECKING: - from pathlib import Path + from pathlib import ( + Path, + ) class DeepDipole(DeepTensor): diff --git a/deepmd/infer/deep_dos.py b/deepmd/infer/deep_dos.py index eb18c3fe69..2f6dc83d00 100644 --- a/deepmd/infer/deep_dos.py +++ b/deepmd/infer/deep_dos.py @@ -1,20 +1,32 @@ import logging -from typing import TYPE_CHECKING -from typing import Callable -from typing import List -from typing import Optional -from typing import Tuple -from typing import Union +from typing import ( + TYPE_CHECKING, + Callable, + List, + Optional, + Tuple, + Union, +) import numpy as np -from deepmd.common import make_default_mesh -from deepmd.infer.deep_eval import DeepEval -from deepmd.utils.batch_size import AutoBatchSize -from deepmd.utils.sess import run_sess +from deepmd.common import ( + make_default_mesh, +) +from deepmd.infer.deep_eval import ( + DeepEval, +) +from deepmd.utils.batch_size import ( + AutoBatchSize, +) +from deepmd.utils.sess import ( + run_sess, +) if TYPE_CHECKING: - from pathlib import Path + from pathlib import ( + Path, + ) log = logging.getLogger(__name__) diff --git a/deepmd/infer/deep_eval.py b/deepmd/infer/deep_eval.py index 410298993c..5b9b024a7d 100644 --- a/deepmd/infer/deep_eval.py +++ b/deepmd/infer/deep_eval.py @@ -1,29 +1,45 @@ -from functools import lru_cache -from typing import TYPE_CHECKING -from typing import List -from typing import Optional -from typing import Union +from functools import ( + lru_cache, +) +from typing import ( + TYPE_CHECKING, + List, + Optional, + Union, +) # from deepmd.descriptor.descriptor import ( # Descriptor, # ) import numpy as np -from deepmd.common import data_requirement -from deepmd.common import expand_sys_str -from deepmd.common import j_loader -from deepmd.common import j_must_have -from deepmd.descriptor import DescrptSeA -from deepmd.env import MODEL_VERSION -from deepmd.env import default_tf_session_config -from deepmd.env import paddle -from deepmd.env import tf -from deepmd.model import EnerModel -from deepmd.utils.batch_size import AutoBatchSize -from deepmd.utils.sess import run_sess +from deepmd.common import ( + j_loader, + j_must_have, +) +from deepmd.descriptor import ( + DescrptSeA, +) +from deepmd.env import ( + MODEL_VERSION, + default_tf_session_config, + paddle, + tf, +) +from deepmd.model import ( + EnerModel, +) +from deepmd.utils.batch_size import ( + AutoBatchSize, +) +from deepmd.utils.sess import ( + run_sess, +) if TYPE_CHECKING: - from pathlib import Path + from pathlib import ( + Path, + ) class DeepEval: @@ -81,7 +97,9 @@ def __init__( if not self.multi_task_mode else j_must_have(model_param, "fitting_net_dict") ) - from deepmd.fit import EnerFitting + from deepmd.fit import ( + EnerFitting, + ) # fitting_param.pop("type", None) fitting_param.pop("_comment", None) @@ -216,6 +234,7 @@ def _get_value( self, tensor_name: str, attr_name: Optional[str] = None ) -> tf.Tensor: """Get TF graph tensor and assign it to class namespace. + Parameters ---------- tensor_name : str @@ -223,10 +242,6 @@ def _get_value( attr_name : Optional[str], optional if specified, class attribute with this name will be created and tensor will be assigned to it, by default None - Returns - ------- - tf.Tensor - loaded tensor """ # do not use os.path.join as it doesn't work on Windows value = None diff --git a/deepmd/infer/deep_polar.py b/deepmd/infer/deep_polar.py index 6cb58cff7c..f08ea9f64b 100644 --- a/deepmd/infer/deep_polar.py +++ b/deepmd/infer/deep_polar.py @@ -1,13 +1,19 @@ -from typing import TYPE_CHECKING -from typing import List -from typing import Optional +from typing import ( + TYPE_CHECKING, + List, + Optional, +) import numpy as np -from deepmd.infer.deep_tensor import DeepTensor +from deepmd.infer.deep_tensor import ( + DeepTensor, +) if TYPE_CHECKING: - from pathlib import Path + from pathlib import ( + Path, + ) class DeepPolar(DeepTensor): diff --git a/deepmd/infer/deep_pot.py b/deepmd/infer/deep_pot.py index 1c91059944..efeaf55bc5 100644 --- a/deepmd/infer/deep_pot.py +++ b/deepmd/infer/deep_pot.py @@ -1,22 +1,35 @@ import logging -from typing import TYPE_CHECKING -from typing import Callable -from typing import List -from typing import Optional -from typing import Tuple -from typing import Union +from typing import ( + TYPE_CHECKING, + Callable, + List, + Optional, + Tuple, + Union, +) import numpy as np -from deepmd.common import make_default_mesh -from deepmd.env import paddle -from deepmd.infer.data_modifier import DipoleChargeModifier -from deepmd.infer.deep_eval import DeepEval -from deepmd.utils.batch_size import AutoBatchSize -from deepmd.utils.sess import run_sess +from deepmd.common import ( + make_default_mesh, +) +from deepmd.env import ( + paddle, +) +from deepmd.infer.deep_eval import ( + DeepEval, +) +from deepmd.utils.batch_size import ( + AutoBatchSize, +) +from deepmd.utils.sess import ( + run_sess, +) if TYPE_CHECKING: - from pathlib import Path + from pathlib import ( + Path, + ) log = logging.getLogger(__name__) diff --git a/deepmd/infer/deep_tensor.py b/deepmd/infer/deep_tensor.py index 8b31d91b2d..ca62b97385 100644 --- a/deepmd/infer/deep_tensor.py +++ b/deepmd/infer/deep_tensor.py @@ -1,16 +1,26 @@ -from typing import TYPE_CHECKING -from typing import List -from typing import Optional -from typing import Tuple +from typing import ( + TYPE_CHECKING, + List, + Optional, + Tuple, +) import numpy as np -from deepmd.common import make_default_mesh -from deepmd.infer.deep_eval import DeepEval -from deepmd.utils.sess import run_sess +from deepmd.common import ( + make_default_mesh, +) +from deepmd.infer.deep_eval import ( + DeepEval, +) +from deepmd.utils.sess import ( + run_sess, +) if TYPE_CHECKING: - from pathlib import Path + from pathlib import ( + Path, + ) class DeepTensor(DeepEval): diff --git a/deepmd/infer/deep_wfc.py b/deepmd/infer/deep_wfc.py index 090ead5a33..36a77de35e 100644 --- a/deepmd/infer/deep_wfc.py +++ b/deepmd/infer/deep_wfc.py @@ -1,9 +1,15 @@ -from typing import TYPE_CHECKING +from typing import ( + TYPE_CHECKING, +) -from deepmd.infer.deep_tensor import DeepTensor +from deepmd.infer.deep_tensor import ( + DeepTensor, +) if TYPE_CHECKING: - from pathlib import Path + from pathlib import ( + Path, + ) class DeepWFC(DeepTensor): diff --git a/deepmd/infer/ewald_recp.py b/deepmd/infer/ewald_recp.py index 405756d7a7..6db1d63520 100644 --- a/deepmd/infer/ewald_recp.py +++ b/deepmd/infer/ewald_recp.py @@ -1,12 +1,18 @@ -from typing import Tuple +from typing import ( + Tuple, +) import numpy as np -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import default_tf_session_config -from deepmd.env import op_module -from deepmd.env import tf -from deepmd.utils.sess import run_sess +from deepmd.env import ( + GLOBAL_TF_FLOAT_PRECISION, + default_tf_session_config, + op_module, + tf, +) +from deepmd.utils.sess import ( + run_sess, +) class EwaldRecp: diff --git a/deepmd/infer/model_devi.py b/deepmd/infer/model_devi.py index 8736573d73..114fb14f30 100644 --- a/deepmd/infer/model_devi.py +++ b/deepmd/infer/model_devi.py @@ -1,12 +1,22 @@ -from typing import Tuple +from typing import ( + Tuple, +) import numpy as np -from deepmd.common import expand_sys_str - -from ..utils.batch_size import AutoBatchSize -from ..utils.data import DeepmdData -from .deep_pot import DeepPot +from deepmd.common import ( + expand_sys_str, +) + +from ..utils.batch_size import ( + AutoBatchSize, +) +from ..utils.data import ( + DeepmdData, +) +from .deep_pot import ( + DeepPot, +) def calc_model_devi_f(fs: np.ndarray) -> Tuple[np.ndarray]: diff --git a/deepmd/lmp.py b/deepmd/lmp.py index 0f6be85f04..72321832af 100644 --- a/deepmd/lmp.py +++ b/deepmd/lmp.py @@ -1,18 +1,30 @@ """Register entry points for lammps-wheel.""" import os import platform -from importlib import import_module -from pathlib import Path -from typing import List -from typing import Optional +from importlib import ( + import_module, +) +from pathlib import ( + Path, +) +from typing import ( + List, + Optional, +) -from packaging.version import Version +from packaging.version import ( + Version, +) -from deepmd.env import TF_VERSION -from deepmd.env import tf +from deepmd.env import ( + TF_VERSION, + tf, +) if Version(TF_VERSION) < Version("2.12"): - from find_libpython import find_libpython + from find_libpython import ( + find_libpython, + ) else: find_libpython = None diff --git a/deepmd/loggers/__init__.py b/deepmd/loggers/__init__.py index 8eb1868ae3..f9cf3087e6 100644 --- a/deepmd/loggers/__init__.py +++ b/deepmd/loggers/__init__.py @@ -1,5 +1,7 @@ """Module taking care of logging duties.""" -from .loggers import set_log_handles +from .loggers import ( + set_log_handles, +) __all__ = ["set_log_handles"] diff --git a/deepmd/loggers/loggers.py b/deepmd/loggers/loggers.py index 3fff9fd2fd..9fe9530482 100644 --- a/deepmd/loggers/loggers.py +++ b/deepmd/loggers/loggers.py @@ -2,13 +2,19 @@ import logging import os -from typing import TYPE_CHECKING -from typing import Optional +from typing import ( + TYPE_CHECKING, + Optional, +) if TYPE_CHECKING: - from pathlib import Path + from pathlib import ( + Path, + ) - from mpi4py import MPI + from mpi4py import ( + MPI, + ) _MPI_APPEND_MODE = MPI.MODE_CREATE | MPI.MODE_APPEND @@ -200,7 +206,9 @@ def set_log_handles( MPI = None if mpi_log: try: - from mpi4py import MPI + from mpi4py import ( + MPI, + ) except ImportError as e: raise RuntimeError( "You cannot specify 'mpi_log' when mpi4py not installed" diff --git a/deepmd/loss/__init__.py b/deepmd/loss/__init__.py index d4d82a1c69..bfd6e57397 100644 --- a/deepmd/loss/__init__.py +++ b/deepmd/loss/__init__.py @@ -1,8 +1,14 @@ -from .dos import DOSLoss -from .ener import EnerDipoleLoss -from .ener import EnerSpinLoss -from .ener import EnerStdLoss -from .tensor import TensorLoss +from .dos import ( + DOSLoss, +) +from .ener import ( + EnerDipoleLoss, + EnerSpinLoss, + EnerStdLoss, +) +from .tensor import ( + TensorLoss, +) __all__ = [ "EnerDipoleLoss", diff --git a/deepmd/loss/dos.py b/deepmd/loss/dos.py index 3373345a95..5a7e67e29c 100644 --- a/deepmd/loss/dos.py +++ b/deepmd/loss/dos.py @@ -1,12 +1,20 @@ import numpy as np -from deepmd.common import add_data_requirement -from deepmd.env import global_cvt_2_ener_float -from deepmd.env import global_cvt_2_tf_float -from deepmd.env import tf -from deepmd.utils.sess import run_sess - -from .loss import Loss +from deepmd.common import ( + add_data_requirement, +) +from deepmd.env import ( + global_cvt_2_ener_float, + global_cvt_2_tf_float, + tf, +) +from deepmd.utils.sess import ( + run_sess, +) + +from .loss import ( + Loss, +) class DOSLoss(Loss): diff --git a/deepmd/loss/ener.py b/deepmd/loss/ener.py index e1e7d89626..b0d453919d 100644 --- a/deepmd/loss/ener.py +++ b/deepmd/loss/ener.py @@ -1,16 +1,25 @@ -from typing import Optional +from typing import ( + Optional, +) import numpy as np -from deepmd.common import add_data_requirement -from deepmd.env import global_cvt_2_ener_float -from deepmd.env import global_cvt_2_pd_float -from deepmd.env import global_cvt_2_tf_float -from deepmd.env import paddle -from deepmd.env import tf -from deepmd.utils.sess import run_sess - -from .loss import Loss +from deepmd.common import ( + add_data_requirement, +) +from deepmd.env import ( + global_cvt_2_ener_float, + global_cvt_2_tf_float, + paddle, + tf, +) +from deepmd.utils.sess import ( + run_sess, +) + +from .loss import ( + Loss, +) class EnerStdLoss(Loss): diff --git a/deepmd/loss/loss.py b/deepmd/loss/loss.py index 7a9d55e106..423d9e118d 100644 --- a/deepmd/loss/loss.py +++ b/deepmd/loss/loss.py @@ -1,9 +1,15 @@ -from abc import ABCMeta -from abc import abstractmethod -from typing import Dict -from typing import Tuple +from abc import ( + ABCMeta, + abstractmethod, +) +from typing import ( + Dict, + Tuple, +) -from deepmd.env import tf +from deepmd.env import ( + tf, +) class Loss(metaclass=ABCMeta): diff --git a/deepmd/loss/tensor.py b/deepmd/loss/tensor.py index ff28b78ed5..e261be2bb1 100644 --- a/deepmd/loss/tensor.py +++ b/deepmd/loss/tensor.py @@ -1,11 +1,19 @@ import numpy as np -from deepmd.common import add_data_requirement -from deepmd.env import global_cvt_2_tf_float -from deepmd.env import tf -from deepmd.utils.sess import run_sess - -from .loss import Loss +from deepmd.common import ( + add_data_requirement, +) +from deepmd.env import ( + global_cvt_2_tf_float, + tf, +) +from deepmd.utils.sess import ( + run_sess, +) + +from .loss import ( + Loss, +) class TensorLoss(Loss): diff --git a/deepmd/model/__init__.py b/deepmd/model/__init__.py index 423b6d2bcb..43f4b4a3a9 100644 --- a/deepmd/model/__init__.py +++ b/deepmd/model/__init__.py @@ -1,10 +1,18 @@ -from .dos import DOSModel -from .ener import EnerModel -from .multi import MultiModel -from .tensor import DipoleModel -from .tensor import GlobalPolarModel -from .tensor import PolarModel -from .tensor import WFCModel +from .dos import ( + DOSModel, +) +from .ener import ( + EnerModel, +) +from .multi import ( + MultiModel, +) +from .tensor import ( + DipoleModel, + GlobalPolarModel, + PolarModel, + WFCModel, +) __all__ = [ "EnerModel", diff --git a/deepmd/model/dos.py b/deepmd/model/dos.py index 911104433e..0da709409f 100644 --- a/deepmd/model/dos.py +++ b/deepmd/model/dos.py @@ -1,13 +1,21 @@ -from typing import List -from typing import Optional - -from deepmd.env import MODEL_VERSION -from deepmd.env import global_cvt_2_ener_float -from deepmd.env import tf - -from .model import Model -from .model_stat import make_stat_input -from .model_stat import merge_sys_stat +from typing import ( + List, + Optional, +) + +from deepmd.env import ( + MODEL_VERSION, + global_cvt_2_ener_float, + tf, +) + +from .model import ( + Model, +) +from .model_stat import ( + make_stat_input, + merge_sys_stat, +) class DOSModel(Model): diff --git a/deepmd/model/ener.py b/deepmd/model/ener.py index 6e9ef36de5..10f26f597e 100644 --- a/deepmd/model/ener.py +++ b/deepmd/model/ener.py @@ -1,23 +1,33 @@ -from typing import TYPE_CHECKING -from typing import List -from typing import Optional - -import numpy as np - -from deepmd.env import MODEL_VERSION -from deepmd.env import global_cvt_2_ener_float -from deepmd.env import op_module -from deepmd.env import paddle -from deepmd.env import tf -from deepmd.utils.pair_tab import PairTab -from deepmd.utils.spin import Spin - -from .model import Model -from .model_stat import make_stat_input -from .model_stat import merge_sys_stat +from typing import ( + TYPE_CHECKING, + List, + Optional, +) + +from deepmd.env import ( + MODEL_VERSION, + paddle, + tf, +) +from deepmd.utils.pair_tab import ( + PairTab, +) +from deepmd.utils.spin import ( + Spin, +) + +from .model import ( + Model, +) +from .model_stat import ( + make_stat_input, + merge_sys_stat, +) if TYPE_CHECKING: - from deepmd.fit import ener + from deepmd.fit import ( + ener, + ) class EnerModel(Model, paddle.nn.Layer): diff --git a/deepmd/model/model.py b/deepmd/model/model.py index 660e30dbce..7c07e1d987 100644 --- a/deepmd/model/model.py +++ b/deepmd/model/model.py @@ -1,13 +1,22 @@ -from abc import ABC -from abc import abstractmethod -from enum import Enum -from typing import List -from typing import Optional -from typing import Union +from abc import ( + ABC, +) +from enum import ( + Enum, +) +from typing import ( + List, + Optional, + Union, +) -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import tf -from deepmd.utils.graph import load_graph_def +from deepmd.env import ( + GLOBAL_TF_FLOAT_PRECISION, + tf, +) +from deepmd.utils.graph import ( + load_graph_def, +) class Model(ABC): diff --git a/deepmd/model/model_stat.py b/deepmd/model/model_stat.py index 764f592414..28f0eb4f1d 100644 --- a/deepmd/model/model_stat.py +++ b/deepmd/model/model_stat.py @@ -1,4 +1,6 @@ -from collections import defaultdict +from collections import ( + defaultdict, +) import numpy as np diff --git a/deepmd/model/multi.py b/deepmd/model/multi.py index 7e616d050e..dcf7566f36 100644 --- a/deepmd/model/multi.py +++ b/deepmd/model/multi.py @@ -1,19 +1,31 @@ import json -from typing import List -from typing import Optional +from typing import ( + List, + Optional, +) import numpy as np -from deepmd.env import MODEL_VERSION -from deepmd.env import global_cvt_2_ener_float -from deepmd.env import op_module -from deepmd.env import tf -from deepmd.utils.graph import get_tensor_by_name_from_graph -from deepmd.utils.pair_tab import PairTab - -from .model import Model -from .model_stat import make_stat_input -from .model_stat import merge_sys_stat +from deepmd.env import ( + MODEL_VERSION, + global_cvt_2_ener_float, + op_module, + tf, +) +from deepmd.utils.graph import ( + get_tensor_by_name_from_graph, +) +from deepmd.utils.pair_tab import ( + PairTab, +) + +from .model import ( + Model, +) +from .model_stat import ( + make_stat_input, + merge_sys_stat, +) class MultiModel(Model): diff --git a/deepmd/model/tensor.py b/deepmd/model/tensor.py index bff3af526f..eb32fa88cf 100644 --- a/deepmd/model/tensor.py +++ b/deepmd/model/tensor.py @@ -1,12 +1,20 @@ -from typing import List -from typing import Optional - -from deepmd.env import MODEL_VERSION -from deepmd.env import tf - -from .model import Model -from .model_stat import make_stat_input -from .model_stat import merge_sys_stat +from typing import ( + List, + Optional, +) + +from deepmd.env import ( + MODEL_VERSION, + tf, +) + +from .model import ( + Model, +) +from .model_stat import ( + make_stat_input, + merge_sys_stat, +) class TensorModel(Model): diff --git a/deepmd/nvnmd/__init__.py b/deepmd/nvnmd/__init__.py index bb3be2895b..f598ff416a 100644 --- a/deepmd/nvnmd/__init__.py +++ b/deepmd/nvnmd/__init__.py @@ -1,8 +1,10 @@ -from . import data -from . import descriptor -from . import entrypoints -from . import fit -from . import utils +from . import ( + data, + descriptor, + entrypoints, + fit, + utils, +) __all__ = [ "data", diff --git a/deepmd/nvnmd/descriptor/se_a.py b/deepmd/nvnmd/descriptor/se_a.py index ba8fb312aa..a18d8b85c9 100644 --- a/deepmd/nvnmd/descriptor/se_a.py +++ b/deepmd/nvnmd/descriptor/se_a.py @@ -2,16 +2,26 @@ import numpy as np -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import op_module -from deepmd.env import tf +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + GLOBAL_TF_FLOAT_PRECISION, + op_module, + tf, +) # -from deepmd.nvnmd.utils.config import nvnmd_cfg -from deepmd.nvnmd.utils.weight import get_normalize -from deepmd.utils.graph import get_tensor_by_name_from_graph -from deepmd.utils.network import embedding_net +from deepmd.nvnmd.utils.config import ( + nvnmd_cfg, +) +from deepmd.nvnmd.utils.weight import ( + get_normalize, +) +from deepmd.utils.graph import ( + get_tensor_by_name_from_graph, +) +from deepmd.utils.network import ( + embedding_net, +) log = logging.getLogger(__name__) diff --git a/deepmd/nvnmd/entrypoints/__init__.py b/deepmd/nvnmd/entrypoints/__init__.py index 5c61662405..6f737c710b 100644 --- a/deepmd/nvnmd/entrypoints/__init__.py +++ b/deepmd/nvnmd/entrypoints/__init__.py @@ -1,5 +1,11 @@ -from .freeze import save_weight -from .mapt import MapTable -from .wrap import Wrap +from .freeze import ( + save_weight, +) +from .mapt import ( + MapTable, +) +from .wrap import ( + Wrap, +) __all__ = ["save_weight", "MapTable", "Wrap"] diff --git a/deepmd/nvnmd/entrypoints/freeze.py b/deepmd/nvnmd/entrypoints/freeze.py index d15cad6e44..019b2f3382 100644 --- a/deepmd/nvnmd/entrypoints/freeze.py +++ b/deepmd/nvnmd/entrypoints/freeze.py @@ -1,8 +1,14 @@ #!/usr/bin/env python3 -from deepmd.env import tf -from deepmd.nvnmd.utils.fio import FioDic -from deepmd.utils.graph import get_tensor_by_name_from_graph +from deepmd.env import ( + tf, +) +from deepmd.nvnmd.utils.fio import ( + FioDic, +) +from deepmd.utils.graph import ( + get_tensor_by_name_from_graph, +) def filter_tensorVariableList(tensorVariableList) -> dict: diff --git a/deepmd/nvnmd/entrypoints/mapt.py b/deepmd/nvnmd/entrypoints/mapt.py index 8ca097d40d..50664a9552 100644 --- a/deepmd/nvnmd/entrypoints/mapt.py +++ b/deepmd/nvnmd/entrypoints/mapt.py @@ -1,18 +1,34 @@ import logging -from typing import Optional +from typing import ( + Optional, +) import numpy as np -from deepmd.env import op_module -from deepmd.env import tf -from deepmd.nvnmd.data.data import jdata_deepmd_input -from deepmd.nvnmd.data.data import jdata_sys -from deepmd.nvnmd.utils.config import nvnmd_cfg -from deepmd.nvnmd.utils.fio import FioDic -from deepmd.nvnmd.utils.network import get_sess -from deepmd.nvnmd.utils.weight import get_filter_weight -from deepmd.nvnmd.utils.weight import get_normalize -from deepmd.utils.sess import run_sess +from deepmd.env import ( + op_module, + tf, +) +from deepmd.nvnmd.data.data import ( + jdata_deepmd_input, + jdata_sys, +) +from deepmd.nvnmd.utils.config import ( + nvnmd_cfg, +) +from deepmd.nvnmd.utils.fio import ( + FioDic, +) +from deepmd.nvnmd.utils.network import ( + get_sess, +) +from deepmd.nvnmd.utils.weight import ( + get_filter_weight, + get_normalize, +) +from deepmd.utils.sess import ( + run_sess, +) log = logging.getLogger(__name__) diff --git a/deepmd/nvnmd/entrypoints/train.py b/deepmd/nvnmd/entrypoints/train.py index 2d9863dbfd..b311ea7819 100644 --- a/deepmd/nvnmd/entrypoints/train.py +++ b/deepmd/nvnmd/entrypoints/train.py @@ -1,15 +1,33 @@ import logging import os -from typing import Optional +from typing import ( + Optional, +) -from deepmd.entrypoints.freeze import freeze -from deepmd.entrypoints.train import train -from deepmd.env import tf -from deepmd.nvnmd.data.data import jdata_deepmd_input -from deepmd.nvnmd.entrypoints.mapt import mapt -from deepmd.nvnmd.entrypoints.wrap import wrap -from deepmd.nvnmd.utils.config import nvnmd_cfg -from deepmd.nvnmd.utils.fio import FioDic +from deepmd.entrypoints.freeze import ( + freeze, +) +from deepmd.entrypoints.train import ( + train, +) +from deepmd.env import ( + tf, +) +from deepmd.nvnmd.data.data import ( + jdata_deepmd_input, +) +from deepmd.nvnmd.entrypoints.mapt import ( + mapt, +) +from deepmd.nvnmd.entrypoints.wrap import ( + wrap, +) +from deepmd.nvnmd.utils.config import ( + nvnmd_cfg, +) +from deepmd.nvnmd.utils.fio import ( + FioDic, +) log = logging.getLogger(__name__) diff --git a/deepmd/nvnmd/entrypoints/wrap.py b/deepmd/nvnmd/entrypoints/wrap.py index e326de509c..4bf12803f2 100644 --- a/deepmd/nvnmd/entrypoints/wrap.py +++ b/deepmd/nvnmd/entrypoints/wrap.py @@ -1,19 +1,37 @@ import logging -from typing import Optional +from typing import ( + Optional, +) import numpy as np -from deepmd.env import op_module -from deepmd.env import tf -from deepmd.nvnmd.data.data import jdata_deepmd_input -from deepmd.nvnmd.data.data import jdata_sys -from deepmd.nvnmd.utils.config import nvnmd_cfg -from deepmd.nvnmd.utils.encode import Encode -from deepmd.nvnmd.utils.fio import FioBin -from deepmd.nvnmd.utils.fio import FioTxt -from deepmd.nvnmd.utils.network import get_sess -from deepmd.nvnmd.utils.weight import get_fitnet_weight -from deepmd.utils.sess import run_sess +from deepmd.env import ( + op_module, + tf, +) +from deepmd.nvnmd.data.data import ( + jdata_deepmd_input, + jdata_sys, +) +from deepmd.nvnmd.utils.config import ( + nvnmd_cfg, +) +from deepmd.nvnmd.utils.encode import ( + Encode, +) +from deepmd.nvnmd.utils.fio import ( + FioBin, + FioTxt, +) +from deepmd.nvnmd.utils.network import ( + get_sess, +) +from deepmd.nvnmd.utils.weight import ( + get_fitnet_weight, +) +from deepmd.utils.sess import ( + run_sess, +) log = logging.getLogger(__name__) diff --git a/deepmd/nvnmd/fit/ener.py b/deepmd/nvnmd/fit/ener.py index 8a2cc69c8e..9a250af82d 100644 --- a/deepmd/nvnmd/fit/ener.py +++ b/deepmd/nvnmd/fit/ener.py @@ -1,6 +1,10 @@ -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import tf -from deepmd.nvnmd.utils.config import nvnmd_cfg +from deepmd.env import ( + GLOBAL_TF_FLOAT_PRECISION, + tf, +) +from deepmd.nvnmd.utils.config import ( + nvnmd_cfg, +) from deepmd.nvnmd.utils.network import one_layer as one_layer_nvnmd __all__ = [ diff --git a/deepmd/nvnmd/utils/__init__.py b/deepmd/nvnmd/utils/__init__.py index 8e35d0e88a..4e201d917e 100644 --- a/deepmd/nvnmd/utils/__init__.py +++ b/deepmd/nvnmd/utils/__init__.py @@ -1,13 +1,27 @@ -from .argcheck import nvnmd_args -from .config import nvnmd_cfg -from .encode import Encode -from .fio import FioBin -from .fio import FioDic -from .fio import FioTxt -from .network import one_layer -from .op import map_nvnmd -from .weight import get_filter_weight -from .weight import get_fitnet_weight +from .argcheck import ( + nvnmd_args, +) +from .config import ( + nvnmd_cfg, +) +from .encode import ( + Encode, +) +from .fio import ( + FioBin, + FioDic, + FioTxt, +) +from .network import ( + one_layer, +) +from .op import ( + map_nvnmd, +) +from .weight import ( + get_filter_weight, + get_fitnet_weight, +) __all__ = [ "nvnmd_args", diff --git a/deepmd/nvnmd/utils/argcheck.py b/deepmd/nvnmd/utils/argcheck.py index e91e135706..a53dae0d5a 100644 --- a/deepmd/nvnmd/utils/argcheck.py +++ b/deepmd/nvnmd/utils/argcheck.py @@ -1,4 +1,6 @@ -from dargs import Argument +from dargs import ( + Argument, +) def nvnmd_args(): diff --git a/deepmd/nvnmd/utils/config.py b/deepmd/nvnmd/utils/config.py index 32b885d7ec..9d756f8ef1 100644 --- a/deepmd/nvnmd/utils/config.py +++ b/deepmd/nvnmd/utils/config.py @@ -2,13 +2,19 @@ import numpy as np -from deepmd.nvnmd.data.data import NVNMD_CITATION -from deepmd.nvnmd.data.data import NVNMD_WELCOME -from deepmd.nvnmd.data.data import jdata_config -from deepmd.nvnmd.data.data import jdata_configs -from deepmd.nvnmd.data.data import jdata_deepmd_input -from deepmd.nvnmd.utils.fio import FioDic -from deepmd.nvnmd.utils.op import r2s +from deepmd.nvnmd.data.data import ( + NVNMD_CITATION, + NVNMD_WELCOME, + jdata_config, + jdata_configs, + jdata_deepmd_input, +) +from deepmd.nvnmd.utils.fio import ( + FioDic, +) +from deepmd.nvnmd.utils.op import ( + r2s, +) log = logging.getLogger(__name__) diff --git a/deepmd/nvnmd/utils/encode.py b/deepmd/nvnmd/utils/encode.py index 905fa638c5..75cd629847 100644 --- a/deepmd/nvnmd/utils/encode.py +++ b/deepmd/nvnmd/utils/encode.py @@ -2,7 +2,9 @@ import numpy as np -from deepmd.nvnmd.data.data import jdata_sys +from deepmd.nvnmd.data.data import ( + jdata_sys, +) log = logging.getLogger(__name__) diff --git a/deepmd/nvnmd/utils/fio.py b/deepmd/nvnmd/utils/fio.py index 04420a84c0..8493bfd15d 100644 --- a/deepmd/nvnmd/utils/fio.py +++ b/deepmd/nvnmd/utils/fio.py @@ -2,7 +2,9 @@ import logging import os import struct -from typing import List +from typing import ( + List, +) import numpy as np diff --git a/deepmd/nvnmd/utils/network.py b/deepmd/nvnmd/utils/network.py index 9dba82ea7b..cf727b3eec 100644 --- a/deepmd/nvnmd/utils/network.py +++ b/deepmd/nvnmd/utils/network.py @@ -2,12 +2,20 @@ import numpy as np -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import op_module -from deepmd.env import tf -from deepmd.nvnmd.utils.config import nvnmd_cfg -from deepmd.nvnmd.utils.weight import get_constant_initializer -from deepmd.utils.network import variable_summaries +from deepmd.env import ( + GLOBAL_TF_FLOAT_PRECISION, + op_module, + tf, +) +from deepmd.nvnmd.utils.config import ( + nvnmd_cfg, +) +from deepmd.nvnmd.utils.weight import ( + get_constant_initializer, +) +from deepmd.utils.network import ( + variable_summaries, +) log = logging.getLogger(__name__) diff --git a/deepmd/nvnmd/utils/weight.py b/deepmd/nvnmd/utils/weight.py index b9a880a434..77208d0d0a 100644 --- a/deepmd/nvnmd/utils/weight.py +++ b/deepmd/nvnmd/utils/weight.py @@ -1,6 +1,8 @@ import logging -from deepmd.env import tf +from deepmd.env import ( + tf, +) log = logging.getLogger(__name__) diff --git a/deepmd/op/__init__.py b/deepmd/op/__init__.py index eac431c247..cf7b8a90ea 100644 --- a/deepmd/op/__init__.py +++ b/deepmd/op/__init__.py @@ -2,7 +2,9 @@ import importlib import logging -from pathlib import Path +from pathlib import ( + Path, +) NOT_LOADABLE = ("__init__.py",) PACKAGE_BASE = "deepmd.op" diff --git a/deepmd/paddle_ops.egg-info/SOURCES.txt b/deepmd/paddle_ops.egg-info/SOURCES.txt index 8933b93cb1..076f6385f2 100644 --- a/deepmd/paddle_ops.egg-info/SOURCES.txt +++ b/deepmd/paddle_ops.egg-info/SOURCES.txt @@ -9,4 +9,4 @@ paddle_ops.egg-info/PKG-INFO paddle_ops.egg-info/SOURCES.txt paddle_ops.egg-info/dependency_links.txt paddle_ops.egg-info/not-zip-safe -paddle_ops.egg-info/top_level.txt \ No newline at end of file +paddle_ops.egg-info/top_level.txt diff --git a/deepmd/paddle_ops.egg-info/dependency_links.txt b/deepmd/paddle_ops.egg-info/dependency_links.txt index 8b13789179..e69de29bb2 100644 --- a/deepmd/paddle_ops.egg-info/dependency_links.txt +++ b/deepmd/paddle_ops.egg-info/dependency_links.txt @@ -1 +0,0 @@ - diff --git a/deepmd/paddle_ops.egg-info/not-zip-safe b/deepmd/paddle_ops.egg-info/not-zip-safe index 8b13789179..e69de29bb2 100644 --- a/deepmd/paddle_ops.egg-info/not-zip-safe +++ b/deepmd/paddle_ops.egg-info/not-zip-safe @@ -1 +0,0 @@ - diff --git a/deepmd/train/run_options.py b/deepmd/train/run_options.py index 6c859919b1..e62ee7ef63 100644 --- a/deepmd/train/run_options.py +++ b/deepmd/train/run_options.py @@ -2,17 +2,27 @@ import logging import os -from pathlib import Path -from typing import TYPE_CHECKING -from typing import List -from typing import Optional - -from deepmd.cluster import get_resource -from deepmd.env import GLOBAL_CONFIG -from deepmd.env import get_tf_default_nthreads -from deepmd.env import global_float_prec -from deepmd.env import tf -from deepmd.loggers import set_log_handles +from pathlib import ( + Path, +) +from typing import ( + TYPE_CHECKING, + List, + Optional, +) + +from deepmd.cluster import ( + get_resource, +) +from deepmd.env import ( + GLOBAL_CONFIG, + get_tf_default_nthreads, + global_float_prec, + tf, +) +from deepmd.loggers import ( + set_log_handles, +) if TYPE_CHECKING: import horovod.tensorflow as HVD diff --git a/deepmd/train/trainer.py b/deepmd/train/trainer.py index b47248e4bf..44ab53fabe 100644 --- a/deepmd/train/trainer.py +++ b/deepmd/train/trainer.py @@ -1,60 +1,82 @@ #!/usr/bin/env python3 -import glob import logging import os -import platform -import shutil import time -from typing import Dict -from typing import List +from typing import ( + Dict, + List, +) -import google.protobuf.message import numpy as np -from packaging.version import Version -from tensorflow.python.client import timeline +from packaging.version import ( + Version, +) # load grad of force module import deepmd.op # noqa: F401 -from deepmd.common import data_requirement -from deepmd.common import get_precision -from deepmd.common import j_must_have -from deepmd.descriptor.descriptor import Descriptor -from deepmd.env import GLOBAL_ENER_FLOAT_PRECISION -from deepmd.env import GLOBAL_PD_FLOAT_PRECISION -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import TF_VERSION -from deepmd.env import get_tf_session_config -from deepmd.env import paddle -from deepmd.env import tf -from deepmd.env import tfv2 -from deepmd.fit import Fitting -from deepmd.fit import ener -from deepmd.loss import DOSLoss -from deepmd.loss import EnerDipoleLoss -from deepmd.loss import EnerSpinLoss -from deepmd.loss import EnerStdLoss -from deepmd.loss import TensorLoss -from deepmd.model import DipoleModel -from deepmd.model import DOSModel -from deepmd.model import EnerModel -from deepmd.model import MultiModel -from deepmd.model import PolarModel -from deepmd.utils import random as dp_random -from deepmd.utils.argcheck import type_embedding_args -from deepmd.utils.data_system import DeepmdDataSystem -from deepmd.utils.errors import GraphTooLargeError -from deepmd.utils.errors import GraphWithoutTensorError -from deepmd.utils.graph import get_tensor_by_name_from_graph -from deepmd.utils.graph import load_graph_def -from deepmd.utils.learning_rate import LearningRateExp -from deepmd.utils.sess import run_sess -from deepmd.utils.spin import Spin -from deepmd.utils.type_embed import TypeEmbedNet +from deepmd.common import ( + data_requirement, + get_precision, + j_must_have, +) +from deepmd.env import ( + GLOBAL_ENER_FLOAT_PRECISION, + GLOBAL_TF_FLOAT_PRECISION, + TF_VERSION, + get_tf_session_config, + paddle, + tf, +) +from deepmd.fit import ( + Fitting, + ener, +) +from deepmd.loss import ( + DOSLoss, + EnerDipoleLoss, + EnerSpinLoss, + EnerStdLoss, + TensorLoss, +) +from deepmd.model import ( + DipoleModel, + DOSModel, + EnerModel, + MultiModel, + PolarModel, +) +from deepmd.utils.argcheck import ( + type_embedding_args, +) +from deepmd.utils.data_system import ( + DeepmdDataSystem, +) +from deepmd.utils.errors import ( + GraphWithoutTensorError, +) +from deepmd.utils.graph import ( + get_tensor_by_name_from_graph, + load_graph_def, +) +from deepmd.utils.learning_rate import ( + LearningRateExp, +) +from deepmd.utils.sess import ( + run_sess, +) +from deepmd.utils.spin import ( + Spin, +) +from deepmd.utils.type_embed import ( + TypeEmbedNet, +) log = logging.getLogger(__name__) # nvnmd -from deepmd.nvnmd.utils.config import nvnmd_cfg +from deepmd.nvnmd.utils.config import ( + nvnmd_cfg, +) def _is_subdir(path, directory): diff --git a/deepmd/utils/__init__.py b/deepmd/utils/__init__.py index 75b8b25b51..e7b79e1f28 100644 --- a/deepmd/utils/__init__.py +++ b/deepmd/utils/__init__.py @@ -1,10 +1,20 @@ # -from .data import DeepmdData -from .data_system import DeepmdDataSystem -from .learning_rate import LearningRateExp -from .pair_tab import PairTab -from .plugin import Plugin -from .plugin import PluginVariant +from .data import ( + DeepmdData, +) +from .data_system import ( + DeepmdDataSystem, +) +from .learning_rate import ( + LearningRateExp, +) +from .pair_tab import ( + PairTab, +) +from .plugin import ( + Plugin, + PluginVariant, +) __all__ = [ "DeepmdData", diff --git a/deepmd/utils/argcheck.py b/deepmd/utils/argcheck.py index 370a67361f..1fe00b4f43 100644 --- a/deepmd/utils/argcheck.py +++ b/deepmd/utils/argcheck.py @@ -1,18 +1,28 @@ import json import logging -from typing import Callable -from typing import List -from typing import Optional - -from dargs import Argument -from dargs import ArgumentEncoder -from dargs import Variant -from dargs import dargs - -from deepmd.common import ACTIVATION_FN_DICT -from deepmd.common import PRECISION_DICT -from deepmd.nvnmd.utils.argcheck import nvnmd_args -from deepmd.utils.plugin import Plugin +from typing import ( + Callable, + List, + Optional, +) + +from dargs import ( + Argument, + ArgumentEncoder, + Variant, + dargs, +) + +from deepmd.common import ( + ACTIVATION_FN_DICT, + PRECISION_DICT, +) +from deepmd.nvnmd.utils.argcheck import ( + nvnmd_args, +) +from deepmd.utils.plugin import ( + Plugin, +) log = logging.getLogger(__name__) diff --git a/deepmd/utils/batch_size.py b/deepmd/utils/batch_size.py index 5b55261d06..a2cafef23e 100644 --- a/deepmd/utils/batch_size.py +++ b/deepmd/utils/batch_size.py @@ -1,12 +1,18 @@ import logging import os -from typing import Callable -from typing import Tuple +from typing import ( + Callable, + Tuple, +) import numpy as np -from deepmd.env import tf -from deepmd.utils.errors import OutOfMemoryError +from deepmd.env import ( + tf, +) +from deepmd.utils.errors import ( + OutOfMemoryError, +) log = logging.getLogger(__name__) diff --git a/deepmd/utils/compat.py b/deepmd/utils/compat.py index 287a835b91..4ec47b53a1 100644 --- a/deepmd/utils/compat.py +++ b/deepmd/utils/compat.py @@ -2,16 +2,22 @@ import json import warnings -from pathlib import Path -from typing import Any -from typing import Dict -from typing import Optional -from typing import Sequence -from typing import Union +from pathlib import ( + Path, +) +from typing import ( + Any, + Dict, + Optional, + Sequence, + Union, +) import numpy as np -from deepmd.common import j_must_have +from deepmd.common import ( + j_must_have, +) def convert_input_v0_v1( diff --git a/deepmd/utils/convert.py b/deepmd/utils/convert.py index 2fe55e2581..4948a8e70f 100644 --- a/deepmd/utils/convert.py +++ b/deepmd/utils/convert.py @@ -1,9 +1,13 @@ import os import textwrap -from google.protobuf import text_format +from google.protobuf import ( + text_format, +) -from deepmd.env import tf +from deepmd.env import ( + tf, +) def detect_model_version(input_model: str): diff --git a/deepmd/utils/data.py b/deepmd/utils/data.py index 8ffb7bc58a..2749a45594 100644 --- a/deepmd/utils/data.py +++ b/deepmd/utils/data.py @@ -1,15 +1,21 @@ #!/usr/bin/env python3 import logging -from typing import List -from typing import Optional +from typing import ( + List, + Optional, +) import numpy as np -from deepmd.env import GLOBAL_ENER_FLOAT_PRECISION -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION +from deepmd.env import ( + GLOBAL_ENER_FLOAT_PRECISION, + GLOBAL_NP_FLOAT_PRECISION, +) from deepmd.utils import random as dp_random -from deepmd.utils.path import DPPath +from deepmd.utils.path import ( + DPPath, +) log = logging.getLogger(__name__) diff --git a/deepmd/utils/data_system.py b/deepmd/utils/data_system.py index dc1fb25464..f7bc1c500d 100644 --- a/deepmd/utils/data_system.py +++ b/deepmd/utils/data_system.py @@ -1,14 +1,20 @@ import collections import logging import warnings -from typing import List -from typing import Optional +from typing import ( + List, + Optional, +) import numpy as np -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, +) from deepmd.utils import random as dp_random -from deepmd.utils.data import DeepmdData +from deepmd.utils.data import ( + DeepmdData, +) log = logging.getLogger(__name__) diff --git a/deepmd/utils/finetune.py b/deepmd/utils/finetune.py index 0107a09d17..9b39d68b30 100644 --- a/deepmd/utils/finetune.py +++ b/deepmd/utils/finetune.py @@ -1,10 +1,16 @@ import json import logging -from typing import Any -from typing import Dict +from typing import ( + Any, + Dict, +) -from deepmd.utils.errors import GraphWithoutTensorError -from deepmd.utils.graph import get_tensor_by_name +from deepmd.utils.errors import ( + GraphWithoutTensorError, +) +from deepmd.utils.graph import ( + get_tensor_by_name, +) log = logging.getLogger(__name__) diff --git a/deepmd/utils/graph.py b/deepmd/utils/graph.py index 9c46c28dc0..71858039b1 100644 --- a/deepmd/utils/graph.py +++ b/deepmd/utils/graph.py @@ -1,16 +1,24 @@ import re -from typing import Dict -from typing import Tuple +from typing import ( + Dict, + Tuple, +) import numpy as np -from deepmd.env import ATTENTION_LAYER_PATTERN -from deepmd.env import EMBEDDING_NET_PATTERN -from deepmd.env import FITTING_NET_PATTERN -from deepmd.env import TYPE_EMBEDDING_PATTERN -from deepmd.env import tf -from deepmd.utils.errors import GraphWithoutTensorError -from deepmd.utils.sess import run_sess +from deepmd.env import ( + ATTENTION_LAYER_PATTERN, + EMBEDDING_NET_PATTERN, + FITTING_NET_PATTERN, + TYPE_EMBEDDING_PATTERN, + tf, +) +from deepmd.utils.errors import ( + GraphWithoutTensorError, +) +from deepmd.utils.sess import ( + run_sess, +) # TODO (JZ): I think in this file we can merge some duplicated lines into one method... diff --git a/deepmd/utils/learning_rate.py b/deepmd/utils/learning_rate.py index 315138010e..d17e99dd1b 100644 --- a/deepmd/utils/learning_rate.py +++ b/deepmd/utils/learning_rate.py @@ -1,10 +1,15 @@ -from typing import Optional +from typing import ( + Optional, +) import numpy as np -from paddle.optimizer import lr +from paddle.optimizer import ( + lr, +) -from deepmd.env import paddle -from deepmd.env import tf +from deepmd.env import ( + tf, +) class LearningRateExp: diff --git a/deepmd/utils/multi_init.py b/deepmd/utils/multi_init.py index 08f1865c91..d5496b47ea 100644 --- a/deepmd/utils/multi_init.py +++ b/deepmd/utils/multi_init.py @@ -1,10 +1,16 @@ import json import logging -from typing import Any -from typing import Dict +from typing import ( + Any, + Dict, +) -from deepmd.utils.errors import GraphWithoutTensorError -from deepmd.utils.graph import get_tensor_by_name +from deepmd.utils.errors import ( + GraphWithoutTensorError, +) +from deepmd.utils.graph import ( + get_tensor_by_name, +) log = logging.getLogger(__name__) diff --git a/deepmd/utils/neighbor_stat.py b/deepmd/utils/neighbor_stat.py index 6f330e5c36..fe5fe04bc1 100644 --- a/deepmd/utils/neighbor_stat.py +++ b/deepmd/utils/neighbor_stat.py @@ -1,16 +1,18 @@ import logging import math -from typing import List -from typing import Tuple +from typing import ( + List, + Tuple, +) import numpy as np -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import default_tf_session_config -from deepmd.env import op_module -from deepmd.env import tf -from deepmd.utils.data_system import DeepmdDataSystem -from deepmd.utils.parallel_op import ParallelOp +from deepmd.env import ( + op_module, +) +from deepmd.utils.data_system import ( + DeepmdDataSystem, +) log = logging.getLogger(__name__) diff --git a/deepmd/utils/network.py b/deepmd/utils/network.py index 6ae3aafedb..c25c5f0589 100644 --- a/deepmd/utils/network.py +++ b/deepmd/utils/network.py @@ -1,11 +1,14 @@ import numpy as np -from paddle import nn -from deepmd.common import get_precision -from deepmd.env import GLOBAL_PD_FLOAT_PRECISION -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import paddle -from deepmd.env import tf +from deepmd.common import ( + get_precision, +) +from deepmd.env import ( + GLOBAL_PD_FLOAT_PRECISION, + GLOBAL_TF_FLOAT_PRECISION, + paddle, + tf, +) def one_layer_rand_seed_shift(): @@ -312,7 +315,7 @@ def __init__( trainable=True, useBN=False, ): - super(OneLayer, self).__init__(name) + super().__init__(name) self.out_features = out_features self.activation_fn = activation_fn self.use_timestep = use_timestep diff --git a/deepmd/utils/pair_tab.py b/deepmd/utils/pair_tab.py index 13dcef438a..b8642c7009 100644 --- a/deepmd/utils/pair_tab.py +++ b/deepmd/utils/pair_tab.py @@ -1,9 +1,13 @@ #!/usr/bin/env python3 -from typing import Tuple +from typing import ( + Tuple, +) import numpy as np -from scipy.interpolate import CubicSpline +from scipy.interpolate import ( + CubicSpline, +) class PairTab: diff --git a/deepmd/utils/parallel_op.py b/deepmd/utils/parallel_op.py index 1453e9377f..db27d5604e 100644 --- a/deepmd/utils/parallel_op.py +++ b/deepmd/utils/parallel_op.py @@ -1,12 +1,18 @@ -from typing import Any -from typing import Callable -from typing import Dict -from typing import Generator -from typing import Optional -from typing import Tuple +from typing import ( + Any, + Callable, + Dict, + Generator, + Optional, + Tuple, +) -from deepmd.env import tf -from deepmd.utils.sess import run_sess +from deepmd.env import ( + tf, +) +from deepmd.utils.sess import ( + run_sess, +) class ParallelOp: diff --git a/deepmd/utils/path.py b/deepmd/utils/path.py index ba1f1e87a2..454eed3d2b 100644 --- a/deepmd/utils/path.py +++ b/deepmd/utils/path.py @@ -1,14 +1,24 @@ import os -from abc import ABC -from abc import abstractmethod -from functools import lru_cache -from pathlib import Path -from typing import List -from typing import Optional +from abc import ( + ABC, + abstractmethod, +) +from functools import ( + lru_cache, +) +from pathlib import ( + Path, +) +from typing import ( + List, + Optional, +) import h5py import numpy as np -from wcmatch.glob import globfilter +from wcmatch.glob import ( + globfilter, +) class DPPath(ABC): diff --git a/deepmd/utils/plugin.py b/deepmd/utils/plugin.py index c49328ef2b..66b4569029 100644 --- a/deepmd/utils/plugin.py +++ b/deepmd/utils/plugin.py @@ -1,8 +1,12 @@ """Base of plugin systems.""" # copied from https://github.com/deepmodeling/dpdata/blob/a3e76d75de53f6076254de82d18605a010dc3b00/dpdata/plugin.py -from abc import ABCMeta -from typing import Callable +from abc import ( + ABCMeta, +) +from typing import ( + Callable, +) class Plugin: diff --git a/deepmd/utils/random.py b/deepmd/utils/random.py index 0632d6bc64..57d0af4d55 100644 --- a/deepmd/utils/random.py +++ b/deepmd/utils/random.py @@ -1,4 +1,6 @@ -from typing import Optional +from typing import ( + Optional, +) import numpy as np diff --git a/deepmd/utils/sess.py b/deepmd/utils/sess.py index 53e0abd850..67bbd36878 100644 --- a/deepmd/utils/sess.py +++ b/deepmd/utils/sess.py @@ -1,7 +1,11 @@ import os -from deepmd.env import tf -from deepmd.utils.errors import OutOfMemoryError +from deepmd.env import ( + tf, +) +from deepmd.utils.errors import ( + OutOfMemoryError, +) def run_sess(sess: tf.Session, *args, **kwargs): diff --git a/deepmd/utils/spin.py b/deepmd/utils/spin.py index 67969869a9..38801fe3b9 100644 --- a/deepmd/utils/spin.py +++ b/deepmd/utils/spin.py @@ -1,7 +1,11 @@ -from typing import List +from typing import ( + List, +) -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import tf +from deepmd.env import ( + GLOBAL_TF_FLOAT_PRECISION, + tf, +) class Spin: diff --git a/deepmd/utils/tabulate.py b/deepmd/utils/tabulate.py index a8ce9fd9d4..aa842178f7 100644 --- a/deepmd/utils/tabulate.py +++ b/deepmd/utils/tabulate.py @@ -1,20 +1,34 @@ import logging -from functools import lru_cache -from typing import Callable -from typing import Dict -from typing import List -from typing import Tuple +from functools import ( + lru_cache, +) +from typing import ( + Callable, + Dict, + List, + Tuple, +) import numpy as np -from scipy.special import comb +from scipy.special import ( + comb, +) import deepmd -from deepmd.common import ACTIVATION_FN_DICT -from deepmd.descriptor import Descriptor -from deepmd.env import op_module -from deepmd.env import tf -from deepmd.utils.graph import get_embedding_net_nodes_from_graph_def -from deepmd.utils.graph import get_tensor_by_name_from_graph +from deepmd.common import ( + ACTIVATION_FN_DICT, +) +from deepmd.descriptor import ( + Descriptor, +) +from deepmd.env import ( + op_module, + tf, +) +from deepmd.utils.graph import ( + get_embedding_net_nodes_from_graph_def, + get_tensor_by_name_from_graph, +) log = logging.getLogger(__name__) diff --git a/deepmd/utils/type_embed.py b/deepmd/utils/type_embed.py index 807c3db431..132c7d2db3 100644 --- a/deepmd/utils/type_embed.py +++ b/deepmd/utils/type_embed.py @@ -1,13 +1,23 @@ -from typing import List -from typing import Optional -from typing import Union +from typing import ( + List, + Optional, + Union, +) -from deepmd.common import get_activation_func -from deepmd.common import get_precision -from deepmd.env import paddle -from deepmd.env import tf -from deepmd.utils.graph import get_type_embedding_net_variables_from_graph_def -from deepmd.utils.network import embedding_net +from deepmd.common import ( + get_activation_func, + get_precision, +) +from deepmd.env import ( + paddle, + tf, +) +from deepmd.utils.graph import ( + get_type_embedding_net_variables_from_graph_def, +) +from deepmd.utils.network import ( + embedding_net, +) def embed_atom_type( diff --git a/deepmd/utils/weight_avg.py b/deepmd/utils/weight_avg.py index 728094e563..b46e3a0d37 100644 --- a/deepmd/utils/weight_avg.py +++ b/deepmd/utils/weight_avg.py @@ -1,7 +1,11 @@ -from collections import defaultdict -from typing import Dict -from typing import List -from typing import Tuple +from collections import ( + defaultdict, +) +from typing import ( + Dict, + List, + Tuple, +) import numpy as np diff --git a/doc/conf.py b/doc/conf.py index 519ce94f1c..5e034b36c1 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -12,11 +12,17 @@ # import os import sys -from datetime import date +from datetime import ( + date, +) -from deepmd.common import ACTIVATION_FN_DICT -from deepmd.common import PRECISION_DICT -from deepmd.utils.argcheck import list_to_doc +from deepmd.common import ( + ACTIVATION_FN_DICT, + PRECISION_DICT, +) +from deepmd.utils.argcheck import ( + list_to_doc, +) sys.path.append(os.path.dirname(__file__)) import sphinx_contrib_exhale_multiproject # noqa: F401 @@ -121,7 +127,9 @@ def classify_index_TS(): def run_apidoc(_): import sys - from sphinx.ext.apidoc import main + from sphinx.ext.apidoc import ( + main, + ) sys.path.append(os.path.join(os.path.dirname(__file__), "..")) cur_dir = os.path.abspath(os.path.dirname(__file__)) diff --git a/doc/getting-started/quick_start.ipynb b/doc/getting-started/quick_start.ipynb index e743b5cf5c..31209ae381 100644 --- a/doc/getting-started/quick_start.ipynb +++ b/doc/getting-started/quick_start.ipynb @@ -1,5 +1,5 @@ { - "cells": [ + "cells": [ { "attachments": {}, "cell_type": "markdown", diff --git a/doc/sphinx_contrib_exhale_multiproject.py b/doc/sphinx_contrib_exhale_multiproject.py index cf0cc9850f..208637aa5e 100644 --- a/doc/sphinx_contrib_exhale_multiproject.py +++ b/doc/sphinx_contrib_exhale_multiproject.py @@ -74,7 +74,9 @@ import os import os.path -from pprint import pprint +from pprint import ( + pprint, +) import exhale import exhale.configs diff --git a/examples/water/lmp/Model_1000000_with_buffer.pdiparams b/examples/water/lmp/Model_1000000_with_buffer.pdiparams deleted file mode 100644 index 3b4a25e6ba..0000000000 Binary files a/examples/water/lmp/Model_1000000_with_buffer.pdiparams and /dev/null differ diff --git a/examples/water/lmp/Model_1000000_with_buffer.pdiparams b/examples/water/lmp/Model_1000000_with_buffer.pdiparams new file mode 120000 index 0000000000..569305c94f --- /dev/null +++ b/examples/water/lmp/Model_1000000_with_buffer.pdiparams @@ -0,0 +1 @@ +/workspace/hesensen/deepmd_backend/deepmd-kit/examples/water/se_e2_a/Model_1000000_with_buffer.pdiparams \ No newline at end of file diff --git a/examples/water/lmp/Model_1000000_with_buffer.pdmodel b/examples/water/lmp/Model_1000000_with_buffer.pdmodel deleted file mode 100644 index fbc0689402..0000000000 Binary files a/examples/water/lmp/Model_1000000_with_buffer.pdmodel and /dev/null differ diff --git a/examples/water/lmp/Model_1000000_with_buffer.pdmodel b/examples/water/lmp/Model_1000000_with_buffer.pdmodel new file mode 120000 index 0000000000..175c7e7080 --- /dev/null +++ b/examples/water/lmp/Model_1000000_with_buffer.pdmodel @@ -0,0 +1 @@ +/workspace/hesensen/deepmd_backend/deepmd-kit/examples/water/se_e2_a/Model_1000000_with_buffer.pdmodel \ No newline at end of file diff --git a/setup.py b/setup.py index 026a8b5fe4..b08fe391df 100644 --- a/setup.py +++ b/setup.py @@ -3,16 +3,24 @@ import os import sys -from packaging.version import Version -from skbuild import setup -from wheel.bdist_wheel import bdist_wheel +from packaging.version import ( + Version, +) +from skbuild import ( + setup, +) +from wheel.bdist_wheel import ( + bdist_wheel, +) topdir = os.path.abspath(os.path.dirname(__file__)) sys.path.insert(0, os.path.join(topdir, "backend")) -from find_tensorflow import find_tensorflow -from find_tensorflow import get_tf_requirement -from find_tensorflow import get_tf_version +from find_tensorflow import ( + find_tensorflow, + get_tf_requirement, + get_tf_version, +) cmake_args = [] extra_scripts = [] diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 7a617d4c02..b53e2bbe8b 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -3,19 +3,22 @@ cmake_minimum_required(VERSION 3.16) project(DeePMD) macro(safe_set_static_flag) - foreach(flag_var - CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE - CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) - if(${flag_var} MATCHES "/MD") - string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") - endif(${flag_var} MATCHES "/MD") - endforeach(flag_var) + foreach(flag_var + CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE + CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) + if(${flag_var} MATCHES "/MD") + string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") + endif(${flag_var} MATCHES "/MD") + endforeach(flag_var) endmacro() if(NOT DEFINED PADDLE_LIB) - message(FATAL_ERROR "please set PADDLE_LIB with -DPADDLE_LIB=/path/paddle/lib") + message( + FATAL_ERROR "please set PADDLE_LIB with -DPADDLE_LIB=/path/paddle/lib") endif() -set(PADDLE_LIB ${PADDLE_LIB} CACHE PATH "/path/paddle/lib") +set(PADDLE_LIB + ${PADDLE_LIB} + CACHE PATH "/path/paddle/lib") include_directories("${PADDLE_LIB}/") set(PADDLE_LIB_THIRD_PARTY_PATH "${PADDLE_LIB}/third_party/install/") @@ -36,64 +39,88 @@ option(USE_TENSORRT "Compile demo with TensorRT." OFF) if(WITH_GPU) if(NOT WIN32) - set(CUDA_LIB "/usr/local/cuda/lib64/" CACHE STRING "CUDA Library") + set(CUDA_LIB + "/usr/local/cuda/lib64/" + CACHE STRING "CUDA Library") else() if(CUDA_LIB STREQUAL "") - set(CUDA_LIB "C:\\Program\ Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v8.0\\lib\\x64") + set(CUDA_LIB + "C:\\Program\ Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v8.0\\lib\\x64" + ) endif() endif(NOT WIN32) endif() -if (NOT WIN32) - if (USE_TENSORRT AND WITH_GPU) - include_directories("${TENSORRT_INCLUDE_DIR}") - link_directories("${TENSORRT_LIB_DIR}") +if(NOT WIN32) + if(USE_TENSORRT AND WITH_GPU) + include_directories("${TENSORRT_INCLUDE_DIR}") + link_directories("${TENSORRT_LIB_DIR}") endif() endif(NOT WIN32) - if(WITH_STATIC_LIB) - set(DEPS ${PADDLE_LIB}/paddle/lib/libpaddle_inference${CMAKE_STATIC_LIBRARY_SUFFIX}) + set(DEPS + ${PADDLE_LIB}/paddle/lib/libpaddle_inference${CMAKE_STATIC_LIBRARY_SUFFIX} + ) else() if(WIN32) - set(DEPS ${PADDLE_LIB}/paddle/lib/libpaddle_inference${CMAKE_STATIC_LIBRARY_SUFFIX}) + set(DEPS + ${PADDLE_LIB}/paddle/lib/libpaddle_inference${CMAKE_STATIC_LIBRARY_SUFFIX} + ) else() - set(DEPS ${PADDLE_LIB}/paddle/lib/libpaddle_inference${CMAKE_SHARED_LIBRARY_SUFFIX}) + set(DEPS + ${PADDLE_LIB}/paddle/lib/libpaddle_inference${CMAKE_SHARED_LIBRARY_SUFFIX} + ) endif() endif() -if (NOT WIN32) +if(NOT WIN32) set(EXTERNAL_LIB "-lrt -ldl -lpthread") - set(DEPS ${DEPS} - ${MATH_LIB} ${MKLDNN_LIB} - glog gflags protobuf xxhash + set(DEPS + ${DEPS} + ${MATH_LIB} + ${MKLDNN_LIB} + glog + gflags + protobuf + xxhash ${EXTERNAL_LIB}) else() - set(DEPS ${DEPS} - ${MATH_LIB} ${MKLDNN_LIB} - glog gflags_static libprotobuf xxhash ${EXTERNAL_LIB}) + set(DEPS + ${DEPS} + ${MATH_LIB} + ${MKLDNN_LIB} + glog + gflags_static + libprotobuf + xxhash + ${EXTERNAL_LIB}) set(DEPS ${DEPS} shlwapi.lib) endif(NOT WIN32) if(WITH_GPU) if(NOT WIN32) - if (USE_TENSORRT) - set(DEPS ${DEPS} ${TENSORRT_LIB_DIR}/libnvinfer${CMAKE_SHARED_LIBRARY_SUFFIX}) - set(DEPS ${DEPS} ${TENSORRT_LIB_DIR}/libnvinfer_plugin${CMAKE_SHARED_LIBRARY_SUFFIX}) + if(USE_TENSORRT) + set(DEPS ${DEPS} + ${TENSORRT_LIB_DIR}/libnvinfer${CMAKE_SHARED_LIBRARY_SUFFIX}) + set(DEPS + ${DEPS} + ${TENSORRT_LIB_DIR}/libnvinfer_plugin${CMAKE_SHARED_LIBRARY_SUFFIX}) endif() set(DEPS ${DEPS} ${CUDA_LIB}/libcudart${CMAKE_SHARED_LIBRARY_SUFFIX}) else() if(USE_TENSORRT) - set(DEPS ${DEPS} ${TENSORRT_LIB_DIR}/nvinfer${CMAKE_STATIC_LIBRARY_SUFFIX}) - set(DEPS ${DEPS} ${TENSORRT_LIB_DIR}/nvinfer_plugin${CMAKE_STATIC_LIBRARY_SUFFIX}) + set(DEPS ${DEPS} + ${TENSORRT_LIB_DIR}/nvinfer${CMAKE_STATIC_LIBRARY_SUFFIX}) + set(DEPS ${DEPS} + ${TENSORRT_LIB_DIR}/nvinfer_plugin${CMAKE_STATIC_LIBRARY_SUFFIX}) endif() - set(DEPS ${DEPS} ${CUDA_LIB}/cudart${CMAKE_STATIC_LIBRARY_SUFFIX} ) - set(DEPS ${DEPS} ${CUDA_LIB}/cublas${CMAKE_STATIC_LIBRARY_SUFFIX} ) - set(DEPS ${DEPS} ${CUDA_LIB}/cudnn${CMAKE_STATIC_LIBRARY_SUFFIX} ) + set(DEPS ${DEPS} ${CUDA_LIB}/cudart${CMAKE_STATIC_LIBRARY_SUFFIX}) + set(DEPS ${DEPS} ${CUDA_LIB}/cublas${CMAKE_STATIC_LIBRARY_SUFFIX}) + set(DEPS ${DEPS} ${CUDA_LIB}/cudnn${CMAKE_STATIC_LIBRARY_SUFFIX}) endif() endif() - option(BUILD_TESTING "Build test and enable converage" OFF) set(DEEPMD_C_ROOT "" @@ -353,32 +380,23 @@ if(BUILD_CPP_IF) endif() endif(BUILD_CPP_IF) -# if(WIN32) -# if(USE_TENSORRT) -# add_custom_command(TARGET ${DEMO_NAME} POST_BUILD -# COMMAND ${CMAKE_COMMAND} -E copy ${TENSORRT_LIB_DIR}/nvinfer${CMAKE_SHARED_LIBRARY_SUFFIX} -# ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE} -# COMMAND ${CMAKE_COMMAND} -E copy ${TENSORRT_LIB_DIR}/nvinfer_plugin${CMAKE_SHARED_LIBRARY_SUFFIX} -# ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE} -# ) -# endif() -# if(WITH_MKL) -# add_custom_command(TARGET ${DEMO_NAME} POST_BUILD -# COMMAND ${CMAKE_COMMAND} -E copy ${MATH_LIB_PATH}/lib/mklml.dll ${CMAKE_BINARY_DIR}/Release -# COMMAND ${CMAKE_COMMAND} -E copy ${MATH_LIB_PATH}/lib/libiomp5md.dll ${CMAKE_BINARY_DIR}/Release -# COMMAND ${CMAKE_COMMAND} -E copy ${MKLDNN_PATH}/lib/mkldnn.dll ${CMAKE_BINARY_DIR}/Release -# ) -# else() -# add_custom_command(TARGET ${DEMO_NAME} POST_BUILD -# COMMAND ${CMAKE_COMMAND} -E copy ${OPENBLAS_LIB_PATH}/lib/openblas.dll ${CMAKE_BINARY_DIR}/Release -# ) -# endif() -# if(NOT WITH_STATIC_LIB) -# add_custom_command(TARGET ${DEMO_NAME} POST_BUILD -# COMMAND ${CMAKE_COMMAND} -E copy "${PADDLE_LIB}/paddle/lib/paddle_fluid.dll" ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE} -# ) -# endif() -# endif() +# if(WIN32) if(USE_TENSORRT) add_custom_command(TARGET ${DEMO_NAME} POST_BUILD +# COMMAND ${CMAKE_COMMAND} -E copy +# ${TENSORRT_LIB_DIR}/nvinfer${CMAKE_SHARED_LIBRARY_SUFFIX} +# ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE} COMMAND ${CMAKE_COMMAND} -E copy +# ${TENSORRT_LIB_DIR}/nvinfer_plugin${CMAKE_SHARED_LIBRARY_SUFFIX} +# ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE} ) endif() if(WITH_MKL) +# add_custom_command(TARGET ${DEMO_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E +# copy ${MATH_LIB_PATH}/lib/mklml.dll ${CMAKE_BINARY_DIR}/Release COMMAND +# ${CMAKE_COMMAND} -E copy ${MATH_LIB_PATH}/lib/libiomp5md.dll +# ${CMAKE_BINARY_DIR}/Release COMMAND ${CMAKE_COMMAND} -E copy +# ${MKLDNN_PATH}/lib/mkldnn.dll ${CMAKE_BINARY_DIR}/Release ) else() +# add_custom_command(TARGET ${DEMO_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E +# copy ${OPENBLAS_LIB_PATH}/lib/openblas.dll ${CMAKE_BINARY_DIR}/Release ) +# endif() if(NOT WITH_STATIC_LIB) add_custom_command(TARGET ${DEMO_NAME} +# POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy +# "${PADDLE_LIB}/paddle/lib/paddle_fluid.dll" +# ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE} ) endif() endif() # uninstall target configure_file( diff --git a/source/api_cc/include/common.h b/source/api_cc/include/common.h index 04621e05af..8d9a8ee2b1 100644 --- a/source/api_cc/include/common.h +++ b/source/api_cc/include/common.h @@ -199,8 +199,9 @@ VT session_get_scalar(tensorflow::Session* session, * @return The value of the tensor. **/ template -VT predictor_get_scalar(const std::shared_ptr& predictor, - const std::string name_); +VT predictor_get_scalar( + const std::shared_ptr& predictor, + const std::string name_); /** * @brief Get the vector of a tensor. diff --git a/source/api_cc/src/DeepPot.cc b/source/api_cc/src/DeepPot.cc index afd7225a71..c76d339f5b 100644 --- a/source/api_cc/src/DeepPot.cc +++ b/source/api_cc/src/DeepPot.cc @@ -717,7 +717,7 @@ void DeepPot::init(const std::string& model, int gpu_num = -1; #if GOOGLE_CUDA || TENSORFLOW_USE_ROCM DPGetDeviceCount(gpu_num); // check current device environment -#endif // GOOGLE_CUDA || TENSORFLOW_USE_ROCM +#endif // GOOGLE_CUDA || TENSORFLOW_USE_ROCM if (use_paddle_inference) { /* tensorflow::DT_DOUBLE = 2 @@ -731,23 +731,25 @@ void DeepPot::init(const std::string& model, [buffer_t_type, [3]] generated name in static_model is: generated_tensor_12 [buffer_t_mt, [4]] generated name in static_model is: generated_tensor_13 [buffer_t_ver, [1]] generated name in static_model is: generated_tensor_14 - [descrpt.buffer_rcut, []] generated name in static_model is: generated_tensor_0 - [descrpt.buffer_ntypes_spin, []] generated name in static_model is: generated_tensor_1 - [descrpt.buffer_ntypes, []] generated name in static_model is: generated_tensor_2 - [descrpt.avg_zero, [2, 552]] generated name in static_model is: eager_tmp_0 - [descrpt.std_ones, [2, 552]] generated name in static_model is: eager_tmp_1 - [descrpt.t_rcut, []] generated name in static_model is: generated_tensor_3 - [descrpt.t_rcut, []] generated name in static_model is: generated_tensor_3 - [descrpt.t_rcut, []] generated name in static_model is: generated_tensor_3 - [descrpt.t_ntypes, []] generated name in static_model is: generated_tensor_4 - [descrpt.t_ntypes, []] generated name in static_model is: generated_tensor_4 - [descrpt.t_ntypes, []] generated name in static_model is: generated_tensor_4 - [descrpt.t_ndescrpt, []] generated name in static_model is: generated_tensor_5 - [descrpt.t_sel, [2]] generated name in static_model is: generated_tensor_6 - [descrpt.t_avg, [2, 552]] generated name in static_model is: generated_tensor_7 - [descrpt.t_std, [2, 552]] generated name in static_model is: generated_tensor_8 - [fitting.buffer_dfparam, []] generated name in static_model is: generated_tensor_9 - [fitting.buffer_daparam, []] generated name in static_model is: generated_tensor_10 + [descrpt.buffer_rcut, []] generated name in static_model is: + generated_tensor_0 [descrpt.buffer_ntypes_spin, []] generated name in + static_model is: generated_tensor_1 [descrpt.buffer_ntypes, []] generated + name in static_model is: generated_tensor_2 [descrpt.avg_zero, [2, 552]] + generated name in static_model is: eager_tmp_0 [descrpt.std_ones, [2, 552]] + generated name in static_model is: eager_tmp_1 [descrpt.t_rcut, []] + generated name in static_model is: generated_tensor_3 [descrpt.t_rcut, []] + generated name in static_model is: generated_tensor_3 [descrpt.t_rcut, []] + generated name in static_model is: generated_tensor_3 [descrpt.t_ntypes, []] + generated name in static_model is: generated_tensor_4 [descrpt.t_ntypes, []] + generated name in static_model is: generated_tensor_4 [descrpt.t_ntypes, []] + generated name in static_model is: generated_tensor_4 [descrpt.t_ndescrpt, + []] generated name in static_model is: generated_tensor_5 [descrpt.t_sel, + [2]] generated name in static_model is: generated_tensor_6 [descrpt.t_avg, + [2, 552]] generated name in static_model is: generated_tensor_7 + [descrpt.t_std, [2, 552]] generated name in static_model is: + generated_tensor_8 [fitting.buffer_dfparam, []] generated name in + static_model is: generated_tensor_9 [fitting.buffer_daparam, []] generated + name in static_model is: generated_tensor_10 **/ model_version = paddle_get_scalar("generated_tensor_14"); dtype = predictor_get_dtype(predictor, "generated_tensor_0"); @@ -761,10 +763,11 @@ void DeepPot::init(const std::string& model, ntypes_spin = 0; dfparam = paddle_get_scalar("generated_tensor_9"); daparam = paddle_get_scalar("generated_tensor_10"); - model_type = paddle_get_scalar("generated_tensor_13");; + model_type = paddle_get_scalar("generated_tensor_13"); + ; inited = true; init_nbor = false; - return ; + return; } // if (!model_compatable(model_version)) { // throw deepmd::deepmd_exception( @@ -1241,22 +1244,22 @@ void DeepPot::compute(ENERGYVTYPE& dener, int ret = 0; if (predictor == nullptr) { /* run tensorflow inference if paddle predictor is nullptr*/ - int ret = session_input_tensors(input_tensors, dcoord, ntypes, - datype, dbox, nlist, fparam, - aparam, atommap, nghost_real, - ago); + int ret = session_input_tensors( + input_tensors, dcoord, ntypes, datype, dbox, nlist, fparam, aparam, + atommap, nghost_real, ago); assert(nloc_real == ret); run_model(dener, dforce, dvirial, datom_energy, datom_virial, session, input_tensors, atommap, nframes, nghost_real); } /* run paddle inference if paddle predictor exist*/ else if (predictor != nullptr) { - int ret = predictor_input_tensors(predictor, dcoord, ntypes, datype, dbox, - nlist, fparam, aparam, atommap, - nghost_real, ago); + int ret = predictor_input_tensors( + predictor, dcoord, ntypes, datype, dbox, nlist, fparam, aparam, + atommap, nghost_real, ago); assert(nloc_real == ret); - paddle_run_model(dener, dforce, dvirial, datom_energy, datom_virial, - predictor, atommap, nframes, nghost_real); + paddle_run_model(dener, dforce, dvirial, datom_energy, + datom_virial, predictor, atommap, nframes, + nghost_real); } } else { int ret = session_input_tensors(input_tensors, dcoord, ntypes, diff --git a/source/api_cc/src/common.cc b/source/api_cc/src/common.cc index 868c851718..aa23e30922 100644 --- a/source/api_cc/src/common.cc +++ b/source/api_cc/src/common.cc @@ -863,9 +863,10 @@ VT deepmd::session_get_scalar(Session* session, } template -VT deepmd::predictor_get_scalar(const std::shared_ptr& predictor, - const std::string name_) { - if (std::is_same::value){ +VT deepmd::predictor_get_scalar( + const std::shared_ptr& predictor, + const std::string name_) { + if (std::is_same::value) { /* NOTE: Convert from ascii code(int64) to std::string A workaround for string data type is not supported in Paddle @@ -874,17 +875,13 @@ VT deepmd::predictor_get_scalar(const std::shared_ptr& if (scalar_tensor->shape().size() == 0) { return VT(); } - const auto &shape = scalar_tensor->shape(); - const int &str_len = std::accumulate( - std::begin(shape), - std::end(shape), - 1, - std::multiplies<>{} - ); + const auto& shape = scalar_tensor->shape(); + const int& str_len = std::accumulate(std::begin(shape), std::end(shape), 1, + std::multiplies<>{}); if (str_len == 0) { return VT(); } - int32_t *scalar_ptr = (int32_t *)malloc(str_len * sizeof(int32_t)); + int32_t* scalar_ptr = (int32_t*)malloc(str_len * sizeof(int32_t)); scalar_tensor->CopyToCpu(scalar_ptr); VT ret; for (int ii = 0; ii < str_len; ++ii) { @@ -895,7 +892,7 @@ VT deepmd::predictor_get_scalar(const std::shared_ptr& } else { /* Vanillia process for other data type below*/ auto scalar_tensor = predictor->GetOutputHandle(name_); - VT *scalar_ptr = (VT *)malloc(1 * sizeof(VT)); + VT* scalar_ptr = (VT*)malloc(1 * sizeof(VT)); scalar_tensor->CopyToCpu(scalar_ptr); return (*scalar_ptr); } @@ -1041,12 +1038,12 @@ template int deepmd::session_get_scalar(Session*, const std::string); template int deepmd::predictor_get_scalar( - const std::shared_ptr& predictor, - const std::string name_); + const std::shared_ptr& predictor, + const std::string name_); template int64_t deepmd::predictor_get_scalar( - const std::shared_ptr& predictor, - const std::string name_); + const std::shared_ptr& predictor, + const std::string name_); template void deepmd::session_get_vector(std::vector&, Session*, @@ -1086,8 +1083,8 @@ template float deepmd::session_get_scalar(Session*, const std::string); template float deepmd::predictor_get_scalar( - const std::shared_ptr& predictor, - const std::string name_); + const std::shared_ptr& predictor, + const std::string name_); template void deepmd::session_get_vector(std::vector&, Session*, @@ -1127,8 +1124,8 @@ template double deepmd::session_get_scalar(Session*, const std::string); template double deepmd::predictor_get_scalar( - const std::shared_ptr& predictor, - const std::string name_); + const std::shared_ptr& predictor, + const std::string name_); template void deepmd::session_get_vector(std::vector&, Session*, diff --git a/source/install/build_tf.py b/source/install/build_tf.py index 4a304676f1..883c654b5c 100755 --- a/source/install/build_tf.py +++ b/source/install/build_tf.py @@ -32,19 +32,33 @@ import tarfile import tempfile import urllib.request -from abc import ABCMeta -from abc import abstractmethod -from abc import abstractproperty -from contextlib import contextmanager -from fnmatch import filter -from functools import lru_cache -from pathlib import Path -from shutil import copy2 -from shutil import copytree -from shutil import ignore_patterns -from typing import Dict -from typing import List -from typing import Optional +from abc import ( + ABCMeta, + abstractmethod, + abstractproperty, +) +from contextlib import ( + contextmanager, +) +from fnmatch import ( + filter, +) +from functools import ( + lru_cache, +) +from pathlib import ( + Path, +) +from shutil import ( + copy2, + copytree, + ignore_patterns, +) +from typing import ( + Dict, + List, + Optional, +) # default config FILE = Path(__file__).parent.absolute() diff --git a/source/lib/paddle_src/CMakeLists.txt b/source/lib/paddle_src/CMakeLists.txt index 92f40f510c..ae4a8ea731 100644 --- a/source/lib/paddle_src/CMakeLists.txt +++ b/source/lib/paddle_src/CMakeLists.txt @@ -10,25 +10,27 @@ if(NOT CUDA_FOUND) endif(NOT CUDA_FOUND) # take dynamic open cudart library replace of static one so it's not required -# when using CPUs -# add_subdirectory(cudart) -# important: it must be before cuda_add_library and any link target to cudart +# when using CPUs add_subdirectory(cudart) important: it must be before +# cuda_add_library and any link target to cudart set(CUDA_LIBRARIES deepmd_dyn_cudart) # set c++ version c++11 set(CMAKE_CXX_STANDARD 11) set(CMAKE_CUDA_STANDARD 11) -# nvcc -o libdeeppaddle_md_op_cuda.so -I/usr/local/cub-1.8.0 -rdc=true -DHIGH_PREC=true -# -gencode arch=compute_61,code=sm_61 -shared -Xcompiler -fPIC deepmd_op.cu -# -L/usr/local/cuda/lib64 -lcudadevrt very important here! Include path to cub. -# for searching device compute capability, +# nvcc -o libdeeppaddle_md_op_cuda.so -I/usr/local/cub-1.8.0 -rdc=true +# -DHIGH_PREC=true -gencode arch=compute_61,code=sm_61 -shared -Xcompiler -fPIC +# deepmd_op.cu -L/usr/local/cuda/lib64 -lcudadevrt very important here! Include +# path to cub. for searching device compute capability, # https://developer.nvidia.com/cuda-gpus # cub has been included in CUDA Toolkit 11, we do not need to include it any # more see https://github.com/NVIDIA/cub include_directories("${PADDLE_LIB}/paddle/include") set(LIB_PATH "paddle/lib") -find_library(PADDLE_FLUID_SHARED_LIB NAMES "libpaddle_inference.so" PATHS ${PADDLE_INFERENCE_DIR}/${LIB_PATH}) +find_library( + PADDLE_FLUID_SHARED_LIB + NAMES "libpaddle_inference.so" + PATHS ${PADDLE_INFERENCE_DIR}/${LIB_PATH}) if(${CUDA_VERSION_MAJOR} LESS_EQUAL "10") include_directories(cub) endif() @@ -223,17 +225,21 @@ endif() file(GLOB SOURCE_FILES "*.cu" "*.cc") cuda_add_library(deepmd_paddle_op_cuda SHARED ${SOURCE_FILES}) -target_link_libraries(deepmd_paddle_op_cuda "${PADDLE_LIB}/paddle/lib/libpaddle_inference.so") +target_link_libraries(deepmd_paddle_op_cuda + "${PADDLE_LIB}/paddle/lib/libpaddle_inference.so") target_include_directories( deepmd_paddle_op_cuda PUBLIC $ - $ - "${PADDLE_LIB}/paddle/include/") + $ "${PADDLE_LIB}/paddle/include/") target_precompile_headers(deepmd_paddle_op_cuda PUBLIC [["device.h"]]) if(APPLE) - set_target_properties(deepmd_paddle_op_cuda PROPERTIES INSTALL_RPATH @loader_path) + set_target_properties(deepmd_paddle_op_cuda PROPERTIES INSTALL_RPATH + @loader_path) else() - set_target_properties(deepmd_paddle_op_cuda PROPERTIES INSTALL_RPATH "$ORIGIN" IMPORTED_LOCATION ${PADDLE_FLUID_SHARED_LIB}) + set_target_properties( + deepmd_paddle_op_cuda + PROPERTIES INSTALL_RPATH "$ORIGIN" IMPORTED_LOCATION + ${PADDLE_FLUID_SHARED_LIB}) endif() if(BUILD_CPP_IF AND NOT BUILD_PY_IF) @@ -245,4 +251,3 @@ endif(BUILD_CPP_IF AND NOT BUILD_PY_IF) if(BUILD_PY_IF) install(TARGETS deepmd_paddle_op_cuda DESTINATION deepmd/op/) endif(BUILD_PY_IF) - diff --git a/source/lib/paddle_src/custom_op_install.py b/source/lib/paddle_src/custom_op_install.py index be5b88e36e..7f2214ca39 100644 --- a/source/lib/paddle_src/custom_op_install.py +++ b/source/lib/paddle_src/custom_op_install.py @@ -1,4 +1,6 @@ -from paddle.utils import cpp_extension +from paddle.utils import ( + cpp_extension, +) # NOTE: 请在本文件的目录下执行:python custom_op_install.py install,以安装自定义算子 diff --git a/source/lib/paddle_src/paddle_prod_env_mat.cu b/source/lib/paddle_src/paddle_prod_env_mat.cu index 42f35bb43e..c18fb7d687 100644 --- a/source/lib/paddle_src/paddle_prod_env_mat.cu +++ b/source/lib/paddle_src/paddle_prod_env_mat.cu @@ -2,6 +2,7 @@ #include #include #include + #include "paddle/extension.h" #define GOOGLE_CUDA 1 @@ -965,17 +966,14 @@ static int _norm_copy_coord_gpu(std::vector* tensor_list, // Tensor FPTYPE_temp; std::vector FPTYPE_temp_shape{nall * 3}; - // use type trait to determine the data type paddle::Tensor tmp_coord_tensor; if (std::is_same::value) { tmp_coord_tensor = paddle::empty( - FPTYPE_temp_shape, paddle::DataType::FLOAT32, paddle::GPUPlace() - ); + FPTYPE_temp_shape, paddle::DataType::FLOAT32, paddle::GPUPlace()); } else if (std::is_same::value) { tmp_coord_tensor = paddle::empty( - FPTYPE_temp_shape, paddle::DataType::FLOAT64, paddle::GPUPlace() - ); + FPTYPE_temp_shape, paddle::DataType::FLOAT64, paddle::GPUPlace()); } else { PD_THROW("invalid data type"); } diff --git a/source/lib/paddle_src/paddle_prod_force.cc b/source/lib/paddle_src/paddle_prod_force.cc index 95c6671984..f077d3e51c 100644 --- a/source/lib/paddle_src/paddle_prod_force.cc +++ b/source/lib/paddle_src/paddle_prod_force.cc @@ -100,9 +100,9 @@ std::vector ProdForceSeAForward( int n_a_sel, int n_r_sel) { if (net_deriv_tensor.place() == paddle::GPUPlace()) { - return ProdForceSeAOpCUDAForward(net_deriv_tensor, in_deriv_tensor, - nlist_tensor, natoms_tensor.copy_to(paddle::CPUPlace(), false), n_a_sel, - n_r_sel); + return ProdForceSeAOpCUDAForward( + net_deriv_tensor, in_deriv_tensor, nlist_tensor, + natoms_tensor.copy_to(paddle::CPUPlace(), false), n_a_sel, n_r_sel); } else if (net_deriv_tensor.place() == paddle::CPUPlace()) { return ProdForceSeAOpCPUForward(net_deriv_tensor, in_deriv_tensor, nlist_tensor, natoms_tensor, n_a_sel, diff --git a/source/lib/paddle_src/paddle_prod_force_grad.cc b/source/lib/paddle_src/paddle_prod_force_grad.cc index f12c2c425d..bd6509c017 100644 --- a/source/lib/paddle_src/paddle_prod_force_grad.cc +++ b/source/lib/paddle_src/paddle_prod_force_grad.cc @@ -122,9 +122,9 @@ std::vector ProdForceSeABackward( int n_a_sel, int n_r_sel) { if (net_deriv_tensor.place() == paddle::GPUPlace()) { - return ProdForceSeAOpCUDABackward(force_grad_tensor, net_deriv_tensor, - in_deriv_tensor, nlist_tensor, - natoms_tensor.copy_to(paddle::CPUPlace(), false), n_a_sel, n_r_sel); + return ProdForceSeAOpCUDABackward( + force_grad_tensor, net_deriv_tensor, in_deriv_tensor, nlist_tensor, + natoms_tensor.copy_to(paddle::CPUPlace(), false), n_a_sel, n_r_sel); } else if (net_deriv_tensor.place() == paddle::CPUPlace()) { return ProdForceSeAOpCPUBackward(force_grad_tensor, net_deriv_tensor, in_deriv_tensor, nlist_tensor, diff --git a/source/lib/paddle_src/paddle_prod_virial.cc b/source/lib/paddle_src/paddle_prod_virial.cc index 299f042694..6b4cbe324f 100644 --- a/source/lib/paddle_src/paddle_prod_virial.cc +++ b/source/lib/paddle_src/paddle_prod_virial.cc @@ -111,9 +111,9 @@ std::vector ProdVirialSeAForward( net_deriv_tensor, in_deriv_tensor, rij_tensor, nlist_tensor, natoms_tensor.copy_to(paddle::CPUPlace(), false), n_a_sel, n_r_sel); } else if (net_deriv_tensor.is_cpu()) { - return ProdVirialSeAOpCPUForward(net_deriv_tensor, in_deriv_tensor, - rij_tensor, nlist_tensor, natoms_tensor.copy_to(paddle::CPUPlace(), false), - n_a_sel, n_r_sel); + return ProdVirialSeAOpCPUForward( + net_deriv_tensor, in_deriv_tensor, rij_tensor, nlist_tensor, + natoms_tensor.copy_to(paddle::CPUPlace(), false), n_a_sel, n_r_sel); } else { PD_THROW("Unsupported device type for ProdVirialSeAForward"); } diff --git a/source/lib/paddle_src/paddle_prod_virial.cu b/source/lib/paddle_src/paddle_prod_virial.cu index 23af9bbd75..d64bcd7063 100644 --- a/source/lib/paddle_src/paddle_prod_virial.cu +++ b/source/lib/paddle_src/paddle_prod_virial.cu @@ -207,7 +207,7 @@ std::vector ProdVirialSeAOpCUDAForward( CHECK_INPUT(in_deriv_tensor); CHECK_INPUT(rij_tensor); CHECK_INPUT(nlist_tensor); - CHECK_INPUT_ON_CPU(natoms_tensor); // TODO: + CHECK_INPUT_ON_CPU(natoms_tensor); // TODO: // 暂时指定python端必须为cpu,gpu的copy_to会导致返回的指针数据不对 CHECK_INPUT_DIM(net_deriv_tensor, 2); diff --git a/source/lib/paddle_src/paddle_prod_virial_grad.cc b/source/lib/paddle_src/paddle_prod_virial_grad.cc index 7bb442b694..39b580bf89 100644 --- a/source/lib/paddle_src/paddle_prod_virial_grad.cc +++ b/source/lib/paddle_src/paddle_prod_virial_grad.cc @@ -129,7 +129,8 @@ std::vector ProdVirialSeABackward( if (virial_grad_tensor.is_gpu()) { return ProdVirialSeAOpCUDABackward( virial_grad_tensor, net_deriv_tensor, in_deriv_tensor, rij_tensor, - nlist_tensor, natoms_tensor.copy_to(paddle::CPUPlace(), false), n_a_sel, n_r_sel); + nlist_tensor, natoms_tensor.copy_to(paddle::CPUPlace(), false), n_a_sel, + n_r_sel); } else if (virial_grad_tensor.is_cpu()) { return ProdVirialSeAOpCPUBackward(virial_grad_tensor, net_deriv_tensor, in_deriv_tensor, rij_tensor, nlist_tensor, diff --git a/source/lmp/pair_deepmd.cpp b/source/lmp/pair_deepmd.cpp index 8922260e5f..29a43422c0 100644 --- a/source/lmp/pair_deepmd.cpp +++ b/source/lmp/pair_deepmd.cpp @@ -834,7 +834,8 @@ void PairDeepMD::settings(int narg, char **arg) { if (numb_models == 1) { try { auto ptr = strstr(arg[0], ".pb"); - deep_pot.init(arg[0], get_node_rank(), (ptr != NULL) ? get_file_content(arg[0]) : ""); + deep_pot.init(arg[0], get_node_rank(), + (ptr != NULL) ? get_file_content(arg[0]) : ""); } catch (deepmd_compat::deepmd_exception &e) { error->one(FLERR, e.what()); } diff --git a/source/lmp/tests/test_deeptensor.py b/source/lmp/tests/test_deeptensor.py index 32fad73404..0029247959 100644 --- a/source/lmp/tests/test_deeptensor.py +++ b/source/lmp/tests/test_deeptensor.py @@ -1,12 +1,18 @@ import os import subprocess as sp import sys -from pathlib import Path +from pathlib import ( + Path, +) import numpy as np import pytest -from lammps import PyLammps -from write_lmp_data import write_lmp_data +from lammps import ( + PyLammps, +) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pb_file = Path(__file__).parent / "graph.pb" diff --git a/source/lmp/tests/test_dplr.py b/source/lmp/tests/test_dplr.py index 0d0efad2c8..b6398b77be 100644 --- a/source/lmp/tests/test_dplr.py +++ b/source/lmp/tests/test_dplr.py @@ -1,12 +1,18 @@ import os import subprocess as sp import sys -from pathlib import Path +from pathlib import ( + Path, +) import numpy as np import pytest -from lammps import PyLammps -from write_lmp_data import write_lmp_data_full +from lammps import ( + PyLammps, +) +from write_lmp_data import ( + write_lmp_data_full, +) pbtxt_file = Path(__file__).parent / "lrmodel.pbtxt" pb_file = Path(__file__).parent / "lrmodel.pb" diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index e5e7eff307..f5cb7bac14 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -1,12 +1,18 @@ import os import subprocess as sp import sys -from pathlib import Path +from pathlib import ( + Path, +) import numpy as np import pytest -from lammps import PyLammps -from write_lmp_data import write_lmp_data +from lammps import ( + PyLammps, +) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pbtxt_file2 = ( diff --git a/source/lmp/tests/test_lammps_3types.py b/source/lmp/tests/test_lammps_3types.py index 07843cdfd2..24ef0fae38 100644 --- a/source/lmp/tests/test_lammps_3types.py +++ b/source/lmp/tests/test_lammps_3types.py @@ -1,12 +1,18 @@ import os import subprocess as sp import sys -from pathlib import Path +from pathlib import ( + Path, +) import numpy as np import pytest -from lammps import PyLammps -from write_lmp_data import write_lmp_data +from lammps import ( + PyLammps, +) +from write_lmp_data import ( + write_lmp_data, +) pbtxt_file = Path(__file__).parent.parent.parent / "tests" / "infer" / "deeppot.pbtxt" pbtxt_file2 = ( diff --git a/source/op/_add_flt_nvnmd_grad.py b/source/op/_add_flt_nvnmd_grad.py index b001602507..0eedd0372c 100644 --- a/source/op/_add_flt_nvnmd_grad.py +++ b/source/op/_add_flt_nvnmd_grad.py @@ -1,8 +1,12 @@ #!/usr/bin/env python3 -from tensorflow.python.framework import ops +from tensorflow.python.framework import ( + ops, +) -from deepmd.env import op_module +from deepmd.env import ( + op_module, +) @ops.RegisterGradient("AddFltNvnmd") diff --git a/source/op/_copy_flt_nvnmd_grad.py b/source/op/_copy_flt_nvnmd_grad.py index 2dbcfcbc49..47b8956143 100644 --- a/source/op/_copy_flt_nvnmd_grad.py +++ b/source/op/_copy_flt_nvnmd_grad.py @@ -1,8 +1,12 @@ #!/usr/bin/env python3 -from tensorflow.python.framework import ops +from tensorflow.python.framework import ( + ops, +) -from deepmd.env import op_module +from deepmd.env import ( + op_module, +) @ops.RegisterGradient("CopyFltNvnmd") diff --git a/source/op/_dotmul_flt_nvnmd_grad.py b/source/op/_dotmul_flt_nvnmd_grad.py index 42bc2614f3..97653b1540 100644 --- a/source/op/_dotmul_flt_nvnmd_grad.py +++ b/source/op/_dotmul_flt_nvnmd_grad.py @@ -1,9 +1,13 @@ #!/usr/bin/env python3 -from tensorflow.python.framework import ops +from tensorflow.python.framework import ( + ops, +) -from deepmd.env import op_module -from deepmd.env import tf +from deepmd.env import ( + op_module, + tf, +) @ops.RegisterGradient("DotmulFltNvnmd") diff --git a/source/op/_flt_nvnmd_grad.py b/source/op/_flt_nvnmd_grad.py index 58408ad616..471bc35b1c 100644 --- a/source/op/_flt_nvnmd_grad.py +++ b/source/op/_flt_nvnmd_grad.py @@ -1,8 +1,12 @@ #!/usr/bin/env python3 -from tensorflow.python.framework import ops +from tensorflow.python.framework import ( + ops, +) -from deepmd.env import op_module +from deepmd.env import ( + op_module, +) @ops.RegisterGradient("FltNvnmd") diff --git a/source/op/_gelu.py b/source/op/_gelu.py index 2255ee61be..19b2a3f240 100644 --- a/source/op/_gelu.py +++ b/source/op/_gelu.py @@ -1,9 +1,13 @@ #!/usr/bin/env python3 """First-order derivatives and second-order derivatives for gelu function.""" import tensorflow -from tensorflow.python.framework import ops +from tensorflow.python.framework import ( + ops, +) -from deepmd.env import op_module +from deepmd.env import ( + op_module, +) try: gelu = tensorflow.nn.gelu diff --git a/source/op/_map_flt_nvnmd_grad.py b/source/op/_map_flt_nvnmd_grad.py index caeb3de171..434701bc6e 100644 --- a/source/op/_map_flt_nvnmd_grad.py +++ b/source/op/_map_flt_nvnmd_grad.py @@ -1,9 +1,13 @@ #!/usr/bin/env python3 -from tensorflow.python.framework import ops +from tensorflow.python.framework import ( + ops, +) -from deepmd.env import op_module -from deepmd.env import tf +from deepmd.env import ( + op_module, + tf, +) @ops.RegisterGradient("MapFltNvnmd") diff --git a/source/op/_matmul_fitnet_nvnmd_grad.py b/source/op/_matmul_fitnet_nvnmd_grad.py index fa4c92d493..77fafb7d24 100644 --- a/source/op/_matmul_fitnet_nvnmd_grad.py +++ b/source/op/_matmul_fitnet_nvnmd_grad.py @@ -1,9 +1,13 @@ #!/usr/bin/env python3 -from tensorflow.python.framework import ops +from tensorflow.python.framework import ( + ops, +) -from deepmd.env import op_module -from deepmd.env import tf +from deepmd.env import ( + op_module, + tf, +) @ops.RegisterGradient("MatmulFitnetNvnmd") diff --git a/source/op/_matmul_flt2fix_nvnmd.py b/source/op/_matmul_flt2fix_nvnmd.py index 670674103d..3b47b14a09 100644 --- a/source/op/_matmul_flt2fix_nvnmd.py +++ b/source/op/_matmul_flt2fix_nvnmd.py @@ -1,9 +1,13 @@ #!/usr/bin/env python3 -from tensorflow.python.framework import ops +from tensorflow.python.framework import ( + ops, +) -from deepmd.env import op_module -from deepmd.env import tf +from deepmd.env import ( + op_module, + tf, +) @ops.RegisterGradient("MatmulFlt2fixNvnmd") diff --git a/source/op/_matmul_flt_nvnmd_grad.py b/source/op/_matmul_flt_nvnmd_grad.py index 1e9f980508..383e464e64 100644 --- a/source/op/_matmul_flt_nvnmd_grad.py +++ b/source/op/_matmul_flt_nvnmd_grad.py @@ -1,9 +1,13 @@ #!/usr/bin/env python3 -from tensorflow.python.framework import ops +from tensorflow.python.framework import ( + ops, +) -from deepmd.env import op_module -from deepmd.env import tf +from deepmd.env import ( + op_module, + tf, +) @ops.RegisterGradient("MatmulFltNvnmd") diff --git a/source/op/_mul_flt_nvnmd_grad.py b/source/op/_mul_flt_nvnmd_grad.py index 634fa56484..e1fb72ac6b 100644 --- a/source/op/_mul_flt_nvnmd_grad.py +++ b/source/op/_mul_flt_nvnmd_grad.py @@ -1,9 +1,13 @@ #!/usr/bin/env python3 -from tensorflow.python.framework import ops +from tensorflow.python.framework import ( + ops, +) -from deepmd.env import op_module -from deepmd.env import tf +from deepmd.env import ( + op_module, + tf, +) @ops.RegisterGradient("MulFltNvnmd") diff --git a/source/op/_prod_force_grad.py b/source/op/_prod_force_grad.py index 3fb5296057..8cdd37675c 100644 --- a/source/op/_prod_force_grad.py +++ b/source/op/_prod_force_grad.py @@ -1,9 +1,13 @@ #!/usr/bin/env python3 """Gradients for prod force.""" -from tensorflow.python.framework import ops +from tensorflow.python.framework import ( + ops, +) -from deepmd.env import op_grads_module +from deepmd.env import ( + op_grads_module, +) @ops.RegisterGradient("ProdForce") diff --git a/source/op/_prod_force_se_a_grad.py b/source/op/_prod_force_se_a_grad.py index 56e36d8a4a..cdfa73e4ad 100644 --- a/source/op/_prod_force_se_a_grad.py +++ b/source/op/_prod_force_se_a_grad.py @@ -1,9 +1,13 @@ #!/usr/bin/env python3 """Gradients for prod force.""" -from tensorflow.python.framework import ops +from tensorflow.python.framework import ( + ops, +) -from deepmd.env import op_grads_module +from deepmd.env import ( + op_grads_module, +) @ops.RegisterGradient("ProdForceSeA") diff --git a/source/op/_prod_force_se_a_mask_grad.py b/source/op/_prod_force_se_a_mask_grad.py index 9fc7a994b7..b4c4f8fabc 100644 --- a/source/op/_prod_force_se_a_mask_grad.py +++ b/source/op/_prod_force_se_a_mask_grad.py @@ -1,9 +1,13 @@ #!/usr/bin/env python3 """Gradients for prod force se_a_mask.""" -from tensorflow.python.framework import ops +from tensorflow.python.framework import ( + ops, +) -from deepmd.env import op_grads_module +from deepmd.env import ( + op_grads_module, +) @ops.RegisterGradient("ProdForceSeAMask") diff --git a/source/op/_prod_force_se_r_grad.py b/source/op/_prod_force_se_r_grad.py index 0a092961a6..447c388912 100644 --- a/source/op/_prod_force_se_r_grad.py +++ b/source/op/_prod_force_se_r_grad.py @@ -1,9 +1,13 @@ #!/usr/bin/env python3 """Gradients for prod force.""" -from tensorflow.python.framework import ops +from tensorflow.python.framework import ( + ops, +) -from deepmd.env import op_grads_module +from deepmd.env import ( + op_grads_module, +) @ops.RegisterGradient("ProdForceSeR") diff --git a/source/op/_prod_virial_grad.py b/source/op/_prod_virial_grad.py index e4c1bad3d0..aa8cca0939 100644 --- a/source/op/_prod_virial_grad.py +++ b/source/op/_prod_virial_grad.py @@ -1,9 +1,13 @@ #!/usr/bin/env python3 """Gradients for prod virial.""" -from tensorflow.python.framework import ops +from tensorflow.python.framework import ( + ops, +) -from deepmd.env import op_grads_module +from deepmd.env import ( + op_grads_module, +) @ops.RegisterGradient("ProdVirial") diff --git a/source/op/_prod_virial_se_a_grad.py b/source/op/_prod_virial_se_a_grad.py index 043bf7b737..6167795b7c 100644 --- a/source/op/_prod_virial_se_a_grad.py +++ b/source/op/_prod_virial_se_a_grad.py @@ -1,9 +1,13 @@ #!/usr/bin/env python3 """Gradients for prod virial.""" -from tensorflow.python.framework import ops +from tensorflow.python.framework import ( + ops, +) -from deepmd.env import op_grads_module +from deepmd.env import ( + op_grads_module, +) @ops.RegisterGradient("ProdVirialSeA") diff --git a/source/op/_prod_virial_se_r_grad.py b/source/op/_prod_virial_se_r_grad.py index c9c395eb7b..bb7680203d 100644 --- a/source/op/_prod_virial_se_r_grad.py +++ b/source/op/_prod_virial_se_r_grad.py @@ -1,9 +1,13 @@ #!/usr/bin/env python3 """Gradients for prod virial.""" -from tensorflow.python.framework import ops +from tensorflow.python.framework import ( + ops, +) -from deepmd.env import op_grads_module +from deepmd.env import ( + op_grads_module, +) @ops.RegisterGradient("ProdVirialSeR") diff --git a/source/op/_quantize_nvnmd_grad.py b/source/op/_quantize_nvnmd_grad.py index c7d2e1d076..64a492c04f 100644 --- a/source/op/_quantize_nvnmd_grad.py +++ b/source/op/_quantize_nvnmd_grad.py @@ -1,8 +1,12 @@ #!/usr/bin/env python3 -from tensorflow.python.framework import ops +from tensorflow.python.framework import ( + ops, +) -from deepmd.env import op_module +from deepmd.env import ( + op_module, +) @ops.RegisterGradient("QuantizeNvnmd") diff --git a/source/op/_soft_min_force_grad.py b/source/op/_soft_min_force_grad.py index 0ea5db0c6d..c8519886d5 100644 --- a/source/op/_soft_min_force_grad.py +++ b/source/op/_soft_min_force_grad.py @@ -1,9 +1,13 @@ #!/usr/bin/env python3 """Gradients for soft min force.""" -from tensorflow.python.framework import ops +from tensorflow.python.framework import ( + ops, +) -from deepmd.env import op_grads_module +from deepmd.env import ( + op_grads_module, +) @ops.RegisterGradient("SoftMinForce") diff --git a/source/op/_soft_min_virial_grad.py b/source/op/_soft_min_virial_grad.py index a12050ee6a..f35bba9080 100644 --- a/source/op/_soft_min_virial_grad.py +++ b/source/op/_soft_min_virial_grad.py @@ -1,9 +1,13 @@ #!/usr/bin/env python3 """Gradients for soft min virial.""" -from tensorflow.python.framework import ops +from tensorflow.python.framework import ( + ops, +) -from deepmd.env import op_grads_module +from deepmd.env import ( + op_grads_module, +) @ops.RegisterGradient("SoftMinVirial") diff --git a/source/op/_tabulate_grad.py b/source/op/_tabulate_grad.py index 369d584e9e..785146cfcc 100644 --- a/source/op/_tabulate_grad.py +++ b/source/op/_tabulate_grad.py @@ -1,9 +1,13 @@ #!/usr/bin/env python3 """Gradients for tabulate.""" -from tensorflow.python.framework import ops +from tensorflow.python.framework import ( + ops, +) -from deepmd.env import op_module +from deepmd.env import ( + op_module, +) # from deepmd.DescrptSeATabulate import last_layer_size diff --git a/source/op/_tanh4_flt_nvnmd_grad.py b/source/op/_tanh4_flt_nvnmd_grad.py index bcfc01dbe9..9ccfe701df 100644 --- a/source/op/_tanh4_flt_nvnmd_grad.py +++ b/source/op/_tanh4_flt_nvnmd_grad.py @@ -1,8 +1,12 @@ #!/usr/bin/env python3 -from tensorflow.python.framework import ops +from tensorflow.python.framework import ( + ops, +) -from deepmd.env import tf +from deepmd.env import ( + tf, +) @ops.RegisterGradient("Tanh4FltNvnmd") diff --git a/source/tests/common.py b/source/tests/common.py index a450fcca00..dcbccd221a 100644 --- a/source/tests/common.py +++ b/source/tests/common.py @@ -8,9 +8,13 @@ import numpy as np from deepmd.common import j_loader as dp_j_loader -from deepmd.entrypoints.main import main -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import tf +from deepmd.entrypoints.main import ( + main, +) +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + tf, +) from deepmd.utils import random as dp_random if GLOBAL_NP_FLOAT_PRECISION == np.float32: diff --git a/source/tests/test_activation_fn_gelu.py b/source/tests/test_activation_fn_gelu.py index ade5afab21..4b0a430c35 100644 --- a/source/tests/test_activation_fn_gelu.py +++ b/source/tests/test_activation_fn_gelu.py @@ -2,9 +2,15 @@ import numpy as np -from deepmd.common import get_activation_func -from deepmd.env import tf -from deepmd.utils.network import embedding_net +from deepmd.common import ( + get_activation_func, +) +from deepmd.env import ( + tf, +) +from deepmd.utils.network import ( + embedding_net, +) class TestGelu(tf.test.TestCase): diff --git a/source/tests/test_adjust_sel.py b/source/tests/test_adjust_sel.py index f9d876f8df..f7908af01c 100644 --- a/source/tests/test_adjust_sel.py +++ b/source/tests/test_adjust_sel.py @@ -6,12 +6,18 @@ import numpy as np # from deepmd.entrypoints.compress import compress -from common import j_loader -from common import run_dp -from common import tests_path +from common import ( + j_loader, + run_dp, + tests_path, +) -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.infer import DeepPot +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, +) +from deepmd.infer import ( + DeepPot, +) if GLOBAL_NP_FLOAT_PRECISION == np.float32: default_places = 4 diff --git a/source/tests/test_argument_parser.py b/source/tests/test_argument_parser.py index 2dd1cf0646..e48a2da24b 100644 --- a/source/tests/test_argument_parser.py +++ b/source/tests/test_argument_parser.py @@ -2,18 +2,28 @@ import re import unittest -from argparse import Namespace -from contextlib import redirect_stderr -from io import StringIO -from typing import TYPE_CHECKING -from typing import Any -from typing import Dict -from typing import List -from typing import Tuple -from typing import Union - -from deepmd.entrypoints.main import get_ll -from deepmd.entrypoints.main import parse_args +from argparse import ( + Namespace, +) +from contextlib import ( + redirect_stderr, +) +from io import ( + StringIO, +) +from typing import ( + TYPE_CHECKING, + Any, + Dict, + List, + Tuple, + Union, +) + +from deepmd.entrypoints.main import ( + get_ll, + parse_args, +) if TYPE_CHECKING: try: diff --git a/source/tests/test_auto_batch_size.py b/source/tests/test_auto_batch_size.py index 5fa7e2c4f7..bd863b2633 100644 --- a/source/tests/test_auto_batch_size.py +++ b/source/tests/test_auto_batch_size.py @@ -3,8 +3,12 @@ import numpy as np -from deepmd.utils.batch_size import AutoBatchSize -from deepmd.utils.errors import OutOfMemoryError +from deepmd.utils.batch_size import ( + AutoBatchSize, +) +from deepmd.utils.errors import ( + OutOfMemoryError, +) class TestAutoBatchSize(unittest.TestCase): diff --git a/source/tests/test_cluster.py b/source/tests/test_cluster.py index 53a2ace763..ceaddf41d4 100644 --- a/source/tests/test_cluster.py +++ b/source/tests/test_cluster.py @@ -1,8 +1,12 @@ import unittest -from unittest import mock - -from deepmd.cluster import local -from deepmd.cluster import slurm +from unittest import ( + mock, +) + +from deepmd.cluster import ( + local, + slurm, +) kHostName = "compute-b24-1" diff --git a/source/tests/test_common.py b/source/tests/test_common.py index 7bfe700a51..c3d6172f5b 100644 --- a/source/tests/test_common.py +++ b/source/tests/test_common.py @@ -1,11 +1,17 @@ import shutil import unittest -from pathlib import Path +from pathlib import ( + Path, +) -from deepmd.common import GLOBAL_TF_FLOAT_PRECISION -from deepmd.common import cast_precision -from deepmd.common import expand_sys_str -from deepmd.env import tf +from deepmd.common import ( + GLOBAL_TF_FLOAT_PRECISION, + cast_precision, + expand_sys_str, +) +from deepmd.env import ( + tf, +) # compute relative path diff --git a/source/tests/test_compat_input.py b/source/tests/test_compat_input.py index 91a51e52c6..df5fcd45f7 100644 --- a/source/tests/test_compat_input.py +++ b/source/tests/test_compat_input.py @@ -1,10 +1,14 @@ import os import unittest -from common import j_loader - -from deepmd.utils.compat import convert_input_v0_v1 -from deepmd.utils.compat import convert_input_v1_v2 +from common import ( + j_loader, +) + +from deepmd.utils.compat import ( + convert_input_v0_v1, + convert_input_v1_v2, +) class TestConvertInput(unittest.TestCase): diff --git a/source/tests/test_data_large_batch.py b/source/tests/test_data_large_batch.py index ba7f425c6d..531c6de4f3 100644 --- a/source/tests/test_data_large_batch.py +++ b/source/tests/test_data_large_batch.py @@ -1,17 +1,33 @@ import unittest import numpy as np -from common import gen_data -from common import j_loader +from common import ( + gen_data, + j_loader, +) from packaging.version import parse as parse_version -from deepmd.common import j_must_have -from deepmd.descriptor import DescrptSeAtten -from deepmd.env import tf -from deepmd.fit import EnerFitting -from deepmd.model import EnerModel -from deepmd.utils.data_system import DeepmdDataSystem -from deepmd.utils.type_embed import TypeEmbedNet +from deepmd.common import ( + j_must_have, +) +from deepmd.descriptor import ( + DescrptSeAtten, +) +from deepmd.env import ( + tf, +) +from deepmd.fit import ( + EnerFitting, +) +from deepmd.model import ( + EnerModel, +) +from deepmd.utils.data_system import ( + DeepmdDataSystem, +) +from deepmd.utils.type_embed import ( + TypeEmbedNet, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 diff --git a/source/tests/test_data_modifier.py b/source/tests/test_data_modifier.py index 793dc0540f..99395f1127 100644 --- a/source/tests/test_data_modifier.py +++ b/source/tests/test_data_modifier.py @@ -1,18 +1,32 @@ import os import numpy as np -from common import Data -from common import j_loader -from common import tests_path - -from deepmd.common import data_requirement -from deepmd.common import j_must_have -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import tf -from deepmd.infer.data_modifier import DipoleChargeModifier -from deepmd.train.run_options import RunOptions -from deepmd.train.trainer import DPTrainer -from deepmd.utils.data_system import DeepmdDataSystem +from common import ( + Data, + j_loader, + tests_path, +) + +from deepmd.common import ( + data_requirement, + j_must_have, +) +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + tf, +) +from deepmd.infer.data_modifier import ( + DipoleChargeModifier, +) +from deepmd.train.run_options import ( + RunOptions, +) +from deepmd.train.trainer import ( + DPTrainer, +) +from deepmd.utils.data_system import ( + DeepmdDataSystem, +) if GLOBAL_NP_FLOAT_PRECISION == np.float32: global_default_fv_hh = 1e-2 diff --git a/source/tests/test_data_modifier_shuffle.py b/source/tests/test_data_modifier_shuffle.py index 62725407de..7a7a9628e1 100644 --- a/source/tests/test_data_modifier_shuffle.py +++ b/source/tests/test_data_modifier_shuffle.py @@ -3,15 +3,29 @@ import numpy as np -from deepmd.common import data_requirement -from deepmd.common import j_must_have -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import tf -from deepmd.infer.data_modifier import DipoleChargeModifier -from deepmd.infer.deep_dipole import DeepDipole -from deepmd.train.run_options import RunOptions -from deepmd.train.trainer import DPTrainer -from deepmd.utils.data_system import DeepmdDataSystem +from deepmd.common import ( + data_requirement, + j_must_have, +) +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + tf, +) +from deepmd.infer.data_modifier import ( + DipoleChargeModifier, +) +from deepmd.infer.deep_dipole import ( + DeepDipole, +) +from deepmd.train.run_options import ( + RunOptions, +) +from deepmd.train.trainer import ( + DPTrainer, +) +from deepmd.utils.data_system import ( + DeepmdDataSystem, +) if GLOBAL_NP_FLOAT_PRECISION == np.float32: global_default_fv_hh = 1e-2 diff --git a/source/tests/test_data_requirement.py b/source/tests/test_data_requirement.py index cc204cc818..c407e3d5bd 100644 --- a/source/tests/test_data_requirement.py +++ b/source/tests/test_data_requirement.py @@ -1,7 +1,9 @@ import unittest -from deepmd.common import add_data_requirement -from deepmd.common import data_requirement +from deepmd.common import ( + add_data_requirement, + data_requirement, +) class TestDataRequirement(unittest.TestCase): diff --git a/source/tests/test_deepdipole.py b/source/tests/test_deepdipole.py index 7b41f1d244..ee96a74392 100644 --- a/source/tests/test_deepdipole.py +++ b/source/tests/test_deepdipole.py @@ -2,15 +2,23 @@ import unittest import numpy as np -from common import finite_difference -from common import strerch_box -from common import tests_path -from common import tf +from common import ( + finite_difference, + strerch_box, + tests_path, + tf, +) from packaging.version import parse as parse_version -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.infer import DeepDipole -from deepmd.utils.convert import convert_pbtxt_to_pb +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, +) +from deepmd.infer import ( + DeepDipole, +) +from deepmd.utils.convert import ( + convert_pbtxt_to_pb, +) if GLOBAL_NP_FLOAT_PRECISION == np.float32: default_places = 4 diff --git a/source/tests/test_deepdos.py b/source/tests/test_deepdos.py index 2d405ee201..c8968c04d5 100644 --- a/source/tests/test_deepdos.py +++ b/source/tests/test_deepdos.py @@ -2,11 +2,19 @@ import unittest import numpy as np -from common import tests_path +from common import ( + tests_path, +) -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.infer import DeepDOS -from deepmd.utils.convert import convert_pbtxt_to_pb +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, +) +from deepmd.infer import ( + DeepDOS, +) +from deepmd.utils.convert import ( + convert_pbtxt_to_pb, +) if GLOBAL_NP_FLOAT_PRECISION == np.float32: default_places = 4 diff --git a/source/tests/test_deepmd_data.py b/source/tests/test_deepmd_data.py index 1166ab9950..3861b37312 100644 --- a/source/tests/test_deepmd_data.py +++ b/source/tests/test_deepmd_data.py @@ -4,10 +4,16 @@ import unittest import numpy as np -from common import tests_path +from common import ( + tests_path, +) -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.utils.data import DeepmdData +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, +) +from deepmd.utils.data import ( + DeepmdData, +) if GLOBAL_NP_FLOAT_PRECISION == np.float32: places = 6 diff --git a/source/tests/test_deepmd_data_sys.py b/source/tests/test_deepmd_data_sys.py index 4b1d6d9509..5ed9d3d3f6 100644 --- a/source/tests/test_deepmd_data_sys.py +++ b/source/tests/test_deepmd_data_sys.py @@ -4,9 +4,15 @@ import numpy as np -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.utils import random -from deepmd.utils.data_system import DeepmdDataSystem +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, +) +from deepmd.utils import ( + random, +) +from deepmd.utils.data_system import ( + DeepmdDataSystem, +) if GLOBAL_NP_FLOAT_PRECISION == np.float32: places = 6 diff --git a/source/tests/test_deeppolar.py b/source/tests/test_deeppolar.py index 28530580e8..10c2fefb33 100644 --- a/source/tests/test_deeppolar.py +++ b/source/tests/test_deeppolar.py @@ -2,13 +2,21 @@ import unittest import numpy as np -from common import tests_path -from common import tf +from common import ( + tests_path, + tf, +) from packaging.version import parse as parse_version -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.infer import DeepPolar -from deepmd.utils.convert import convert_pbtxt_to_pb +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, +) +from deepmd.infer import ( + DeepPolar, +) +from deepmd.utils.convert import ( + convert_pbtxt_to_pb, +) if GLOBAL_NP_FLOAT_PRECISION == np.float32: default_places = 4 diff --git a/source/tests/test_deeppot_a.py b/source/tests/test_deeppot_a.py index 57cf70beaf..a0a3bd0f33 100644 --- a/source/tests/test_deeppot_a.py +++ b/source/tests/test_deeppot_a.py @@ -3,19 +3,27 @@ import unittest import numpy as np -from common import run_dp -from common import tests_path +from common import ( + run_dp, + tests_path, +) -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import MODEL_VERSION -from deepmd.infer import DeepPot -from deepmd.utils.convert import convert_dp10_to_dp11 -from deepmd.utils.convert import convert_dp012_to_dp10 -from deepmd.utils.convert import convert_dp12_to_dp13 -from deepmd.utils.convert import convert_dp13_to_dp20 -from deepmd.utils.convert import convert_dp20_to_dp21 -from deepmd.utils.convert import convert_pbtxt_to_pb -from deepmd.utils.convert import detect_model_version +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + MODEL_VERSION, +) +from deepmd.infer import ( + DeepPot, +) +from deepmd.utils.convert import ( + convert_dp10_to_dp11, + convert_dp012_to_dp10, + convert_dp12_to_dp13, + convert_dp13_to_dp20, + convert_dp20_to_dp21, + convert_pbtxt_to_pb, + detect_model_version, +) if GLOBAL_NP_FLOAT_PRECISION == np.float32: default_places = 4 @@ -664,9 +672,13 @@ def test_1frame_atm(self): np.testing.assert_almost_equal(vv.ravel(), expected_sv.ravel(), default_places) def test_ase(self): - from ase import Atoms + from ase import ( + Atoms, + ) - from deepmd.calculator import DP + from deepmd.calculator import ( + DP, + ) water = Atoms( "OHHOHH", diff --git a/source/tests/test_deeppot_r.py b/source/tests/test_deeppot_r.py index acc11b8305..36d840b831 100644 --- a/source/tests/test_deeppot_r.py +++ b/source/tests/test_deeppot_r.py @@ -2,11 +2,19 @@ import unittest import numpy as np -from common import tests_path +from common import ( + tests_path, +) -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.infer import DeepPot -from deepmd.utils.convert import convert_pbtxt_to_pb +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, +) +from deepmd.infer import ( + DeepPot, +) +from deepmd.utils.convert import ( + convert_pbtxt_to_pb, +) if GLOBAL_NP_FLOAT_PRECISION == np.float32: default_places = 4 diff --git a/source/tests/test_deeppot_spin.py b/source/tests/test_deeppot_spin.py index 0d4db8fd57..516633b9e6 100644 --- a/source/tests/test_deeppot_spin.py +++ b/source/tests/test_deeppot_spin.py @@ -2,11 +2,19 @@ import unittest import numpy as np -from common import tests_path +from common import ( + tests_path, +) -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.infer import DeepPot -from deepmd.utils.convert import convert_pbtxt_to_pb +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, +) +from deepmd.infer import ( + DeepPot, +) +from deepmd.utils.convert import ( + convert_pbtxt_to_pb, +) if GLOBAL_NP_FLOAT_PRECISION == np.float32: default_places = 4 diff --git a/source/tests/test_descrpt_nonsmth.py b/source/tests/test_descrpt_nonsmth.py index 3e24465f84..a0e560c331 100644 --- a/source/tests/test_descrpt_nonsmth.py +++ b/source/tests/test_descrpt_nonsmth.py @@ -1,17 +1,21 @@ import unittest import numpy as np -from common import Data -from common import force_dw_test -from common import force_test -from common import virial_dw_test -from common import virial_test +from common import ( + Data, + force_dw_test, + force_test, + virial_dw_test, + virial_test, +) # load grad of force module -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import op_module -from deepmd.env import tf +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + GLOBAL_TF_FLOAT_PRECISION, + op_module, + tf, +) class Inter: diff --git a/source/tests/test_descrpt_se_a_mask.py b/source/tests/test_descrpt_se_a_mask.py index d5011f9c58..b5281b0ed4 100644 --- a/source/tests/test_descrpt_se_a_mask.py +++ b/source/tests/test_descrpt_se_a_mask.py @@ -2,14 +2,26 @@ import pathlib import numpy as np -from common import DataSystem -from common import j_loader +from common import ( + DataSystem, + j_loader, +) -from deepmd.common import j_must_have -from deepmd.descriptor import DescrptSeAMask -from deepmd.env import tf -from deepmd.infer import DeepPot -from deepmd.utils.convert import convert_pbtxt_to_pb +from deepmd.common import ( + j_must_have, +) +from deepmd.descriptor import ( + DescrptSeAMask, +) +from deepmd.env import ( + tf, +) +from deepmd.infer import ( + DeepPot, +) +from deepmd.utils.convert import ( + convert_pbtxt_to_pb, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 diff --git a/source/tests/test_descrpt_se_a_type.py b/source/tests/test_descrpt_se_a_type.py index 604a909b85..e143709b47 100644 --- a/source/tests/test_descrpt_se_a_type.py +++ b/source/tests/test_descrpt_se_a_type.py @@ -1,12 +1,22 @@ import numpy as np -from common import DataSystem -from common import gen_data -from common import j_loader - -from deepmd.common import j_must_have -from deepmd.descriptor import DescrptSeA -from deepmd.env import tf -from deepmd.utils.type_embed import TypeEmbedNet +from common import ( + DataSystem, + gen_data, + j_loader, +) + +from deepmd.common import ( + j_must_have, +) +from deepmd.descriptor import ( + DescrptSeA, +) +from deepmd.env import ( + tf, +) +from deepmd.utils.type_embed import ( + TypeEmbedNet, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 diff --git a/source/tests/test_descrpt_se_atten.py b/source/tests/test_descrpt_se_atten.py index 459190ac16..cfa2cdaae5 100644 --- a/source/tests/test_descrpt_se_atten.py +++ b/source/tests/test_descrpt_se_atten.py @@ -1,15 +1,25 @@ import unittest import numpy as np -from common import DataSystem -from common import gen_data -from common import j_loader +from common import ( + DataSystem, + gen_data, + j_loader, +) from packaging.version import parse as parse_version -from deepmd.common import j_must_have -from deepmd.descriptor import DescrptSeAtten -from deepmd.env import tf -from deepmd.utils.type_embed import TypeEmbedNet +from deepmd.common import ( + j_must_have, +) +from deepmd.descriptor import ( + DescrptSeAtten, +) +from deepmd.env import ( + tf, +) +from deepmd.utils.type_embed import ( + TypeEmbedNet, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 diff --git a/source/tests/test_descrpt_se_r.py b/source/tests/test_descrpt_se_r.py index 6778136b91..362d64f58d 100644 --- a/source/tests/test_descrpt_se_r.py +++ b/source/tests/test_descrpt_se_r.py @@ -1,17 +1,21 @@ import unittest import numpy as np -from common import Data -from common import force_dw_test -from common import force_test -from common import virial_dw_test -from common import virial_test +from common import ( + Data, + force_dw_test, + force_test, + virial_dw_test, + virial_test, +) # load grad of force module -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import op_module -from deepmd.env import tf +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + GLOBAL_TF_FLOAT_PRECISION, + op_module, + tf, +) class Inter: diff --git a/source/tests/test_descrpt_sea_ef.py b/source/tests/test_descrpt_sea_ef.py index 545920cd3e..ef0712c5ae 100644 --- a/source/tests/test_descrpt_sea_ef.py +++ b/source/tests/test_descrpt_sea_ef.py @@ -1,17 +1,21 @@ import unittest import numpy as np -from common import Data -from common import force_dw_test -from common import force_test -from common import virial_dw_test -from common import virial_test +from common import ( + Data, + force_dw_test, + force_test, + virial_dw_test, + virial_test, +) # load grad of force module -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import op_module -from deepmd.env import tf +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + GLOBAL_TF_FLOAT_PRECISION, + op_module, + tf, +) class Inter: diff --git a/source/tests/test_descrpt_sea_ef_para.py b/source/tests/test_descrpt_sea_ef_para.py index f7dff2151f..68696ac4f0 100644 --- a/source/tests/test_descrpt_sea_ef_para.py +++ b/source/tests/test_descrpt_sea_ef_para.py @@ -1,17 +1,21 @@ import unittest import numpy as np -from common import Data -from common import force_dw_test -from common import force_test -from common import virial_dw_test -from common import virial_test +from common import ( + Data, + force_dw_test, + force_test, + virial_dw_test, + virial_test, +) # load grad of force module -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import op_module -from deepmd.env import tf +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + GLOBAL_TF_FLOAT_PRECISION, + op_module, + tf, +) class Inter: diff --git a/source/tests/test_descrpt_sea_ef_rot.py b/source/tests/test_descrpt_sea_ef_rot.py index 9098422662..cdeb51350e 100644 --- a/source/tests/test_descrpt_sea_ef_rot.py +++ b/source/tests/test_descrpt_sea_ef_rot.py @@ -2,12 +2,16 @@ import numpy as np -from deepmd.descriptor import DescrptSeA -from deepmd.descriptor import DescrptSeAEfLower -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import op_module -from deepmd.env import tf +from deepmd.descriptor import ( + DescrptSeA, + DescrptSeAEfLower, +) +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + GLOBAL_TF_FLOAT_PRECISION, + op_module, + tf, +) class TestEfRot(tf.test.TestCase): diff --git a/source/tests/test_descrpt_sea_ef_vert.py b/source/tests/test_descrpt_sea_ef_vert.py index e8b48583b5..67269cff77 100644 --- a/source/tests/test_descrpt_sea_ef_vert.py +++ b/source/tests/test_descrpt_sea_ef_vert.py @@ -1,17 +1,21 @@ import unittest import numpy as np -from common import Data -from common import force_dw_test -from common import force_test -from common import virial_dw_test -from common import virial_test +from common import ( + Data, + force_dw_test, + force_test, + virial_dw_test, + virial_test, +) # load grad of force module -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import op_module -from deepmd.env import tf +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + GLOBAL_TF_FLOAT_PRECISION, + op_module, + tf, +) class Inter: diff --git a/source/tests/test_descrpt_smooth.py b/source/tests/test_descrpt_smooth.py index 3092ffd8c8..a42bfa91dc 100644 --- a/source/tests/test_descrpt_smooth.py +++ b/source/tests/test_descrpt_smooth.py @@ -1,17 +1,21 @@ import unittest import numpy as np -from common import Data -from common import force_dw_test -from common import force_test -from common import virial_dw_test -from common import virial_test +from common import ( + Data, + force_dw_test, + force_test, + virial_dw_test, + virial_test, +) # load grad of force module -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import op_module -from deepmd.env import tf +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + GLOBAL_TF_FLOAT_PRECISION, + op_module, + tf, +) class Inter: diff --git a/source/tests/test_dipole_se_a.py b/source/tests/test_dipole_se_a.py index ca6bb968e3..6203338cf7 100644 --- a/source/tests/test_dipole_se_a.py +++ b/source/tests/test_dipole_se_a.py @@ -1,15 +1,27 @@ import numpy as np -from common import DataSystem -from common import finite_difference -from common import gen_data -from common import j_loader -from common import strerch_box - -from deepmd.common import j_must_have -from deepmd.descriptor import DescrptSeA -from deepmd.env import tf -from deepmd.fit import DipoleFittingSeA -from deepmd.model import DipoleModel +from common import ( + DataSystem, + finite_difference, + gen_data, + j_loader, + strerch_box, +) + +from deepmd.common import ( + j_must_have, +) +from deepmd.descriptor import ( + DescrptSeA, +) +from deepmd.env import ( + tf, +) +from deepmd.fit import ( + DipoleFittingSeA, +) +from deepmd.model import ( + DipoleModel, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 diff --git a/source/tests/test_dipole_se_a_tebd.py b/source/tests/test_dipole_se_a_tebd.py index 2a8fb93e83..5eda943255 100644 --- a/source/tests/test_dipole_se_a_tebd.py +++ b/source/tests/test_dipole_se_a_tebd.py @@ -1,19 +1,33 @@ import unittest import numpy as np -from common import DataSystem -from common import finite_difference -from common import gen_data -from common import j_loader -from common import strerch_box +from common import ( + DataSystem, + finite_difference, + gen_data, + j_loader, + strerch_box, +) from packaging.version import parse as parse_version -from deepmd.common import j_must_have -from deepmd.descriptor import DescrptSeA -from deepmd.env import tf -from deepmd.fit import DipoleFittingSeA -from deepmd.model import DipoleModel -from deepmd.utils.type_embed import TypeEmbedNet +from deepmd.common import ( + j_must_have, +) +from deepmd.descriptor import ( + DescrptSeA, +) +from deepmd.env import ( + tf, +) +from deepmd.fit import ( + DipoleFittingSeA, +) +from deepmd.model import ( + DipoleModel, +) +from deepmd.utils.type_embed import ( + TypeEmbedNet, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 diff --git a/source/tests/test_dipolecharge.py b/source/tests/test_dipolecharge.py index b3119f08eb..8fce3c2e12 100644 --- a/source/tests/test_dipolecharge.py +++ b/source/tests/test_dipolecharge.py @@ -2,11 +2,19 @@ import unittest import numpy as np -from common import tests_path +from common import ( + tests_path, +) -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.infer import DipoleChargeModifier -from deepmd.utils.convert import convert_pbtxt_to_pb +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, +) +from deepmd.infer import ( + DipoleChargeModifier, +) +from deepmd.utils.convert import ( + convert_pbtxt_to_pb, +) if GLOBAL_NP_FLOAT_PRECISION == np.float32: default_places = 4 diff --git a/source/tests/test_embedding_net.py b/source/tests/test_embedding_net.py index a50a071af3..7fb238e9e2 100644 --- a/source/tests/test_embedding_net.py +++ b/source/tests/test_embedding_net.py @@ -2,8 +2,12 @@ import numpy as np -from deepmd.env import tf -from deepmd.utils.network import embedding_net +from deepmd.env import ( + tf, +) +from deepmd.utils.network import ( + embedding_net, +) class Inter(tf.test.TestCase): diff --git a/source/tests/test_env.py b/source/tests/test_env.py index 25480f8056..e1864306c3 100644 --- a/source/tests/test_env.py +++ b/source/tests/test_env.py @@ -1,7 +1,11 @@ import unittest -from unittest import mock +from unittest import ( + mock, +) -from deepmd import env +from deepmd import ( + env, +) class TestTFThreadCount(unittest.TestCase): diff --git a/source/tests/test_ewald.py b/source/tests/test_ewald.py index b5b805ce74..0f6fb85228 100644 --- a/source/tests/test_ewald.py +++ b/source/tests/test_ewald.py @@ -1,10 +1,14 @@ import numpy as np -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import tf -from deepmd.infer.ewald_recp import EwaldRecp -from deepmd.infer.ewald_recp import op_module +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + GLOBAL_TF_FLOAT_PRECISION, + tf, +) +from deepmd.infer.ewald_recp import ( + EwaldRecp, + op_module, +) if GLOBAL_NP_FLOAT_PRECISION == np.float32: global_default_fv_hh = 1e-2 diff --git a/source/tests/test_examples.py b/source/tests/test_examples.py index 13c0bc2758..138a7205b5 100644 --- a/source/tests/test_examples.py +++ b/source/tests/test_examples.py @@ -2,10 +2,16 @@ could pass the argument checking. """ import unittest -from pathlib import Path +from pathlib import ( + Path, +) -from deepmd.common import j_loader -from deepmd.utils.argcheck import normalize +from deepmd.common import ( + j_loader, +) +from deepmd.utils.argcheck import ( + normalize, +) p_examples = Path(__file__).parent.parent.parent / "examples" diff --git a/source/tests/test_finetune_se_atten.py b/source/tests/test_finetune_se_atten.py index d0e0601636..18c89f0153 100644 --- a/source/tests/test_finetune_se_atten.py +++ b/source/tests/test_finetune_se_atten.py @@ -4,18 +4,32 @@ import unittest import numpy as np -from common import j_loader -from common import run_dp -from common import tests_path +from common import ( + j_loader, + run_dp, + tests_path, +) from packaging.version import parse as parse_version -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import tf -from deepmd.infer import DeepPotential -from deepmd.utils.argcheck import normalize -from deepmd.utils.compat import update_deepmd_input -from deepmd.utils.data_system import DeepmdDataSystem -from deepmd.utils.graph import get_tensor_by_name +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + tf, +) +from deepmd.infer import ( + DeepPotential, +) +from deepmd.utils.argcheck import ( + normalize, +) +from deepmd.utils.compat import ( + update_deepmd_input, +) +from deepmd.utils.data_system import ( + DeepmdDataSystem, +) +from deepmd.utils.graph import ( + get_tensor_by_name, +) if GLOBAL_NP_FLOAT_PRECISION == np.float32: default_places = 4 diff --git a/source/tests/test_fitting_dos.py b/source/tests/test_fitting_dos.py index c91bf6d3d7..7e4c5f4c07 100644 --- a/source/tests/test_fitting_dos.py +++ b/source/tests/test_fitting_dos.py @@ -1,12 +1,22 @@ import numpy as np -from common import DataSystem -from common import gen_data -from common import j_loader - -from deepmd.common import j_must_have -from deepmd.descriptor import DescrptSeA -from deepmd.env import tf -from deepmd.fit import DOSFitting +from common import ( + DataSystem, + gen_data, + j_loader, +) + +from deepmd.common import ( + j_must_have, +) +from deepmd.descriptor import ( + DescrptSeA, +) +from deepmd.env import ( + tf, +) +from deepmd.fit import ( + DOSFitting, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 diff --git a/source/tests/test_fitting_ener_type.py b/source/tests/test_fitting_ener_type.py index fe4c452490..ca0c7afd79 100644 --- a/source/tests/test_fitting_ener_type.py +++ b/source/tests/test_fitting_ener_type.py @@ -1,12 +1,22 @@ import numpy as np -from common import DataSystem -from common import gen_data -from common import j_loader - -from deepmd.common import j_must_have -from deepmd.descriptor import DescrptSeA -from deepmd.env import tf -from deepmd.fit import EnerFitting +from common import ( + DataSystem, + gen_data, + j_loader, +) + +from deepmd.common import ( + j_must_have, +) +from deepmd.descriptor import ( + DescrptSeA, +) +from deepmd.env import ( + tf, +) +from deepmd.fit import ( + EnerFitting, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 diff --git a/source/tests/test_fitting_stat.py b/source/tests/test_fitting_stat.py index 536f130d7a..8ea1ff8b68 100644 --- a/source/tests/test_fitting_stat.py +++ b/source/tests/test_fitting_stat.py @@ -1,11 +1,19 @@ import unittest -from collections import defaultdict +from collections import ( + defaultdict, +) import numpy as np -from common import j_loader +from common import ( + j_loader, +) -from deepmd.descriptor import DescrptSeA -from deepmd.fit import EnerFitting +from deepmd.descriptor import ( + DescrptSeA, +) +from deepmd.fit import ( + EnerFitting, +) input_json = "water_se_a_afparam.json" diff --git a/source/tests/test_gen_stat_data.py b/source/tests/test_gen_stat_data.py index 48e7deeb6e..eac279a3a4 100644 --- a/source/tests/test_gen_stat_data.py +++ b/source/tests/test_gen_stat_data.py @@ -4,13 +4,21 @@ import dpdata import numpy as np -from deepmd.descriptor import DescrptSeA -from deepmd.fit import EnerFitting -from deepmd.model.model_stat import _make_all_stat_ref -from deepmd.model.model_stat import make_stat_input -from deepmd.model.model_stat import merge_sys_stat +from deepmd.descriptor import ( + DescrptSeA, +) +from deepmd.fit import ( + EnerFitting, +) +from deepmd.model.model_stat import ( + _make_all_stat_ref, + make_stat_input, + merge_sys_stat, +) from deepmd.utils import random as dp_random -from deepmd.utils.data_system import DeepmdDataSystem +from deepmd.utils.data_system import ( + DeepmdDataSystem, +) def gen_sys(nframes, atom_types): diff --git a/source/tests/test_get_potential.py b/source/tests/test_get_potential.py index 9d13c48074..869325e1c3 100644 --- a/source/tests/test_get_potential.py +++ b/source/tests/test_get_potential.py @@ -1,13 +1,19 @@ """Test if `DeepPotential` facto function returns the right type of potential.""" import unittest -from pathlib import Path - -from deepmd.infer import DeepDipole -from deepmd.infer import DeepPolar -from deepmd.infer import DeepPot -from deepmd.infer import DeepPotential -from deepmd.utils.convert import convert_pbtxt_to_pb +from pathlib import ( + Path, +) + +from deepmd.infer import ( + DeepDipole, + DeepPolar, + DeepPot, + DeepPotential, +) +from deepmd.utils.convert import ( + convert_pbtxt_to_pb, +) class TestGetPotential(unittest.TestCase): diff --git a/source/tests/test_init_frz_model_multi.py b/source/tests/test_init_frz_model_multi.py index b4ea0d42c0..e7cf2a5f7f 100644 --- a/source/tests/test_init_frz_model_multi.py +++ b/source/tests/test_init_frz_model_multi.py @@ -3,18 +3,34 @@ import unittest import numpy as np -from common import j_loader -from common import run_dp -from common import tests_path - -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import tf -from deepmd.train.run_options import RunOptions -from deepmd.train.trainer import DPTrainer -from deepmd.utils.argcheck import normalize -from deepmd.utils.compat import update_deepmd_input -from deepmd.utils.data_system import DeepmdDataSystem -from deepmd.utils.multi_init import replace_model_params_with_frz_multi_model +from common import ( + j_loader, + run_dp, + tests_path, +) + +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + tf, +) +from deepmd.train.run_options import ( + RunOptions, +) +from deepmd.train.trainer import ( + DPTrainer, +) +from deepmd.utils.argcheck import ( + normalize, +) +from deepmd.utils.compat import ( + update_deepmd_input, +) +from deepmd.utils.data_system import ( + DeepmdDataSystem, +) +from deepmd.utils.multi_init import ( + replace_model_params_with_frz_multi_model, +) if GLOBAL_NP_FLOAT_PRECISION == np.float32: default_places = 4 diff --git a/source/tests/test_init_frz_model_se_a.py b/source/tests/test_init_frz_model_se_a.py index 554a0f0054..2e73254e84 100644 --- a/source/tests/test_init_frz_model_se_a.py +++ b/source/tests/test_init_frz_model_se_a.py @@ -3,17 +3,31 @@ import unittest import numpy as np -from common import j_loader -from common import run_dp -from common import tests_path - -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import tf -from deepmd.train.run_options import RunOptions -from deepmd.train.trainer import DPTrainer -from deepmd.utils.argcheck import normalize -from deepmd.utils.compat import update_deepmd_input -from deepmd.utils.data_system import DeepmdDataSystem +from common import ( + j_loader, + run_dp, + tests_path, +) + +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + tf, +) +from deepmd.train.run_options import ( + RunOptions, +) +from deepmd.train.trainer import ( + DPTrainer, +) +from deepmd.utils.argcheck import ( + normalize, +) +from deepmd.utils.compat import ( + update_deepmd_input, +) +from deepmd.utils.data_system import ( + DeepmdDataSystem, +) if GLOBAL_NP_FLOAT_PRECISION == np.float32: default_places = 4 diff --git a/source/tests/test_init_frz_model_se_a_type.py b/source/tests/test_init_frz_model_se_a_type.py index 11acc5a237..dd09f0d3c2 100644 --- a/source/tests/test_init_frz_model_se_a_type.py +++ b/source/tests/test_init_frz_model_se_a_type.py @@ -3,17 +3,31 @@ import unittest import numpy as np -from common import j_loader -from common import run_dp -from common import tests_path - -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import tf -from deepmd.train.run_options import RunOptions -from deepmd.train.trainer import DPTrainer -from deepmd.utils.argcheck import normalize -from deepmd.utils.compat import update_deepmd_input -from deepmd.utils.data_system import DeepmdDataSystem +from common import ( + j_loader, + run_dp, + tests_path, +) + +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + tf, +) +from deepmd.train.run_options import ( + RunOptions, +) +from deepmd.train.trainer import ( + DPTrainer, +) +from deepmd.utils.argcheck import ( + normalize, +) +from deepmd.utils.compat import ( + update_deepmd_input, +) +from deepmd.utils.data_system import ( + DeepmdDataSystem, +) if GLOBAL_NP_FLOAT_PRECISION == np.float32: default_places = 4 diff --git a/source/tests/test_init_frz_model_se_atten.py b/source/tests/test_init_frz_model_se_atten.py index 3c5bb940b7..86a4fd86b9 100644 --- a/source/tests/test_init_frz_model_se_atten.py +++ b/source/tests/test_init_frz_model_se_atten.py @@ -3,18 +3,32 @@ import unittest import numpy as np -from common import j_loader -from common import run_dp -from common import tests_path +from common import ( + j_loader, + run_dp, + tests_path, +) from packaging.version import parse as parse_version -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import tf -from deepmd.train.run_options import RunOptions -from deepmd.train.trainer import DPTrainer -from deepmd.utils.argcheck import normalize -from deepmd.utils.compat import update_deepmd_input -from deepmd.utils.data_system import DeepmdDataSystem +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + tf, +) +from deepmd.train.run_options import ( + RunOptions, +) +from deepmd.train.trainer import ( + DPTrainer, +) +from deepmd.utils.argcheck import ( + normalize, +) +from deepmd.utils.compat import ( + update_deepmd_input, +) +from deepmd.utils.data_system import ( + DeepmdDataSystem, +) if GLOBAL_NP_FLOAT_PRECISION == np.float32: default_places = 4 diff --git a/source/tests/test_init_frz_model_se_r.py b/source/tests/test_init_frz_model_se_r.py index 0c312e9ded..04fb62d45d 100644 --- a/source/tests/test_init_frz_model_se_r.py +++ b/source/tests/test_init_frz_model_se_r.py @@ -3,17 +3,31 @@ import unittest import numpy as np -from common import j_loader -from common import run_dp -from common import tests_path - -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import tf -from deepmd.train.run_options import RunOptions -from deepmd.train.trainer import DPTrainer -from deepmd.utils.argcheck import normalize -from deepmd.utils.compat import update_deepmd_input -from deepmd.utils.data_system import DeepmdDataSystem +from common import ( + j_loader, + run_dp, + tests_path, +) + +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + tf, +) +from deepmd.train.run_options import ( + RunOptions, +) +from deepmd.train.trainer import ( + DPTrainer, +) +from deepmd.utils.argcheck import ( + normalize, +) +from deepmd.utils.compat import ( + update_deepmd_input, +) +from deepmd.utils.data_system import ( + DeepmdDataSystem, +) if GLOBAL_NP_FLOAT_PRECISION == np.float32: default_places = 4 diff --git a/source/tests/test_init_frz_model_spin.py b/source/tests/test_init_frz_model_spin.py index f17a1c3079..18fcb71773 100644 --- a/source/tests/test_init_frz_model_spin.py +++ b/source/tests/test_init_frz_model_spin.py @@ -3,17 +3,31 @@ import unittest import numpy as np -from common import j_loader -from common import run_dp -from common import tests_path - -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import tf -from deepmd.train.run_options import RunOptions -from deepmd.train.trainer import DPTrainer -from deepmd.utils.argcheck import normalize -from deepmd.utils.compat import update_deepmd_input -from deepmd.utils.data_system import DeepmdDataSystem +from common import ( + j_loader, + run_dp, + tests_path, +) + +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + tf, +) +from deepmd.train.run_options import ( + RunOptions, +) +from deepmd.train.trainer import ( + DPTrainer, +) +from deepmd.utils.argcheck import ( + normalize, +) +from deepmd.utils.compat import ( + update_deepmd_input, +) +from deepmd.utils.data_system import ( + DeepmdDataSystem, +) if GLOBAL_NP_FLOAT_PRECISION == np.float32: default_places = 4 diff --git a/source/tests/test_lammps.py b/source/tests/test_lammps.py index 341b70fdfd..c1a8036a7f 100644 --- a/source/tests/test_lammps.py +++ b/source/tests/test_lammps.py @@ -1,9 +1,13 @@ import os import subprocess import unittest -from pathlib import Path +from pathlib import ( + Path, +) -from deepmd.utils.convert import convert_pbtxt_to_pb +from deepmd.utils.convert import ( + convert_pbtxt_to_pb, +) @unittest.skipIf( diff --git a/source/tests/test_layer_name.py b/source/tests/test_layer_name.py index 9f3d412ffa..db7bb18d2a 100644 --- a/source/tests/test_layer_name.py +++ b/source/tests/test_layer_name.py @@ -1,15 +1,27 @@ import numpy as np -from common import DataSystem -from common import del_data -from common import gen_data -from common import j_loader - -from deepmd.common import j_must_have -from deepmd.descriptor import DescrptSeA -from deepmd.env import tf -from deepmd.fit import DipoleFittingSeA -from deepmd.fit import EnerFitting -from deepmd.model import MultiModel +from common import ( + DataSystem, + del_data, + gen_data, + j_loader, +) + +from deepmd.common import ( + j_must_have, +) +from deepmd.descriptor import ( + DescrptSeA, +) +from deepmd.env import ( + tf, +) +from deepmd.fit import ( + DipoleFittingSeA, + EnerFitting, +) +from deepmd.model import ( + MultiModel, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 diff --git a/source/tests/test_mixed_prec_training.py b/source/tests/test_mixed_prec_training.py index f710f793f4..4becf9464b 100644 --- a/source/tests/test_mixed_prec_training.py +++ b/source/tests/test_mixed_prec_training.py @@ -6,12 +6,18 @@ import numpy as np # from deepmd.entrypoints.compress import compress -from common import j_loader -from common import run_dp -from common import tests_path -from packaging.version import Version +from common import ( + j_loader, + run_dp, + tests_path, +) +from packaging.version import ( + Version, +) -from deepmd.env import TF_VERSION +from deepmd.env import ( + TF_VERSION, +) def _file_delete(file): diff --git a/source/tests/test_model_compression_se_a.py b/source/tests/test_model_compression_se_a.py index 9e66f419ff..dcd42184ca 100644 --- a/source/tests/test_model_compression_se_a.py +++ b/source/tests/test_model_compression_se_a.py @@ -6,12 +6,18 @@ import numpy as np # from deepmd.entrypoints.compress import compress -from common import j_loader -from common import run_dp -from common import tests_path - -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.infer import DeepPot +from common import ( + j_loader, + run_dp, + tests_path, +) + +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, +) +from deepmd.infer import ( + DeepPot, +) if GLOBAL_NP_FLOAT_PRECISION == np.float32: default_places = 4 @@ -371,9 +377,13 @@ def test_1frame_atm(self): np.testing.assert_almost_equal(vv0, vv1, default_places) def test_ase(self): - from ase import Atoms + from ase import ( + Atoms, + ) - from deepmd.calculator import DP + from deepmd.calculator import ( + DP, + ) water0 = Atoms( "OHHOHH", diff --git a/source/tests/test_model_compression_se_a_type_one_side_exclude_types.py b/source/tests/test_model_compression_se_a_type_one_side_exclude_types.py index 6cf332f42d..c39c6470ed 100644 --- a/source/tests/test_model_compression_se_a_type_one_side_exclude_types.py +++ b/source/tests/test_model_compression_se_a_type_one_side_exclude_types.py @@ -6,12 +6,18 @@ import numpy as np # from deepmd.entrypoints.compress import compress -from common import j_loader -from common import run_dp -from common import tests_path - -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.infer import DeepPot +from common import ( + j_loader, + run_dp, + tests_path, +) + +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, +) +from deepmd.infer import ( + DeepPot, +) if GLOBAL_NP_FLOAT_PRECISION == np.float32: default_places = 4 diff --git a/source/tests/test_model_compression_se_r.py b/source/tests/test_model_compression_se_r.py index 3751ff09d2..f85546b7ee 100644 --- a/source/tests/test_model_compression_se_r.py +++ b/source/tests/test_model_compression_se_r.py @@ -6,12 +6,18 @@ import numpy as np # from deepmd.entrypoints.compress import compress -from common import j_loader -from common import run_dp -from common import tests_path - -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.infer import DeepPot +from common import ( + j_loader, + run_dp, + tests_path, +) + +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, +) +from deepmd.infer import ( + DeepPot, +) if GLOBAL_NP_FLOAT_PRECISION == np.float32: default_places = 4 @@ -379,9 +385,13 @@ def test_1frame_atm(self): np.testing.assert_almost_equal(vv0, vv1, default_places) def test_ase(self): - from ase import Atoms + from ase import ( + Atoms, + ) - from deepmd.calculator import DP + from deepmd.calculator import ( + DP, + ) water0 = Atoms( "OHHOHH", diff --git a/source/tests/test_model_compression_se_t.py b/source/tests/test_model_compression_se_t.py index fc6b0e3f18..0e33430158 100644 --- a/source/tests/test_model_compression_se_t.py +++ b/source/tests/test_model_compression_se_t.py @@ -6,12 +6,18 @@ import numpy as np # from deepmd.entrypoints.compress import compress -from common import j_loader -from common import run_dp -from common import tests_path - -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.infer import DeepPot +from common import ( + j_loader, + run_dp, + tests_path, +) + +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, +) +from deepmd.infer import ( + DeepPot, +) if GLOBAL_NP_FLOAT_PRECISION == np.float32: default_places = 4 @@ -401,9 +407,13 @@ def test_1frame_atm(self): np.testing.assert_almost_equal(vv0, vv1, default_places) def test_ase(self): - from ase import Atoms + from ase import ( + Atoms, + ) - from deepmd.calculator import DP + from deepmd.calculator import ( + DP, + ) water0 = Atoms( "OHHOHH", diff --git a/source/tests/test_model_devi.py b/source/tests/test_model_devi.py index 5091648d6c..20dd57386b 100644 --- a/source/tests/test_model_devi.py +++ b/source/tests/test_model_devi.py @@ -4,16 +4,24 @@ import numpy as np -from deepmd.infer import DeepPotential -from deepmd.infer import calc_model_devi -from deepmd.infer.model_devi import make_model_devi +from deepmd.infer import ( + DeepPotential, + calc_model_devi, +) +from deepmd.infer.model_devi import ( + make_model_devi, +) sys.path.insert(0, os.path.abspath(os.path.dirname(__file__))) -from common import del_data -from common import gen_data -from common import tests_path +from common import ( + del_data, + gen_data, + tests_path, +) -from deepmd.utils.convert import convert_pbtxt_to_pb +from deepmd.utils.convert import ( + convert_pbtxt_to_pb, +) class TestMakeModelDevi(unittest.TestCase): diff --git a/source/tests/test_model_devi_mix.py b/source/tests/test_model_devi_mix.py index d3c166c935..4dcb34bd48 100644 --- a/source/tests/test_model_devi_mix.py +++ b/source/tests/test_model_devi_mix.py @@ -4,18 +4,28 @@ import numpy as np -from deepmd.infer import DeepPotential -from deepmd.infer import calc_model_devi -from deepmd.infer.model_devi import make_model_devi +from deepmd.infer import ( + DeepPotential, + calc_model_devi, +) +from deepmd.infer.model_devi import ( + make_model_devi, +) sys.path.insert(0, os.path.abspath(os.path.dirname(__file__))) -from common import del_data -from common import gen_data -from common import tests_path +from common import ( + del_data, + gen_data, + tests_path, +) from packaging.version import parse as parse_version -from deepmd.env import tf -from deepmd.utils.convert import convert_pbtxt_to_pb +from deepmd.env import ( + tf, +) +from deepmd.utils.convert import ( + convert_pbtxt_to_pb, +) @unittest.skipIf( diff --git a/source/tests/test_model_dos.py b/source/tests/test_model_dos.py index f267e3d5a3..a6c880046e 100644 --- a/source/tests/test_model_dos.py +++ b/source/tests/test_model_dos.py @@ -1,14 +1,26 @@ import numpy as np -from common import DataSystem -from common import del_data -from common import gen_data -from common import j_loader +from common import ( + DataSystem, + del_data, + gen_data, + j_loader, +) -from deepmd.common import j_must_have -from deepmd.descriptor import DescrptSeA -from deepmd.env import tf -from deepmd.fit import DOSFitting -from deepmd.model import DOSModel +from deepmd.common import ( + j_must_have, +) +from deepmd.descriptor import ( + DescrptSeA, +) +from deepmd.env import ( + tf, +) +from deepmd.fit import ( + DOSFitting, +) +from deepmd.model import ( + DOSModel, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 diff --git a/source/tests/test_model_loc_frame.py b/source/tests/test_model_loc_frame.py index 68d53badaa..f33c571ed3 100644 --- a/source/tests/test_model_loc_frame.py +++ b/source/tests/test_model_loc_frame.py @@ -1,13 +1,25 @@ import numpy as np -from common import DataSystem -from common import gen_data -from common import j_loader +from common import ( + DataSystem, + gen_data, + j_loader, +) -from deepmd.common import j_must_have -from deepmd.descriptor import DescrptLocFrame -from deepmd.env import tf -from deepmd.fit import EnerFitting -from deepmd.model import EnerModel +from deepmd.common import ( + j_must_have, +) +from deepmd.descriptor import ( + DescrptLocFrame, +) +from deepmd.env import ( + tf, +) +from deepmd.fit import ( + EnerFitting, +) +from deepmd.model import ( + EnerModel, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 diff --git a/source/tests/test_model_multi.py b/source/tests/test_model_multi.py index bdd21c28e2..faa682c3a1 100644 --- a/source/tests/test_model_multi.py +++ b/source/tests/test_model_multi.py @@ -1,17 +1,29 @@ import numpy as np -from common import DataSystem -from common import del_data -from common import finite_difference -from common import gen_data -from common import j_loader -from common import strerch_box - -from deepmd.common import j_must_have -from deepmd.descriptor import DescrptSeA -from deepmd.env import tf -from deepmd.fit import DipoleFittingSeA -from deepmd.fit import EnerFitting -from deepmd.model import MultiModel +from common import ( + DataSystem, + del_data, + finite_difference, + gen_data, + j_loader, + strerch_box, +) + +from deepmd.common import ( + j_must_have, +) +from deepmd.descriptor import ( + DescrptSeA, +) +from deepmd.env import ( + tf, +) +from deepmd.fit import ( + DipoleFittingSeA, + EnerFitting, +) +from deepmd.model import ( + MultiModel, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 diff --git a/source/tests/test_model_se_a.py b/source/tests/test_model_se_a.py index 0ac359c00f..ec88aceac2 100644 --- a/source/tests/test_model_se_a.py +++ b/source/tests/test_model_se_a.py @@ -1,16 +1,30 @@ import dpdata import numpy as np -from common import DataSystem -from common import del_data -from common import gen_data -from common import j_loader - -from deepmd.common import j_must_have -from deepmd.descriptor import DescrptSeA -from deepmd.env import tf -from deepmd.fit import EnerFitting -from deepmd.model import EnerModel -from deepmd.utils.type_embed import TypeEmbedNet +from common import ( + DataSystem, + del_data, + gen_data, + j_loader, +) + +from deepmd.common import ( + j_must_have, +) +from deepmd.descriptor import ( + DescrptSeA, +) +from deepmd.env import ( + tf, +) +from deepmd.fit import ( + EnerFitting, +) +from deepmd.model import ( + EnerModel, +) +from deepmd.utils.type_embed import ( + TypeEmbedNet, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 diff --git a/source/tests/test_model_se_a_aparam.py b/source/tests/test_model_se_a_aparam.py index b183e2593f..1745ffb642 100644 --- a/source/tests/test_model_se_a_aparam.py +++ b/source/tests/test_model_se_a_aparam.py @@ -1,13 +1,25 @@ import numpy as np -from common import DataSystem -from common import gen_data -from common import j_loader +from common import ( + DataSystem, + gen_data, + j_loader, +) -from deepmd.common import j_must_have -from deepmd.descriptor import DescrptSeA -from deepmd.env import tf -from deepmd.fit import EnerFitting -from deepmd.model import EnerModel +from deepmd.common import ( + j_must_have, +) +from deepmd.descriptor import ( + DescrptSeA, +) +from deepmd.env import ( + tf, +) +from deepmd.fit import ( + EnerFitting, +) +from deepmd.model import ( + EnerModel, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 diff --git a/source/tests/test_model_se_a_ebd.py b/source/tests/test_model_se_a_ebd.py index 52b67135f4..34832e2b5b 100644 --- a/source/tests/test_model_se_a_ebd.py +++ b/source/tests/test_model_se_a_ebd.py @@ -1,13 +1,25 @@ import numpy as np -from common import DataSystem -from common import gen_data -from common import j_loader - -from deepmd.common import j_must_have -from deepmd.descriptor.se_a_ebd import DescrptSeAEbd -from deepmd.env import tf -from deepmd.fit import EnerFitting -from deepmd.model import EnerModel +from common import ( + DataSystem, + gen_data, + j_loader, +) + +from deepmd.common import ( + j_must_have, +) +from deepmd.descriptor.se_a_ebd import ( + DescrptSeAEbd, +) +from deepmd.env import ( + tf, +) +from deepmd.fit import ( + EnerFitting, +) +from deepmd.model import ( + EnerModel, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 diff --git a/source/tests/test_model_se_a_fparam.py b/source/tests/test_model_se_a_fparam.py index e553f07045..bd3e3c0c20 100644 --- a/source/tests/test_model_se_a_fparam.py +++ b/source/tests/test_model_se_a_fparam.py @@ -1,13 +1,25 @@ import numpy as np -from common import DataSystem -from common import gen_data -from common import j_loader - -from deepmd.common import j_must_have -from deepmd.descriptor import DescrptSeA -from deepmd.env import tf -from deepmd.fit import EnerFitting -from deepmd.model import EnerModel +from common import ( + DataSystem, + gen_data, + j_loader, +) + +from deepmd.common import ( + j_must_have, +) +from deepmd.descriptor import ( + DescrptSeA, +) +from deepmd.env import ( + tf, +) +from deepmd.fit import ( + EnerFitting, +) +from deepmd.model import ( + EnerModel, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 diff --git a/source/tests/test_model_se_a_srtab.py b/source/tests/test_model_se_a_srtab.py index af3c0c96b6..36bc955f0a 100644 --- a/source/tests/test_model_se_a_srtab.py +++ b/source/tests/test_model_se_a_srtab.py @@ -1,15 +1,27 @@ import os import numpy as np -from common import DataSystem -from common import gen_data -from common import j_loader - -from deepmd.common import j_must_have -from deepmd.descriptor import DescrptSeA -from deepmd.env import tf -from deepmd.fit import EnerFitting -from deepmd.model import EnerModel +from common import ( + DataSystem, + gen_data, + j_loader, +) + +from deepmd.common import ( + j_must_have, +) +from deepmd.descriptor import ( + DescrptSeA, +) +from deepmd.env import ( + tf, +) +from deepmd.fit import ( + EnerFitting, +) +from deepmd.model import ( + EnerModel, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 diff --git a/source/tests/test_model_se_a_type.py b/source/tests/test_model_se_a_type.py index 4a3f6b6c02..b7e72eb3aa 100644 --- a/source/tests/test_model_se_a_type.py +++ b/source/tests/test_model_se_a_type.py @@ -1,14 +1,28 @@ import numpy as np -from common import DataSystem -from common import gen_data -from common import j_loader - -from deepmd.common import j_must_have -from deepmd.descriptor import DescrptSeA -from deepmd.env import tf -from deepmd.fit import EnerFitting -from deepmd.model import EnerModel -from deepmd.utils.type_embed import TypeEmbedNet +from common import ( + DataSystem, + gen_data, + j_loader, +) + +from deepmd.common import ( + j_must_have, +) +from deepmd.descriptor import ( + DescrptSeA, +) +from deepmd.env import ( + tf, +) +from deepmd.fit import ( + EnerFitting, +) +from deepmd.model import ( + EnerModel, +) +from deepmd.utils.type_embed import ( + TypeEmbedNet, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 diff --git a/source/tests/test_model_se_atten.py b/source/tests/test_model_se_atten.py index ce44acc886..b473c43c10 100644 --- a/source/tests/test_model_se_atten.py +++ b/source/tests/test_model_se_atten.py @@ -1,17 +1,31 @@ import unittest import numpy as np -from common import DataSystem -from common import gen_data -from common import j_loader +from common import ( + DataSystem, + gen_data, + j_loader, +) from packaging.version import parse as parse_version -from deepmd.common import j_must_have -from deepmd.descriptor import DescrptSeAtten -from deepmd.env import tf -from deepmd.fit import EnerFitting -from deepmd.model import EnerModel -from deepmd.utils.type_embed import TypeEmbedNet +from deepmd.common import ( + j_must_have, +) +from deepmd.descriptor import ( + DescrptSeAtten, +) +from deepmd.env import ( + tf, +) +from deepmd.fit import ( + EnerFitting, +) +from deepmd.model import ( + EnerModel, +) +from deepmd.utils.type_embed import ( + TypeEmbedNet, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 diff --git a/source/tests/test_model_se_r.py b/source/tests/test_model_se_r.py index bab92b8ac5..15771c9ec8 100644 --- a/source/tests/test_model_se_r.py +++ b/source/tests/test_model_se_r.py @@ -1,13 +1,25 @@ import numpy as np -from common import DataSystem -from common import gen_data -from common import j_loader - -from deepmd.common import j_must_have -from deepmd.descriptor import DescrptSeR -from deepmd.env import tf -from deepmd.fit import EnerFitting -from deepmd.model import EnerModel +from common import ( + DataSystem, + gen_data, + j_loader, +) + +from deepmd.common import ( + j_must_have, +) +from deepmd.descriptor import ( + DescrptSeR, +) +from deepmd.env import ( + tf, +) +from deepmd.fit import ( + EnerFitting, +) +from deepmd.model import ( + EnerModel, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 diff --git a/source/tests/test_model_se_t.py b/source/tests/test_model_se_t.py index 8bd331e2c5..108baea3fc 100644 --- a/source/tests/test_model_se_t.py +++ b/source/tests/test_model_se_t.py @@ -1,13 +1,25 @@ import numpy as np -from common import DataSystem -from common import gen_data -from common import j_loader - -from deepmd.common import j_must_have -from deepmd.descriptor import DescrptSeT -from deepmd.env import tf -from deepmd.fit import EnerFitting -from deepmd.model import EnerModel +from common import ( + DataSystem, + gen_data, + j_loader, +) + +from deepmd.common import ( + j_must_have, +) +from deepmd.descriptor import ( + DescrptSeT, +) +from deepmd.env import ( + tf, +) +from deepmd.fit import ( + EnerFitting, +) +from deepmd.model import ( + EnerModel, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 diff --git a/source/tests/test_model_spin.py b/source/tests/test_model_spin.py index ba1e13b0f2..0bd2856552 100644 --- a/source/tests/test_model_spin.py +++ b/source/tests/test_model_spin.py @@ -1,17 +1,31 @@ import unittest import numpy as np -from common import DataSystem -from common import del_data -from common import gen_data -from common import j_loader +from common import ( + DataSystem, + del_data, + gen_data, + j_loader, +) -from deepmd.common import j_must_have -from deepmd.descriptor import DescrptSeA -from deepmd.env import tf -from deepmd.fit import EnerFitting -from deepmd.model import EnerModel -from deepmd.utils.spin import Spin +from deepmd.common import ( + j_must_have, +) +from deepmd.descriptor import ( + DescrptSeA, +) +from deepmd.env import ( + tf, +) +from deepmd.fit import ( + EnerFitting, +) +from deepmd.model import ( + EnerModel, +) +from deepmd.utils.spin import ( + Spin, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 diff --git a/source/tests/test_neighbor_stat.py b/source/tests/test_neighbor_stat.py index 7cba930c57..64f314759f 100644 --- a/source/tests/test_neighbor_stat.py +++ b/source/tests/test_neighbor_stat.py @@ -4,7 +4,9 @@ import dpdata import numpy as np -from deepmd.entrypoints.neighbor_stat import neighbor_stat +from deepmd.entrypoints.neighbor_stat import ( + neighbor_stat, +) def gen_sys(nframes): diff --git a/source/tests/test_nvnmd_entrypoints.py b/source/tests/test_nvnmd_entrypoints.py index 752aef452b..9070cad478 100644 --- a/source/tests/test_nvnmd_entrypoints.py +++ b/source/tests/test_nvnmd_entrypoints.py @@ -2,19 +2,37 @@ import unittest import numpy as np -from common import tests_path +from common import ( + tests_path, +) -from deepmd.env import tf -from deepmd.nvnmd.data.data import jdata_deepmd_input -from deepmd.nvnmd.entrypoints.freeze import save_weight -from deepmd.nvnmd.entrypoints.mapt import mapt -from deepmd.nvnmd.entrypoints.train import normalized_input -from deepmd.nvnmd.entrypoints.train import normalized_input_qnn -from deepmd.nvnmd.entrypoints.wrap import wrap -from deepmd.nvnmd.utils.config import nvnmd_cfg -from deepmd.nvnmd.utils.fio import FioBin -from deepmd.nvnmd.utils.fio import FioJsonDic -from deepmd.nvnmd.utils.fio import FioNpyDic +from deepmd.env import ( + tf, +) +from deepmd.nvnmd.data.data import ( + jdata_deepmd_input, +) +from deepmd.nvnmd.entrypoints.freeze import ( + save_weight, +) +from deepmd.nvnmd.entrypoints.mapt import ( + mapt, +) +from deepmd.nvnmd.entrypoints.train import ( + normalized_input, + normalized_input_qnn, +) +from deepmd.nvnmd.entrypoints.wrap import ( + wrap, +) +from deepmd.nvnmd.utils.config import ( + nvnmd_cfg, +) +from deepmd.nvnmd.utils.fio import ( + FioBin, + FioJsonDic, + FioNpyDic, +) class TestNvnmdFreeze(tf.test.TestCase): diff --git a/source/tests/test_nvnmd_op.py b/source/tests/test_nvnmd_op.py index b99fb64a37..1f54da29c5 100644 --- a/source/tests/test_nvnmd_op.py +++ b/source/tests/test_nvnmd_op.py @@ -2,11 +2,15 @@ import unittest import numpy as np -from common import tests_path - -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import op_module -from deepmd.env import tf +from common import ( + tests_path, +) + +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + op_module, + tf, +) class TestOpAddFltNvnmd(tf.test.TestCase): diff --git a/source/tests/test_nvnmd_se_a.py b/source/tests/test_nvnmd_se_a.py index 351cb91c36..fcc96ad811 100644 --- a/source/tests/test_nvnmd_se_a.py +++ b/source/tests/test_nvnmd_se_a.py @@ -2,20 +2,32 @@ import unittest import numpy as np -from common import j_loader +from common import ( + j_loader, +) -from deepmd.descriptor import DescrptSeA -from deepmd.env import tf +from deepmd.descriptor import ( + DescrptSeA, +) +from deepmd.env import ( + tf, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 GLOBAL_NP_FLOAT_PRECISION = np.float64 # -from common import tests_path +from common import ( + tests_path, +) -from deepmd.nvnmd.data.data import jdata_deepmd_input -from deepmd.nvnmd.utils.config import nvnmd_cfg +from deepmd.nvnmd.data.data import ( + jdata_deepmd_input, +) +from deepmd.nvnmd.utils.config import ( + nvnmd_cfg, +) class TestModel(tf.test.TestCase): diff --git a/source/tests/test_nvnmd_utils.py b/source/tests/test_nvnmd_utils.py index 629a1cc8c8..eafd1b4d6c 100644 --- a/source/tests/test_nvnmd_utils.py +++ b/source/tests/test_nvnmd_utils.py @@ -3,10 +3,18 @@ import numpy as np -from deepmd.env import tf -from deepmd.nvnmd.data.data import jdata_deepmd_input -from deepmd.nvnmd.utils.config import nvnmd_cfg -from deepmd.nvnmd.utils.network import one_layer +from deepmd.env import ( + tf, +) +from deepmd.nvnmd.data.data import ( + jdata_deepmd_input, +) +from deepmd.nvnmd.utils.config import ( + nvnmd_cfg, +) +from deepmd.nvnmd.utils.network import ( + one_layer, +) class TestNvnmdNetwork(tf.test.TestCase): diff --git a/source/tests/test_parallel_training.py b/source/tests/test_parallel_training.py index 72dcfb6be9..e2e78bde99 100644 --- a/source/tests/test_parallel_training.py +++ b/source/tests/test_parallel_training.py @@ -2,9 +2,13 @@ import subprocess as sp import unittest -from common import tests_path +from common import ( + tests_path, +) -from deepmd.cluster.local import get_gpus +from deepmd.cluster.local import ( + get_gpus, +) class TestSingleMachine(unittest.TestCase): diff --git a/source/tests/test_polar_se_a.py b/source/tests/test_polar_se_a.py index 22950d610e..30834431c1 100644 --- a/source/tests/test_polar_se_a.py +++ b/source/tests/test_polar_se_a.py @@ -1,15 +1,27 @@ import numpy as np -from common import DataSystem -from common import finite_difference -from common import gen_data -from common import j_loader -from common import strerch_box - -from deepmd.common import j_must_have -from deepmd.descriptor import DescrptSeA -from deepmd.env import tf -from deepmd.fit import PolarFittingSeA -from deepmd.model import PolarModel +from common import ( + DataSystem, + finite_difference, + gen_data, + j_loader, + strerch_box, +) + +from deepmd.common import ( + j_must_have, +) +from deepmd.descriptor import ( + DescrptSeA, +) +from deepmd.env import ( + tf, +) +from deepmd.fit import ( + PolarFittingSeA, +) +from deepmd.model import ( + PolarModel, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 diff --git a/source/tests/test_polar_se_a_tebd.py b/source/tests/test_polar_se_a_tebd.py index c0f5a6a6fe..a60b86a5ea 100644 --- a/source/tests/test_polar_se_a_tebd.py +++ b/source/tests/test_polar_se_a_tebd.py @@ -1,19 +1,33 @@ import unittest import numpy as np -from common import DataSystem -from common import finite_difference -from common import gen_data -from common import j_loader -from common import strerch_box +from common import ( + DataSystem, + finite_difference, + gen_data, + j_loader, + strerch_box, +) from packaging.version import parse as parse_version -from deepmd.common import j_must_have -from deepmd.descriptor import DescrptSeA -from deepmd.env import tf -from deepmd.fit import PolarFittingSeA -from deepmd.model import PolarModel -from deepmd.utils.type_embed import TypeEmbedNet +from deepmd.common import ( + j_must_have, +) +from deepmd.descriptor import ( + DescrptSeA, +) +from deepmd.env import ( + tf, +) +from deepmd.fit import ( + PolarFittingSeA, +) +from deepmd.model import ( + PolarModel, +) +from deepmd.utils.type_embed import ( + TypeEmbedNet, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 diff --git a/source/tests/test_prod_env_mat.py b/source/tests/test_prod_env_mat.py index 59db7881a1..4dd3b0e52e 100644 --- a/source/tests/test_prod_env_mat.py +++ b/source/tests/test_prod_env_mat.py @@ -1,9 +1,11 @@ import numpy as np -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import op_module -from deepmd.env import tf +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, + GLOBAL_TF_FLOAT_PRECISION, + op_module, + tf, +) class TestProdEnvMat(tf.test.TestCase): diff --git a/source/tests/test_prod_force.py b/source/tests/test_prod_force.py index 9b1b7f9f20..880a849605 100644 --- a/source/tests/test_prod_force.py +++ b/source/tests/test_prod_force.py @@ -3,9 +3,11 @@ import numpy as np -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import op_module -from deepmd.env import tf +from deepmd.env import ( + GLOBAL_TF_FLOAT_PRECISION, + op_module, + tf, +) class TestProdForce(tf.test.TestCase): diff --git a/source/tests/test_prod_force_grad.py b/source/tests/test_prod_force_grad.py index 0c649440ab..bfe4f5d12c 100644 --- a/source/tests/test_prod_force_grad.py +++ b/source/tests/test_prod_force_grad.py @@ -1,8 +1,10 @@ import numpy as np -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import op_grads_module -from deepmd.env import tf +from deepmd.env import ( + GLOBAL_TF_FLOAT_PRECISION, + op_grads_module, + tf, +) class TestProdForceGrad(tf.test.TestCase): diff --git a/source/tests/test_prod_virial.py b/source/tests/test_prod_virial.py index 8f8682ea68..d1f7431048 100644 --- a/source/tests/test_prod_virial.py +++ b/source/tests/test_prod_virial.py @@ -1,8 +1,10 @@ import numpy as np -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import op_module -from deepmd.env import tf +from deepmd.env import ( + GLOBAL_TF_FLOAT_PRECISION, + op_module, + tf, +) class TestProdVirial(tf.test.TestCase): diff --git a/source/tests/test_prod_virial_grad.py b/source/tests/test_prod_virial_grad.py index 5adfff0ea2..ebf019b620 100644 --- a/source/tests/test_prod_virial_grad.py +++ b/source/tests/test_prod_virial_grad.py @@ -1,8 +1,10 @@ import numpy as np -from deepmd.env import GLOBAL_TF_FLOAT_PRECISION -from deepmd.env import op_grads_module -from deepmd.env import tf +from deepmd.env import ( + GLOBAL_TF_FLOAT_PRECISION, + op_grads_module, + tf, +) class TestProdVirialGrad(tf.test.TestCase): diff --git a/source/tests/test_sel_idx.py b/source/tests/test_sel_idx.py index 300f19b689..303897d3b9 100644 --- a/source/tests/test_sel_idx.py +++ b/source/tests/test_sel_idx.py @@ -2,7 +2,9 @@ import numpy as np -from deepmd.common import select_idx_map +from deepmd.common import ( + select_idx_map, +) class TestSelIdx(unittest.TestCase): diff --git a/source/tests/test_tab_nonsmth.py b/source/tests/test_tab_nonsmth.py index 9394420604..5e042f7225 100644 --- a/source/tests/test_tab_nonsmth.py +++ b/source/tests/test_tab_nonsmth.py @@ -2,18 +2,26 @@ import unittest import numpy as np -from common import Data -from common import force_dw_test -from common import force_test -from common import virial_dw_test -from common import virial_test -from test_descrpt_nonsmth import Inter +from common import ( + Data, + force_dw_test, + force_test, + virial_dw_test, + virial_test, +) +from test_descrpt_nonsmth import ( + Inter, +) # load grad of force module import deepmd.op # noqa: F401 -from deepmd.env import op_module -from deepmd.env import tf -from deepmd.utils.pair_tab import PairTab +from deepmd.env import ( + op_module, + tf, +) +from deepmd.utils.pair_tab import ( + PairTab, +) def _make_tab(ntype): diff --git a/source/tests/test_tab_smooth.py b/source/tests/test_tab_smooth.py index 32e5c1464b..56b0f269c4 100644 --- a/source/tests/test_tab_smooth.py +++ b/source/tests/test_tab_smooth.py @@ -2,17 +2,25 @@ import unittest import numpy as np -from common import Data -from common import force_dw_test -from common import force_test -from common import virial_dw_test -from common import virial_test -from test_descrpt_smooth import Inter +from common import ( + Data, + force_dw_test, + force_test, + virial_dw_test, + virial_test, +) +from test_descrpt_smooth import ( + Inter, +) # load grad of force module -from deepmd.env import op_module -from deepmd.env import tf -from deepmd.utils.pair_tab import PairTab +from deepmd.env import ( + op_module, + tf, +) +from deepmd.utils.pair_tab import ( + PairTab, +) def _make_tab(ntype): diff --git a/source/tests/test_tabulate.py b/source/tests/test_tabulate.py index d689c9828c..845fb1031e 100644 --- a/source/tests/test_tabulate.py +++ b/source/tests/test_tabulate.py @@ -2,9 +2,13 @@ import numpy as np -from deepmd.common import gelu -from deepmd.env import op_module -from deepmd.env import tf +from deepmd.common import ( + gelu, +) +from deepmd.env import ( + op_module, + tf, +) # Now just test some OPs utilized by DPTabulate sourced in /opt/deepmd-kit/source/op/unaggregated_grad.cc diff --git a/source/tests/test_train.py b/source/tests/test_train.py index 4ef724afb8..7f6617a5f1 100644 --- a/source/tests/test_train.py +++ b/source/tests/test_train.py @@ -1,11 +1,15 @@ import unittest -from unittest.mock import patch +from unittest.mock import ( + patch, +) -from deepmd.entrypoints.train import parse_auto_sel -from deepmd.entrypoints.train import parse_auto_sel_ratio -from deepmd.entrypoints.train import update_one_sel -from deepmd.entrypoints.train import update_sel -from deepmd.entrypoints.train import wrap_up_4 +from deepmd.entrypoints.train import ( + parse_auto_sel, + parse_auto_sel_ratio, + update_one_sel, + update_sel, + wrap_up_4, +) class TestTrain(unittest.TestCase): diff --git a/source/tests/test_transfer.py b/source/tests/test_transfer.py index b2e879e9da..14f88c17dc 100644 --- a/source/tests/test_transfer.py +++ b/source/tests/test_transfer.py @@ -3,12 +3,20 @@ import unittest import numpy as np -from common import run_dp -from common import tests_path +from common import ( + run_dp, + tests_path, +) -from deepmd.env import GLOBAL_NP_FLOAT_PRECISION -from deepmd.infer import DeepPot -from deepmd.utils.convert import convert_pbtxt_to_pb +from deepmd.env import ( + GLOBAL_NP_FLOAT_PRECISION, +) +from deepmd.infer import ( + DeepPot, +) +from deepmd.utils.convert import ( + convert_pbtxt_to_pb, +) if GLOBAL_NP_FLOAT_PRECISION == np.float32: default_places = 4 diff --git a/source/tests/test_type_embed.py b/source/tests/test_type_embed.py index a18881bc2f..87718c1280 100644 --- a/source/tests/test_type_embed.py +++ b/source/tests/test_type_embed.py @@ -1,8 +1,12 @@ import numpy as np -from deepmd.env import tf -from deepmd.utils.type_embed import TypeEmbedNet -from deepmd.utils.type_embed import embed_atom_type +from deepmd.env import ( + tf, +) +from deepmd.utils.type_embed import ( + TypeEmbedNet, + embed_atom_type, +) class TestTypeEbd(tf.test.TestCase): diff --git a/source/tests/test_type_one_side.py b/source/tests/test_type_one_side.py index ff4bd2d031..2f6ff81e76 100644 --- a/source/tests/test_type_one_side.py +++ b/source/tests/test_type_one_side.py @@ -1,11 +1,19 @@ import numpy as np -from common import DataSystem -from common import gen_data -from common import j_loader - -from deepmd.common import j_must_have -from deepmd.descriptor import Descriptor -from deepmd.env import tf +from common import ( + DataSystem, + gen_data, + j_loader, +) + +from deepmd.common import ( + j_must_have, +) +from deepmd.descriptor import ( + Descriptor, +) +from deepmd.env import ( + tf, +) GLOBAL_ENER_FLOAT_PRECISION = tf.float64 GLOBAL_TF_FLOAT_PRECISION = tf.float64 diff --git a/source/tests/test_virtual_type.py b/source/tests/test_virtual_type.py index 29b76da614..98ab84cf93 100644 --- a/source/tests/test_virtual_type.py +++ b/source/tests/test_virtual_type.py @@ -3,15 +3,27 @@ import unittest import numpy as np -from common import gen_data -from common import j_loader -from common import tests_path +from common import ( + gen_data, + j_loader, + tests_path, +) -from deepmd.common import j_must_have -from deepmd.infer import DeepPot -from deepmd.utils.convert import convert_pbtxt_to_pb -from deepmd.utils.data_system import DeepmdDataSystem -from deepmd.utils.neighbor_stat import NeighborStat +from deepmd.common import ( + j_must_have, +) +from deepmd.infer import ( + DeepPot, +) +from deepmd.utils.convert import ( + convert_pbtxt_to_pb, +) +from deepmd.utils.data_system import ( + DeepmdDataSystem, +) +from deepmd.utils.neighbor_stat import ( + NeighborStat, +) class TestVirtualType(unittest.TestCase):