Skip to content

Add initialization checking in BFGS, and replace the old BFGS with a new one in CG-BFGS.#7117

Open
19hello wants to merge 2 commits intodeepmodeling:developfrom
19hello:fix_bfgs
Open

Add initialization checking in BFGS, and replace the old BFGS with a new one in CG-BFGS.#7117
19hello wants to merge 2 commits intodeepmodeling:developfrom
19hello:fix_bfgs

Conversation

@19hello
Copy link
Collaborator

@19hello 19hello commented Mar 23, 2026

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 #...

Unit Tests and/or Case Tests for my changes

  • A unit test is added for each new feature or bug fix.

What's changed?

  • Example: My changes might affect the performance of the application under certain conditions, and I have tested the impact on various scenarios...

Any changes of core modules? (ignore if not applicable)

  • Example: I have added a new virtual function in the esolver base class in order to ...

Copilot AI review requested due to automatic review settings March 23, 2026 07:37
Copy link

Copilot AI left a comment

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 updates the ionic relaxation flow to switch cg_bfgs into the newer/traditional BFGS implementation safely (by adding lazy initialization), and also modifies the OpenMPI stage1 build configuration.

Changes:

  • Switch cg_bfgs -> bfgs handoff to select relax_method[1] = "1" (the BFGS/bfgs_trad path).
  • Add lazy initialization (is_initialized) to BFGS so relax_step() can be called safely without a prior explicit allocate().
  • Update the OpenMPI installer to pass explicit compiler selections to ./configure.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
toolchain/scripts/stage1/install_openmpi.sh Forces compiler variables during OpenMPI configure (may affect toolchain portability).
source/source_relax/ions_move_cg.cpp Changes the cg_bfgs threshold switch to select bfgs_trad (relax_method[1]="1").
source/source_relax/bfgs.h Adds an is_initialized flag to support safe lazy initialization.
source/source_relax/bfgs.cpp Lazily calls allocate() from relax_step() if needed.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +95 to +98
CC=gcc \
CXX=g++ \
FC=gfortran \
F77=gfortran \
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

Hardcoding CC=gcc, CXX=g++, FC=gfortran, and F77=gfortran here overrides any compiler selection coming from toolchain.conf/toolchain.env (e.g., Intel/Clang toolchains, cross-compilers) and can make OpenMPI fail to build on systems without GNU Fortran installed. Consider respecting existing environment/toolchain variables (e.g., CC="${CC:-gcc}" etc.) or omitting these assignments and letting the toolchain drive the compiler choice, consistent with the other MPI install scripts.

Suggested change
CC=gcc \
CXX=g++ \
FC=gfortran \
F77=gfortran \
CC="${CC:-gcc}" \
CXX="${CXX:-g++}" \
FC="${FC:-gfortran}" \
F77="${F77:-gfortran}" \

Copilot uses AI. Check for mistakes.
Comment on lines +39 to +42
if(!is_initialized)
{
allocate(ucell.nat);
}
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

relax_step() now lazily calls allocate() when the object hasn't been initialized. There are existing unit tests for BFGS in source/source_relax/test/bfgs_test.cpp, but none cover this new path (calling relax_step() without a prior allocate()). Please add a test to assert that relax_step() succeeds and initializes internal state when allocate() was not called explicitly (this is particularly important for the cg_bfgs -> bfgs_trad switch).

Copilot uses AI. Check for mistakes.
@mohanchen mohanchen added Bugs Bugs that only solvable with sufficient knowledge of DFT Refactor Refactor ABACUS codes GeometryRelaxation Issues related to geometry relaxation labels Mar 23, 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 GeometryRelaxation Issues related to geometry relaxation Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants