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

fix(tf): throw RuntimeError for se_a + type_embedding #3861

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 9 additions & 4 deletions deepmd/tf/descriptor/se_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@
self.stat_descrpt *= tf.reshape(mask, tf.shape(self.stat_descrpt))
self.sub_sess = tf.Session(graph=sub_graph, config=default_tf_session_config)
self.original_sel = None
self.use_tebd: Optional[bool] = None

Check warning on line 304 in deepmd/tf/descriptor/se_a.py

View check run for this annotation

Codecov / codecov/patch

deepmd/tf/descriptor/se_a.py#L304

Added line #L304 was not covered by tests

def get_rcut(self) -> float:
"""Returns the cut-off radius."""
Expand Down Expand Up @@ -746,8 +747,10 @@
):
if input_dict is not None:
type_embedding = input_dict.get("type_embedding", None)
self.use_tebd = True

Check warning on line 750 in deepmd/tf/descriptor/se_a.py

View check run for this annotation

Codecov / codecov/patch

deepmd/tf/descriptor/se_a.py#L750

Added line #L750 was not covered by tests
else:
type_embedding = None
self.use_tebd = False

Check warning on line 753 in deepmd/tf/descriptor/se_a.py

View check run for this annotation

Codecov / codecov/patch

deepmd/tf/descriptor/se_a.py#L753

Added line #L753 was not covered by tests
if self.stripped_type_embedding and type_embedding is None:
raise RuntimeError("type_embedding is required for se_a_tebd_v2 model.")
start_index = 0
Expand Down Expand Up @@ -1406,7 +1409,7 @@
raise NotImplementedError(
"Serialization is unsupported when tebd_input_mode is set to 'strip'"
)
if (self.original_sel != self.sel_a).any():
if self.original_sel is not None and (self.original_sel != self.sel_a).any():

Check warning on line 1412 in deepmd/tf/descriptor/se_a.py

View check run for this annotation

Codecov / codecov/patch

deepmd/tf/descriptor/se_a.py#L1412

Added line #L1412 was not covered by tests
raise NotImplementedError(
"Adjusting sel is unsupported by the native model"
)
Expand All @@ -1416,9 +1419,11 @@
raise NotImplementedError("spin is unsupported")
assert self.davg is not None
assert self.dstd is not None
# TODO: tf: handle type embedding in DescrptSeA.serialize
# not sure how to handle type embedding - type embedding is not a model parameter,
# but instead a part of the input data. Maybe the interface should be refactored...
assert self.use_tebd is not None
if self.use_tebd:
raise RuntimeError(

Check warning on line 1424 in deepmd/tf/descriptor/se_a.py

View check run for this annotation

Codecov / codecov/patch

deepmd/tf/descriptor/se_a.py#L1422-L1424

Added lines #L1422 - L1424 were not covered by tests
"Serialization is unsupported when type_embedding is used."
)

return {
"@class": "Descriptor",
Expand Down
3 changes: 3 additions & 0 deletions source/tests/tf/test_model_se_a_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,6 @@ def test_model(self):
np.testing.assert_almost_equal(e, refe, places)
np.testing.assert_almost_equal(f, reff, places)
np.testing.assert_almost_equal(v, refv, places)

with self.assertRaises(RuntimeError):
descrpt.serialize(suffix="se_a_type")
Loading