Skip to content

Fix bug: Reset BFGS history after cell changes#7507

Merged
mohanchen merged 2 commits into
deepmodeling:developfrom
19hello:fix-bfgs-reset-after-cell-change
Jun 25, 2026
Merged

Fix bug: Reset BFGS history after cell changes#7507
mohanchen merged 2 commits into
deepmodeling:developfrom
19hello:fix-bfgs-reset-after-cell-change

Conversation

@19hello

@19hello 19hello commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Reminder

  • Have you linked an issue with this pull request?
  • Have you added adequate unit tests and/or case tests for your pull request?
  • Have you noticed possible changes of behavior below or in the linked issue?
  • Have you explained the changes of codes in core modules of ESolver, HSolver, ElecState, Hamilt, Operator or Psi? (ignore if not applicable)

Linked Issue

Fix #4140

Unit Tests and/or Case Tests for my changes

Added IonsMoveMethodsTest.ResetAfterCellChange in the existing source/source_relax/test/ions_move_methods_test.cpp.

  • The test covers both ionic BFGS and traditional ionic BFGS reset paths after a cell change.
  • Verified that optimizer state is reset, including convergence flag, update iteration, energy history, BFGS history arrays, inverse Hessian, trust radius, and traditional BFGS initialization state.

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:

  • Adds reset functions for ionic BFGS and traditional ionic BFGS.
  • Adds Ions_Move_Methods::reset_after_cell_change.
  • Calls this reset after the cell is updated in relax_nsync.cpp.
  • Registers and extends the existing ions_move_methods_test.cpp unit test target.

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.

Copilot AI review requested due to automatic review settings June 22, 2026 08:40

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.

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 in IonCellOptimizer::relax_step().
  • Add reset APIs to ionic optimizers (Ions_Move_BFGS::reset(), Ions_Move_BFGS2::reset()) and wire them through Ions_Move_Methods.
  • Clear common convergence/iteration/energy-tracking state in Ions_Move_Methods when 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.

Comment thread source/source_relax/ions_move_methods.cpp Outdated
Comment thread source/source_relax/ions_move_methods.cpp
@19hello 19hello force-pushed the fix-bfgs-reset-after-cell-change branch from 287755e to 26fc7b7 Compare June 22, 2026 08:46
@mohanchen mohanchen added Bugs Bugs that only solvable with sufficient knowledge of DFT Refactor Refactor ABACUS codes labels Jun 22, 2026

@mohanchen mohanchen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.
@19hello 19hello force-pushed the fix-bfgs-reset-after-cell-change branch from fcba7da to de9923d Compare June 25, 2026 07:07
@mohanchen mohanchen merged commit 4b1fc7d into deepmodeling:develop Jun 25, 2026
16 checks passed
@mohanchen mohanchen changed the title Reset BFGS history after cell changes Fix bug: Reset BFGS history after cell changes Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bugs Bugs that only solvable with sufficient knowledge of DFT Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BFGS in cell-relax cannot lead to convergence (48-atom C system)

3 participants