Fix bug: Reset BFGS history after cell changes#7507
Merged
mohanchen merged 2 commits intoJun 25, 2026
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to improve the robustness of cell-relax workflows by resetting ionic BFGS-related optimizer history whenever the unit cell changes, avoiding reuse of stale quasi-Newton state across discontinuous cell updates.
Changes:
- Call a new
Ions_Move_Methods::reset_after_cell_change()hook after cell updates inIonCellOptimizer::relax_step(). - Add reset APIs to ionic optimizers (
Ions_Move_BFGS::reset(),Ions_Move_BFGS2::reset()) and wire them throughIons_Move_Methods. - Clear common convergence/iteration/energy-tracking state in
Ions_Move_Methodswhen a reset is triggered.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| source/source_relax/relax_nsync.cpp | Triggers ionic optimizer reset after a cell change during cell-relax. |
| source/source_relax/ions_move_methods.h | Declares the new reset_after_cell_change() API. |
| source/source_relax/ions_move_methods.cpp | Implements reset logic and logging for BFGS-related methods. |
| source/source_relax/ions_move_bfgs.h | Declares Ions_Move_BFGS::reset(). |
| source/source_relax/ions_move_bfgs.cpp | Implements BFGS state/history reset behavior. |
| source/source_relax/ions_move_bfgs2.h | Declares Ions_Move_BFGS2::reset(). |
| source/source_relax/ions_move_bfgs2.cpp | Implements traditional BFGS2 “reinitialize on next step” reset behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
287755e to
26fc7b7
Compare
Fixes deepmodeling#4140. This PR resets ionic BFGS state after an actual cell update in cell-relax so the optimizer does not reuse coordinates, gradients, Hessian history, trust radius, or traditional BFGS initialization from the previous cell. The test coverage now lives in the existing ions_move_methods_test.cpp target and checks both new BFGS and traditional BFGS reset paths.
fcba7da to
de9923d
Compare
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.
Reminder
Linked Issue
Fix #4140
Unit Tests and/or Case Tests for my changes
Added
IonsMoveMethodsTest.ResetAfterCellChangein the existingsource/source_relax/test/ions_move_methods_test.cpp.What's changed?
This PR fixes the cell-relax BFGS convergence issue reported in #4140.
When the lattice is changed during cell-relax, the previous ionic BFGS history is no longer consistent with the updated cell. Reusing the old positions, gradients, inverse Hessian, trust radius, and traditional BFGS state can make the optimizer continue from invalid history and eventually hit the "trust radius is too small" failure.
The PR adds reset logic after an actual cell update:
After this change, ionic BFGS starts with clean optimizer history after each accepted cell change, avoiding reuse of stale BFGS state from the previous cell.