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: cuda tests of linear and pair atomic model #3248

Merged
merged 9 commits into from
Feb 9, 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
20 changes: 10 additions & 10 deletions deepmd/pt/model/model/pairtab_atomic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
)

import torch
from torch import (
nn,
)

from deepmd.dpmodel import (
FittingOutputDef,
Expand All @@ -22,9 +19,12 @@
from .base_atomic_model import (
BaseAtomicModel,
)
from .model import (

Check warning on line 22 in deepmd/pt/model/model/pairtab_atomic_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/model/pairtab_atomic_model.py#L22

Added line #L22 was not covered by tests
BaseModel,
)


class PairTabModel(nn.Module, BaseAtomicModel):
class PairTabModel(BaseModel, BaseAtomicModel):

Check warning on line 27 in deepmd/pt/model/model/pairtab_atomic_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/model/pairtab_atomic_model.py#L27

Added line #L27 was not covered by tests
"""Pairwise tabulation energy model.

This model can be used to tabulate the pairwise energy between atoms for either
Expand Down Expand Up @@ -62,11 +62,11 @@
tab_info,
tab_data,
) = self.tab.get() # this returns -> Tuple[np.array, np.array]
self.tab_info = torch.from_numpy(tab_info)
self.tab_data = torch.from_numpy(tab_data)
self.register_buffer("tab_info", torch.from_numpy(tab_info))
self.register_buffer("tab_data", torch.from_numpy(tab_data))

Check warning on line 66 in deepmd/pt/model/model/pairtab_atomic_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/model/pairtab_atomic_model.py#L65-L66

Added lines #L65 - L66 were not covered by tests
else:
self.tab_info = None
self.tab_data = None
self.register_buffer("tab_info", None)
self.register_buffer("tab_data", None)

Check warning on line 69 in deepmd/pt/model/model/pairtab_atomic_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/model/pairtab_atomic_model.py#L68-L69

Added lines #L68 - L69 were not covered by tests

# self.model_type = "ener"
# self.model_version = MODEL_VERSION ## this shoud be in the parent class
Expand Down Expand Up @@ -118,8 +118,8 @@
tab = PairTab.deserialize(data["tab"])
tab_model = cls(None, rcut, sel)
tab_model.tab = tab
tab_model.tab_info = torch.from_numpy(tab_model.tab.tab_info)
tab_model.tab_data = torch.from_numpy(tab_model.tab.tab_data)
tab_model.register_buffer("tab_info", torch.from_numpy(tab_model.tab.tab_info))
tab_model.register_buffer("tab_data", torch.from_numpy(tab_model.tab.tab_data))

Check warning on line 122 in deepmd/pt/model/model/pairtab_atomic_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/model/pairtab_atomic_model.py#L121-L122

Added lines #L121 - L122 were not covered by tests
return tab_model

def forward_atomic(
Expand Down
10 changes: 5 additions & 5 deletions source/tests/pt/model/test_linear_atomic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def test_pairwise(self, mock_loadtxt):
[0.25, 0.0, 0.0, 0.0],
]
)
extended_atype = torch.tensor([[0, 0]])
nlist = torch.tensor([[[1], [-1]]])
extended_atype = torch.tensor([[0, 0]]).to(env.DEVICE)
nlist = torch.tensor([[[1], [-1]]]).to(env.DEVICE)

ds = DescrptSeA(
rcut=0.3,
Expand All @@ -82,7 +82,7 @@ def test_pairwise(self, mock_loadtxt):
zbl_model,
sw_rmin=0.1,
sw_rmax=0.25,
)
).to(env.DEVICE)
wgt_res = []
for dist in np.linspace(0.05, 0.3, 10):
extended_coord = torch.tensor(
Expand All @@ -92,7 +92,7 @@ def test_pairwise(self, mock_loadtxt):
[0.0, dist, 0.0],
],
]
)
).to(env.DEVICE)

wgt_model.forward_atomic(extended_coord, extended_atype, nlist)

Expand All @@ -112,7 +112,7 @@ def test_pairwise(self, mock_loadtxt):
[0.0, 0.0],
],
dtype=torch.float64,
)
).to(env.DEVICE)
torch.testing.assert_close(results, excepted_res, rtol=0.0001, atol=0.0001)


Expand Down
Loading