Skip to content

fix(ase): symmetrize reshaped virial stress#5799

Open
njzjz wants to merge 1 commit into
deepmodeling:masterfrom
njzjz:codex/code-scan-5689
Open

fix(ase): symmetrize reshaped virial stress#5799
njzjz wants to merge 1 commit into
deepmodeling:masterfrom
njzjz:codex/code-scan-5689

Conversation

@njzjz

@njzjz njzjz commented Jul 14, 2026

Copy link
Copy Markdown
Member

Summary

  • reshape the nine-component model virial before transposing it
  • project the virial onto ASE's symmetric Cauchy stress convention
  • preserve the original, potentially asymmetric virial matrix in results["virial"]
  • add a backend-independent mock regression with independently observable shear components

Root cause and fix

The calculator stored v[0].reshape(3, 3) as the virial, but formed stress from:

v[0].copy() + v[0].copy().T

v[0] is one-dimensional with shape (9,), and transposing a one-dimensional NumPy array is a no-op. The calculation therefore selected only one side of each off-diagonal pair when converting to ASE Voigt order.

The code now names the reshaped 3 x 3 virial, preserves it unchanged in the results dictionary, and computes:

-0.5 * (virial + virial.T) / volume

This matches ASE's symmetric stress convention and retains tensile-positive sign handling. It does not hide the original virial: callers can still inspect any antisymmetric component through results["virial"].

Why existing tests missed this

Standard conservative DeePMD models normally return a total virial that is already symmetric up to floating-point noise. Existing calculator integration tests use such real model output and mainly check permutation consistency, so the ineffective transpose was numerically invisible.

The new lightweight regression mocks the model with the intentionally asymmetric virial:

[[1, 2, 3],
 [4, 5, 6],
 [7, 8, 9]]

For volume 8, the correct ASE Voigt shear entries are based on averages yz=7, xz=5, and xy=3. The previous implementation deterministically returned the single-sided values 6, 3, and 2; the fixed implementation returns the expected symmetric values and leaves the stored virial unchanged.

Validation

  • old calculation reproduced the incorrect deterministic shear values
  • new backend-independent regression: passed
  • existing PyTorch calculator tests: 2 passed
  • independent review found no sign, Voigt-order, PBC, or backend-coupling issues
  • ruff format --check .
  • ruff check .
  • git diff --check

Closes #5689.

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

Reshape the nine-component virial before transposing and project it onto ASE symmetric Cauchy stress while preserving the original virial matrix. Add a backend-independent asymmetric mock regression for the Voigt shear components.

Coding-Agent: Codex
Codex-Version: codex-cli 0.144.1
Model: gpt-5.6-sol
Reasoning-Effort: xhigh
Copilot AI review requested due to automatic review settings July 14, 2026 19:38

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.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@njzjz, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 22 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6ee7fae4-41ba-4d57-8653-064bd33b71f8

📥 Commits

Reviewing files that changed from the base of the PR and between 3122138 and 0486337.

📒 Files selected for processing (2)
  • deepmd/calculator.py
  • source/tests/test_calculator.py
✨ 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.

@dosubot dosubot Bot added the bug label Jul 14, 2026
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.

[Code scan] Symmetrize ASE calculator stress after reshaping virial

3 participants