From e675f071bd8be0da341e3a34de1ff15dd533b4dd Mon Sep 17 00:00:00 2001 From: "njzjz-bot (driven by OpenClaw (model: gpt-5.4))[bot]" <48687836+njzjz-bot@users.noreply.github.com> Date: Sat, 11 Apr 2026 04:47:49 +0000 Subject: [PATCH 1/4] test(consistent): curate DPA3 descriptor matrix\n\nApply the curated-case parameterization pattern from #5378 to the\nDPA3 descriptor consistent tests so the coverage stays reviewable\nwithout relying on a Cartesian-product explosion.\n\nAuthored by OpenClaw (model: gpt-5.4) --- .../tests/consistent/descriptor/test_dpa3.py | 145 ++++++++++++++---- 1 file changed, 112 insertions(+), 33 deletions(-) diff --git a/source/tests/consistent/descriptor/test_dpa3.py b/source/tests/consistent/descriptor/test_dpa3.py index bca0759f5c..1d2e5383c5 100644 --- a/source/tests/consistent/descriptor/test_dpa3.py +++ b/source/tests/consistent/descriptor/test_dpa3.py @@ -21,7 +21,7 @@ INSTALLED_PT, INSTALLED_PT_EXPT, CommonTest, - parameterized, + parameterized_cases, ) from .common import ( DescriptorAPITest, @@ -62,24 +62,118 @@ descrpt_dpa3_args, ) +DPA3_CASE_FIELDS = ( + "update_residual_init", + "exclude_types", + "update_angle", + "a_compress_rate", + "a_compress_e_rate", + "a_compress_use_split", + "optim_update", + "edge_init_use_dist", + "use_exp_switch", + "use_dynamic_sel", + "use_loc_mapping", + "fix_stat_std", + "n_multi_edge_message", + "precision", + "add_chg_spin_ebd", +) + + +DPA3_BASELINE_CASE = { + "update_residual_init": "const", + "exclude_types": [], + "update_angle": True, + "a_compress_rate": 0, + "a_compress_e_rate": 1, + "a_compress_use_split": True, + "optim_update": True, + "edge_init_use_dist": True, + "use_exp_switch": True, + "use_dynamic_sel": True, + "use_loc_mapping": True, + "fix_stat_std": 0.3, + "n_multi_edge_message": 1, + "precision": "float64", + "add_chg_spin_ebd": False, +} + + +def dpa3_case(**overrides: Any) -> tuple: + case = DPA3_BASELINE_CASE | overrides + return tuple(case[field] for field in DPA3_CASE_FIELDS) + + +DPA3_CURATED_CASES = ( + # Baseline coverage. + dpa3_case(), + # Descriptor-level edge cases. + dpa3_case(exclude_types=[[0, 1]]), + dpa3_case(use_loc_mapping=False), + dpa3_case(add_chg_spin_ebd=True), + # Repflow compression branches. + dpa3_case(a_compress_rate=1), + dpa3_case(a_compress_e_rate=2), + # Repflow update toggles. + dpa3_case(optim_update=False), + dpa3_case(edge_init_use_dist=False), + dpa3_case(use_exp_switch=False), + dpa3_case(use_dynamic_sel=False), + # One mixed high-risk path to keep interactions covered. + dpa3_case( + exclude_types=[[0, 1]], + a_compress_rate=1, + a_compress_e_rate=2, + optim_update=False, + edge_init_use_dist=False, + use_exp_switch=False, + use_dynamic_sel=False, + use_loc_mapping=False, + add_chg_spin_ebd=True, + ), +) -@parameterized( - ("const",), # update_residual_init - ([], [[0, 1]]), # exclude_types - (True,), # update_angle - (0, 1), # a_compress_rate - (1, 2), # a_compress_e_rate - (True,), # a_compress_use_split - (True, False), # optim_update - (True, False), # edge_init_use_dist - (True, False), # use_exp_switch - (True, False), # use_dynamic_sel - (True, False), # use_loc_mapping - (0.3,), # fix_stat_std - (1,), # n_multi_edge_message - ("float64",), # precision - (False, True), # add_chg_spin_ebd + +DPA3_DESCRIPTOR_API_CASE_FIELDS = DPA3_CASE_FIELDS[:-1] + + +def dpa3_descriptor_api_case(**overrides: Any) -> tuple: + case = DPA3_BASELINE_CASE | overrides + return tuple(case[field] for field in DPA3_DESCRIPTOR_API_CASE_FIELDS) + + +DPA3_DESCRIPTOR_API_CURATED_CASES = ( + # Baseline coverage. + dpa3_descriptor_api_case(), + # Descriptor serialization / config toggles. + dpa3_descriptor_api_case(exclude_types=[[0, 1]]), + dpa3_descriptor_api_case(use_loc_mapping=False), + dpa3_descriptor_api_case(fix_stat_std=0.0), + # Repflow compression branches. + dpa3_descriptor_api_case(a_compress_rate=1), + dpa3_descriptor_api_case(a_compress_e_rate=2), + # Repflow update toggles. + dpa3_descriptor_api_case(optim_update=False), + dpa3_descriptor_api_case(edge_init_use_dist=False), + dpa3_descriptor_api_case(use_exp_switch=False), + dpa3_descriptor_api_case(use_dynamic_sel=False), + # One mixed high-risk path to keep interactions covered. + dpa3_descriptor_api_case( + exclude_types=[[0, 1]], + a_compress_rate=1, + a_compress_e_rate=2, + optim_update=False, + edge_init_use_dist=False, + use_exp_switch=False, + use_dynamic_sel=False, + use_loc_mapping=False, + fix_stat_std=0.0, + ), ) + + +@parameterized_cases(*DPA3_CURATED_CASES) class TestDPA3(CommonTest, DescriptorTest, unittest.TestCase): @property def data(self) -> dict: @@ -430,22 +524,7 @@ def atol(self) -> float: raise ValueError(f"Unknown precision: {precision}") -@parameterized( - ("const",), # update_residual_init - ([], [[0, 1]]), # exclude_types - (True,), # update_angle - (0, 1), # a_compress_rate - (1, 2), # a_compress_e_rate - (True,), # a_compress_use_split - (True, False), # optim_update - (True, False), # edge_init_use_dist - (True, False), # use_exp_switch - (True, False), # use_dynamic_sel - (True, False), # use_loc_mapping - (0.3, 0.0), # fix_stat_std - (1,), # n_multi_edge_message - ("float64",), # precision -) +@parameterized_cases(*DPA3_DESCRIPTOR_API_CURATED_CASES) class TestDPA3DescriptorAPI(DescriptorAPITest, unittest.TestCase): """Test consistency of BaseDescriptor API methods across backends.""" From 48a9d71f4886d5d0a3547e906160b3ca0757765d Mon Sep 17 00:00:00 2001 From: "njzjz-bot (driven by OpenClaw (model: gpt-5.4))[bot]" <48687836+njzjz-bot@users.noreply.github.com> Date: Sat, 11 Apr 2026 06:04:57 +0000 Subject: [PATCH 2/4] test(consistent): cover DPA3 API charge-spin serialization\n\nKeep add_chg_spin_ebd in the curated DPA3 descriptor API case\nmatrix so serialization coverage includes the conditional charge/spin\nembedding path noted in review.\n\nAuthored by OpenClaw (model: gpt-5.4) --- source/tests/consistent/descriptor/test_dpa3.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/tests/consistent/descriptor/test_dpa3.py b/source/tests/consistent/descriptor/test_dpa3.py index 1d2e5383c5..acbbac39e7 100644 --- a/source/tests/consistent/descriptor/test_dpa3.py +++ b/source/tests/consistent/descriptor/test_dpa3.py @@ -135,7 +135,7 @@ def dpa3_case(**overrides: Any) -> tuple: ) -DPA3_DESCRIPTOR_API_CASE_FIELDS = DPA3_CASE_FIELDS[:-1] +DPA3_DESCRIPTOR_API_CASE_FIELDS = DPA3_CASE_FIELDS def dpa3_descriptor_api_case(**overrides: Any) -> tuple: @@ -150,6 +150,7 @@ def dpa3_descriptor_api_case(**overrides: Any) -> tuple: dpa3_descriptor_api_case(exclude_types=[[0, 1]]), dpa3_descriptor_api_case(use_loc_mapping=False), dpa3_descriptor_api_case(fix_stat_std=0.0), + dpa3_descriptor_api_case(add_chg_spin_ebd=True), # Repflow compression branches. dpa3_descriptor_api_case(a_compress_rate=1), dpa3_descriptor_api_case(a_compress_e_rate=2), @@ -169,6 +170,7 @@ def dpa3_descriptor_api_case(**overrides: Any) -> tuple: use_dynamic_sel=False, use_loc_mapping=False, fix_stat_std=0.0, + add_chg_spin_ebd=True, ), ) @@ -550,6 +552,7 @@ def data(self) -> dict: fix_stat_std, n_multi_edge_message, precision, + add_chg_spin_ebd, ) = self.param return { "ntypes": self.ntypes, @@ -590,4 +593,5 @@ def data(self) -> dict: "env_protection": 0.0, "use_loc_mapping": use_loc_mapping, "trainable": False, + "add_chg_spin_ebd": add_chg_spin_ebd, } From e82992089b01e205d080be51637dd57cb89b33b0 Mon Sep 17 00:00:00 2001 From: "njzjz-bot (driven by OpenClaw (model: gpt-5.4))[bot]" <48687836+njzjz-bot@users.noreply.github.com> Date: Sat, 11 Apr 2026 06:44:41 +0000 Subject: [PATCH 3/4] test(consistent): mark unused DPA3 case fields\n\nPrefix intentionally unused unpacked variables in the curated DPA3\nconsistent tests so ruff no longer reports RUF059 on the helper\nproperties and setup code.\n\nAuthored by OpenClaw (model: gpt-5.4) --- .../tests/consistent/descriptor/test_dpa3.py | 202 +++++++++--------- 1 file changed, 101 insertions(+), 101 deletions(-) diff --git a/source/tests/consistent/descriptor/test_dpa3.py b/source/tests/consistent/descriptor/test_dpa3.py index acbbac39e7..faa5134f66 100644 --- a/source/tests/consistent/descriptor/test_dpa3.py +++ b/source/tests/consistent/descriptor/test_dpa3.py @@ -241,41 +241,41 @@ def data(self) -> dict: @property def skip_pt(self) -> bool: ( - update_residual_init, - exclude_types, - update_angle, - a_compress_rate, - a_compress_e_rate, - a_compress_use_split, - optim_update, - edge_init_use_dist, - use_exp_switch, - use_dynamic_sel, - use_loc_mapping, - fix_stat_std, - n_multi_edge_message, - precision, - add_chg_spin_ebd, + _update_residual_init, + _exclude_types, + _update_angle, + _a_compress_rate, + _a_compress_e_rate, + _a_compress_use_split, + _optim_update, + _edge_init_use_dist, + _use_exp_switch, + _use_dynamic_sel, + _use_loc_mapping, + _fix_stat_std, + _n_multi_edge_message, + _precision, + _add_chg_spin_ebd, ) = self.param return CommonTest.skip_pt @property def skip_pd(self) -> bool: ( - update_residual_init, - exclude_types, - update_angle, - a_compress_rate, - a_compress_e_rate, - a_compress_use_split, - optim_update, - edge_init_use_dist, - use_exp_switch, - use_dynamic_sel, - use_loc_mapping, - fix_stat_std, - n_multi_edge_message, - precision, + _update_residual_init, + _exclude_types, + _update_angle, + _a_compress_rate, + _a_compress_e_rate, + _a_compress_use_split, + _optim_update, + _edge_init_use_dist, + _use_exp_switch, + _use_dynamic_sel, + _use_loc_mapping, + _fix_stat_std, + _n_multi_edge_message, + _precision, add_chg_spin_ebd, ) = self.param return True if add_chg_spin_ebd else CommonTest.skip_pd @@ -283,42 +283,42 @@ def skip_pd(self) -> bool: @property def skip_dp(self) -> bool: ( - update_residual_init, - exclude_types, - update_angle, - a_compress_rate, - a_compress_e_rate, - a_compress_use_split, - optim_update, - edge_init_use_dist, - use_exp_switch, - use_dynamic_sel, - use_loc_mapping, - fix_stat_std, - n_multi_edge_message, - precision, - add_chg_spin_ebd, + _update_residual_init, + _exclude_types, + _update_angle, + _a_compress_rate, + _a_compress_e_rate, + _a_compress_use_split, + _optim_update, + _edge_init_use_dist, + _use_exp_switch, + _use_dynamic_sel, + _use_loc_mapping, + _fix_stat_std, + _n_multi_edge_message, + _precision, + _add_chg_spin_ebd, ) = self.param return CommonTest.skip_dp @property def skip_tf(self) -> bool: ( - update_residual_init, - exclude_types, - update_angle, - a_compress_rate, - a_compress_e_rate, - a_compress_use_split, - optim_update, - edge_init_use_dist, - use_exp_switch, - use_dynamic_sel, - use_loc_mapping, - fix_stat_std, - n_multi_edge_message, - precision, - add_chg_spin_ebd, + _update_residual_init, + _exclude_types, + _update_angle, + _a_compress_rate, + _a_compress_e_rate, + _a_compress_use_split, + _optim_update, + _edge_init_use_dist, + _use_exp_switch, + _use_dynamic_sel, + _use_loc_mapping, + _fix_stat_std, + _n_multi_edge_message, + _precision, + _add_chg_spin_ebd, ) = self.param return True @@ -369,20 +369,20 @@ def setUp(self) -> None: ) self.natoms = np.array([6, 6, 2, 4], dtype=np.int32) ( - update_residual_init, - exclude_types, - update_angle, - a_compress_rate, - a_compress_e_rate, - a_compress_use_split, - optim_update, - edge_init_use_dist, - use_exp_switch, - use_dynamic_sel, - use_loc_mapping, - fix_stat_std, - n_multi_edge_message, - precision, + _update_residual_init, + _exclude_types, + _update_angle, + _a_compress_rate, + _a_compress_e_rate, + _a_compress_use_split, + _optim_update, + _edge_init_use_dist, + _use_exp_switch, + _use_dynamic_sel, + _use_loc_mapping, + _fix_stat_std, + _n_multi_edge_message, + _precision, add_chg_spin_ebd, ) = self.param # fparam for charge=5, spin=1 when add_chg_spin_ebd is True @@ -475,21 +475,21 @@ def extract_ret(self, ret: Any, backend) -> tuple[np.ndarray, ...]: def rtol(self) -> float: """Relative tolerance for comparing the return value.""" ( - update_residual_init, - exclude_types, - update_angle, - a_compress_rate, - a_compress_e_rate, - a_compress_use_split, - optim_update, - edge_init_use_dist, - use_exp_switch, - use_dynamic_sel, - use_loc_mapping, - fix_stat_std, - n_multi_edge_message, + _update_residual_init, + _exclude_types, + _update_angle, + _a_compress_rate, + _a_compress_e_rate, + _a_compress_use_split, + _optim_update, + _edge_init_use_dist, + _use_exp_switch, + _use_dynamic_sel, + _use_loc_mapping, + _fix_stat_std, + _n_multi_edge_message, precision, - add_chg_spin_ebd, + _add_chg_spin_ebd, ) = self.param if precision == "float64": return 1e-10 @@ -502,21 +502,21 @@ def rtol(self) -> float: def atol(self) -> float: """Absolute tolerance for comparing the return value.""" ( - update_residual_init, - exclude_types, - update_angle, - a_compress_rate, - a_compress_e_rate, - a_compress_use_split, - optim_update, - edge_init_use_dist, - use_exp_switch, - use_dynamic_sel, - use_loc_mapping, - fix_stat_std, - n_multi_edge_message, + _update_residual_init, + _exclude_types, + _update_angle, + _a_compress_rate, + _a_compress_e_rate, + _a_compress_use_split, + _optim_update, + _edge_init_use_dist, + _use_exp_switch, + _use_dynamic_sel, + _use_loc_mapping, + _fix_stat_std, + _n_multi_edge_message, precision, - add_chg_spin_ebd, + _add_chg_spin_ebd, ) = self.param if precision == "float64": return 1e-6 # need to fix in the future, see issue https://github.com/deepmodeling/deepmd-kit/issues/3786 From 5b14fcaa9f648349944b1ec1d3bc4c5126a14981 Mon Sep 17 00:00:00 2001 From: "njzjz-bot (driven by OpenClaw (model: gpt-5.4))[bot]" <48687836+njzjz-bot@users.noreply.github.com> Date: Sat, 11 Apr 2026 06:49:00 +0000 Subject: [PATCH 4/4] test(consistent): harden DPA3 case builders\n\nDeep-copy the DPA3 baseline case and validate override keys in the\ncurated-case helpers so mutable fields do not leak across cases and\ntypos fail fast.\n\nAuthored by OpenClaw (model: gpt-5.4) --- .../tests/consistent/descriptor/test_dpa3.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/source/tests/consistent/descriptor/test_dpa3.py b/source/tests/consistent/descriptor/test_dpa3.py index faa5134f66..b067ca94dc 100644 --- a/source/tests/consistent/descriptor/test_dpa3.py +++ b/source/tests/consistent/descriptor/test_dpa3.py @@ -1,5 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import unittest +from copy import ( + deepcopy, +) from typing import ( Any, ) @@ -100,9 +103,17 @@ } +def _build_dpa3_case(fields: tuple[str, ...], **overrides: Any) -> tuple: + unknown = set(overrides) - set(DPA3_BASELINE_CASE) + if unknown: + raise KeyError(f"Unknown DPA3 case override(s): {sorted(unknown)}") + case = deepcopy(DPA3_BASELINE_CASE) + case.update(overrides) + return tuple(case[field] for field in fields) + + def dpa3_case(**overrides: Any) -> tuple: - case = DPA3_BASELINE_CASE | overrides - return tuple(case[field] for field in DPA3_CASE_FIELDS) + return _build_dpa3_case(DPA3_CASE_FIELDS, **overrides) DPA3_CURATED_CASES = ( @@ -139,8 +150,7 @@ def dpa3_case(**overrides: Any) -> tuple: def dpa3_descriptor_api_case(**overrides: Any) -> tuple: - case = DPA3_BASELINE_CASE | overrides - return tuple(case[field] for field in DPA3_DESCRIPTOR_API_CASE_FIELDS) + return _build_dpa3_case(DPA3_DESCRIPTOR_API_CASE_FIELDS, **overrides) DPA3_DESCRIPTOR_API_CURATED_CASES = (