Skip to content

docs(dpmodel): document mathematical operations#5787

Merged
njzjz merged 6 commits into
deepmodeling:masterfrom
njzjz-bot:docs/dpmodel-equations
Jul 17, 2026
Merged

docs(dpmodel): document mathematical operations#5787
njzjz merged 6 commits into
deepmodeling:masterfrom
njzjz-bot:docs/dpmodel-equations

Conversation

@njzjz-bot

@njzjz-bot njzjz-bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor
  • docs(dpmodel): document mathematical operations
  • docs(dpmodel): formulate atomic and model classes

Summary by CodeRabbit

  • Documentation
    • Expanded and refined docstrings across atomic models, descriptors, fitting networks, and loss/objective modules with clearer math-formatted explanations.
    • Added more explicit descriptions of additive reductions (e.g., energies/dipoles/polarizabilities), attention/representation update behaviors, and descriptor workflow conventions.
    • Improved loss documentation to better define targets, cumulative-bin formulation, masking/padding exclusions, normalization conventions, and learning-rate–dependent prefactors.
    • No functional behavior or public APIs were changed.

njzjz-bot added 2 commits July 14, 2026 10:41
Add NumPyDoc equations for environment construction, switching functions, neural layers, type embeddings, spherical harmonics, and loss objectives. Clarify normalization, masking, residual, and extensive-property conventions.

Coding-Agent: Codex
Codex-Version: codex-cli 0.144.1
Model: gpt-5.6-sol
Reasoning-Effort: xhigh
Document mathematical mappings for atomic models, output models, fitting nets, attention layers, losses, and utility abstractions.

Coding-Agent: Codex
Codex-Version: codex-cli 0.144.1
Model: gpt-5.6-sol
Reasoning-Effort: xhigh
@dosubot dosubot Bot added the Docs label Jul 14, 2026
@njzjz njzjz changed the title docs/dpmodel equations docs(dpmodel): document mathematical operations Jul 14, 2026
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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

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: 6bc3591b-07d6-45f5-bab8-de9538ecb563

📥 Commits

Reviewing files that changed from the base of the PR and between 0bc929d and 3740aa9.

📒 Files selected for processing (13)
  • deepmd/dpmodel/atomic_model/base_atomic_model.py
  • deepmd/dpmodel/atomic_model/dipole_atomic_model.py
  • deepmd/dpmodel/atomic_model/polar_atomic_model.py
  • deepmd/dpmodel/descriptor/dpa1.py
  • deepmd/dpmodel/descriptor/dpa3.py
  • deepmd/dpmodel/descriptor/dpa4.py
  • deepmd/dpmodel/descriptor/repformers.py
  • deepmd/dpmodel/fitting/dos_fitting.py
  • deepmd/dpmodel/fitting/ener_fitting.py
  • deepmd/dpmodel/loss/ener.py
  • deepmd/dpmodel/loss/ener_spin.py
  • deepmd/dpmodel/model/dp_zbl_model.py
  • deepmd/dpmodel/utils/network.py
🚧 Files skipped from review as they are similar to previous changes (12)
  • deepmd/dpmodel/atomic_model/dipole_atomic_model.py
  • deepmd/dpmodel/fitting/dos_fitting.py
  • deepmd/dpmodel/fitting/ener_fitting.py
  • deepmd/dpmodel/atomic_model/polar_atomic_model.py
  • deepmd/dpmodel/descriptor/dpa4.py
  • deepmd/dpmodel/model/dp_zbl_model.py
  • deepmd/dpmodel/loss/ener_spin.py
  • deepmd/dpmodel/descriptor/dpa1.py
  • deepmd/dpmodel/utils/network.py
  • deepmd/dpmodel/descriptor/repformers.py
  • deepmd/dpmodel/descriptor/dpa3.py
  • deepmd/dpmodel/loss/ener.py

📝 Walkthrough

Walkthrough

This documentation-only change adds or expands mathematical and behavioral docstrings across atomic models, descriptors, fitting and loss modules, models, and utility components. No runtime logic, control flow, method signatures, or public APIs changed.

Changes

Model and fitting documentation

Layer / File(s) Summary
Model and fitting formulations
deepmd/dpmodel/atomic_model/*, deepmd/dpmodel/model/*, deepmd/dpmodel/fitting/*
Docstrings describe atomic-to-global reductions, combined energy and force definitions, and fitting targets.

Descriptor documentation

Layer / File(s) Summary
Descriptor components
deepmd/dpmodel/descriptor/*
Class and method docstrings describe attention, representation initialization and updates, equivariant operations, residual flows, and descriptor readout equations.

Loss documentation

Layer / File(s) Summary
Loss objectives and call contracts
deepmd/dpmodel/loss/*
Loss documentation specifies mathematical objectives, Huber and smooth-MAE forms, normalization, masking, scheduling, and diagnostics.

Utility and network documentation

Layer / File(s) Summary
Utility and neural-network behavior
deepmd/dpmodel/utils/*
Docstrings document environment matrices, network layers, normalization, spherical harmonics, type embeddings, learning-rate schedules, and neighbor selection.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

Suggested labels: Docs

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 51.28% 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 matches the PR’s main change: adding mathematical-operation documentation across dpmodel.
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.

Actionable comments posted: 4

🤖 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 `@deepmd/dpmodel/atomic_model/base_atomic_model.py`:
- Around line 56-60: Update the class docstring for the base atomic model to
explicitly define \mathcal N_i as the atom-i neighbor environment, clarifying
whether it represents the neighbor list, coordinates, or complete local
environment; keep the existing mapping equation unchanged.

In `@deepmd/dpmodel/descriptor/dpa1.py`:
- Line 2401: Update the docstring near GatedAttentionLayer.call to describe only
the projected gated self-attention output, removing the H + residual equation.
Document the residual addition instead on NeighborGatedAttentionLayer.call,
where the H plus attention result is actually applied.

In `@deepmd/dpmodel/descriptor/repformers.py`:
- Around line 968-969: Update the equations in
deepmd/dpmodel/descriptor/repformers.py at lines 968-969, 1099-1100, and 1272 to
match the implemented attention pipeline: document masked and smoothed softmax
attention with angular weighting at lines 968-969 instead of raw logits,
document O = AV at lines 1099-1100 while noting softmax and preprocessing occur
in Atten2Map, and include /sqrt(hidden_dim) scaling plus optional smoothing and
masking in the local-attention equation at line 1272.

In `@deepmd/dpmodel/model/property_model.py`:
- Around line 34-35: Update the PropertyModel class docstring to distinguish
reduction behavior by property type: state that extensive properties use p=∑ᵢ
pᵢ, while intensive properties use the configured intensive reduction instead of
implying all properties are summed.
🪄 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: 4587d592-5c02-408b-972b-524be61b8cd4

📥 Commits

Reviewing files that changed from the base of the PR and between c16dc8f and 0c930f4.

📒 Files selected for processing (29)
  • deepmd/dpmodel/atomic_model/base_atomic_model.py
  • deepmd/dpmodel/atomic_model/dipole_atomic_model.py
  • deepmd/dpmodel/atomic_model/dos_atomic_model.py
  • deepmd/dpmodel/atomic_model/energy_atomic_model.py
  • deepmd/dpmodel/atomic_model/polar_atomic_model.py
  • deepmd/dpmodel/atomic_model/property_atomic_model.py
  • deepmd/dpmodel/descriptor/dpa1.py
  • deepmd/dpmodel/descriptor/dpa2.py
  • deepmd/dpmodel/descriptor/repflows.py
  • deepmd/dpmodel/descriptor/repformers.py
  • deepmd/dpmodel/fitting/dos_fitting.py
  • deepmd/dpmodel/fitting/ener_fitting.py
  • deepmd/dpmodel/loss/dos.py
  • deepmd/dpmodel/loss/ener.py
  • deepmd/dpmodel/loss/loss.py
  • deepmd/dpmodel/loss/property.py
  • deepmd/dpmodel/loss/tensor.py
  • deepmd/dpmodel/model/dipole_model.py
  • deepmd/dpmodel/model/dos_model.py
  • deepmd/dpmodel/model/dp_zbl_model.py
  • deepmd/dpmodel/model/polar_model.py
  • deepmd/dpmodel/model/property_model.py
  • deepmd/dpmodel/utils/env_mat.py
  • deepmd/dpmodel/utils/env_mat_stat.py
  • deepmd/dpmodel/utils/learning_rate.py
  • deepmd/dpmodel/utils/network.py
  • deepmd/dpmodel/utils/spherical_harmonics.py
  • deepmd/dpmodel/utils/type_embed.py
  • deepmd/dpmodel/utils/update_sel.py

Comment thread deepmd/dpmodel/atomic_model/base_atomic_model.py Outdated
Comment thread deepmd/dpmodel/descriptor/dpa1.py Outdated
Comment thread deepmd/dpmodel/descriptor/repformers.py Outdated
Comment thread deepmd/dpmodel/model/property_model.py Outdated
@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.58%. Comparing base (2c0a54e) to head (3740aa9).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5787      +/-   ##
==========================================
- Coverage   79.76%   79.58%   -0.19%     
==========================================
  Files        1023     1022       -1     
  Lines      117463   117351     -112     
  Branches     4325     4311      -14     
==========================================
- Hits        93691    93390     -301     
- Misses      22229    22409     +180     
- Partials     1543     1552       +9     

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

Coding-Agent: Codex
Codex-Version: codex-cli 0.144.1
Model: gpt-5.6-sol
Reasoning-Effort: xhigh

@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: 1

🤖 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 `@deepmd/dpmodel/descriptor/dpa4.py`:
- Around line 172-180: Update the descriptor documentation around _apply_readout
to define \mathcal D_i as the scalar output after applying the configured
readout to \mathbf h_i^{(L)}, rather than the pre-readout \mathbf h_i^{(L,0,0)}.
Explain that the identity mode preserves the scalar coefficient, while "glu" and
"mlp" fold higher-degree coefficients into the l=0 output before extraction.
🪄 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: be83e5e2-6dbb-46c6-805d-78ff8007693f

📥 Commits

Reviewing files that changed from the base of the PR and between 0c930f4 and 3fcba13.

📒 Files selected for processing (6)
  • deepmd/dpmodel/descriptor/dpa1.py
  • deepmd/dpmodel/descriptor/dpa3.py
  • deepmd/dpmodel/descriptor/dpa4.py
  • deepmd/dpmodel/descriptor/repformers.py
  • deepmd/dpmodel/fitting/dpa4_ener.py
  • deepmd/dpmodel/loss/ener_spin.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • deepmd/dpmodel/descriptor/dpa1.py
  • deepmd/dpmodel/descriptor/repformers.py

Comment thread deepmd/dpmodel/descriptor/dpa4.py Outdated
Coding-Agent: Codex
Codex-Version: codex-cli 0.144.1
Model: gpt-5.6-sol
Reasoning-Effort: xhigh

@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: 1

🤖 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 `@deepmd/dpmodel/descriptor/dpa1.py`:
- Around line 2420-2433: Update the projected gated self-attention docstring
around the displayed Q/K/V equations to document optional query/key/value
normalization and use the implementation’s scaling_factor or temperature instead
of fixed 1/sqrt(d). Clarify that angular weights are applied after softmax,
while masks and cutoff smoothing affect the pre-softmax attention logits.
🪄 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: f0936ec6-52c1-45e1-b0c8-8c4578f639a9

📥 Commits

Reviewing files that changed from the base of the PR and between 3fcba13 and e58c60f.

📒 Files selected for processing (5)
  • deepmd/dpmodel/atomic_model/base_atomic_model.py
  • deepmd/dpmodel/descriptor/dpa1.py
  • deepmd/dpmodel/descriptor/dpa4.py
  • deepmd/dpmodel/descriptor/repformers.py
  • deepmd/dpmodel/model/property_model.py
🚧 Files skipped from review as they are similar to previous changes (4)
  • deepmd/dpmodel/model/property_model.py
  • deepmd/dpmodel/atomic_model/base_atomic_model.py
  • deepmd/dpmodel/descriptor/dpa4.py
  • deepmd/dpmodel/descriptor/repformers.py

Comment thread deepmd/dpmodel/descriptor/dpa1.py
Coding-Agent: Codex
Codex-Version: codex-cli 0.144.1
Model: gpt-5.6-sol
Reasoning-Effort: xhigh

@OutisLi OutisLi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The new mathematical documentation currently misstates the ZBL model coupling as a direct sum. The implementation uses a coordinate-dependent switched interpolation, so this formula needs to be corrected before merging.

Comment thread deepmd/dpmodel/model/dp_zbl_model.py Outdated

@OutisLi OutisLi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One additional mathematical documentation issue in the DPA4 interaction equation:

Comment thread deepmd/dpmodel/descriptor/dpa4.py Outdated

@OutisLi OutisLi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One additional DPA4 readout documentation issue:

Comment thread deepmd/dpmodel/descriptor/dpa4.py Outdated

@OutisLi OutisLi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One additional attention-operator documentation issue:

Comment thread deepmd/dpmodel/descriptor/repformers.py Outdated

@OutisLi OutisLi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One additional DPA3 message-passing documentation issue:

Comment thread deepmd/dpmodel/descriptor/dpa3.py Outdated

@OutisLi OutisLi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One additional equivariant-output documentation issue:

Comment thread deepmd/dpmodel/atomic_model/dipole_atomic_model.py Outdated

@OutisLi OutisLi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One additional tensor-output documentation issue:

Comment thread deepmd/dpmodel/atomic_model/polar_atomic_model.py Outdated

@OutisLi OutisLi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One additional generated-API-documentation issue:

Comment thread deepmd/dpmodel/utils/network.py Outdated

@OutisLi OutisLi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One additional loss-normalization documentation issue:

Comment thread deepmd/dpmodel/loss/ener_spin.py Outdated

@OutisLi OutisLi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One additional base-class API documentation issue:

Comment thread deepmd/dpmodel/atomic_model/base_atomic_model.py Outdated

@OutisLi OutisLi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One additional DPA1 attention-operator documentation issue:

Comment thread deepmd/dpmodel/descriptor/dpa1.py Outdated

@OutisLi OutisLi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One additional generated fitting-API documentation regression:

Comment thread deepmd/dpmodel/fitting/ener_fitting.py Outdated

@OutisLi OutisLi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One final low-priority return-semantics documentation issue:

Comment thread deepmd/dpmodel/loss/ener.py
Align the ZBL, attention, descriptor, equivariant-output, and loss documentation with the implemented operations. Preserve inherited fitting API parameter documentation for AutoAPI and numpydoc.

Coding-Agent: Codex
Codex-Version: codex-cli 0.144.1
Model: gpt-5.6-sol
Reasoning-Effort: xhigh
@njzjz-bot

njzjz-bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

Fixed the 13 unresolved review threads and pushed commit 3740aa92.

Main corrections:

  • Updated the ZBL documentation to describe the coordinate-dependent DP/ZBL switching interpolation and explain the force contribution from the switching weight.
  • Aligned the DPA4 residual/readout, DPA3 RepFlow, and DPA1/Repformer attention descriptions with the implemented computation topology.
  • Completed the rotation-matrix reconstruction for dipole and polarizability outputs.
  • Corrected the spin-loss expression to use component-wise averaging and fixed the EnergyLoss diagnostic semantics.
  • Restored AutoAPI/numpydoc parameter documentation for NativeLayer, EnergyFittingNet, and DOSFittingNet.

Validation:

  • ruff format .
  • ruff check .
  • git diff --check
  • changed-file compileall
  • numpydoc ClassDoc parameter parsing
  • dp --version / dp -h

Coding agent: Codex
Codex version: codex-cli 0.144.4
Model: gpt-5.6-sol
Reasoning effort: xhigh

wanghan-iapcm
wanghan-iapcm previously approved these changes Jul 15, 2026

@wanghan-iapcm wanghan-iapcm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Docstring-only change; verified no executable code was added or removed. The math descriptions match the implementations (dipole/polar reconstruction, energy/DOS/property sums, gated-attention layer), and the fitting classes compose their equation onto the inherited base doc (+ InvarFitting.doc) so the numpydoc Parameters sections are preserved for AutoAPI. LGTM.

@njzjz
njzjz requested a review from OutisLi July 15, 2026 11:56
@wanghan-iapcm
wanghan-iapcm dismissed their stale review July 15, 2026 15:37

Dismissing to re-review through the /code-review skill per process.

@wanghan-iapcm wanghan-iapcm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-reviewed via the code-review skill. Documentation-only (verified: all deletions are docstring rewrites; the doc = math + Base.doc compose pattern preserves the inherited numpydoc Parameters). Formulas checked against the implementations across atomic models, descriptors (dpa1 attention, dpa3 message-passing), fittings, losses, and utils -- no incorrect formulas (spherical harmonics verified numerically). Only cosmetic/minor sub-threshold notes (a Sphinx block-quote indentation in the dos/ener fitting doc concatenation, and a few formulas that omit a secondary term); non-blocking. LGTM.

@njzjz-bot

Copy link
Copy Markdown
Contributor Author

The documentation corrections requested in the earlier review are already present on the current head; the review threads are resolved/outdated and the current diff remains documentation-only. Please re-review the current head when convenient.

Coding agent: Codex
Codex version: codex-cli 0.144.4
Model: gpt-5.6-sol
Reasoning effort: xhigh

@OutisLi
OutisLi added this pull request to the merge queue Jul 16, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 16, 2026
@njzjz
njzjz added this pull request to the merge queue Jul 16, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Jul 16, 2026
@njzjz
njzjz added this pull request to the merge queue Jul 17, 2026
Merged via the queue into deepmodeling:master with commit 8f298eb Jul 17, 2026
66 of 68 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