Skip to content

docs: add mathematical formulas to fitting classes#5256

Merged
iProzd merged 4 commits intodeepmodeling:masterfrom
njzjz-bot:add-fitting-formulas
Feb 26, 2026
Merged

docs: add mathematical formulas to fitting classes#5256
iProzd merged 4 commits intodeepmodeling:masterfrom
njzjz-bot:add-fitting-formulas

Conversation

@njzjz-bot
Copy link
Contributor

@njzjz-bot njzjz-bot commented Feb 23, 2026

Summary

Add detailed mathematical formulas to fitting class docstrings following numpydoc convention.

Changes

Added formulas to the following classes:

  • DipoleFitting: Dipole computation from rotation matrix

    • Formula: μ = M · R where M is fitting network output and R is rotation matrix
  • PolarFitting: Polarizability tensor with diagonal/full fitting modes

    • Diagonal fitting: α = R^T · diag(p) · R
    • Full matrix fitting: α = R^T · P · R

Convention

Following numpydoc convention, parameters are documented in class docstrings, not in __init__ docstrings.

Statistics

  • 2 files changed
  • 41 insertions(+)
  • 1 deletion(-)

Authored by OpenClaw (model: GLM-5)

Summary by CodeRabbit

  • Documentation
    • Expanded mathematical documentation for dipole computation from model outputs and rotation matrices; clarified notation and step-by-step calculations.
    • Added detailed explanations of polarizability tensor fitting for both diagonal and full-matrix approaches, including how rotation information integrates with network outputs.
    • Clarified assumptions and computation flow; no functional behavior changes.

Add mathematical formulas to fitting class docstrings:
- DipoleFitting: dipole computation from rotation matrix
- PolarFitting: polarizability tensor with diagonal/full fitting

Follow numpydoc convention: parameters in class docstring.
@dosubot
Copy link

dosubot bot commented Feb 23, 2026

Related Documentation

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

How did I do? Any feedback?  Join Discord

@dosubot dosubot bot added the Docs label Feb 23, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c735ce9 and 9b165eb.

📒 Files selected for processing (2)
  • deepmd/dpmodel/fitting/dipole_fitting.py
  • deepmd/dpmodel/fitting/polarizability_fitting.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • deepmd/dpmodel/fitting/dipole_fitting.py
  • deepmd/dpmodel/fitting/polarizability_fitting.py

📝 Walkthrough

Walkthrough

Extended class-level docstrings in two fitting modules to add detailed mathematical descriptions of how dipole vectors and polarizability tensors are computed from network outputs and rotation matrices; no functional code or public API signatures changed.

Changes

Cohort / File(s) Summary
Fitting Class Documentation
deepmd/dpmodel/fitting/dipole_fitting.py, deepmd/dpmodel/fitting/polarizability_fitting.py
Expanded and clarified docstrings for DipoleFitting and PolarFitting: added mathematical definitions for M^i and R^i, described network-output interpretation and composition, detailed rotation-matrix application, and explained diagonal vs full polarizability handling. No runtime logic or public signatures modified.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested reviewers

  • anyangml
  • wanghan-iapcm
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding mathematical formulas to fitting class docstrings in DipoleFitting and PolarFitting classes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@deepmd/dpmodel/fitting/polarizability_fitting.py`:
- Around line 58-64: The docstring's full-matrix formula is misleading because
the implementation symmetrizes the network output (out = (out +
xp.matrix_transpose(out)) / 2) before constructing alpha; update the docstring
in polarizability_fitting.py to state that P^i is the symmetrized prediction
(e.g., P^i_sym = (P^i + P^{i,T})/2) or explicitly replace \mathbf{P}^i in the
formula with its symmetric form, and mention that this symmetrization is applied
when fit_diag=False so the resulting \boldsymbol{\alpha}^i is guaranteed
symmetric.

The full matrix fitting symmetrizes the network output before
use: P = (P_raw + P_raw^T) / 2, ensuring a symmetric polarizability
tensor.
@codecov
Copy link

codecov bot commented Feb 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.00%. Comparing base (352a2b5) to head (9b165eb).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5256   +/-   ##
=======================================
  Coverage   82.00%   82.00%           
=======================================
  Files         750      750           
  Lines       75082    75080    -2     
  Branches     3615     3615           
=======================================
+ Hits        61572    61573    +1     
+ Misses      12347    12345    -2     
+ Partials     1163     1162    -1     

☔ 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 requested a review from Copilot February 23, 2026 04:20
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds more explicit mathematical formulas to fitting class docstrings (numpydoc-style) to clarify how dipole and polarizability tensors are computed from network outputs and rotation matrices.

Changes:

  • Expanded DipoleFitting docstring with math for dipole computation and network definition.
  • Expanded PolarFitting docstring with math for diagonal vs full polarizability fitting modes.
  • Corrected a typo in the DipoleFitting class description.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
deepmd/dpmodel/fitting/polarizability_fitting.py Adds detailed math documentation for diagonal/full polarizability fitting and network outputs.
deepmd/dpmodel/fitting/dipole_fitting.py Adds dipole computation formula and network definition; fixes “diploe” typo.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- dipole_fitting: add 'an' before 'activation function'
- polarizability_fitting: add R^i shape, clarify local-frame tensor,
  explain symmetry preservation in A^T S A form
@njzjz-bot
Copy link
Contributor Author

Fixed:

  • dipole_fitting: added 'an' for grammar correction
  • polarizability_fitting: added R^i shape, clarified local-frame tensor, explained symmetry preservation

Commit: c735ce9

Add explicit definition of m_1 as the embedding width in both
dipole_fitting and polarizability_fitting docstrings.
@iProzd iProzd added this pull request to the merge queue Feb 25, 2026
Merged via the queue into deepmodeling:master with commit bf982ab Feb 26, 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.

5 participants