Skip to content

Commit 3713712

Browse files
committed
fix: use real-only initial wavefunctions in PPCG unit test
H and S are real symmetric operators whose eigenvectors are real. The previous complex random initialization produced complex off-diagonal elements in the H-gram matrix (max |Im| ~ 0.5 for nband=3), causing Re(<psi_i|H|psi_j>) != <psi_i|H|psi_j>. The gamma_dot function only returns the real part, so all subspace Gram matrices (built via gram()) computed wrong off-diagonals, leading to incorrect eigenvalues from sygvd. With real-only psi all inner products are real and gamma_dot is exact, so both BLOCK_SUBSPACE and CONJUGATE_GRADIENT strategies should now converge to the correct eigenvalues.
1 parent 49f70c2 commit 3713712

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

source/source_hsolver/test/diago_ppcg_test.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,14 @@ class DiagoPPCGTest : public ::testing::Test
7575
std::mt19937 rng(42);
7676
std::uniform_real_distribution<Real> dist(-1.0, 1.0);
7777

78+
// Use real-only initial guess. H and S are real symmetric, so the
79+
// exact eigenvectors are real and any imaginary component can only
80+
// slow convergence. Keeping psi real also avoids the need for
81+
// complex-Hermitian Gram matrices in the subspace eigenvalue solves.
7882
psi.assign(ld * nband, T(0));
7983
for (int j = 0; j < nband; ++j)
8084
for (int i = 0; i < n_dim; ++i)
81-
psi[i + j * ld] = T(dist(rng), dist(rng));
85+
psi[i + j * ld] = T(dist(rng), 0.0);
8286

8387
// Gram-Schmidt orthonormalisation (S = I)
8488
for (int j = 0; j < nband; ++j) {

0 commit comments

Comments
 (0)