Skip to content

Guard energy rescale against unphysical steps (silent NaN) - #55

Draft
zyxwwxyz wants to merge 2 commits into
mainfrom
resc
Draft

zyxwwxyz wants to merge 2 commits into
mainfrom
resc

Conversation

@zyxwwxyz

@zyxwwxyz zyxwwxyz commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Both the ASE VelocityVerlet.step() and the i-PI VV steppers computed the momentum rescale factor as alpha = sqrt(1 - (E_new - E_old) / E_kin) with no guard: if a step's energy increase exceeded the post-step kinetic energy, the discriminant went negative and np.sqrt silently returned NaN, corrupting momenta with no error raised and no test coverage on this path.
  • Both now raise a clear RuntimeError when this happens, naming the energy jump and kinetic energy involved.
  • The rescale factor is also now exposed for monitoring: dyn.alpha in ASE, and motion.flashmd_alpha in i-PI (nan on any step where rescaling didn't run), which can be registered as a custom i-PI property to get a genuine .out file column.
  • Documented all of this in docs/energy.md, including the i-PI wiring (custom property registration + XML <properties> entry) and the KeyError pitfall if only the XML side is edited.

Test plan

  • ruff check on changed files

🤖 Generated with Claude Code

zyxwwxyz and others added 2 commits September 4, 2026 20:18
…oring

Previously, if a FlashMD step increased the total energy by more than the
post-step kinetic energy could absorb, the rescale factor's discriminant
went negative and np.sqrt silently returned NaN, corrupting momenta with
no error raised. Both the ASE and i-PI integrators now raise a clear
RuntimeError instead.

Also expose the rescale factor for monitoring: ASE's VelocityVerlet stores
it as `dyn.alpha`, and the i-PI steppers write it to `motion.flashmd_alpha`
(nan when rescaling didn't run), which can be registered as a custom
property to appear as a column in the .out file.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Clarified the explanation of energy rescaling and error handling in the documentation.
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.

1 participant