Add WFN-history backend for Gamma-only NAO calculations#7442
Add WFN-history backend for Gamma-only NAO calculations#7442Growl1234 wants to merge 10 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds Gamma-only LCAO wavefunction-history extrapolation (use_prev_wf) by snapshotting the previous step’s coefficients and reorthonormalizing them against the current overlap matrix before SCF.
Changes:
- Introduces LCAO wavefunction snapshot/history helpers and a Gamma-only reorthonormalization routine.
- Wires extrapolation into the LCAO ESolver flow and adds
wfc_extrapinput validation/handling (including skipping charge extrapolation when enabled). - Updates CMake to enforce a minimum C++ standard and adds a new
module_extrapsubdirectory target.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| source/source_lcao/module_extrap/wf_snapshot_lcao.h | Stores/restores full Psi coefficient snapshots plus occupations. |
| source/source_lcao/module_extrap/wf_orthonormalize_lcao.h | Declares Gamma-only reorthonormalization API + diagnostic result struct. |
| source/source_lcao/module_extrap/wf_orthonormalize_lcao.cpp | Implements MPI-aware assembly + Cholesky-based reorthonormalization. |
| source/source_lcao/module_extrap/wf_history_lcao.h | Defines wavefunction history class and apply-result diagnostics. |
| source/source_lcao/module_extrap/wf_history_lcao.cpp | Implements history management and use_prev_wf apply path. |
| source/source_lcao/module_extrap/wf_extrap_method.h | Adds extrapolation method/status enums and string conversions. |
| source/source_lcao/module_extrap/CMakeLists.txt | Adds lcao_extrap object library target for new module sources. |
| source/source_lcao/CMakeLists.txt | Enables module_extrap subdir and adds new sources to LCAO objects list. |
| source/source_io/module_parameter/read_input_item_system.cpp | Adds wfc_extrap input item, docs, and validation checks. |
| source/source_io/module_parameter/input_parameter.h | Adds wfc_extrap parameter with default "none". |
| source/source_esolver/esolver_ks_lcao.h | Adds wf_history_lcao_ member to ESolver. |
| source/source_esolver/esolver_ks_lcao.cpp | Initializes history, prepares overlap early, applies extrapolation, rebuilds density, updates history after SCF. |
| source/source_esolver/esolver_fp.cpp | Skips charge extrapolation when wfc_extrap is enabled (LCAO, istep>0). |
| CMakeLists.txt | Enforces a minimum C++ standard globally (now 14). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if constexpr (!std::is_same<TK, double>::value) | ||
| { | ||
| result.status = WfcExtrapStatus::Unsupported; | ||
| return result; | ||
| } | ||
| else |
There was a problem hiding this comment.
For conservativeness, this PR only drops C++11 support, as the C++11 build fails, while C++14 only reports a warning. I have doubt if modifying the code just to keep compatibility with a rather old C++ standard is worth the effort.
| add_subdirectory(module_extrap) | ||
| list(APPEND objects | ||
| hamilt_lcao.cpp | ||
| module_operator_lcao/operator_lcao.cpp |
There was a problem hiding this comment.
Looks like module_operator_lcao also acts like this, so I'm hesitating here...
| module_extrap/wf_history_lcao.cpp | ||
| module_extrap/wf_orthonormalize_lcao.cpp |
| metric.assign(static_cast<std::size_t>(nactive_bands) * static_cast<std::size_t>(nactive_bands), 0.0); | ||
| std::vector<double> coeff_s(static_cast<std::size_t>(nactive_bands) * static_cast<std::size_t>(nbasis), 0.0); |
There was a problem hiding this comment.
I kept the explicit loops for clarity in the initial MPI-aware backend, and the current timing shows that this part is not the dominant cost yet. I agree that these contractions should eventually be replaced by BLAS calls and reusable work buffers for larger NAO bases, but I'd prefer to include it in follow-up PRs.
| for (int ib = 0; ib < nactive_bands; ++ib) | ||
| { | ||
| for (int mu = 0; mu < nbasis; ++mu) | ||
| { | ||
| double value = 0.0; | ||
| for (int nu = 0; nu < nbasis; ++nu) | ||
| { | ||
| value += coeff[idx(ib, nu, nbasis)] * overlap[idx(nu, mu, nbasis)]; | ||
| } | ||
| coeff_s[idx(ib, mu, nbasis)] = value; | ||
| } | ||
| } | ||
|
|
||
| for (int ib = 0; ib < nactive_bands; ++ib) | ||
| { | ||
| for (int jb = 0; jb <= ib; ++jb) | ||
| { | ||
| double value = 0.0; | ||
| for (int mu = 0; mu < nbasis; ++mu) | ||
| { | ||
| value += coeff_s[idx(ib, mu, nbasis)] * coeff[idx(jb, mu, nbasis)]; | ||
| } | ||
| metric[idx(ib, jb, nactive_bands)] = value; | ||
| metric[idx(jb, ib, nactive_bands)] = value; | ||
| } | ||
| } |
This PR introduces an optional WFN-based initialization path for NAO calculations.
A new
wfc_extrap use_prev_wfpath is added. It stores the converged wavefunction from the previous ionic step, rebuilds the current overlap matrix, reorthonormalizes the previous wavefunction with the current overlap matrix, and then reconstructs the density matrix and charge density before entering the normal SCF cycle. When this path is enabled, the existing charge-density extrapolation is skipped, so the initial density is generated from the WFN-history backend instead of being extrapolated directly in real space.The implementation currently focuses on the Gamma-only backend, including MPI-distributed matrices. This is intended as a common backend for future improvements and more WFN-based predictors such as ASPC and GExt_PROJ.
Here's a simple test that shows the accuracy and effectiveness of the WFN-based path: test.zip. The regtesting is left for a next commit.
To be discussed
The support for C++11 standard is dropped in order to pass the non-MPI building test (I didn't think it's worth modifying the code just to keep C++11 compatibility). If there's any code that still relies on C++11 please let me know.
What's planned to resolve in the future PRs