Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions deepmd/descriptor/se_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from deepmd.env import GLOBAL_NP_FLOAT_PRECISION
from deepmd.env import op_module
from deepmd.env import default_tf_session_config
from deepmd.utils.network import embedding_net
from deepmd.utils.network import embedding_net, embedding_net_rand_seed_shift
from deepmd.utils.tabulate import DeepTabulate
from deepmd.utils.type_embed import embed_atom_type

Expand All @@ -23,12 +23,13 @@ def __init__ (self,
axis_neuron: int = 8,
resnet_dt: bool = False,
trainable: bool = True,
seed: int = 1,
seed: int = None,
type_one_side: bool = True,
exclude_types: List[int] = [],
exclude_types: List[List[int]] = [],
set_davg_zero: bool = False,
activation_function: str = 'tanh',
precision: str = 'default'
precision: str = 'default',
uniform_seed: bool = False
) -> None:
"""
Constructor
Expand Down Expand Up @@ -62,6 +63,8 @@ def __init__ (self,
The activation function in the embedding net. Supported options are {0}
precision
The precision of the embedding net parameters. Supported options are {1}
uniform_seed
Only for the purpose of backward compatibility, retrieves the old behavior of using the random seed
"""
self.sel_a = sel
self.rcut_r = rcut
Expand All @@ -70,6 +73,8 @@ def __init__ (self,
self.n_axis_neuron = axis_neuron
self.filter_resnet_dt = resnet_dt
self.seed = seed
self.uniform_seed = uniform_seed
self.seed_shift = embedding_net_rand_seed_shift(self.filter_neuron)
self.trainable = trainable
self.filter_activation_fn = get_activation_func(activation_function)
self.filter_precision = get_precision(precision)
Expand Down Expand Up @@ -459,7 +464,7 @@ def _pass_filter(self,
[ 0, start_index* self.ndescrpt],
[-1, natoms[2+type_i]* self.ndescrpt] )
inputs_i = tf.reshape(inputs_i, [-1, self.ndescrpt])
layer, qmat = self._filter(tf.cast(inputs_i, self.filter_precision), type_i, name='filter_type_'+str(type_i)+suffix, natoms=natoms, reuse=reuse, seed = self.seed, trainable = trainable, activation_fn = self.filter_activation_fn)
layer, qmat = self._filter(tf.cast(inputs_i, self.filter_precision), type_i, name='filter_type_'+str(type_i)+suffix, natoms=natoms, reuse=reuse, trainable = trainable, activation_fn = self.filter_activation_fn)
layer = tf.reshape(layer, [tf.shape(inputs)[0], natoms[2+type_i] * self.get_dim_out()])
qmat = tf.reshape(qmat, [tf.shape(inputs)[0], natoms[2+type_i] * self.get_dim_rot_mat_1() * 3])
output.append(layer)
Expand All @@ -469,7 +474,7 @@ def _pass_filter(self,
inputs_i = inputs
inputs_i = tf.reshape(inputs_i, [-1, self.ndescrpt])
type_i = -1
layer, qmat = self._filter(tf.cast(inputs_i, self.filter_precision), type_i, name='filter_type_all'+suffix, natoms=natoms, reuse=reuse, seed = self.seed, trainable = trainable, activation_fn = self.filter_activation_fn, type_embedding=type_embedding)
layer, qmat = self._filter(tf.cast(inputs_i, self.filter_precision), type_i, name='filter_type_all'+suffix, natoms=natoms, reuse=reuse, trainable = trainable, activation_fn = self.filter_activation_fn, type_embedding=type_embedding)
layer = tf.reshape(layer, [tf.shape(inputs)[0], natoms[0] * self.get_dim_out()])
qmat = tf.reshape(qmat, [tf.shape(inputs)[0], natoms[0] * self.get_dim_rot_mat_1() * 3])
output.append(layer)
Expand Down Expand Up @@ -567,7 +572,6 @@ def _filter_lower(
activation_fn = None,
bavg = 0.0,
stddev = 1.0,
seed = None,
trainable = True,
suffix = '',
):
Expand Down Expand Up @@ -610,8 +614,10 @@ def _filter_lower(
name_suffix = suffix,
stddev = stddev,
bavg = bavg,
seed = seed,
trainable = trainable)
seed = self.seed,
trainable = trainable,
uniform_seed = self.uniform_seed)
if not self.uniform_seed: self.seed += self.seed_shift
else:
w = tf.zeros((outputs_size[0], outputs_size[-1]), dtype=GLOBAL_TF_FLOAT_PRECISION)
xyz_scatter = tf.matmul(xyz_scatter, w)
Expand All @@ -631,7 +637,6 @@ def _filter(
bavg=0.0,
name='linear',
reuse=None,
seed=None,
trainable = True):
nframes = tf.shape(tf.reshape(inputs, [-1, natoms[0], self.ndescrpt]))[0]
# natom x (nei x 4)
Expand All @@ -654,7 +659,6 @@ def _filter(
activation_fn = activation_fn,
stddev = stddev,
bavg = bavg,
seed = seed,
trainable = trainable,
suffix = "_"+str(type_i))
if type_i == 0:
Expand All @@ -674,7 +678,6 @@ def _filter(
activation_fn = activation_fn,
stddev = stddev,
bavg = bavg,
seed = seed,
trainable = trainable)
# natom x nei x outputs_size
# xyz_scatter = tf.concat(xyz_scatter_total, axis=1)
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 @@ -20,7 +20,7 @@ def __init__ (self,
axis_neuron: int = 8,
resnet_dt: bool = False,
trainable: bool = True,
seed: int = 1,
seed: int = None,
type_one_side: bool = True,
type_nchanl : int = 2,
type_nlayer : int = 1,
Expand Down
44 changes: 26 additions & 18 deletions deepmd/descriptor/se_a_ef.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ def __init__(self,
axis_neuron: int = 8,
resnet_dt: bool = False,
trainable: bool = True,
seed: int = 1,
seed: int = None,
type_one_side: bool = True,
exclude_types: List[int] = [],
set_davg_zero: bool = False,
activation_function: str = 'tanh',
precision: str = 'default'
precision: str = 'default',
uniform_seed = False
) -> None:
"""
Constructor
Expand Down Expand Up @@ -59,6 +60,8 @@ def __init__(self,
The activation function in the embedding net. Supported options are {0}
precision
The precision of the embedding net parameters. Supported options are {1}
uniform_seed
Only for the purpose of backward compatibility, retrieves the old behavior of using the random seed
"""
self.descrpt_para = DescrptSeAEfLower(
op_module.descrpt_se_a_ef_para,
Expand All @@ -75,6 +78,7 @@ def __init__(self,
set_davg_zero,
activation_function,
precision,
uniform_seed,
)
self.descrpt_vert = DescrptSeAEfLower(
op_module.descrpt_se_a_ef_vert,
Expand All @@ -91,6 +95,7 @@ def __init__(self,
set_davg_zero,
activation_function,
precision,
uniform_seed,
)

def get_rcut (self) -> float:
Expand Down Expand Up @@ -274,27 +279,30 @@ def __init__ (self,
axis_neuron: int = 8,
resnet_dt: bool = False,
trainable: bool = True,
seed: int = 1,
seed: int = None,
type_one_side: bool = True,
exclude_types: List[int] = [],
set_davg_zero: bool = False,
activation_function: str = 'tanh',
precision: str = 'default'
precision: str = 'default',
uniform_seed : bool = False,
) -> None:
DescrptSeA.__init__(self,
rcut,
rcut_smth,
sel,
neuron,
axis_neuron,
resnet_dt,
trainable,
seed,
type_one_side,
exclude_types,
set_davg_zero,
activation_function,
precision
DescrptSeA.__init__(
self,
rcut,
rcut_smth,
sel,
neuron,
axis_neuron,
resnet_dt,
trainable,
seed,
type_one_side,
exclude_types,
set_davg_zero,
activation_function,
precision,
uniform_seed
)
# DescrptSeA.__init__(self, **jdata)
# args = ClassArg()\
Expand Down
23 changes: 15 additions & 8 deletions deepmd/descriptor/se_r.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from deepmd.env import GLOBAL_NP_FLOAT_PRECISION
from deepmd.env import op_module
from deepmd.env import default_tf_session_config
from deepmd.utils.network import embedding_net
from deepmd.utils.network import embedding_net, embedding_net_rand_seed_shift

class DescrptSeR ():
@docstring_parameter(list_to_doc(ACTIVATION_FN_DICT.keys()), list_to_doc(PRECISION_DICT.keys()))
Expand All @@ -19,12 +19,14 @@ def __init__ (self,
neuron: List[int] = [24,48,96],
resnet_dt: bool = False,
trainable: bool = True,
seed: int = 1,
seed: int = None,
type_one_side: bool = True,
exclude_types: List[int] = [],
set_davg_zero: bool = False,
activation_function: str = 'tanh',
precision: str = 'default'):
precision: str = 'default',
uniform_seed: bool = False
) -> None:
"""
Constructor

Expand Down Expand Up @@ -53,6 +55,8 @@ def __init__ (self,
The activation function in the embedding net. Supported options are {0}
precision
The precision of the embedding net parameters. Supported options are {1}
uniform_seed
Only for the purpose of backward compatibility, retrieves the old behavior of using the random seed
"""
# args = ClassArg()\
# .add('sel', list, must = True) \
Expand All @@ -74,6 +78,8 @@ def __init__ (self,
self.filter_neuron = neuron
self.filter_resnet_dt = resnet_dt
self.seed = seed
self.uniform_seed = uniform_seed
self.seed_shift = embedding_net_rand_seed_shift(self.filter_neuron)
self.trainable = trainable
self.filter_activation_fn = get_activation_func(activation_function)
self.filter_precision = get_precision(precision)
Expand Down Expand Up @@ -374,15 +380,15 @@ def _pass_filter(self,
[ 0, start_index* self.ndescrpt],
[-1, natoms[2+type_i]* self.ndescrpt] )
inputs_i = tf.reshape(inputs_i, [-1, self.ndescrpt])
layer = self._filter_r(tf.cast(inputs_i, self.filter_precision), type_i, name='filter_type_'+str(type_i)+suffix, natoms=natoms, reuse=reuse, seed = self.seed, trainable = trainable, activation_fn = self.filter_activation_fn)
layer = self._filter_r(tf.cast(inputs_i, self.filter_precision), type_i, name='filter_type_'+str(type_i)+suffix, natoms=natoms, reuse=reuse, trainable = trainable, activation_fn = self.filter_activation_fn)
layer = tf.reshape(layer, [tf.shape(inputs)[0], natoms[2+type_i] * self.get_dim_out()])
output.append(layer)
start_index += natoms[2+type_i]
else :
inputs_i = inputs
inputs_i = tf.reshape(inputs_i, [-1, self.ndescrpt])
type_i = -1
layer = self._filter_r(tf.cast(inputs_i, self.filter_precision), type_i, name='filter_type_all'+suffix, natoms=natoms, reuse=reuse, seed = self.seed, trainable = trainable, activation_fn = self.filter_activation_fn)
layer = self._filter_r(tf.cast(inputs_i, self.filter_precision), type_i, name='filter_type_all'+suffix, natoms=natoms, reuse=reuse, trainable = trainable, activation_fn = self.filter_activation_fn)
layer = tf.reshape(layer, [tf.shape(inputs)[0], natoms[0] * self.get_dim_out()])
output.append(layer)
output = tf.concat(output, axis = 1)
Expand Down Expand Up @@ -442,7 +448,6 @@ def _filter_r(self,
bavg=0.0,
name='linear',
reuse=None,
seed=None,
trainable = True):
# natom x nei
outputs_size = [1] + self.filter_neuron
Expand All @@ -468,8 +473,10 @@ def _filter_r(self,
name_suffix = "_"+str(type_i),
stddev = stddev,
bavg = bavg,
seed = seed,
trainable = trainable)
seed = self.seed,
trainable = trainable,
uniform_seed = self.uniform_seed)
if not self.uniform_seed: self.seed += self.seed_shift
else:
w = tf.zeros((outputs_size[0], outputs_size[-1]), dtype=GLOBAL_TF_FLOAT_PRECISION)
xyz_scatter = tf.matmul(xyz_scatter, w)
Expand Down
20 changes: 13 additions & 7 deletions deepmd/descriptor/se_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from deepmd.env import GLOBAL_NP_FLOAT_PRECISION
from deepmd.env import op_module
from deepmd.env import default_tf_session_config
from deepmd.utils.network import embedding_net
from deepmd.utils.network import embedding_net, embedding_net_rand_seed_shift

class DescrptSeT ():
@docstring_parameter(list_to_doc(ACTIVATION_FN_DICT.keys()), list_to_doc(PRECISION_DICT.keys()))
Expand All @@ -19,10 +19,11 @@ def __init__ (self,
neuron: List[int] = [24,48,96],
resnet_dt: bool = False,
trainable: bool = True,
seed: int = 1,
seed: int = None,
set_davg_zero: bool = False,
activation_function: str = 'tanh',
precision: str = 'default'
precision: str = 'default',
uniform_seed: bool = False
) -> None:
"""
Constructor
Expand Down Expand Up @@ -50,13 +51,17 @@ def __init__ (self,
The activation function in the embedding net. Supported options are {0}
precision
The precision of the embedding net parameters. Supported options are {1}
uniform_seed
Only for the purpose of backward compatibility, retrieves the old behavior of using the random seed
"""
self.sel_a = sel
self.rcut_r = rcut
self.rcut_r_smth = rcut_smth
self.filter_neuron = neuron
self.filter_resnet_dt = resnet_dt
self.seed = seed
self.uniform_seed = uniform_seed
self.seed_shift = embedding_net_rand_seed_shift(self.filter_neuron)
self.trainable = trainable
self.filter_activation_fn = get_activation_func(activation_function)
self.filter_precision = get_precision(precision)
Expand Down Expand Up @@ -372,7 +377,7 @@ def _pass_filter(self,
inputs_i = inputs
inputs_i = tf.reshape(inputs_i, [-1, self.ndescrpt])
type_i = -1
layer, qmat = self._filter(tf.cast(inputs_i, self.filter_precision), type_i, name='filter_type_all'+suffix, natoms=natoms, reuse=reuse, seed = self.seed, trainable = trainable, activation_fn = self.filter_activation_fn)
layer, qmat = self._filter(tf.cast(inputs_i, self.filter_precision), type_i, name='filter_type_all'+suffix, natoms=natoms, reuse=reuse, trainable = trainable, activation_fn = self.filter_activation_fn)
layer = tf.reshape(layer, [tf.shape(inputs)[0], natoms[0] * self.get_dim_out()])
# qmat = tf.reshape(qmat, [tf.shape(inputs)[0], natoms[0] * self.get_dim_rot_mat_1() * 3])
output.append(layer)
Expand Down Expand Up @@ -443,7 +448,6 @@ def _filter(self,
bavg=0.0,
name='linear',
reuse=None,
seed=None,
trainable = True):
# natom x (nei x 4)
shape = inputs.get_shape().as_list()
Expand Down Expand Up @@ -492,8 +496,10 @@ def _filter(self,
name_suffix = f"_{type_i}_{type_j}",
stddev = stddev,
bavg = bavg,
seed = seed,
trainable = trainable)
seed = self.seed,
trainable = trainable,
uniform_seed = self.uniform_seed)
if not self.uniform_seed: self.seed += self.seed_shift
# with natom x nei_type_i x nei_type_j x out_size
ebd_env_ij = tf.reshape(ebd_env_ij, [-1, nei_type_i, nei_type_j, outputs_size[-1]])
# with natom x out_size
Expand Down
Loading