Skip to content

Commit

Permalink
fix errors detected by ruff
Browse files Browse the repository at this point in the history
Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
  • Loading branch information
njzjz committed Sep 12, 2023
1 parent c6a79aa commit f51b9df
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 16 deletions.
3 changes: 2 additions & 1 deletion data/raw/shuffle_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def _main():
tmp = np.reshape(tmp, [nframe, -1])
nframe = tmp.shape[0]
idx = np.arange(nframe)
np.random.shuffle(idx)
rng = np.random.default_rng()
rng.shuffle(idx)

for ii in raws:
data = np.loadtxt(inpath + "/" + ii)
Expand Down
9 changes: 8 additions & 1 deletion deepmd/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
)
from typing import (
TYPE_CHECKING,
ClassVar,
Dict,
List,
Optional,
Expand Down Expand Up @@ -69,7 +70,13 @@ class DP(Calculator):
"""

name = "DP"
implemented_properties = ["energy", "free_energy", "forces", "virial", "stress"]
implemented_properties: ClassVar[List[str]] = [
"energy",
"free_energy",
"forces",
"virial",
"stress",
]

def __init__(
self,
Expand Down
2 changes: 1 addition & 1 deletion deepmd/descriptor/se_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class DescrptSeA(DescrptSe):
.. [1] Linfeng Zhang, Jiequn Han, Han Wang, Wissam A. Saidi, Roberto Car, and E. Weinan. 2018.
End-to-end symmetry preserving inter-atomic potential energy model for finite and extended
systems. In Proceedings of the 32nd International Conference on Neural Information Processing
Systems (NIPS'18). Curran Associates Inc., Red Hook, NY, USA, 44414451.
Systems (NIPS'18). Curran Associates Inc., Red Hook, NY, USA, 4441-4451.
"""

def __init__(
Expand Down
2 changes: 1 addition & 1 deletion deepmd/descriptor/se_a_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class DescrptSeAMask(DescrptSeA):
.. [1] Linfeng Zhang, Jiequn Han, Han Wang, Wissam A. Saidi, Roberto Car, and E. Weinan. 2018.
End-to-end symmetry preserving inter-atomic potential energy model for finite and extended
systems. In Proceedings of the 32nd International Conference on Neural Information Processing
Systems (NIPS'18). Curran Associates Inc., Red Hook, NY, USA, 44414451.
Systems (NIPS'18). Curran Associates Inc., Red Hook, NY, USA, 4441-4451.
"""

def __init__(
Expand Down
4 changes: 3 additions & 1 deletion deepmd/infer/deep_tensor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
from typing import (
TYPE_CHECKING,
ClassVar,
Dict,
List,
Optional,
Tuple,
Expand Down Expand Up @@ -39,7 +41,7 @@ class DeepTensor(DeepEval):
The input map for tf.import_graph_def. Only work with default tf graph
"""

tensors = {
tensors: ClassVar[Dict[str, str]] = {
# descriptor attrs
"t_ntypes": "descrpt_attr/ntypes:0",
"t_rcut": "descrpt_attr/rcut:0",
Expand Down
6 changes: 3 additions & 3 deletions deepmd/utils/argcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def descrpt_se_a_args():
doc_axis_neuron = "Size of the submatrix of G (embedding matrix)."
doc_activation_function = f'The activation function in the embedding net. Supported activation functions are {list_to_doc(ACTIVATION_FN_DICT.keys())} Note that "gelu" denotes the custom operator version, and "gelu_tf" denotes the TF standard version. If you set "None" or "none" here, no activation function will be used.'
doc_resnet_dt = 'Whether to use a "Timestep" in the skip connection'
doc_type_one_side = r"If true, the embedding network parameters vary by types of neighbor atoms only, so there will be $N_\text{types}$ sets of embedding network parameters. Otherwise, the embedding network parameters vary by types of centric atoms and types of neighbor atoms, so there will be $N_\text{types}^2$ sets of embedding network parameters."
doc_type_one_side = r"If true, the embedding network parameters vary by types of neighbor atoms only, so there will be $N_\text{types}$ sets of embedding network parameters. Otherwise, the embedding network parameters vary by types of centric atoms and types of neighbor atoms, so there will be $N_\text{types}^2$ sets of embedding network parameters."
doc_precision = f"The precision of the embedding net parameters, supported options are {list_to_doc(PRECISION_DICT.keys())} Default follows the interface precision."
doc_trainable = "If the parameters in the embedding net is trainable"
doc_seed = "Random seed for parameter initialization"
Expand Down Expand Up @@ -281,7 +281,7 @@ def descrpt_se_r_args():
doc_neuron = "Number of neurons in each hidden layers of the embedding net. When two layers are of the same size or one layer is twice as large as the previous layer, a skip connection is built."
doc_activation_function = f'The activation function in the embedding net. Supported activation functions are {list_to_doc(ACTIVATION_FN_DICT.keys())} Note that "gelu" denotes the custom operator version, and "gelu_tf" denotes the TF standard version. If you set "None" or "none" here, no activation function will be used.'
doc_resnet_dt = 'Whether to use a "Timestep" in the skip connection'
doc_type_one_side = r"If true, the embedding network parameters vary by types of neighbor atoms only, so there will be $N_\text{types}$ sets of embedding network parameters. Otherwise, the embedding network parameters vary by types of centric atoms and types of neighbor atoms, so there will be $N_\text{types}^2$ sets of embedding network parameters."
doc_type_one_side = r"If true, the embedding network parameters vary by types of neighbor atoms only, so there will be $N_\text{types}$ sets of embedding network parameters. Otherwise, the embedding network parameters vary by types of centric atoms and types of neighbor atoms, so there will be $N_\text{types}^2$ sets of embedding network parameters."
doc_precision = f"The precision of the embedding net parameters, supported options are {list_to_doc(PRECISION_DICT.keys())} Default follows the interface precision."
doc_trainable = "If the parameters in the embedding net are trainable"
doc_seed = "Random seed for parameter initialization"
Expand Down Expand Up @@ -345,7 +345,7 @@ def descrpt_se_atten_common_args():
doc_axis_neuron = "Size of the submatrix of G (embedding matrix)."
doc_activation_function = f'The activation function in the embedding net. Supported activation functions are {list_to_doc(ACTIVATION_FN_DICT.keys())} Note that "gelu" denotes the custom operator version, and "gelu_tf" denotes the TF standard version. If you set "None" or "none" here, no activation function will be used.'
doc_resnet_dt = 'Whether to use a "Timestep" in the skip connection'
doc_type_one_side = r"If true, the embedding network parameters vary by types of neighbor atoms only, so there will be $N_\text{types}$ sets of embedding network parameters. Otherwise, the embedding network parameters vary by types of centric atoms and types of neighbor atoms, so there will be $N_\text{types}^2$ sets of embedding network parameters."
doc_type_one_side = r"If true, the embedding network parameters vary by types of neighbor atoms only, so there will be $N_\text{types}$ sets of embedding network parameters. Otherwise, the embedding network parameters vary by types of centric atoms and types of neighbor atoms, so there will be $N_\text{types}^2$ sets of embedding network parameters."
doc_precision = f"The precision of the embedding net parameters, supported options are {list_to_doc(PRECISION_DICT.keys())} Default follows the interface precision."
doc_trainable = "If the parameters in the embedding net is trainable"
doc_seed = "Random seed for parameter initialization"
Expand Down
2 changes: 1 addition & 1 deletion deepmd/utils/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def embedding_net(
References
----------
.. [1] Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Identitymappings
in deep residual networks. InComputer Vision ECCV 2016,pages 630645. Springer
in deep residual networks. InComputer Vision - ECCV 2016,pages 630-645. Springer
International Publishing, 2016.
"""
input_shape = xx.get_shape().as_list()
Expand Down
2 changes: 1 addition & 1 deletion deepmd_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def main_parser() -> argparse.ArgumentParser:
# The table is composed of fifth-order polynomial coefficients and is assembled
# from two sub-tables. The first table takes the step(parameter) as it's uniform
# step, while the second table takes 10 * step as it\s uniform step
#  The range of the first table is automatically detected by deepmd-kit, while the
# The range of the first table is automatically detected by deepmd-kit, while the
# second table ranges from the first table's upper boundary(upper) to the
# extrapolate(parameter) * upper.
parser_compress = subparsers.add_parser(
Expand Down
8 changes: 4 additions & 4 deletions source/tests/test_descrpt_sea_ef_rot.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def make_test_data(self, nframes):
one_type = []
for ii in range(2, 2 + self.ntypes):
one_type = one_type + [ii - 2 for jj in range(self.natoms[ii])]
np.random.shuffle(one_type)
np.random.shuffle(one_type) # noqa: NPY002
one_type = np.array(one_type, dtype=int).reshape([1, -1])
dtype = np.tile(one_type, [nframes, 1])
defield = np.random.random(dcoord.shape)
Expand Down Expand Up @@ -162,7 +162,7 @@ def test_rot_axis(self, suffix=""):
)
self.sess.run(tf.global_variables_initializer())

np.random.seed(0)
np.random.seed(0) # noqa: NPY002
# make test data
nframes = 2
dcoord, dbox, dtype, defield = self.make_test_data(nframes)
Expand Down Expand Up @@ -308,7 +308,7 @@ def test_rot_diff_axis(self, suffix=""):
)
self.sess.run(tf.global_variables_initializer())

np.random.seed(0)
np.random.seed(0) # noqa: NPY002
# make test data
nframes = 2
dcoord, dbox, dtype, defield = self.make_test_data(nframes)
Expand Down Expand Up @@ -423,7 +423,7 @@ def test_rot_field_corot(self, suffix=""):
)
self.sess.run(tf.global_variables_initializer())

np.random.seed(0)
np.random.seed(0) # noqa: NPY002
# make test data
nframes = 2
dcoord, dbox, dtype, defield = self.make_test_data(nframes)
Expand Down
4 changes: 2 additions & 2 deletions source/tests/test_fitting_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ def _make_fake_data(sys_natoms, sys_nframes, avgs, stds):
tmp_data_a = []
for jj in range(ndof):
tmp_data_f.append(
np.random.normal(
np.random.normal( # noqa: NPY002
loc=avgs[jj], scale=stds[jj], size=(sys_nframes[ii], 1)
)
)
tmp_data_a.append(
np.random.normal(
np.random.normal( # noqa: NPY002
loc=avgs[jj], scale=stds[jj], size=(sys_nframes[ii], sys_natoms[ii])
)
)
Expand Down

0 comments on commit f51b9df

Please sign in to comment.