Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 15, 2023
1 parent 1bba8ae commit 7eebac3
Show file tree
Hide file tree
Showing 70 changed files with 204 additions and 281 deletions.
6 changes: 2 additions & 4 deletions deepmd/descriptor/hybrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,8 @@ def build(
The output descriptor
"""
with tf.variable_scope("descrpt_attr" + suffix, reuse=reuse):
t_rcut = tf.constant(
self.get_rcut(), name="rcut", dtype=GLOBAL_TF_FLOAT_PRECISION
)
t_ntypes = tf.constant(self.get_ntypes(), name="ntypes", dtype=tf.int32)
tf.constant(self.get_rcut(), name="rcut", dtype=GLOBAL_TF_FLOAT_PRECISION)
tf.constant(self.get_ntypes(), name="ntypes", dtype=tf.int32)
all_dout = []
for idx, ii in enumerate(self.descrpt_list):
dout = ii.build(
Expand Down
4 changes: 2 additions & 2 deletions deepmd/descriptor/loc_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,12 @@ def build(
davg = np.zeros([self.ntypes, self.ndescrpt])
if dstd is None:
dstd = np.ones([self.ntypes, self.ndescrpt])
t_rcut = tf.constant(
tf.constant(
np.max([self.rcut_r, self.rcut_a]),
name="rcut",
dtype=GLOBAL_TF_FLOAT_PRECISION,
)
t_ntypes = tf.constant(self.ntypes, name="ntypes", dtype=tf.int32)
tf.constant(self.ntypes, name="ntypes", dtype=tf.int32)
self.t_avg = tf.get_variable(
"t_avg",
davg.shape,
Expand Down
6 changes: 3 additions & 3 deletions deepmd/descriptor/se_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,13 +556,13 @@ def build(
davg = np.zeros([self.ntypes, self.ndescrpt])
if dstd is None:
dstd = np.ones([self.ntypes, self.ndescrpt])
t_rcut = tf.constant(
tf.constant(
np.max([self.rcut_r, self.rcut_a]),
name="rcut",
dtype=GLOBAL_TF_FLOAT_PRECISION,
)
t_ntypes = tf.constant(self.ntypes, name="ntypes", dtype=tf.int32)
t_ndescrpt = tf.constant(self.ndescrpt, name="ndescrpt", dtype=tf.int32)
tf.constant(self.ntypes, name="ntypes", dtype=tf.int32)
tf.constant(self.ndescrpt, name="ndescrpt", dtype=tf.int32)
t_sel = tf.constant(self.sel_a, name="sel", dtype=tf.int32)
t_original_sel = tf.constant(
self.original_sel if self.original_sel is not None else self.sel_a,
Expand Down
2 changes: 1 addition & 1 deletion deepmd/descriptor/se_a_ebd.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def _embedding_net(
"""
# natom x (nei x 4)
inputs = tf.reshape(inputs, [-1, self.ndescrpt])
shape = inputs.get_shape().as_list()
inputs.get_shape().as_list()
outputs_size = [1, *filter_neuron]
with tf.variable_scope(name, reuse=reuse):
xyz_scatter_total = []
Expand Down
8 changes: 4 additions & 4 deletions deepmd/descriptor/se_a_ef.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,14 +470,14 @@ def build(
davg = np.zeros([self.ntypes, self.ndescrpt])
if dstd is None:
dstd = np.ones([self.ntypes, self.ndescrpt])
t_rcut = tf.constant(
tf.constant(
np.max([self.rcut_r, self.rcut_a]),
name="rcut",
dtype=GLOBAL_TF_FLOAT_PRECISION,
)
t_ntypes = tf.constant(self.ntypes, name="ntypes", dtype=tf.int32)
t_ndescrpt = tf.constant(self.ndescrpt, name="ndescrpt", dtype=tf.int32)
t_sel = tf.constant(self.sel_a, name="sel", dtype=tf.int32)
tf.constant(self.ntypes, name="ntypes", dtype=tf.int32)
tf.constant(self.ndescrpt, name="ndescrpt", dtype=tf.int32)
tf.constant(self.sel_a, name="sel", dtype=tf.int32)
self.t_avg = tf.get_variable(
"t_avg",
davg.shape,
Expand Down
18 changes: 7 additions & 11 deletions deepmd/descriptor/se_a_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,8 @@ def __init__(
nei_type = np.append(nei_type, ii * np.ones(self.sel_a[ii])) # like a mask
self.nei_type = tf.constant(nei_type, dtype=tf.int32)

avg_zero = np.zeros([self.ntypes, self.ndescrpt]).astype(
GLOBAL_NP_FLOAT_PRECISION
)
std_ones = np.ones([self.ntypes, self.ndescrpt]).astype(
GLOBAL_NP_FLOAT_PRECISION
)
np.zeros([self.ntypes, self.ndescrpt]).astype(GLOBAL_NP_FLOAT_PRECISION)
np.ones([self.ntypes, self.ndescrpt]).astype(GLOBAL_NP_FLOAT_PRECISION)
sub_graph = tf.Graph()
with sub_graph.as_default():
name_pfx = "d_sea_mask_"
Expand Down Expand Up @@ -306,7 +302,7 @@ def build(
"""
aparam = input_dict["aparam"]
with tf.variable_scope("fitting_attr" + suffix, reuse=reuse):
t_aparam_nall = tf.constant(True, name="aparam_nall", dtype=tf.bool)
tf.constant(True, name="aparam_nall", dtype=tf.bool)
self.mask = tf.cast(aparam, tf.int32)
self.mask = tf.reshape(self.mask, [-1, natoms[1]])

Expand All @@ -315,14 +311,14 @@ def build(
davg = np.zeros([self.ntypes, self.ndescrpt])
if dstd is None:
dstd = np.ones([self.ntypes, self.ndescrpt])
t_rcut = tf.constant(
tf.constant(
self.rcut,
name="rcut",
dtype=GLOBAL_TF_FLOAT_PRECISION,
)
t_ntypes = tf.constant(self.ntypes, name="ntypes", dtype=tf.int32)
t_ndescrpt = tf.constant(self.ndescrpt, name="ndescrpt", dtype=tf.int32)
t_sel = tf.constant(self.sel_a, name="sel", dtype=tf.int32)
tf.constant(self.ntypes, name="ntypes", dtype=tf.int32)
tf.constant(self.ndescrpt, name="ndescrpt", dtype=tf.int32)
tf.constant(self.sel_a, name="sel", dtype=tf.int32)
"""
self.t_avg = tf.get_variable('t_avg',
davg.shape,
Expand Down
8 changes: 4 additions & 4 deletions deepmd/descriptor/se_atten.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,13 +556,13 @@ def build(
davg = np.zeros([self.ntypes, self.ndescrpt])
if dstd is None:
dstd = np.ones([self.ntypes, self.ndescrpt])
t_rcut = tf.constant(
tf.constant(
np.max([self.rcut_r, self.rcut_a]),
name="rcut",
dtype=GLOBAL_TF_FLOAT_PRECISION,
)
t_ntypes = tf.constant(self.ntypes, name="ntypes", dtype=tf.int32)
t_ndescrpt = tf.constant(self.ndescrpt, name="ndescrpt", dtype=tf.int32)
tf.constant(self.ntypes, name="ntypes", dtype=tf.int32)
tf.constant(self.ndescrpt, name="ndescrpt", dtype=tf.int32)
t_sel = tf.constant(self.sel_a, name="sel", dtype=tf.int32)
t_original_sel = tf.constant(
self.original_sel if self.original_sel is not None else self.sel_a,
Expand Down Expand Up @@ -1257,7 +1257,7 @@ def _filter(
reuse=None,
trainable=True,
):
nframes = tf.shape(tf.reshape(inputs, [-1, natoms[0], self.ndescrpt]))[0]
tf.shape(tf.reshape(inputs, [-1, natoms[0], self.ndescrpt]))[0]
# natom x (nei x 4)
shape = inputs.get_shape().as_list()
outputs_size = [1, *self.filter_neuron]
Expand Down
10 changes: 4 additions & 6 deletions deepmd/descriptor/se_r.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,10 @@ def build(
davg = np.zeros([self.ntypes, self.ndescrpt])
if dstd is None:
dstd = np.ones([self.ntypes, self.ndescrpt])
t_rcut = tf.constant(
self.rcut, name="rcut", dtype=GLOBAL_TF_FLOAT_PRECISION
)
t_ntypes = tf.constant(self.ntypes, name="ntypes", dtype=tf.int32)
t_ndescrpt = tf.constant(self.ndescrpt, name="ndescrpt", dtype=tf.int32)
t_sel = tf.constant(self.sel_a, name="sel", dtype=tf.int32)
tf.constant(self.rcut, name="rcut", dtype=GLOBAL_TF_FLOAT_PRECISION)
tf.constant(self.ntypes, name="ntypes", dtype=tf.int32)
tf.constant(self.ndescrpt, name="ndescrpt", dtype=tf.int32)
tf.constant(self.sel_a, name="sel", dtype=tf.int32)
self.t_avg = tf.get_variable(
"t_avg",
davg.shape,
Expand Down
12 changes: 5 additions & 7 deletions deepmd/descriptor/se_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,14 +432,14 @@ def build(
davg = np.zeros([self.ntypes, self.ndescrpt])
if dstd is None:
dstd = np.ones([self.ntypes, self.ndescrpt])
t_rcut = tf.constant(
tf.constant(
np.max([self.rcut_r, self.rcut_a]),
name="rcut",
dtype=GLOBAL_TF_FLOAT_PRECISION,
)
t_ntypes = tf.constant(self.ntypes, name="ntypes", dtype=tf.int32)
t_ndescrpt = tf.constant(self.ndescrpt, name="ndescrpt", dtype=tf.int32)
t_sel = tf.constant(self.sel_a, name="sel", dtype=tf.int32)
tf.constant(self.ntypes, name="ntypes", dtype=tf.int32)
tf.constant(self.ndescrpt, name="ndescrpt", dtype=tf.int32)
tf.constant(self.sel_a, name="sel", dtype=tf.int32)
self.t_avg = tf.get_variable(
"t_avg",
davg.shape,
Expand Down Expand Up @@ -545,10 +545,8 @@ def prod_force_virial(
def _pass_filter(
self, inputs, atype, natoms, input_dict, reuse=None, suffix="", trainable=True
):
start_index = 0
inputs = tf.reshape(inputs, [-1, natoms[0], self.ndescrpt])
output = []
output_qmat = []
inputs_i = inputs
inputs_i = tf.reshape(inputs_i, [-1, self.ndescrpt])
type_i = -1
Expand Down Expand Up @@ -632,7 +630,7 @@ def _filter(
trainable=True,
):
# natom x (nei x 4)
shape = inputs.get_shape().as_list()
inputs.get_shape().as_list()
outputs_size = [1, *self.filter_neuron]
with tf.variable_scope(name, reuse=reuse):
start_index_i = 0
Expand Down
2 changes: 1 addition & 1 deletion deepmd/entrypoints/compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def compress(
def _check_compress_type(graph: tf.Graph):
try:
t_model_type = bytes.decode(get_tensor_by_name_from_graph(graph, "model_type"))
except GraphWithoutTensorError as e:
except GraphWithoutTensorError:

Check warning on line 189 in deepmd/entrypoints/compress.py

View check run for this annotation

Codecov / codecov/patch

deepmd/entrypoints/compress.py#L189

Added line #L189 was not covered by tests
# Compatible with the upgraded model, which has no 'model_type' info
t_model_type = None

Expand Down
1 change: 0 additions & 1 deletion deepmd/entrypoints/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ def test(
if len(all_sys) == 0:
raise RuntimeError("Did not find valid system")
err_coll = []
siz_coll = []

# init random seed
if rand_seed is not None:
Expand Down
7 changes: 3 additions & 4 deletions deepmd/fit/dos.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,9 @@ def build(
self.aparam_inv_std = 1.0

with tf.variable_scope("fitting_attr" + suffix, reuse=reuse):
t_dfparam = tf.constant(self.numb_fparam, name="dfparam", dtype=tf.int32)
t_daparam = tf.constant(self.numb_aparam, name="daparam", dtype=tf.int32)
t_numb_dos = tf.constant(self.numb_dos, name="numb_dos", dtype=tf.int32)
tf.constant(self.numb_fparam, name="dfparam", dtype=tf.int32)
tf.constant(self.numb_aparam, name="daparam", dtype=tf.int32)
tf.constant(self.numb_dos, name="numb_dos", dtype=tf.int32)

self.t_bias_dos = tf.get_variable(
"t_bias_dos",
Expand Down Expand Up @@ -530,7 +530,6 @@ def build(
inputs = tf.concat(
[tf.reshape(inputs, [-1, self.dim_descrpt]), atype_embed], axis=1
)
original_dim_descrpt = self.dim_descrpt
self.dim_descrpt = self.dim_descrpt + type_shape[1]
inputs = tf.reshape(inputs, [-1, natoms[0], self.dim_descrpt])
final_layer = self._build_lower(
Expand Down
4 changes: 2 additions & 2 deletions deepmd/fit/ener.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,8 @@ def build(
self.bias_atom_e = self.bias_atom_e[:ntypes_atom]

with tf.variable_scope("fitting_attr" + suffix, reuse=reuse):
t_dfparam = tf.constant(self.numb_fparam, name="dfparam", dtype=tf.int32)
t_daparam = tf.constant(self.numb_aparam, name="daparam", dtype=tf.int32)
tf.constant(self.numb_fparam, name="dfparam", dtype=tf.int32)
tf.constant(self.numb_aparam, name="daparam", dtype=tf.int32)
self.t_bias_atom_e = tf.get_variable(
"t_bias_atom_e",
self.bias_atom_e.shape,
Expand Down
2 changes: 1 addition & 1 deletion deepmd/fit/polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def compute_input_stats(self, all_stat, protection=1e-2):

# YWolfeee: support polar normalization, initialize to a more appropriate point
if self.shift_diag:
mean_polar = np.zeros([len(self.sel_type), 9])
np.zeros([len(self.sel_type), 9])

Check warning on line 166 in deepmd/fit/polar.py

View check run for this annotation

Codecov / codecov/patch

deepmd/fit/polar.py#L166

Added line #L166 was not covered by tests
sys_matrix, polar_bias = [], []
for ss in range(len(all_stat["type"])):
atom_has_polar = [
Expand Down
22 changes: 8 additions & 14 deletions deepmd/infer/data_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,34 +91,29 @@ def __init__(
def build_fv_graph(self) -> tf.Tensor:
"""Build the computational graph for the force and virial inference."""
with tf.variable_scope("modifier_attr"):
t_mdl_name = tf.constant(self.model_name, name="mdl_name", dtype=tf.string)
t_modi_type = tf.constant(
self.modifier_prefix, name="type", dtype=tf.string
)
t_mdl_charge_map = tf.constant(
tf.constant(self.model_name, name="mdl_name", dtype=tf.string)
tf.constant(self.modifier_prefix, name="type", dtype=tf.string)
tf.constant(
" ".join([str(ii) for ii in self.model_charge_map]),
name="mdl_charge_map",
dtype=tf.string,
)
t_sys_charge_map = tf.constant(
tf.constant(
" ".join([str(ii) for ii in self.sys_charge_map]),
name="sys_charge_map",
dtype=tf.string,
)
t_ewald_h = tf.constant(self.ewald_h, name="ewald_h", dtype=tf.float64)
t_ewald_b = tf.constant(
self.ewald_beta, name="ewald_beta", dtype=tf.float64
)
tf.constant(self.ewald_h, name="ewald_h", dtype=tf.float64)
tf.constant(self.ewald_beta, name="ewald_beta", dtype=tf.float64)
with self.graph.as_default():
return self._build_fv_graph_inner()

def _build_fv_graph_inner(self):
self.t_ef = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name="t_ef")
nf = 10
nfxnas = 64 * nf
64 * nf
nfxna = 192 * nf
nf = -1
nfxnas = -1
nfxna = -1
self.t_box_reshape = tf.reshape(self.t_box, [-1, 9])
t_nframes = tf.shape(self.t_box_reshape)[0]
Expand Down Expand Up @@ -348,7 +343,6 @@ def _eval_fv(self, coords, cells, atom_types, ext_f):
default_mesh = make_default_mesh(True, False)

# evaluate
tensor = []
feed_dict_test = {}
feed_dict_test[self.t_natoms] = natoms_vec
feed_dict_test[self.t_type] = np.tile(atom_types, [nframes, 1]).reshape([-1])
Expand Down Expand Up @@ -436,7 +430,7 @@ def modify_data(self, data: dict, data_sys: DeepmdData) -> None:
box = data["box"][:get_nframes, :]
atype = data["type"][:get_nframes, :]
atype = atype[0]
nframes = coord.shape[0]
coord.shape[0]

Check warning on line 433 in deepmd/infer/data_modifier.py

View check run for this annotation

Codecov / codecov/patch

deepmd/infer/data_modifier.py#L433

Added line #L433 was not covered by tests

tot_e, tot_f, tot_v = self.eval(coord, box, atype)

Expand Down
2 changes: 1 addition & 1 deletion deepmd/loss/dos.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def build(self, learning_rate, natoms, model_dict, label_dict, suffix):
tf.square(diff_atom_cdf), name="l2_acdf_" + suffix
)

atom_norm = 1.0 / global_cvt_2_tf_float(natoms[0])
1.0 / global_cvt_2_tf_float(natoms[0])

Check warning on line 103 in deepmd/loss/dos.py

View check run for this annotation

Codecov / codecov/patch

deepmd/loss/dos.py#L103

Added line #L103 was not covered by tests
atom_norm_ener = 1.0 / global_cvt_2_ener_float(natoms[0])
pref_dos = global_cvt_2_ener_float(
find_dos
Expand Down
2 changes: 1 addition & 1 deletion deepmd/loss/ener.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def build(self, learning_rate, natoms, model_dict, label_dict, suffix):
force_label = label_dict["force"]
virial_label = label_dict["virial"]
atom_ener_label = label_dict["atom_ener"]
atom_pref = label_dict["atom_pref"]
label_dict["atom_pref"]
find_energy = label_dict["find_energy"]
find_force = label_dict["find_force"]
find_virial = label_dict["find_virial"]
Expand Down
8 changes: 4 additions & 4 deletions deepmd/model/dos.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ def build(
if input_dict is None:
input_dict = {}
with tf.variable_scope("model_attr" + suffix, reuse=reuse):
t_tmap = tf.constant(" ".join(self.type_map), name="tmap", dtype=tf.string)
t_mt = tf.constant(self.model_type, name="model_type", dtype=tf.string)
t_ver = tf.constant(MODEL_VERSION, name="model_version", dtype=tf.string)
t_od = tf.constant(self.numb_dos, name="output_dim", dtype=tf.int32)
tf.constant(" ".join(self.type_map), name="tmap", dtype=tf.string)
tf.constant(self.model_type, name="model_type", dtype=tf.string)
tf.constant(MODEL_VERSION, name="model_version", dtype=tf.string)
tf.constant(self.numb_dos, name="output_dim", dtype=tf.int32)

coord = tf.reshape(coord_, [-1, natoms[1] * 3])
atype = tf.reshape(atype_, [-1, natoms[1]])
Expand Down
8 changes: 4 additions & 4 deletions deepmd/model/ener.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ def build(
if input_dict is None:
input_dict = {}
with tf.variable_scope("model_attr" + suffix, reuse=reuse):
t_tmap = tf.constant(" ".join(self.type_map), name="tmap", dtype=tf.string)
t_mt = tf.constant(self.model_type, name="model_type", dtype=tf.string)
t_ver = tf.constant(MODEL_VERSION, name="model_version", dtype=tf.string)
tf.constant(" ".join(self.type_map), name="tmap", dtype=tf.string)
tf.constant(self.model_type, name="model_type", dtype=tf.string)
tf.constant(MODEL_VERSION, name="model_version", dtype=tf.string)

if self.srtab is not None:
tab_info, tab_data = self.srtab.get()
Expand Down Expand Up @@ -211,7 +211,7 @@ def build(
input_dict["type_embedding"] = type_embedding
# spin if any
if self.spin is not None:
type_spin = self.spin.build(
self.spin.build(
reuse=reuse,
suffix=suffix,
)
Expand Down
Loading

0 comments on commit 7eebac3

Please sign in to comment.