From d93d4a2685c125648e17e30cc29f89890c09ff8d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 21 Mar 2023 01:31:07 +0000 Subject: [PATCH 1/3] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/psf/black: 22.12.0 → 23.1.0](https://github.com/psf/black/compare/22.12.0...23.1.0) - [github.com/charliermarsh/ruff-pre-commit: v0.0.243 → v0.0.257](https://github.com/charliermarsh/ruff-pre-commit/compare/v0.0.243...v0.0.257) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 017c54c544..e630577dc5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: - id: check-toml # Python - repo: https://github.com/psf/black - rev: 22.12.0 + rev: 23.1.0 hooks: - id: black-jupyter - repo: https://github.com/PyCQA/isort @@ -26,7 +26,7 @@ repos: files: \.py$ - repo: https://github.com/charliermarsh/ruff-pre-commit # Ruff version. - rev: v0.0.243 + rev: v0.0.257 hooks: - id: ruff args: ["--fix"] From 21f721032f0080daa6ae1198ae5a62b3bb026947 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 21 Mar 2023 01:31:36 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- deepmd/calculator.py | 2 +- deepmd/entrypoints/compress.py | 2 +- deepmd/infer/deep_dipole.py | 3 +-- deepmd/infer/deep_polar.py | 4 +--- deepmd/infer/deep_pot.py | 1 - deepmd/infer/deep_wfc.py | 3 +-- deepmd/loggers/loggers.py | 1 - deepmd/model/ener.py | 1 - deepmd/model/multi.py | 1 - deepmd/model/tensor.py | 1 - deepmd/nvnmd/entrypoints/wrap.py | 2 +- deepmd/train/trainer.py | 2 -- deepmd/utils/compat.py | 1 - doc/conf.py | 1 - source/install/build_tf.py | 2 -- source/tests/test_argument_parser.py | 1 - source/tests/test_compat_input.py | 1 - source/tests/test_descrpt_sea_ef_rot.py | 2 +- source/tests/test_get_potential.py | 1 - 19 files changed, 7 insertions(+), 25 deletions(-) diff --git a/deepmd/calculator.py b/deepmd/calculator.py index cd361eed5f..4777bc80bc 100644 --- a/deepmd/calculator.py +++ b/deepmd/calculator.py @@ -75,7 +75,7 @@ def __init__( model: Union[str, "Path"], label: str = "DP", type_dict: Dict[str, int] = None, - **kwargs + **kwargs, ) -> None: Calculator.__init__(self, label=label, **kwargs) self.dp = DeepPotential(str(Path(model).resolve())) diff --git a/deepmd/entrypoints/compress.py b/deepmd/entrypoints/compress.py index 6e5ea4f087..36d38c2f8b 100644 --- a/deepmd/entrypoints/compress.py +++ b/deepmd/entrypoints/compress.py @@ -55,7 +55,7 @@ def compress( mpi_log: str, log_path: Optional[str], log_level: int, - **kwargs + **kwargs, ): """Compress model. diff --git a/deepmd/infer/deep_dipole.py b/deepmd/infer/deep_dipole.py index 8988083a5e..e7eb1061de 100644 --- a/deepmd/infer/deep_dipole.py +++ b/deepmd/infer/deep_dipole.py @@ -37,7 +37,6 @@ def __init__( load_prefix: str = "load", default_tf_graph: bool = False, ) -> None: - # use this in favor of dict update to move attribute from class to # instance namespace self.tensors = dict( @@ -45,7 +44,7 @@ def __init__( # output tensor "t_tensor": "o_dipole:0", }, - **self.tensors + **self.tensors, ) DeepTensor.__init__( diff --git a/deepmd/infer/deep_polar.py b/deepmd/infer/deep_polar.py index d76ae5ccad..f08ea9f64b 100644 --- a/deepmd/infer/deep_polar.py +++ b/deepmd/infer/deep_polar.py @@ -41,7 +41,6 @@ def __init__( load_prefix: str = "load", default_tf_graph: bool = False, ) -> None: - # use this in favor of dict update to move attribute from class to # instance namespace self.tensors = dict( @@ -49,7 +48,7 @@ def __init__( # output tensor "t_tensor": "o_polar:0", }, - **self.tensors + **self.tensors, ) DeepTensor.__init__( @@ -84,7 +83,6 @@ class DeepGlobalPolar(DeepTensor): def __init__( self, model_file: str, load_prefix: str = "load", default_tf_graph: bool = False ) -> None: - self.tensors.update( { "t_sel_type": "model_attr/sel_type:0", diff --git a/deepmd/infer/deep_pot.py b/deepmd/infer/deep_pot.py index 67a371b58e..7e13c77761 100644 --- a/deepmd/infer/deep_pot.py +++ b/deepmd/infer/deep_pot.py @@ -75,7 +75,6 @@ def __init__( default_tf_graph: bool = False, auto_batch_size: Union[bool, int, AutoBatchSize] = True, ) -> None: - # add these tensors on top of what is defined by DeepTensor Class # use this in favor of dict update to move attribute from class to # instance namespace diff --git a/deepmd/infer/deep_wfc.py b/deepmd/infer/deep_wfc.py index ef7866f04d..36a77de35e 100644 --- a/deepmd/infer/deep_wfc.py +++ b/deepmd/infer/deep_wfc.py @@ -37,7 +37,6 @@ def __init__( load_prefix: str = "load", default_tf_graph: bool = False, ) -> None: - # use this in favor of dict update to move attribute from class to # instance namespace self.tensors = dict( @@ -45,7 +44,7 @@ def __init__( # output tensor "t_tensor": "o_wfc:0", }, - **self.tensors + **self.tensors, ) DeepTensor.__init__( self, diff --git a/deepmd/loggers/loggers.py b/deepmd/loggers/loggers.py index 4249d7fb3d..9fe9530482 100644 --- a/deepmd/loggers/loggers.py +++ b/deepmd/loggers/loggers.py @@ -235,7 +235,6 @@ def set_log_handles( # * add file handler *************************************************************** if log_path: - # create directory log_path.parent.mkdir(exist_ok=True, parents=True) diff --git a/deepmd/model/ener.py b/deepmd/model/ener.py index ff8fca6932..a925640cf2 100644 --- a/deepmd/model/ener.py +++ b/deepmd/model/ener.py @@ -151,7 +151,6 @@ def build( suffix="", reuse=None, ): - if input_dict is None: input_dict = {} with tf.variable_scope("model_attr" + suffix, reuse=reuse): diff --git a/deepmd/model/multi.py b/deepmd/model/multi.py index d69e08eea8..dcf7566f36 100644 --- a/deepmd/model/multi.py +++ b/deepmd/model/multi.py @@ -183,7 +183,6 @@ def build( suffix="", reuse=None, ): - if input_dict is None: input_dict = {} with tf.variable_scope("model_attr" + suffix, reuse=reuse): diff --git a/deepmd/model/tensor.py b/deepmd/model/tensor.py index 8446fcad8f..eb32fa88cf 100644 --- a/deepmd/model/tensor.py +++ b/deepmd/model/tensor.py @@ -117,7 +117,6 @@ def build( suffix="", reuse=None, ): - if input_dict is None: input_dict = {} with tf.variable_scope("model_attr" + suffix, reuse=reuse): diff --git a/deepmd/nvnmd/entrypoints/wrap.py b/deepmd/nvnmd/entrypoints/wrap.py index 3fbd8b0b10..4bf12803f2 100644 --- a/deepmd/nvnmd/entrypoints/wrap.py +++ b/deepmd/nvnmd/entrypoints/wrap.py @@ -459,7 +459,7 @@ def wrap( nvnmd_weight: Optional[str] = "nvnmd/weight.npy", nvnmd_map: Optional[str] = "nvnmd/map.npy", nvnmd_model: Optional[str] = "nvnmd/model.pb", - **kwargs + **kwargs, ): wrapObj = Wrap(nvnmd_config, nvnmd_weight, nvnmd_map, nvnmd_model) wrapObj.wrap() diff --git a/deepmd/train/trainer.py b/deepmd/train/trainer.py index 46f1a0d038..b105c13d40 100644 --- a/deepmd/train/trainer.py +++ b/deepmd/train/trainer.py @@ -729,7 +729,6 @@ def _init_session(self): run_sess(self.sess, bcast_op) def train(self, train_data=None, valid_data=None): - # if valid_data is None: # no validation set specified. # valid_data = train_data # using training set as validation set. @@ -793,7 +792,6 @@ def train(self, train_data=None, valid_data=None): total_train_time = 0.0 while cur_batch < stop_batch: - # first round validation: if not self.multi_task_mode: train_batch = train_data.get_batch() diff --git a/deepmd/utils/compat.py b/deepmd/utils/compat.py index 0005e0abdf..4ec47b53a1 100644 --- a/deepmd/utils/compat.py +++ b/deepmd/utils/compat.py @@ -287,7 +287,6 @@ def remove_decay_rate(jdata: Dict[str, Any]): def convert_input_v1_v2( jdata: Dict[str, Any], warning: bool = True, dump: Optional[Union[str, Path]] = None ) -> Dict[str, Any]: - tr_cfg = jdata["training"] tr_data_keys = { "systems", diff --git a/doc/conf.py b/doc/conf.py index 2fd0dcdc33..1216914b29 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -150,7 +150,6 @@ def run_apidoc(_): def setup(app): - # Add hook for building doxygen xml when needed app.connect("builder-inited", run_apidoc) diff --git a/source/install/build_tf.py b/source/install/build_tf.py index d2510e75da..883c654b5c 100755 --- a/source/install/build_tf.py +++ b/source/install/build_tf.py @@ -162,7 +162,6 @@ def post_process(self): with tarfile.open(self.path) as tar: def is_within_directory(directory, target): - abs_directory = os.path.abspath(directory) abs_target = os.path.abspath(target) @@ -171,7 +170,6 @@ def is_within_directory(directory, target): return prefix == abs_directory def safe_extract(tar, path=".", members=None, *, numeric_owner=False): - for member in tar.getmembers(): member_path = os.path.join(path, member.name) if not is_within_directory(path, member_path): diff --git a/source/tests/test_argument_parser.py b/source/tests/test_argument_parser.py index 8c881b4829..7b0c9c1205 100644 --- a/source/tests/test_argument_parser.py +++ b/source/tests/test_argument_parser.py @@ -90,7 +90,6 @@ def attr_and_type_check( mapping = {**{"command": dict(type=str, value=command)}, **mapping} for argument, test_data in mapping.items(): - # get expected type expected_type = test_data["type"] diff --git a/source/tests/test_compat_input.py b/source/tests/test_compat_input.py index e8a443931b..df5fcd45f7 100644 --- a/source/tests/test_compat_input.py +++ b/source/tests/test_compat_input.py @@ -39,7 +39,6 @@ def assertDictAlmostEqual(self, d1, d2, msg=None, places=7): self.assertAlmostEqual(d1[kk], d2[kk], places=places, msg=msg) def test_json_yaml_equal(self): - inputs = ("water_v1", "water_se_a_v1") for i in inputs: diff --git a/source/tests/test_descrpt_sea_ef_rot.py b/source/tests/test_descrpt_sea_ef_rot.py index ec48f859e1..cdeb51350e 100644 --- a/source/tests/test_descrpt_sea_ef_rot.py +++ b/source/tests/test_descrpt_sea_ef_rot.py @@ -66,7 +66,7 @@ def build_efv(self, dcoord, dbox, dtype, tnatoms, name, op, reuse=None): "rcut_smth": 5.5, "seed": 1, "uniform_seed": True, - } + }, ) else: descrpt = DescrptSeA( diff --git a/source/tests/test_get_potential.py b/source/tests/test_get_potential.py index e07ed3b3e8..869325e1c3 100644 --- a/source/tests/test_get_potential.py +++ b/source/tests/test_get_potential.py @@ -49,7 +49,6 @@ def tearDown(self): f.unlink() def test_factory(self): - msg = "Returned wrong type of potential. Expected: {}, got: {}" dp = DeepPotential(self.work_dir / "deep_dipole.pb") From 8c83333c40524f43e81e2c21081360f393fc9540 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 21 Mar 2023 16:11:59 -0400 Subject: [PATCH 3/3] fix D403 --- deepmd/descriptor/se_a.py | 2 +- deepmd/descriptor/se_atten.py | 2 +- deepmd/nvnmd/utils/config.py | 2 +- deepmd/utils/neighbor_stat.py | 2 +- deepmd/utils/path.py | 8 ++++---- source/tests/common.py | 6 +++--- source/tests/test_deepmd_data_sys.py | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/deepmd/descriptor/se_a.py b/deepmd/descriptor/se_a.py index 2bff523608..73221c1f91 100644 --- a/deepmd/descriptor/se_a.py +++ b/deepmd/descriptor/se_a.py @@ -866,7 +866,7 @@ def _filter_lower( trainable=True, suffix="", ): - """input env matrix, returns R.G.""" + """Input env matrix, returns R.G.""" outputs_size = [1] + self.filter_neuron # cut-out inputs # with natom x (nei_type_i x 4) diff --git a/deepmd/descriptor/se_atten.py b/deepmd/descriptor/se_atten.py index ba8fa9adfa..9c3834e764 100644 --- a/deepmd/descriptor/se_atten.py +++ b/deepmd/descriptor/se_atten.py @@ -793,7 +793,7 @@ def _filter_lower( name="filter_", reuse=None, ): - """input env matrix, returns R.G.""" + """Input env matrix, returns R.G.""" outputs_size = [1] + self.filter_neuron # cut-out inputs # with natom x (nei_type_i x 4) diff --git a/deepmd/nvnmd/utils/config.py b/deepmd/nvnmd/utils/config.py index ff379d6dc6..9d756f8ef1 100644 --- a/deepmd/nvnmd/utils/config.py +++ b/deepmd/nvnmd/utils/config.py @@ -163,7 +163,7 @@ def init_fitn(self, jdata: dict, jdata_parent: dict = {}) -> dict: return jdata def init_dpin(self, jdata: dict, jdata_parent: dict = {}) -> dict: - r"""initial members about other deepmd input.""" + r"""Initial members about other deepmd input.""" return jdata def init_size(self, jdata: dict, jdata_parent: dict = {}) -> dict: diff --git a/deepmd/utils/neighbor_stat.py b/deepmd/utils/neighbor_stat.py index eebe33d7a0..9b23bc9d76 100644 --- a/deepmd/utils/neighbor_stat.py +++ b/deepmd/utils/neighbor_stat.py @@ -89,7 +89,7 @@ def builder(): self.sub_sess = tf.Session(graph=sub_graph, config=default_tf_session_config) def get_stat(self, data: DeepmdDataSystem) -> Tuple[float, List[int]]: - """get the data statistics of the training data, including nearest nbor distance between atoms, max nbor size of atoms. + """Get the data statistics of the training data, including nearest nbor distance between atoms, max nbor size of atoms. Parameters ---------- diff --git a/deepmd/utils/path.py b/deepmd/utils/path.py index e19a3f8a1d..454eed3d2b 100644 --- a/deepmd/utils/path.py +++ b/deepmd/utils/path.py @@ -106,7 +106,7 @@ def __truediv__(self, key: str) -> "DPPath": @abstractmethod def __lt__(self, other: "DPPath") -> bool: - """whether this DPPath is less than other for sorting.""" + """Whether this DPPath is less than other for sorting.""" @abstractmethod def __str__(self) -> str: @@ -204,7 +204,7 @@ def __truediv__(self, key: str) -> "DPPath": return type(self)(self.path / key) def __lt__(self, other: "DPOSPath") -> bool: - """whether this DPPath is less than other for sorting.""" + """Whether this DPPath is less than other for sorting.""" return self.path < other.path def __str__(self) -> str: @@ -349,11 +349,11 @@ def _connect_path(self, path: str) -> str: return f"{self.name}/{path}" def __lt__(self, other: "DPH5Path") -> bool: - """whether this DPPath is less than other for sorting.""" + """Whether this DPPath is less than other for sorting.""" if self.root_path == other.root_path: return self.name < other.name return self.root_path < other.root_path def __str__(self) -> str: - """returns path of self.""" + """Returns path of self.""" return f"{self.root_path}#{self.name}" diff --git a/source/tests/common.py b/source/tests/common.py index 8fc303c1d7..dcbccd221a 100644 --- a/source/tests/common.py +++ b/source/tests/common.py @@ -660,7 +660,7 @@ def stats_energy(self): return np.average(eners) def load_energy(self, set_name, nframes, nvalues, energy_file, atom_energy_file): - """return : coeff_ener, ener, coeff_atom_ener, atom_ener.""" + """Return : coeff_ener, ener, coeff_atom_ener, atom_ener.""" # load atom_energy coeff_atom_ener, atom_ener = self.load_data( set_name, atom_energy_file, [nframes, nvalues], False @@ -765,13 +765,13 @@ def get_set(self, data, idx=None): return new_data def get_test(self): - """returned property prefector [4] in order: + """Returned property prefector [4] in order: energy, force, virial, atom_ener. """ return self.get_set(self.test_set) def get_batch(self, batch_size): - """returned property prefector [4] in order: + """Returned property prefector [4] in order: energy, force, virial, atom_ener. """ set_size = self.batch_set["energy"].shape[0] diff --git a/source/tests/test_deepmd_data_sys.py b/source/tests/test_deepmd_data_sys.py index 9df48c3f57..5ed9d3d3f6 100644 --- a/source/tests/test_deepmd_data_sys.py +++ b/source/tests/test_deepmd_data_sys.py @@ -403,7 +403,7 @@ def test_sys_prob_floating_point_error(self): self.assertEqual(ds.sys_probs.size, len(sys_probs)) def test_get_mixed_batch(self): - """test get_batch with mixed system.""" + """Test get_batch with mixed system.""" batch_size = "mixed:3" test_size = 2