Add initialization checking in BFGS, and replace the old BFGS with a new one in CG-BFGS.#7117
Add initialization checking in BFGS, and replace the old BFGS with a new one in CG-BFGS.#711719hello wants to merge 2 commits intodeepmodeling:developfrom
Conversation
There was a problem hiding this comment.
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 -> bfgshandoff to selectrelax_method[1] = "1"(theBFGS/bfgs_tradpath). - Add lazy initialization (
is_initialized) toBFGSsorelax_step()can be called safely without a prior explicitallocate(). - 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.
| CC=gcc \ | ||
| CXX=g++ \ | ||
| FC=gfortran \ | ||
| F77=gfortran \ |
There was a problem hiding this comment.
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.
| CC=gcc \ | |
| CXX=g++ \ | |
| FC=gfortran \ | |
| F77=gfortran \ | |
| CC="${CC:-gcc}" \ | |
| CXX="${CXX:-g++}" \ | |
| FC="${FC:-gfortran}" \ | |
| F77="${F77:-gfortran}" \ |
| if(!is_initialized) | ||
| { | ||
| allocate(ucell.nat); | ||
| } |
There was a problem hiding this comment.
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).
Reminder
Linked Issue
Fix #...
Unit Tests and/or Case Tests for my changes
What's changed?
Any changes of core modules? (ignore if not applicable)