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): fix DeepEval degradation for virtual types #3464

Merged
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
4 changes: 4 additions & 0 deletions deepmd/infer/deep_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@
atom_types : np.ndarray
The atom types of all frames, in shape nframes * natoms.
"""
if np.count_nonzero(atom_types[0] == -1) > 0:

Check warning on line 245 in deepmd/infer/deep_eval.py

View check run for this annotation

Codecov / codecov/patch

deepmd/infer/deep_eval.py#L245

Added line #L245 was not covered by tests
# assume mixed_types if there are virtual types, even when
# the atom types of all frames are the same
return False

Check warning on line 248 in deepmd/infer/deep_eval.py

View check run for this annotation

Codecov / codecov/patch

deepmd/infer/deep_eval.py#L248

Added line #L248 was not covered by tests
return np.all(np.equal(atom_types, atom_types[0]))

@property
Expand Down
5 changes: 5 additions & 0 deletions deepmd/tf/infer/deep_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,11 @@
natoms_vec[1] = natoms
for ii in range(self.ntypes):
natoms_vec[ii + 2] = np.count_nonzero(atom_types[0] == ii)
if np.count_nonzero(atom_types[0] == -1) > 0:

Check warning on line 492 in deepmd/tf/infer/deep_eval.py

View check run for this annotation

Codecov / codecov/patch

deepmd/tf/infer/deep_eval.py#L492

Added line #L492 was not covered by tests
# contains virtual atoms
# energy fitting sums over natoms_vec[2:] instead of reading from natoms_vec[0]
# causing errors for shape mismatch
natoms_vec[2] += np.count_nonzero(atom_types[0] == -1)

Check warning on line 496 in deepmd/tf/infer/deep_eval.py

View check run for this annotation

Codecov / codecov/patch

deepmd/tf/infer/deep_eval.py#L496

Added line #L496 was not covered by tests
return natoms_vec

def eval_typeebd(self) -> np.ndarray:
Expand Down