Skip to content

cipsi: assign each state its own eigenvector's eigenvalue in do_diag (qp3) - #435

Merged
scemama merged 1 commit into
QuantumPackage:qp3from
scemama:issue433-do-diag-index-qp3
Nov 26, 2026
Merged

scemama merged 1 commit into
QuantumPackage:qp3from
scemama:issue433-do-diag-index-qp3

Conversation

@scemama

@scemama scemama commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Fix

fill_buffer_$DOUBLE (src/cipsi/selection.irp.f), the per-candidate do_diag block that runs for multi-state runs: after DSYEV on the (N_states+1)x(N_states+1) matrix [E0 | mat; mat' | Hii+E_shift], the eigenvectors sit in pt2_matrix by columns (column j is the eigenvector of eigvalues(j)). The old code computed iwork(j) = maxloc(pt2_matrix, DIM=1) — the dominant row of eigenvector j — and then used iwork(k) as an eigenvalue index for state k, mixing eigenvector and state indices. A state could be assigned the external-determinant eigenvalue (≈ Hii + E_shift − E0), corrupting the reported PT2 to O(1e4) Ha for N_states ≥ 3 (issue #433: 17160.5 / −46231.3 / 16045.9977 instead of −0.78691 / −0.86549 / −0.81740).

The dimensionally correct reading: state k takes the eigenvalue of the eigenvector whose largest component lies in row k. The two readings coincide for N_states=2 whenever the dominant-row map is an involution, which is why 2-state runs looked healthy.

Single hunk, F90 only, no declaration change.

Verification (Ampere, 3-state + 2-state matrix, both arms)

Fixture: 3-state wavefunction, 3500 determinants (truncated from 156417, ranked by max |c| over the 3 state columns, renormalized), state order (2,3,1), 128 MOs. pt2 program, OMP_NUM_THREADS=1, QP_NTHREADS_PT2=2, pt2_relative_error=5e-2 (stochastic), fresh EZFIO copy per run. Final per-state PT2 values, Ha:

state T0 buggy (3 st) T1a/T1b fixed (3 st) T2 fixed, det (3 st)
1 +3600.550 −0.702037 −0.702245
2 −22594.484 −0.664221 −0.664438
3 +11713.779 −0.669508 −0.669925
  • G1: all three buggy T0 states corrupted (O(1e3–1e4) Ha); fixed T2 O(1) — PASS both arms.
  • G2: max |T1 − T2| = 4.2e-4 Ha ≤ 2e-2, no |PT2| > 1 in T1a/T1b — PASS (T1a/T1b bit-identical: deterministic seed, spread 0).
  • G3: T0 vs T1 Variance / Norm² agree to ~1e-14 — the walk is upstream of the buggy post-processing and unaffected, as the issue predicts — PASS.
  • G4 (2-state control): |T3 − T3d| ≤ 2.2e-4 Ha; the buggy 2-state run gives −0.702037 / −0.664221, not corrupted (the bug needs N_states ≥ 3) — PASS.

Both arms (dev-stable tip 45d4cb5b; qp3 tip c2d4ac2b) agree to ~1e-8 on every value.

Binaries (sha256):

binary sha256
pt2-devstable-buggy 5f0bc5f8a2d34925f67e0f17427e33a2589eccec6dfce8a642cbf90bb06e3b00
pt2-devstable-fixed 8bbe628d0005d4a2dc802a2bd3184b12ec0df040e0461e0b7518dd93113bd7f2
pt2-qp3-buggy 31f6ea3fa442a758e9e69410a21be4373b16d6fce86de129048e67bf55749628
pt2-qp3-fixed 38e6c697ba8d59f28517e8e4926e1d1b24bb2c4780fe38885645826f081bb19e

Note: the dev-stable arm was built with gfortran 7.5.0 + MKL because the current dev-stable tip does not compile with ifort 2021.9 (separate upstream build regression, 0ee7e5f8 symmetry_det character-provider rewrite, error #6401); the hunk is plain F90 and the compiler does not affect its semantics.

Cherry-pick of dev-stable commit 760b177 (PR #434); identical single hunk (hunk header line 830 here vs 807 on dev-stable). Verified on qp3 tip c2d4ac2, which is an ancestor of the current qp3 tip 0a9ad26; the do_diag block is byte-identical at both, and none of the intermediate commits touch it.

In fill_buffer_$DOUBLE, after DSYEV on the (N_states+1)x(N_states+1) matrix
[E0 | mat; mat' | Hii+E_shift], the eigenvectors sit in pt2_matrix by
columns: column j is the eigenvector of eigvalues(j). The old code computed
iwork(j) = maxloc(pt2_matrix, DIM=1), the dominant ROW of eigenvector j, and
then used iwork(k) as an eigenvalue index for state k, mixing eigenvector and
state indices. The dimensionally correct reading: state k takes the
eigenvalue of the eigenvector whose largest component lies in row k.

The two readings coincide for N_states=2 whenever the dominant-row map is an
involution (the typical case), which is why 2-state runs looked healthy; for
N_states=3 a state can be assigned the external-determinant eigenvalue
~ Hii + E_shift - E0, producing the O(1e4) Ha PT2 values reported in issue
QuantumPackage#433 (17160.5 / -46231.3 / 16045.9977 instead of -0.78691012 /
-0.86549405 / -0.81739619).

Fixes QuantumPackage#433
@scemama
scemama merged commit 2da98fb into QuantumPackage:qp3 Nov 26, 2026
@scemama
scemama deleted the issue433-do-diag-index-qp3 branch November 26, 2026 11:29
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