From e0bb0145a300621b5e3efacad292727c5f531f22 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 6 Jan 2025 16:42:23 +0800 Subject: [PATCH] fix(pt): fix clearing the list in set_eval_descriptor_hook Fix #4533. Signed-off-by: Jinzhe Zeng --- deepmd/pt/model/atomic_model/dp_atomic_model.py | 3 ++- source/tests/infer/test_models.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/deepmd/pt/model/atomic_model/dp_atomic_model.py b/deepmd/pt/model/atomic_model/dp_atomic_model.py index c988d63213..3758e5ea22 100644 --- a/deepmd/pt/model/atomic_model/dp_atomic_model.py +++ b/deepmd/pt/model/atomic_model/dp_atomic_model.py @@ -69,7 +69,8 @@ def __init__( def set_eval_descriptor_hook(self, enable: bool) -> None: """Set the hook for evaluating descriptor and clear the cache for descriptor list.""" self.enable_eval_descriptor_hook = enable - self.eval_descriptor_list = [] + # = [] does not work; See #4533 + self.eval_descriptor_list.clear() def eval_descriptor(self) -> torch.Tensor: """Evaluate the descriptor.""" diff --git a/source/tests/infer/test_models.py b/source/tests/infer/test_models.py index a79ce0ab21..c0543e91cd 100644 --- a/source/tests/infer/test_models.py +++ b/source/tests/infer/test_models.py @@ -159,6 +159,10 @@ def test_descriptor(self) -> None: descpt = self.dp.eval_descriptor(result.coord, result.box, result.atype) expected_descpt = result.descriptor np.testing.assert_almost_equal(descpt.ravel(), expected_descpt.ravel()) + # See #4533 + descpt = self.dp.eval_descriptor(result.coord, result.box, result.atype) + expected_descpt = result.descriptor + np.testing.assert_almost_equal(descpt.ravel(), expected_descpt.ravel()) def test_2frame_atm(self) -> None: for ii, result in enumerate(self.case.results):