Skip to content

Conversation

@janosh
Copy link
Collaborator

@janosh janosh commented Feb 9, 2026

Summary

  • Store initial refined cells as reference_cells in from_state() and track cumulative strain in adjust_cell()
  • When total deformation exceeds max_cumulative_strain (default 0.5), clamp the cell update to stay within the strain envelope
  • Clamp (instead of reject) per-step deformations > 0.25 so the optimizer can still make progress
  • Propagate reference_cells through reindex(), merge(), select_constraint(), and select_sub_constraint()

Builds on #438 (FixSymmetry constraint). The per-step deformation check (max_delta <= 0.25) catches large single-step cell changes but not slow cumulative drift across many steps that can cause phase transitions (e.g. hexagonal → tetragonal cell collapse).

Complementary to #443 which fixes L-BFGS history contamination from unsymmetrized forces — that PR addresses force-direction drift, this one addresses cell-deformation drift.

Test plan

  • Existing test_large_deformation_clamped updated: verifies per-step clamping and cumulative strain bound
  • New test_cumulative_strain_clamp_direct: 20 small anisotropic stretches that individually pass per-step check but cumulatively exceed the limit; verifies clamping and symmetry preservation

Store initial refined cells as reference_cells and check cumulative
strain in adjust_cell(). When total deformation exceeds
max_cumulative_strain (default 0.5), clamp the cell update to stay
within the strain envelope. Also clamp (instead of reject) per-step
deformations > 0.25 so the optimizer can still make progress.

Propagate reference_cells through reindex(), merge(),
select_constraint(), and select_sub_constraint().
- Raise RuntimeError on NaN/Inf deformation gradient instead of
  silently propagating (the raise→clamp refactor broke the old
  NaN-catching `not (x <= 0.25)` idiom)
- Tighten test_large_deformation_clamped bound from 0.5 to 0.25
  (was asserting cumulative limit, not per-step limit)
- Validate reference_cells length in __init__
- Add max_cumulative_strain to merge() validation
- Fix stale docstring and misleading test comment
- Test NaN deformation raises RuntimeError (mutation-verified)
- Test mismatched reference_cells length raises ValueError
- Use math.isfinite() instead of isnan()/isinf()
- Inline single-use clamped_strain variable
@janosh janosh force-pushed the cumulative-strain-guard branch 4 times, most recently from 0dd5822 to a7198f4 Compare February 9, 2026 18:27
mattersim and fairchem (via torchtnt) import pkg_resources at
module level. Python 3.12 no longer bundles setuptools by default,
and recent GitHub runner image updates removed it.
@janosh janosh force-pushed the cumulative-strain-guard branch from a7198f4 to 5bd271f Compare February 9, 2026 18:34
@janosh janosh merged commit 1b7fb10 into main Feb 9, 2026
66 of 67 checks passed
@janosh janosh deleted the cumulative-strain-guard branch February 9, 2026 18:45
@orionarcher
Copy link
Collaborator

This looks like a nice change @janosh. IMO in general it'd be best to get a review on non-trivial changes before merging in.

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