Skip to content

test(consistent): use curated cases throughout#5606

Open
njzjz wants to merge 3 commits into
deepmodeling:masterfrom
njzjz:test/consistent-curated-cases
Open

test(consistent): use curated cases throughout#5606
njzjz wants to merge 3 commits into
deepmodeling:masterfrom
njzjz:test/consistent-curated-cases

Conversation

@njzjz

@njzjz njzjz commented Jun 29, 2026

Copy link
Copy Markdown
Member

Summary

  • replace remaining consistent-test class parameterization with explicit CURATED_CASES
  • add baseline/override helpers for larger descriptor and fitting matrices
  • keep small model/loss matrices as explicit curated tuples

Tests

  • ruff format .
  • ruff check .
  • pytest --collect-only -q source/tests/consistent/test_activation.py source/tests/consistent/test_learning_rate.py source/tests/consistent/test_type_embedding.py source/tests/consistent/descriptor/test_se_r.py source/tests/consistent/descriptor/test_se_t.py source/tests/consistent/descriptor/test_se_t_tebd.py source/tests/consistent/descriptor/test_se_atten_v2.py source/tests/consistent/fitting/test_dipole.py source/tests/consistent/fitting/test_dos.py source/tests/consistent/fitting/test_dpa4_ener.py source/tests/consistent/fitting/test_ener.py source/tests/consistent/fitting/test_polar.py source/tests/consistent/fitting/test_property.py source/tests/consistent/loss/test_dos.py source/tests/consistent/loss/test_ener.py source/tests/consistent/loss/test_ener_spin.py source/tests/consistent/loss/test_property.py source/tests/consistent/loss/test_tensor.py source/tests/consistent/model/test_dipole.py source/tests/consistent/model/test_dos.py source/tests/consistent/model/test_dpa1.py source/tests/consistent/model/test_ener.py source/tests/consistent/model/test_frozen.py source/tests/consistent/model/test_linear_ener.py source/tests/consistent/model/test_polar.py source/tests/consistent/model/test_property.py source/tests/consistent/model/test_zbl_ener.py
  • pytest source/tests/consistent/test_learning_rate.py -q

Summary by CodeRabbit

  • Tests
    • Standardized test parametrization across consistency, fitting, loss, and model suites using curated scenario sets.
    • Expanded and refined covered combinations while reducing redundant/duplicated cases.
    • Improved reliability of compute/load test flows by preventing unintended in-place mutation during execution.

@njzjz njzjz requested review from iProzd and wanghan-iapcm and removed request for wanghan-iapcm June 29, 2026 17:53
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3753a085-753c-4b71-8c34-73e4edd67172

📥 Commits

Reviewing files that changed from the base of the PR and between 2e3e021 and ccdeedb.

📒 Files selected for processing (23)
  • source/tests/consistent/descriptor/test_se_atten_v2.py
  • source/tests/consistent/descriptor/test_se_r.py
  • source/tests/consistent/descriptor/test_se_t.py
  • source/tests/consistent/descriptor/test_se_t_tebd.py
  • source/tests/consistent/fitting/test_dipole.py
  • source/tests/consistent/fitting/test_dos.py
  • source/tests/consistent/fitting/test_ener.py
  • source/tests/consistent/fitting/test_polar.py
  • source/tests/consistent/fitting/test_property.py
  • source/tests/consistent/loss/test_dos.py
  • source/tests/consistent/loss/test_ener.py
  • source/tests/consistent/loss/test_ener_spin.py
  • source/tests/consistent/loss/test_property.py
  • source/tests/consistent/loss/test_tensor.py
  • source/tests/consistent/model/test_dipole.py
  • source/tests/consistent/model/test_dos.py
  • source/tests/consistent/model/test_dpa1.py
  • source/tests/consistent/model/test_ener.py
  • source/tests/consistent/model/test_polar.py
  • source/tests/consistent/model/test_property.py
  • source/tests/consistent/test_activation.py
  • source/tests/consistent/test_learning_rate.py
  • source/tests/consistent/test_type_embedding.py
🚧 Files skipped from review as they are similar to previous changes (18)
  • source/tests/consistent/test_activation.py
  • source/tests/consistent/model/test_dos.py
  • source/tests/consistent/loss/test_dos.py
  • source/tests/consistent/loss/test_property.py
  • source/tests/consistent/test_type_embedding.py
  • source/tests/consistent/fitting/test_ener.py
  • source/tests/consistent/loss/test_tensor.py
  • source/tests/consistent/fitting/test_property.py
  • source/tests/consistent/fitting/test_polar.py
  • source/tests/consistent/model/test_property.py
  • source/tests/consistent/loss/test_ener.py
  • source/tests/consistent/fitting/test_dipole.py
  • source/tests/consistent/test_learning_rate.py
  • source/tests/consistent/loss/test_ener_spin.py
  • source/tests/consistent/model/test_dipole.py
  • source/tests/consistent/model/test_ener.py
  • source/tests/consistent/descriptor/test_se_t.py
  • source/tests/consistent/descriptor/test_se_t_tebd.py

📝 Walkthrough

Walkthrough

Across the consistent test suites, parameterized is replaced with parameterized_cases. Several modules now define ordered case fields, baseline case dictionaries, helper builders, and curated case tuples used by the updated test decorators.

Changes

Migrate consistent tests to parameterized_cases

Layer / File(s) Summary
Descriptor test parameterization refactor
source/tests/consistent/descriptor/test_se_atten_v2.py, source/tests/consistent/descriptor/test_se_r.py, source/tests/consistent/descriptor/test_se_t.py, source/tests/consistent/descriptor/test_se_t_tebd.py
Imports parameterized_cases; adds *_CASE_FIELDS, *_BASELINE_CASE, case helper functions, and *_CURATED_CASES constants; updates both primary and DescriptorAPI class decorators.
Fitting test parameterization refactor
source/tests/consistent/fitting/test_dipole.py, source/tests/consistent/fitting/test_dos.py, source/tests/consistent/fitting/test_dpa4_ener.py, source/tests/consistent/fitting/test_ener.py, source/tests/consistent/fitting/test_polar.py, source/tests/consistent/fitting/test_property.py
Imports parameterized_cases; introduces curated case collections, baseline dicts, and override helpers; updates class decorators for all fitting test classes.
Loss test parameterization refactor
source/tests/consistent/loss/test_dos.py, source/tests/consistent/loss/test_ener.py, source/tests/consistent/loss/test_ener_spin.py, source/tests/consistent/loss/test_property.py, source/tests/consistent/loss/test_tensor.py
Replaces duplicate or Cartesian-product @parameterized args with named *_CURATED_CASES tuples covering distinct parameter combinations; updates all loss test class decorators.
Model test parameterization refactor
source/tests/consistent/model/test_dipole.py, source/tests/consistent/model/test_dos.py, source/tests/consistent/model/test_dpa1.py, source/tests/consistent/model/test_ener.py, source/tests/consistent/model/test_frozen.py, source/tests/consistent/model/test_linear_ener.py, source/tests/consistent/model/test_polar.py, source/tests/consistent/model/test_property.py, source/tests/consistent/model/test_zbl_ener.py
Adds curated exclusion/stat case tuples; updates multiple class decorators per file to @parameterized_cases; some files expand the set of parameter combinations exercised.
Activation, learning rate, and type embedding test refactor
source/tests/consistent/test_activation.py, source/tests/consistent/test_learning_rate.py, source/tests/consistent/test_type_embedding.py
Introduces ACTIVATION_FUNCTION_CURATED_CASES, SILUT_VARIANT_CURATED_CASES, LEARNING_RATE_CURATED_CASES, and TYPE_EMBEDDING_CURATED_CASES; updates class decorators.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • deepmodeling/deepmd-kit#5378: Introduced the parameterized_cases mechanism that this PR applies uniformly across the remaining consistent test modules.

Suggested labels

enhancement

Suggested reviewers

  • iProzd
  • wanghan-iapcm
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.15% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: replacing consistent tests with curated cases throughout.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 OpenGrep (1.23.0)
source/tests/consistent/fitting/test_dipole.py

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.13][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist

source/tests/consistent/fitting/test_dos.py

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.15][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist

source/tests/consistent/descriptor/test_se_t.py

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.20][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist

  • 20 others

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
source/tests/consistent/test_type_embedding.py (1)

75-77: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Fail fast on unknown override keys.

A misspelled override is silently ignored here: the merged dict keeps the extra key, but tuple construction only reads TYPE_EMBEDDING_CASE_FIELDS. That can accidentally leave the baseline value in place and reduce case coverage without any signal.

Proposed guard
 def type_embedding_case(**overrides: Any) -> tuple:
+    unknown = set(overrides) - set(TYPE_EMBEDDING_CASE_FIELDS)
+    if unknown:
+        raise ValueError(f"Unknown type-embedding case fields: {sorted(unknown)}")
     case = TYPE_EMBEDDING_BASELINE_CASE | overrides
     return tuple(case[field] for field in TYPE_EMBEDDING_CASE_FIELDS)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@source/tests/consistent/test_type_embedding.py` around lines 75 - 77, The
type_embedding_case helper silently ignores misspelled override keys when
merging TYPE_EMBEDDING_BASELINE_CASE with overrides. Update type_embedding_case
to validate overrides against TYPE_EMBEDDING_CASE_FIELDS before building the
tuple, and raise an error for any unknown key so bad inputs fail fast instead of
falling back to baseline values. Use the existing type_embedding_case function
and TYPE_EMBEDDING_CASE_FIELDS/TYPE_EMBEDDING_BASELINE_CASE symbols to keep the
check centralized.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@source/tests/consistent/model/test_dpa1.py`:
- Around line 58-64: The curated DPA1_ENER test cases no longer cover the
smooth-type-embedding branch, so restore that configuration in
DPA1_ENER_CURATED_CASES and keep the related model coverage in test_dpa1.py.
Update the parameterized_cases setup so the suite still exercises the descriptor
mode wired through data(), using the existing DPA1_ENER_CURATED_CASES and
test_dpa1 symbols to place the new case consistently with the current matrix.

In `@source/tests/consistent/model/test_polar.py`:
- Around line 1221-1229: The new curated exclusion cases in the stat test are
reusing the same sampled inputs across dp, pt, and pt_expt, and
compute_or_load_stat mutates natoms in place when atom_exclude_types is
non-empty. Update the test logic in test_polar to apply the same deepcopy
protection already used in test_ener so each backend gets an independent copy of
self.np_sampled and self.pt_sampled before stat computation.

---

Nitpick comments:
In `@source/tests/consistent/test_type_embedding.py`:
- Around line 75-77: The type_embedding_case helper silently ignores misspelled
override keys when merging TYPE_EMBEDDING_BASELINE_CASE with overrides. Update
type_embedding_case to validate overrides against TYPE_EMBEDDING_CASE_FIELDS
before building the tuple, and raise an error for any unknown key so bad inputs
fail fast instead of falling back to baseline values. Use the existing
type_embedding_case function and
TYPE_EMBEDDING_CASE_FIELDS/TYPE_EMBEDDING_BASELINE_CASE symbols to keep the
check centralized.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a06fd2ff-36be-4203-a399-ee618de680a4

📥 Commits

Reviewing files that changed from the base of the PR and between 58bef11 and 2e3e021.

📒 Files selected for processing (27)
  • source/tests/consistent/descriptor/test_se_atten_v2.py
  • source/tests/consistent/descriptor/test_se_r.py
  • source/tests/consistent/descriptor/test_se_t.py
  • source/tests/consistent/descriptor/test_se_t_tebd.py
  • source/tests/consistent/fitting/test_dipole.py
  • source/tests/consistent/fitting/test_dos.py
  • source/tests/consistent/fitting/test_dpa4_ener.py
  • source/tests/consistent/fitting/test_ener.py
  • source/tests/consistent/fitting/test_polar.py
  • source/tests/consistent/fitting/test_property.py
  • source/tests/consistent/loss/test_dos.py
  • source/tests/consistent/loss/test_ener.py
  • source/tests/consistent/loss/test_ener_spin.py
  • source/tests/consistent/loss/test_property.py
  • source/tests/consistent/loss/test_tensor.py
  • source/tests/consistent/model/test_dipole.py
  • source/tests/consistent/model/test_dos.py
  • source/tests/consistent/model/test_dpa1.py
  • source/tests/consistent/model/test_ener.py
  • source/tests/consistent/model/test_frozen.py
  • source/tests/consistent/model/test_linear_ener.py
  • source/tests/consistent/model/test_polar.py
  • source/tests/consistent/model/test_property.py
  • source/tests/consistent/model/test_zbl_ener.py
  • source/tests/consistent/test_activation.py
  • source/tests/consistent/test_learning_rate.py
  • source/tests/consistent/test_type_embedding.py

Comment on lines +58 to +64
DPA1_ENER_CURATED_CASES = (
("strip", False),
("concat", False),
)


@parameterized_cases(*DPA1_ENER_CURATED_CASES)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Restore smooth_type_embedding=True coverage.

This curated list drops that branch entirely, so this model-level suite no longer exercises a descriptor mode that is still wired into data().

Proposed fix
 DPA1_ENER_CURATED_CASES = (
     ("strip", False),
+    ("strip", True),
     ("concat", False),
+    ("concat", True),
 )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
DPA1_ENER_CURATED_CASES = (
("strip", False),
("concat", False),
)
@parameterized_cases(*DPA1_ENER_CURATED_CASES)
DPA1_ENER_CURATED_CASES = (
("strip", False),
("strip", True),
("concat", False),
("concat", True),
)
`@parameterized_cases`(*DPA1_ENER_CURATED_CASES)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@source/tests/consistent/model/test_dpa1.py` around lines 58 - 64, The curated
DPA1_ENER test cases no longer cover the smooth-type-embedding branch, so
restore that configuration in DPA1_ENER_CURATED_CASES and keep the related model
coverage in test_dpa1.py. Update the parameterized_cases setup so the suite
still exercises the descriptor mode wired through data(), using the existing
DPA1_ENER_CURATED_CASES and test_dpa1 symbols to place the new case consistently
with the current matrix.

Comment thread source/tests/consistent/model/test_polar.py
@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.35%. Comparing base (58bef11) to head (2e3e021).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5606      +/-   ##
==========================================
- Coverage   82.37%   82.35%   -0.02%     
==========================================
  Files         902      902              
  Lines      101529   101528       -1     
  Branches     4058     4058              
==========================================
- Hits        83630    83614      -16     
- Misses      16434    16451      +17     
+ Partials     1465     1463       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant