Skip to content

Add PPCG iterative diagonalization solver to source/source_hsolver/.#7404

Open
Silver-Moon-Over-Snow wants to merge 7 commits into
deepmodeling:developfrom
Silver-Moon-Over-Snow:ppcg
Open

Add PPCG iterative diagonalization solver to source/source_hsolver/.#7404
Silver-Moon-Over-Snow wants to merge 7 commits into
deepmodeling:developfrom
Silver-Moon-Over-Snow:ppcg

Conversation

@Silver-Moon-Over-Snow
Copy link
Copy Markdown

@Silver-Moon-Over-Snow Silver-Moon-Over-Snow commented May 30, 2026

Summary

Add PPCG iterative diagonalization solver to source/source_hsolver/.

Two strategies

Strategy Status Description
CONJUGATE_GRADIENT ✅ Working Band-by-band Polak-Ribiere CG with line minimization
BLOCK_SUBSPACE ⚠️ Known issue NaN with S=I (needs stability fix)

Changes

  • diago_ppcg.h — Template class header
  • diago_ppcg.cpp — Full implementation with LAPACK bindings
  • test/diago_ppcg_test.cpp — GTest unit test (1D particle-in-a-box)
  • CMakeLists.txt / test/CMakeLists.txt — Build integration

Bug fix

potrf retry: saves original matrix before applying diagonal shift, restores before each retry — prevents accumulated shifts from corrupting the matrix.

Test result (CG)

1D particle-in-a-box (n=10): error = 4.3e-12

Known limitation

BLOCK_SUBSPACE strategy has numerical instability with S=I, unrelated to this fix.

Silver-Moon-Over-Snow and others added 6 commits March 28, 2026 13:19
Consider the previous contributions made by classmates, I'm only capable to make small difference without disrupting the entire program ---- like such a small "static".
…w_Small-Changes

2025PKUCourseHW5: Case: 1 - Change rank_seed_offset to static const
…ent)

Add PPCG iterative diagonalization with two strategies:
- CONJUGATE_GRADIENT: band-by-band Polak-Ribiere CG (verified working)
- BLOCK_SUBSPACE: block subspace diagonalization

Includes potrf retry fix: save/restore original matrix before applying
diagonal shift, preventing accumulated shifts from corrupting the matrix.

Test: 1D particle-in-a-box (n_dim=10), CG strategy matches exact
eigenvalues with error 4.3e-12.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Silver-Moon-Over-Snow Silver-Moon-Over-Snow changed the title Ppcg Add PPCG iterative diagonalization solver to source/source_hsolver/. May 30, 2026
…ormalization

Three fixes for numerical stability:

1. potrf: save/restore original matrix before diagonal shift retries,
   preventing accumulated shifts from corrupting the Cholesky factor.

2. sygvd/syevd: skip workspace query (lwork=-1) and allocate directly.
   The LAPACK replacement ignores workspace queries, causing the second
   call to operate on already-transformed data, corrupting eigenvalues.

3. Block subspace: add chol_qr + hpsi/spi recomputation after
   update_one_block and every rayleigh_ritz, keeping wavefunctions
   S-orthonormal and preventing numerical drift of H|psi> and S|psi>.

Results (1D particle-in-a-box, S=I):
- CG nband=1: error 4.3e-12 (unchanged, already working)
- BLOCK_SUBSPACE nband=1: no longer NaN, converges (to wrong eigenvalue
  due to algorithmic limitation with S=I)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant