Skip to content

docs: add mathematical formulas to model classes#5258

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

docs: add mathematical formulas to model classes#5258
iProzd merged 7 commits intodeepmodeling:masterfrom
njzjz-bot:add-model-formulas

Conversation

@njzjz-bot
Copy link
Contributor

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

Summary

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

Changes

Added formulas to the following classes:

  • DPModelCommon: Descriptor + fitting pipeline

    • D = Descriptor(R, types)
    • y = Fitting(D)
  • SpinModel: Virtual atom positions and torque conversion

    • r_virtual = r_real + s · σ
    • τ = F_virtual × σ

Convention

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

Statistics

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

Authored by OpenClaw (model: GLM-5)

Summary by CodeRabbit

  • Documentation
    • Expanded user-facing documentation for core model components: model reduction and differentiation math for energy/forces/virials, spin input preprocessing, virtual-atom creation/placement, interactions among real/virtual/ghost atoms, and conversion of virtual-atom forces into magnetic torques. All changes are descriptive only; no functional or behavioral modifications.

Add mathematical formulas to model class docstrings:
- DPModelCommon: descriptor + fitting pipeline
- SpinModel: virtual atom positions and torque conversion

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

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Added and expanded class-level docstrings in the deepmd model package for DPModelCommon, SpinModel, and EnergyModel describing responsibilities, data flows, neighbor selection, fitting-network access, model prediction pipeline, spin preprocessing, virtual/ghost-atom handling, and conversion of virtual-atom forces into magnetic torques. No code logic, behavior, or public API changes.

Changes

Cohort / File(s) Summary
Model docstrings
deepmd/dpmodel/model/dp_model.py, deepmd/dpmodel/model/spin_model.py, deepmd/dpmodel/model/ener_model.py
Added or expanded class-level docstrings for DPModelCommon, SpinModel, and EnergyModel describing mathematical definitions (energy reduction, force/virial differentiation), spin input preprocessing, virtual/ghost-atom handling, and force→torque conversion. No functional or API changes.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested reviewers

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

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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 title accurately describes the main change: adding mathematical formulas to model class docstrings across DPModelCommon, SpinModel, and EnergyModel.

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

✨ Finishing Touches
🧪 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.

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/model/spin_model.py`:
- Around line 32-49: The module docstring in spin_model.py contains LaTeX
backslashes (e.g., \boldsymbol, \tau, \times, \cdot) which are being interpreted
as Python escape sequences; update the triple-quoted docstring to a raw string
by adding the r prefix (i.e., change """...""" to r"""...""") at the top of
spin_model.py (the docstring for the Spin model wrapper) so the backslashes are
preserved literally.

@njzjz njzjz requested a review from Copilot February 23, 2026 04:21
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 numpydoc-style mathematical formulas to key model class docstrings to clarify the prediction pipeline and spin/virtual-atom mechanics.

Changes:

  • Expanded SpinModel docstring with virtual-atom position and torque equations.
  • Added an r"""...""" class docstring to DPModelCommon describing the descriptor→fitting pipeline.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
deepmd/dpmodel/model/spin_model.py Documents spin preprocessing, virtual-atom construction, and torque conversion with LaTeX math.
deepmd/dpmodel/model/dp_model.py Documents the common DP model prediction pipeline using numpydoc + LaTeX math.

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

D301: Use r""" if any backslashes in a docstring
@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 (6ac195a).
⚠️ Report is 8 commits behind head on master.

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

☔ 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.

…ntiation

Model layer sums atomic energies and computes forces/virials
by differentiation, not descriptor+fitting pipeline.
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/model/dp_model.py`:
- Around line 37-41: The virial formula in the docstring uses per-atom energy
E^i but should use the total potential energy E to match the force definition;
update the math to Xi = - sum_i (partial E / partial r_i) ⊗ r_i (or equivalently
Xi = - sum_i r_i ⊗ F_i) so it references total energy E instead of E^i, and then
reconcile/remove the workaround in transform_output.py that "pops atomic virial"
(or update that code to compute the virial from the total E via dp_model.py's
Xi) to ensure the implementation and documentation use the same
total-energy-based virial.

ℹ️ Review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between af2147d and 09eae6d.

📒 Files selected for processing (1)
  • deepmd/dpmodel/model/dp_model.py

njzjz-bot and others added 2 commits February 23, 2026 19:06
DPModelCommon is a generic base class. The energy-specific formulas
for reduction (E = sum E^i) and differentiation (forces, virials)
belong in EnergyModel.
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

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


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

- spin_model: use single backslashes in raw string for LaTeX
- ener_model: virial formula uses total energy E, not per-atom E^i
@iProzd iProzd added this pull request to the merge queue Feb 25, 2026
Merged via the queue into deepmodeling:master with commit eaed387 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