Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

breaking: add energy bias to tab potential #2670

Merged
merged 4 commits into from
Jul 20, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions deepmd/fit/ener.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,12 +689,14 @@
outs = tf.reshape(final_layer, [tf.shape(inputs)[0], natoms[0]])
# add bias
self.atom_ener_before = outs * atype_filter
self.add_type = tf.reshape(
# atomic bias energy from data statistics
self.atom_bias_ener = tf.reshape(

Check warning on line 693 in deepmd/fit/ener.py

View check run for this annotation

Codecov / codecov/patch

deepmd/fit/ener.py#L693

Added line #L693 was not covered by tests
tf.nn.embedding_lookup(self.t_bias_atom_e, self.atype_nloc),
[tf.shape(inputs)[0], tf.reduce_sum(natoms[2 : 2 + ntypes_atom])],
)
outs = outs + self.add_type
outs = outs + self.atom_bias_ener

Check warning on line 697 in deepmd/fit/ener.py

View check run for this annotation

Codecov / codecov/patch

deepmd/fit/ener.py#L697

Added line #L697 was not covered by tests
outs *= atype_filter
self.atom_bias_ener *= atype_filter

Check warning on line 699 in deepmd/fit/ener.py

View check run for this annotation

Codecov / codecov/patch

deepmd/fit/ener.py#L699

Added line #L699 was not covered by tests
self.atom_ener_after = outs

if self.tot_ener_zero:
Expand Down
6 changes: 6 additions & 0 deletions deepmd/model/ener.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
The lower boundary of the interpolation between short-range tabulated interaction and DP. It is only required when `use_srtab` is provided.
sw_rmin
The upper boundary of the interpolation between short-range tabulated interaction and DP. It is only required when `use_srtab` is provided.
srtab_add_bias : bool
Whether add energy bias from the statistics of the data to short-range tabulated atomic energy. It only takes effect when `use_srtab` is provided.
spin
spin
data_stat_nsample
Expand All @@ -78,6 +80,7 @@
smin_alpha: Optional[float] = None,
sw_rmin: Optional[float] = None,
sw_rmax: Optional[float] = None,
srtab_add_bias: bool = True,
spin: Optional[Spin] = None,
data_bias_nsample: int = 10,
**kwargs,
Expand All @@ -96,6 +99,7 @@
sw_rmin=sw_rmin,
sw_rmax=sw_rmax,
spin=spin,
srtab_add_bias=srtab_add_bias,
**kwargs,
)
self.numb_fparam = self.fitting.get_numb_fparam()
Expand Down Expand Up @@ -263,6 +267,8 @@
sel_a=sel_a,
sel_r=sel_r,
)
if self.srtab_add_bias:
tab_atom_ener += self.fitting.atom_bias_ener

Check warning on line 271 in deepmd/model/ener.py

View check run for this annotation

Codecov / codecov/patch

deepmd/model/ener.py#L270-L271

Added lines #L270 - L271 were not covered by tests
energy_diff = tab_atom_ener - tf.reshape(atom_ener, [-1, natoms[0]])
tab_atom_ener = tf.reshape(sw_lambda, [-1]) * tf.reshape(
tab_atom_ener, [-1]
Expand Down
4 changes: 4 additions & 0 deletions deepmd/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
The lower boundary of the interpolation between short-range tabulated interaction and DP. It is only required when `use_srtab` is provided.
sw_rmin
The upper boundary of the interpolation between short-range tabulated interaction and DP. It is only required when `use_srtab` is provided.
srtab_add_bias : bool
Whether add energy bias from the statistics of the data to short-range tabulated atomic energy. It only takes effect when `use_srtab` is provided.
spin
spin
compress
Expand Down Expand Up @@ -104,6 +106,7 @@
smin_alpha: Optional[float] = None,
sw_rmin: Optional[float] = None,
sw_rmax: Optional[float] = None,
srtab_add_bias: bool = True,
spin: Optional[Spin] = None,
compress: Optional[dict] = None,
**kwargs,
Expand Down Expand Up @@ -131,6 +134,7 @@
self.smin_alpha = smin_alpha
self.sw_rmin = sw_rmin
self.sw_rmax = sw_rmax
self.srtab_add_bias = srtab_add_bias

Check warning on line 137 in deepmd/model/model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/model/model.py#L137

Added line #L137 was not covered by tests
else:
self.srtab = None

Expand Down
8 changes: 8 additions & 0 deletions deepmd/utils/argcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@
doc_smin_alpha = "The short-range tabulated interaction will be swithed according to the distance of the nearest neighbor. This distance is calculated by softmin. This parameter is the decaying parameter in the softmin. It is only required when `use_srtab` is provided."
doc_sw_rmin = "The lower boundary of the interpolation between short-range tabulated interaction and DP. It is only required when `use_srtab` is provided."
doc_sw_rmax = "The upper boundary of the interpolation between short-range tabulated interaction and DP. It is only required when `use_srtab` is provided."
doc_srtab_add_bias = "Whether add energy bias from the statistics of the data to short-range tabulated atomic energy. It only takes effect when `use_srtab` is provided."

Check warning on line 761 in deepmd/utils/argcheck.py

View check run for this annotation

Codecov / codecov/patch

deepmd/utils/argcheck.py#L761

Added line #L761 was not covered by tests
doc_compress_config = "Model compression configurations"
doc_spin = "The settings for systems with spin."
return Argument(
Expand Down Expand Up @@ -790,6 +791,13 @@
Argument("smin_alpha", float, optional=True, doc=doc_smin_alpha),
Argument("sw_rmin", float, optional=True, doc=doc_sw_rmin),
Argument("sw_rmax", float, optional=True, doc=doc_sw_rmax),
Argument(
"srtab_add_bias",
bool,
optional=True,
default=True,
doc=doc_srtab_add_bias,
),
Argument(
"type_embedding",
dict,
Expand Down