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

chore(tests): ensure the same result of frame 0 and 1 #4442

Open
wants to merge 3 commits into
base: devel
Choose a base branch
from
Open
Changes from 2 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
18 changes: 13 additions & 5 deletions source/tests/universal/common/cases/model/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,18 @@ def test_has_message_passing(self) -> None:
def test_forward(self) -> None:
"""Test forward and forward_lower."""
test_spin = getattr(self, "test_spin", False)
nf = 1
nf = 2
natoms = 5
aprec = (
0
if self.aprec_dict.get("test_forward", None) is None
else self.aprec_dict["test_forward"]
)
rng = np.random.default_rng(GLOBAL_SEED)
coord = 4.0 * rng.random([natoms, 3]).reshape([nf, -1])
atype = np.array([0, 0, 0, 1, 1], dtype=int).reshape([nf, -1])
spin = 0.5 * rng.random([natoms, 3]).reshape([nf, -1])
cell = 6.0 * np.eye(3).reshape([nf, 9])
coord = 4.0 * rng.random([1, natoms, 3]).repeat(nf, 0).reshape([nf, -1])
atype = np.array([[0, 0, 0, 1, 1] * nf], dtype=int).reshape([nf, -1])
spin = 0.5 * rng.random([1, natoms, 3]).repeat(nf, 0).reshape([nf, -1])
cell = 6.0 * np.repeat(np.eye(3)[None, ...], nf, axis=0).reshape([nf, 9])
coord_ext, atype_ext, mapping, nlist = extend_input_and_build_neighbor_list(
coord,
atype,
Expand Down Expand Up @@ -183,6 +183,14 @@ def test_forward(self) -> None:
ret_lower.append(module.forward_lower(**input_dict_lower))

for kk in ret[0]:
# ensure the first frame and the second frame are the same
if ret[0][kk] is not None:
np.testing.assert_allclose(
ret[0][kk][0],
ret[0][kk][1],
err_msg=f"compare {kk} between frame 0 and 1",
)

subret = []
for rr in ret:
if rr is not None:
Expand Down
Loading