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

convert exclude_types to sel_type #3418

Merged
merged 1 commit into from
Mar 6, 2024
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
2 changes: 1 addition & 1 deletion deepmd/dpmodel/fitting/general_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def get_sel_type(self) -> List[int]:
to the result of the model.
If returning an empty list, all atom types are selected.
"""
return []
return [ii for ii in range(self.ntypes) if ii not in self.exclude_types]

def __setitem__(self, key, value):
if key in ["bias_atom_e"]:
Expand Down
10 changes: 9 additions & 1 deletion deepmd/pt/model/task/fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,14 +388,22 @@ def get_dim_aparam(self) -> int:
"""Get the number (dimension) of atomic parameters of this atomic model."""
return self.numb_aparam

# make jit happy
exclude_types: List[int]
wanghan-iapcm marked this conversation as resolved.
Show resolved Hide resolved

def get_sel_type(self) -> List[int]:
"""Get the selected atom types of this model.

Only atoms with selected atom types have atomic contribution
to the result of the model.
If returning an empty list, all atom types are selected.
"""
return []
# make jit happy
sel_type: List[int] = []
for ii in range(self.ntypes):
if ii not in self.exclude_types:
sel_type.append(ii)
return sel_type

def __setitem__(self, key, value):
if key in ["bias_atom_e"]:
Expand Down
4 changes: 4 additions & 0 deletions source/tests/common/dpmodel/test_fitting_invar_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ def test_self_consistency(
ret0 = ifn0(dd[0], atype, fparam=ifp, aparam=iap)
ret1 = ifn1(dd[0], atype, fparam=ifp, aparam=iap)
np.testing.assert_allclose(ret0["energy"], ret1["energy"])
sel_set = set(ifn0.get_sel_type())
exclude_set = set(et)
self.assertEqual(sel_set | exclude_set, set(range(self.nt)))
self.assertEqual(sel_set & exclude_set, set())

def test_mask(self):
nf, nloc, nnei = self.nlist.shape
Expand Down
1 change: 1 addition & 0 deletions source/tests/pt/model/test_ener_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def test_consistency(
to_numpy_array(ret0["foo"]),
to_numpy_array(ret2["foo"]),
)
self.assertEqual(ft0.get_sel_type(), ft1.get_sel_type())

def test_new_old(
self,
Expand Down