Skip to content

Add WFN-history backend for Gamma-only NAO calculations#7442

Open
Growl1234 wants to merge 10 commits into
deepmodeling:developfrom
Growl1234:wfn-history
Open

Add WFN-history backend for Gamma-only NAO calculations#7442
Growl1234 wants to merge 10 commits into
deepmodeling:developfrom
Growl1234:wfn-history

Conversation

@Growl1234
Copy link
Copy Markdown

@Growl1234 Growl1234 commented Jun 6, 2026

This PR introduces an optional WFN-based initialization path for NAO calculations.

A new wfc_extrap use_prev_wf path 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

  • Further reducing SCF iterations requires a more accurate WFN prediction, which would be more complicated because the wavefunction coefficients live in a nonorthogonal moving NAO basis. The backend therefore has to handle wavefunction history ownership, current-overlap reconstruction, distributed matrix layout, S-orthonormalization, occupation handling, and density reconstruction consistently.
  • For k-point case it's even harder because the backend has to handle complex per-k wavefunctions, k-dependent overlap matrices $S(k)$, local/global k-point ownership, density-matrix reconstruction from all k-points, and PBC phase or convention corrections between ionic steps.

Copilot AI review requested due to automatic review settings June 6, 2026 09:12
Copy link
Copy Markdown

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

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_extrap input validation/handling (including skipping charge extrapolation when enabled).
  • Updates CMake to enforce a minimum C++ standard and adds a new module_extrap subdirectory 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.

Comment on lines +101 to +106
if constexpr (!std::is_same<TK, double>::value)
{
result.status = WfcExtrapStatus::Unsupported;
return result;
}
else
Copy link
Copy Markdown
Author

@Growl1234 Growl1234 Jun 6, 2026

Choose a reason for hiding this comment

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

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.

Comment thread source/source_lcao/module_extrap/CMakeLists.txt Outdated
Comment on lines +9 to 12
add_subdirectory(module_extrap)
list(APPEND objects
hamilt_lcao.cpp
module_operator_lcao/operator_lcao.cpp
Copy link
Copy Markdown
Author

@Growl1234 Growl1234 Jun 6, 2026

Choose a reason for hiding this comment

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

Looks like module_operator_lcao also acts like this, so I'm hesitating here...

Comment on lines +27 to +28
module_extrap/wf_history_lcao.cpp
module_extrap/wf_orthonormalize_lcao.cpp
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Same as above.

Comment on lines +72 to +73
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);
Copy link
Copy Markdown
Author

@Growl1234 Growl1234 Jun 6, 2026

Choose a reason for hiding this comment

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

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.

Comment on lines +78 to +103
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;
}
}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Same as above.

@mohanchen mohanchen added the Refactor Refactor ABACUS codes label Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants