Conversation
* fix: address release readiness issues * chore: remove stale release codename * fix: preserve Windows release version ordering * test: use relative license path in Windows installer fixture --------- Co-authored-by: Xiaoxuan Yu <apple578799@outlook.com>
wszqkzqk
force-pushed
the
fix/minimization-adam-numeric
branch
from
September 26, 2026 06:44
63a15b1 to
585ea1c
Compare
wszqkzqk
force-pushed
the
fix/minimization-adam-numeric
branch
from
September 26, 2026 06:52
585ea1c to
3689bf3
Compare
wszqkzqk
marked this pull request as draft
September 26, 2026 08:19
The dynamic-dt (Adam) minimizer diverged to NaN when removing clashes: the second-moment update f*f overflowed float to inf, the first moment was applied as gradient-descent momentum instead of the bias-corrected Adam step, the learning rate was inflated 20.455x by the dt unit conversion, and LJ forces overflowing float at tiny separations entered the optimizer. Store the root of the second moment and evaluate the recurrence in double precision, apply the bias-corrected Adam step directly with an unconverted learning_rate (3e-4, configurable via minimization.learning_rate), drop the mass preconditioner for a coordinate-space optimizer, and clamp forces to +-1e10 so overflow cannot enter the optimizer (the scale-invariant step is unaffected). The tip3p bad_coordinate validation case now converges (final potential below the -4000 threshold); the 744k-atom M5 case matches the reference optimizer step for step with no NaN. Signed-off-by: Zhou Qiankang <wszqkzqk@qq.com>
wszqkzqk
force-pushed
the
fix/minimization-adam-numeric
branch
from
September 26, 2026 09:47
3689bf3 to
18b1d88
Compare
wszqkzqk
marked this pull request as ready for review
September 26, 2026 09:49
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
对含 clash 的结构做 minimization 消除 clash 时,势能很快变为 inf 再变为 NaN,最小化无法继续。仓库自带的验证用例 test_min.py 的 tip3p bad_coordinate 在当前 master 上可直接复现。
根源在 Adam 优化器的数值实现。二阶矩以 float 计算$f^2$ ,坐标严重重叠时力可达 $10^{23}$ 量级,平方后溢出为 inf。一阶矩随后又被当作动量加入坐标积分,原子沿原始力方向每步移动 max_move,直到相互重叠。同时 minimization 的学习率被时间单位换算放大了 20.455 倍,实际步长 6.1e-3 Å 远超预期。当原子被压到极小间距时,LJ 力超出 float 上限变为 inf,进入优化器后传播为 NaN。
方案
只改动 SPONGE/MD_core/min.hpp 和 min.h 中的一行。
二阶矩改存平方根,递推在 double 下进行:
double 下平方不溢出,开根号后回到 float 可表示范围,任意有限的 float 力都有可表示的优化器状态,与原递推数学上严格等价。偏差校正同样在 double 下计算。
坐标更新改为直接施加偏差校正后的 Adam 位移:
动量状态不再参与坐标更新。
Adam 步长改用独立的 learning_rate,默认 3e-4 Å,不再经过时间单位换算,同时新增 minimization.learning_rate 输入项。
一阶矩不再乘质量逆,两个矩统一为坐标空间中同一个量的矩,与标准 Adam 一致。mass_inverse 为 0 的原子保持不动,虚拟位点行为不变。
进入优化器前把每个力分量钳制在$\pm 10^{10}$ 。Adam 单步位移不超过学习率,与力的大小无关,钳制不改变轨迹方向,但能阻止 inf 进入优化器,保证最小化在坐标严重重叠的初始结构上存活。
非 Adam 路径 minimization_dynamic_dt = 0 逐位不变。
验证
test_min.py 的 tip3p bad_coordinate 用例修复前从 step 1000 起为 nan,修复后通过,10 万步最终势能低于 -4000 阈值。74 万原子的体系无约束最小化 1000 步正常收敛,无 NaN。同一用例多次运行均未出现 NaN。TIP3P 正常坐标 minimization 单调收敛,最速下降路径与 NVE 测试通过。改动位于设备无关内核,CPU 构建已验证,对 CUDA 路径同样生效。