Skip to content

Comments

feat(pt_expt): add dos, dipole, polar and property fittings#5254

Merged
njzjz merged 3 commits intodeepmodeling:masterfrom
wanghan-iapcm:feat-other-fitting
Feb 22, 2026
Merged

feat(pt_expt): add dos, dipole, polar and property fittings#5254
njzjz merged 3 commits intodeepmodeling:masterfrom
wanghan-iapcm:feat-other-fitting

Conversation

@wanghan-iapcm
Copy link
Collaborator

@wanghan-iapcm wanghan-iapcm commented Feb 22, 2026

Summary by CodeRabbit

  • New Features

    • Added experimental fitting model wrappers for dipole, DOS, polarizability, and property fitting.
  • Bug Fixes

    • Ensured polarizability identity tensor is created on the correct device to avoid hardware mismatches.
  • Tests

    • Added comprehensive test suites and test-path wiring for the experimental fitting models, covering serialization, export, tracing, and gradient checks.
  • Chores

    • Removed some implicit model-registration hooks in experimental fittings.

@wanghan-iapcm wanghan-iapcm requested a review from njzjz February 22, 2026 09:03
@dosubot
Copy link

dosubot bot commented Feb 22, 2026

Related Documentation

Checked 0 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 22, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

Adds PT-Expt fitting wrappers and exports for dipole, DOS, polarizability, and property models, updates dpmodel polarizability device allocation for the identity tensor, and adds corresponding conditional test wiring plus dedicated PT-Expt test suites.

Changes

Cohort / File(s) Summary
Device fix
deepmd/dpmodel/fitting/polarizability_fitting.py
Specify device when creating the 3×3 identity tensor (xp.eye(..., device=array_api_compat.device(descriptor)) so the bias eye is allocated on the descriptor device.
PT-Expt exports
deepmd/pt_expt/fitting/__init__.py
Add imports and export entries (__all__) for DipoleFitting, DOSFittingNet, PolarFitting, and PropertyFittingNet.
PT-Expt wrapper modules
deepmd/pt_expt/fitting/dipole_fitting.py, deepmd/pt_expt/fitting/dos_fitting.py, deepmd/pt_expt/fitting/polarizability_fitting.py, deepmd/pt_expt/fitting/property_fitting.py
Add thin wrapper classes that subclass DP-model counterparts, decorated with @BaseFitting.register(...) and @torch_module (no extra logic). Some removed module-level registration calls in related files.
Consistent tests — PT-Expt wiring
source/tests/consistent/fitting/test_dipole.py, source/tests/consistent/fitting/test_dos.py, source/tests/consistent/fitting/test_polar.py, source/tests/consistent/fitting/test_property.py
Add conditional PT-Expt imports, pt_expt_class attributes, skip_pt_expt properties, and eval_pt_expt() methods to exercise the experimental PT pathway alongside existing backends.
PT-Expt test suites
source/tests/pt_expt/fitting/test_dipole_fitting.py, source/tests/pt_expt/fitting/test_dos_fitting.py, source/tests/pt_expt/fitting/test_polar_fitting.py, source/tests/pt_expt/fitting/test_property_fitting.py
Add comprehensive PT-Expt tests exercising self-consistency, serialization round-trip, torch export, and FX tracing (including gradient checks) for each fitting type.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • njzjz
  • iProzd
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 2.27% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately and clearly describes the main changes: adding DOS, dipole, polar, and property fitting models to the pt_expt module.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (4)
source/tests/pt_expt/fitting/test_polar_fitting.py (1)

37-37: Prefix unused unpacked variables with _

Same RUF059 pattern as test_property_fitting.pynf and nnei are unused at lines 37, 94, and 131.

♻️ Proposed fix
-        nf, nloc, nnei = self.nlist.shape
+        _nf, nloc, _nnei = self.nlist.shape

Apply at lines 37, 94, and 131.

Also applies to: 94-94, 131-131

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@source/tests/pt_expt/fitting/test_polar_fitting.py` at line 37, Replace the
unused unpacked variables by prefixing them with underscores where self.nlist is
unpacked (the assignment "nf, nloc, nnei = self.nlist.shape" in
test_polar_fitting.py and the analogous unpackings later): change "nf" to "_nf"
and "nnei" to "_nnei" (or simply "_") so only the used "nloc" remains as a
normal variable; update each occurrence (the unpackings at the three locations)
to avoid unused-variable warnings while keeping the same semantics.
source/tests/consistent/fitting/test_dos.py (1)

202-209: Prefix unused unpacked variables with _ in eval_pt_expt

Ruff (RUF059) flags resnet_dt, precision, mixed_types, and numb_dos as unused in this unpack. Only numb_fparam and numb_aparam are used.

♻️ Proposed fix
-        (
-            resnet_dt,
-            precision,
-            mixed_types,
-            numb_fparam,
-            numb_aparam,
-            numb_dos,
-        ) = self.param
+        (
+            _resnet_dt,
+            _precision,
+            _mixed_types,
+            numb_fparam,
+            numb_aparam,
+            _numb_dos,
+        ) = self.param
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@source/tests/consistent/fitting/test_dos.py` around lines 202 - 209, In the
eval_pt_expt unpack in test_dos.py, prefix unused variables to satisfy Ruff
RUF059: change the tuple unpack so resnet_dt, precision, mixed_types, and
numb_dos are renamed to _resnet_dt, _precision, _mixed_types, and _numb_dos
while keeping numb_fparam and numb_aparam as-is; update the unpack expression
near the eval_pt_expt function to use these underscored names so only the
actually used symbols (numb_fparam, numb_aparam) remain referenced.
source/tests/pt_expt/fitting/test_property_fitting.py (1)

37-37: Prefix unused unpacked variables with _

nf and nnei are unused in all three tuple unpackings. Ruff (RUF059) flags these across lines 37, 90, and 127.

♻️ Proposed fix
-        nf, nloc, nnei = self.nlist.shape
+        _nf, nloc, _nnei = self.nlist.shape

Apply the same change at lines 37, 90, and 127.

Also applies to: 90-90, 127-127

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@source/tests/pt_expt/fitting/test_property_fitting.py` at line 37, Two
variables from the tuple unpacking of self.nlist.shape are unused; change the
unpacking to prefix unused names with an underscore (e.g., replace occurrences
like "nf, nloc, nnei = self.nlist.shape" with "_nf, nloc, _nnei =
self.nlist.shape") to satisfy Ruff RUF059; apply the same change to the other
two unpackings of self.nlist.shape in the file.
source/tests/consistent/fitting/test_property.py (1)

211-219: Prefix unused unpacked variables with _ in eval_pt_expt

Ruff (RUF059) flags resnet_dt, precision, mixed_types, task_dim, and intensive as unused. Only numb_fparam and numb_aparam are consumed.

♻️ Proposed fix
-        (
-            resnet_dt,
-            precision,
-            mixed_types,
-            numb_fparam,
-            numb_aparam,
-            task_dim,
-            intensive,
-        ) = self.param
+        (
+            _resnet_dt,
+            _precision,
+            _mixed_types,
+            numb_fparam,
+            numb_aparam,
+            _task_dim,
+            _intensive,
+        ) = self.param
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@source/tests/consistent/fitting/test_property.py` around lines 211 - 219, The
tuple unpacking in eval_pt_expt assigns several variables that are never used;
rename the unused ones by prefixing with an underscore so only numb_fparam and
numb_aparam remain as used names (e.g., change resnet_dt, precision,
mixed_types, task_dim, intensive to _resnet_dt, _precision, _mixed_types,
_task_dim, _intensive in the tuple assignment inside eval_pt_expt) so the linter
(RUF059) no longer flags them as unused.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@source/tests/consistent/fitting/test_dos.py`:
- Around line 202-209: In the eval_pt_expt unpack in test_dos.py, prefix unused
variables to satisfy Ruff RUF059: change the tuple unpack so resnet_dt,
precision, mixed_types, and numb_dos are renamed to _resnet_dt, _precision,
_mixed_types, and _numb_dos while keeping numb_fparam and numb_aparam as-is;
update the unpack expression near the eval_pt_expt function to use these
underscored names so only the actually used symbols (numb_fparam, numb_aparam)
remain referenced.

In `@source/tests/consistent/fitting/test_property.py`:
- Around line 211-219: The tuple unpacking in eval_pt_expt assigns several
variables that are never used; rename the unused ones by prefixing with an
underscore so only numb_fparam and numb_aparam remain as used names (e.g.,
change resnet_dt, precision, mixed_types, task_dim, intensive to _resnet_dt,
_precision, _mixed_types, _task_dim, _intensive in the tuple assignment inside
eval_pt_expt) so the linter (RUF059) no longer flags them as unused.

In `@source/tests/pt_expt/fitting/test_polar_fitting.py`:
- Line 37: Replace the unused unpacked variables by prefixing them with
underscores where self.nlist is unpacked (the assignment "nf, nloc, nnei =
self.nlist.shape" in test_polar_fitting.py and the analogous unpackings later):
change "nf" to "_nf" and "nnei" to "_nnei" (or simply "_") so only the used
"nloc" remains as a normal variable; update each occurrence (the unpackings at
the three locations) to avoid unused-variable warnings while keeping the same
semantics.

In `@source/tests/pt_expt/fitting/test_property_fitting.py`:
- Line 37: Two variables from the tuple unpacking of self.nlist.shape are
unused; change the unpacking to prefix unused names with an underscore (e.g.,
replace occurrences like "nf, nloc, nnei = self.nlist.shape" with "_nf, nloc,
_nnei = self.nlist.shape") to satisfy Ruff RUF059; apply the same change to the
other two unpackings of self.nlist.shape in the file.

@codecov
Copy link

codecov bot commented Feb 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.11%. Comparing base (ccad0fb) to head (6a71537).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5254   +/-   ##
=======================================
  Coverage   82.10%   82.11%           
=======================================
  Files         745      749    +4     
  Lines       74875    74904   +29     
  Branches     3615     3615           
=======================================
+ Hits        61478    61507   +29     
+ Misses      12235    12233    -2     
- Partials     1162     1164    +2     

☔ View full report in Codecov by Sentry.
📢 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 added this pull request to the merge queue Feb 22, 2026
Merged via the queue into deepmodeling:master with commit 5eb5400 Feb 22, 2026
70 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.

2 participants