Skip to content

Commit

Permalink
add place holders to PairTab. fix test: asserting equal between floats
Browse files Browse the repository at this point in the history
  • Loading branch information
Han Wang committed Feb 1, 2024
1 parent 553ef53 commit f54c724
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
8 changes: 8 additions & 0 deletions deepmd/pt/model/model/pair_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ def distinguish_types(self) -> bool:
# to match DPA1 and DPA2.
return False

def serialize(self) -> dict:
# place holder, implemantated in future PR
raise NotImplementedError

def deserialize(cls):

Check notice

Code scanning / CodeQL

First parameter of a method is not named 'self' Note

Normal methods should have 'self', rather than 'cls', as their first parameter.
# place holder, implemantated in future PR
raise NotImplementedError

def forward_atomic(
self,
extended_coord,
Expand Down
22 changes: 9 additions & 13 deletions source/tests/pt/test_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,18 @@ def test_rotation(self):
result1 = self.model(**get_data(self.origin_batch))
result2 = self.model(**get_data(self.rotated_batch))
rotation = torch.from_numpy(self.rotation).to(env.DEVICE)
self.assertTrue(result1["energy"] == result2["energy"])
self.assertAlmostEqual(result1["energy"], result2["energy"])
if "force" in result1:
self.assertTrue(
torch.allclose(
result2["force"][0], torch.matmul(rotation, result1["force"][0].T).T
)
torch.testing.assert_close(
result2["force"][0], torch.matmul(rotation, result1["force"][0].T).T
)
if "virial" in result1:
self.assertTrue(
torch.allclose(
result2["virial"][0].view([3, 3]),
torch.matmul(
torch.matmul(rotation, result1["virial"][0].view([3, 3]).T),
rotation.T,
),
)
torch.testing.assert_close(
result2["virial"][0].view([3, 3]),
torch.matmul(
torch.matmul(rotation, result1["virial"][0].view([3, 3]).T),
rotation.T,
),
)


Expand Down

0 comments on commit f54c724

Please sign in to comment.