Skip to content

test(dpa4): enable array-api-strict consistency tests#5751

Merged
OutisLi merged 3 commits into
deepmodeling:masterfrom
njzjz:feat/dpa4-array-api-strict
Jul 12, 2026
Merged

test(dpa4): enable array-api-strict consistency tests#5751
OutisLi merged 3 commits into
deepmodeling:masterfrom
njzjz:feat/dpa4-array-api-strict

Conversation

@njzjz

@njzjz njzjz commented Jul 7, 2026

Copy link
Copy Markdown
Member

Summary

  • add array-api-strict wrappers for the DPA4 descriptor and SeZM energy fitting net
  • enable array-api-strict coverage in the existing DPA4 descriptor/fitting consistent tests
  • make DPA4 scalar RMSNorm indexing array-api-strict compliant and lazy-load DPA4 PT test classes during PT-only execution

Validation

  • ruff format .
  • ruff check .
  • pytest source/tests/consistent/descriptor/test_dpa4.py source/tests/consistent/fitting/test_dpa4_ener.py -q -k array_api_strict -> 32 passed, 224 deselected
  • pytest source/tests/consistent/descriptor/test_dpa4.py source/tests/consistent/fitting/test_dpa4_ener.py -q -k dp_self_consistent -> 16 passed, 240 deselected

Summary by CodeRabbit

  • New Features
    • Expanded strict array-API coverage for the DPA4 descriptor and DPA4 energy fitting workflow, including new DPA4 strict descriptor exports and energy fitting wrappers.
  • Bug Fixes
    • Corrected 2D input normalization scaling so the applied scale matches the expected channel layout.
  • Tests
    • Updated consistency tests to conditionally enable the strict backend and added strict-backend evaluation helpers for descriptor and energy outputs.

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added the Python label Jul 7, 2026
@dosubot dosubot Bot added the enhancement label Jul 7, 2026
Comment thread source/tests/array_api_strict/descriptor/dpa4.py Fixed
Comment thread source/tests/array_api_strict/descriptor/dpa4.py Fixed
Comment thread source/tests/array_api_strict/fitting/dpa4_ener.py Fixed
@coderabbitai

coderabbitai Bot commented Jul 7, 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: 8f7c92e8-6638-4840-8e2e-47bf92def831

📥 Commits

Reviewing files that changed from the base of the PR and between 1ea384c and 55a1c15.

📒 Files selected for processing (2)
  • source/tests/consistent/descriptor/test_dpa4.py
  • source/tests/consistent/fitting/test_dpa4_ener.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • source/tests/consistent/descriptor/test_dpa4.py
  • source/tests/consistent/fitting/test_dpa4_ener.py

📝 Walkthrough

Walkthrough

This PR fixes 2D ScalarRMSNorm scaling and adds array-api-strict DPA4 descriptor and fitting wrappers, registration setup, and consistency-test execution.

Changes

ScalarRMSNorm Fix

Layer / File(s) Summary
2D adam_scale slice
deepmd/dpmodel/descriptor/dpa4_nn/norm.py
Changes the 2D adam_scale index from [0] to [0, :] before elementwise scaling.

Array-API-Strict DPA4 Support

Layer / File(s) Summary
Registration imports
source/tests/array_api_strict/common.py
Adds DPA4 descriptor and fitting modules to strict registration setup.
Strict descriptor wrapper
source/tests/array_api_strict/descriptor/dpa4.py, source/tests/array_api_strict/descriptor/__init__.py
Adds DescrptDPA4, registers aliases and DPModel mappings, and exports the descriptor.
Strict fitting wrapper
source/tests/array_api_strict/fitting/dpa4_ener.py, source/tests/array_api_strict/fitting/__init__.py
Adds strict fitting wrappers, updates NETWORK_TYPE_MAP, and exports SeZMEnergyFittingNet.
Consistency test wiring
source/tests/consistent/descriptor/test_dpa4.py, source/tests/consistent/fitting/test_dpa4_ener.py
Enables array-api-strict DPA4 evaluation with conditional backend loading and output conversion.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant TestDPA4Ener
  participant array_api_strict
  participant SeZMEnergyFittingNet
  participant to_numpy_array

  TestDPA4Ener->>array_api_strict: asarray(inputs and atype)
  TestDPA4Ener->>SeZMEnergyFittingNet: evaluate strict arrays
  SeZMEnergyFittingNet-->>TestDPA4Ener: energy output
  TestDPA4Ener->>to_numpy_array: convert energy
Loading

Possibly related PRs

Suggested labels: bug

Suggested reviewers: iProzd, OutisLi

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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: enabling array-api-strict consistency tests for DPA4.
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

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.

🧹 Nitpick comments (1)
source/tests/array_api_strict/fitting/dpa4_ener.py (1)

21-46: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Drop the redundant register_dpmodel_mapping calls
@array_api_strict_module already registers the GLUFittingNetDP and SeZMNetworkCollectionDP converters here, so the explicit calls at lines 38-46 just overwrite the same entries and can be removed for consistency.

🤖 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/array_api_strict/fitting/dpa4_ener.py` around lines 21 - 46,
Remove the redundant explicit register_dpmodel_mapping calls in the
array_api_strict dpa4_ener module, since the `@array_api_strict_module` decorator
already registers the GLUFittingNetDP and SeZMNetworkCollectionDP converters.
Keep the wrapper classes like GLUFittingNet and SeZMNetworkCollection, but
delete the duplicate mapping registrations so the module relies on the
decorator-based registration consistently.
🤖 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.

Nitpick comments:
In `@source/tests/array_api_strict/fitting/dpa4_ener.py`:
- Around line 21-46: Remove the redundant explicit register_dpmodel_mapping
calls in the array_api_strict dpa4_ener module, since the
`@array_api_strict_module` decorator already registers the GLUFittingNetDP and
SeZMNetworkCollectionDP converters. Keep the wrapper classes like GLUFittingNet
and SeZMNetworkCollection, but delete the duplicate mapping registrations so the
module relies on the decorator-based registration consistently.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 04436c20-ae4a-4583-8b28-59bda92631dd

📥 Commits

Reviewing files that changed from the base of the PR and between 1cd6556 and 668dd1f.

📒 Files selected for processing (8)
  • deepmd/dpmodel/descriptor/dpa4_nn/norm.py
  • source/tests/array_api_strict/common.py
  • source/tests/array_api_strict/descriptor/__init__.py
  • source/tests/array_api_strict/descriptor/dpa4.py
  • source/tests/array_api_strict/fitting/__init__.py
  • source/tests/array_api_strict/fitting/dpa4_ener.py
  • source/tests/consistent/descriptor/test_dpa4.py
  • source/tests/consistent/fitting/test_dpa4_ener.py

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.53%. Comparing base (1cd6556) to head (55a1c15).
⚠️ Report is 12 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5751      +/-   ##
==========================================
- Coverage   79.61%   79.53%   -0.09%     
==========================================
  Files        1014     1015       +1     
  Lines      115360   115780     +420     
  Branches     4274     4276       +2     
==========================================
+ Hits        91843    92084     +241     
- Misses      21976    22153     +177     
- Partials     1541     1543       +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.

@njzjz

njzjz commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

Addressed the CodeRabbit review in a5b9a6d: removed the redundant register_dpmodel_mapping calls in source/tests/array_api_strict/fitting/dpa4_ener.py and kept the decorator-based registration.

Restore the established eager conditional-import pattern for the PyTorch backends while retaining the array-api-strict coverage.

Coding-Agent: Codex
Codex-Version: codex-cli 0.144.1
Model: gpt-5.6-sol
Reasoning-Effort: xhigh
@njzjz
njzjz force-pushed the feat/dpa4-array-api-strict branch from 1ea384c to 55a1c15 Compare July 11, 2026 05:57
@OutisLi
OutisLi added this pull request to the merge queue Jul 11, 2026
Merged via the queue into deepmodeling:master with commit 49eeda7 Jul 12, 2026
57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants