Skip to content

Commit de735a7

Browse files
committed
Refactor IOTest to separate atomic results in evaluation tests
1 parent c39d25b commit de735a7

1 file changed

Lines changed: 21 additions & 16 deletions

File tree

source/tests/consistent/io/test_io.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ def test_deep_eval(self) -> None:
140140
nframes = self.atype.shape[0]
141141
prefix = "test_consistent_io_" + self.__class__.__name__.lower()
142142
rets = []
143+
rets_atomic = []
143144
rets_nopbc = []
145+
rets_nopbc_atomic = []
144146
for backend_name, suffix_idx in (
145147
# unfortunately, jax2tf cannot work with tf v1 behaviors
146148
("jax", 2) if DP_TEST_TF2_ONLY else ("tensorflow", 0),
@@ -183,7 +185,8 @@ def test_deep_eval(self) -> None:
183185
aparam=aparam,
184186
atomic=True,
185187
)
186-
rets.append(ret)
188+
rets.append(ret[:3])
189+
rets_atomic.append(ret[3:])
187190
ret = deep_eval.eval(
188191
self.coords,
189192
None,
@@ -200,22 +203,24 @@ def test_deep_eval(self) -> None:
200203
aparam=aparam,
201204
atomic=True,
202205
)
203-
rets_nopbc.append(ret)
204-
for ret in rets[1:]:
205-
for vv1, vv2 in zip(rets[0], ret, strict=True):
206-
if np.isnan(vv2).all():
207-
# expect all nan if not supported
208-
continue
209-
np.testing.assert_allclose(vv1, vv2, rtol=1e-12, atol=1e-12)
206+
rets_nopbc.append(ret[:3])
207+
rets_nopbc_atomic.append(ret[3:])
210208

211-
for idx, ret in enumerate(rets_nopbc[1:]):
212-
for vv1, vv2 in zip(rets_nopbc[0], ret, strict=True):
213-
if np.isnan(vv2).all():
214-
# expect all nan if not supported
215-
continue
216-
np.testing.assert_allclose(
217-
vv1, vv2, rtol=1e-12, atol=1e-12, err_msg=f"backend {idx + 1}"
218-
)
209+
for rets_idx, rets_x in enumerate(
210+
(rets, rets_atomic, rets_nopbc, rets_nopbc_atomic)
211+
):
212+
for idx, ret in enumerate(rets_x[1:]):
213+
for vv1, vv2 in zip(rets_x[0], ret, strict=True):
214+
if np.isnan(vv2).all():
215+
# expect all nan if not supported
216+
continue
217+
np.testing.assert_allclose(
218+
vv1,
219+
vv2,
220+
rtol=1e-12,
221+
atol=1e-12,
222+
err_msg=f"backend {idx + 1} for rets_idx {rets_idx}",
223+
)
219224

220225

221226
class TestDeepPot(unittest.TestCase, IOTest):

0 commit comments

Comments
 (0)