Skip to content

use nonnegative cell volumes when normalizing stress - #257

Open
ZenAlexa wants to merge 1 commit into
CederGroupHub:mainfrom
ZenAlexa:contrib/positive-cell-volume
Open

ZenAlexa wants to merge 1 commit into
CederGroupHub:mainfrom
ZenAlexa:contrib/positive-cell-volume

Conversation

@ZenAlexa

@ZenAlexa ZenAlexa commented Nov 14, 2026 •

Copy link
Copy Markdown

Summary

Left-handed cells currently reverse the predicted stress because BatchedGraph.from_graphs uses the signed lattice triple product as the volume. Exchanging two lattice basis vectors preserves the physical lattice and Cartesian atom positions, and the stress normalization requires the nonnegative physical volume abs(det(lattice)).

Apply abs() at the existing volume owner and document the volume unit. The existing cross/dot implementation is retained, including its MPS compatibility, and the strain definition, graph conversion, energy/force paths and checkpoint format stay unchanged.

Reproduction

For the same two-atom Si structure represented with left-handed basis vectors, the original ASE calculator reports σxx ≈ +0.01204520 eV/ų. The energy-strain finite difference gives approximately -0.01202048 eV/ų, and the candidate reports approximately -0.01204520 eV/ų. The finite-strain C11 changes from approximately -155.616 GPa to +155.616 GPa, matching the right-handed representation's approximately +155.605 GPa result.

This also reaches real consumers. Five FIRE cell-relaxation steps raise the original left-handed system's total energy from approximately -10.521078 to -9.365305 eV. With this patch, it decreases to approximately -10.626108 eV, matching the right-handed control's approximately -10.626107 eV.

Verification

  • Six persistent scenarios cover basis permutation, basis sign changes, spatial reflection, mixed-handedness batches, all six independent strain components, StructOptimizer with FrechetCellFilter, trajectory readback, and StructureData → Trainer.train → SGD → checkpoint recovery.
  • The new scenarios give 5 failed and 1 passed on main at b9a6c15860237297a5a5169660e83b2e61a78e76, and 6 passed with the patch. The candidate plus existing model, relaxation and trainer regressions gives 226 passed and 3 accelerator cases deselected.
  • Independently checked sheared Si and NaCl cells under determinant-minus-one integer basis changes. The right-handed energy, forces and stress are bitwise unchanged in these CPU controls. Left-handed energy and forces are also bitwise unchanged, and stress receives the sign correction. All six strain components agree with independent central energy differences within the scenario tolerances.
  • Physically equivalent right-handed and mixed-handedness training data now produce matching stress-loss gradients and checkpoint predictions. The largest observed checkpoint weight difference changes from approximately 5.61e-4 to 1.19e-7.
  • An additional real MPS mixed-handedness Si batch executes on mps:0, returns finite energy/forces/stress and passes the equivalence checks. MPS training and relaxation remain unrun.
  • Ruff 0.7.4 lint/format checks and git diff --check pass.

CPU execution used macOS arm64, Python 3.12.14, PyTorch 2.14.1, ASE 3.29.0 and pymatgen 2026.10.24. CUDA, XPU, other operating systems and the full accelerator training matrix remain unrun. The atomate2 report in #240 requires a separate reproducer.

Copilot AI balanced review requested due to automatic review settings November 14, 2026 09:16

Copilot AI left a comment

Copy link
Copy Markdown

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 insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 2 medium

Results:
2 new issues

Category Results
Security 2 medium

View in Codacy

🟢 Metrics 32 complexity

Metric Results
Complexity 32

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants