Repository navigation
Description
Summary. In a 3-state run of the stochastic PT2 (pt2, do_pt2=T, branch qp3, commit e3165f6a), all three printed PT2 values are wrong once the stochastic walk actually runs. The process exits 0, and the walk diagnostics (Variance, Norm², generator blocks) are identical to a healthy run. The do_diag post-processing block in select_connected mixes eigenvector and state indices; the error survives at N_states=2 only by accident.
Observed vs reference. Fixture: EzFIO, 3322 determinants, 128 MOs, 3 states ordered [walkable (base state 2, teeth 9), walkable (base state 3, teeth 11), flat (base state 1, top |c|² = 0.9999998, no comb)]. pt2_relative_error = 5e-2, OMP_NUM_THREADS=1, QP_NTHREADS_PT2=2, pristine binary sha256 e35888a3a025421ab186a7c02cbc5d42c57d039b6d2e43e6e7f9ea060b0ff19b, exit 0.
| state | printed PT2 | expected PT2 |
|---|---|---|
| 1 | 17160.5 | -0.78691012 |
| 2 | -46231.3 | -0.86549405 |
| 3 | 16045.9977 | -0.81739619 |
Expected values: deterministic PT2 (do_pt2=F) on the same states gives -0.78691012 and -0.86549405; -0.81739619 comes from a run whose flat state is first (the whole-routine guard then sends the entire run down the deterministic path).
Mechanism. src/cipsi/selection.irp.f:832-836, inside if (do_diag):
pt2_matrix = dabs(pt2_matrix)
iwork(1:N_states+1) = maxloc(pt2_matrix,DIM=1)
do k=1,N_states
e_pert(k) = eigvalues(iwork(k)) - E0(k)
enddoAfter DSYEV('V'), pt2_matrix holds the eigenvectors. maxloc(...,DIM=1) returns, for each eigenvector (column), the row (state) of its largest component. The loop then uses that row index to pick an eigenvalue for state k: the eigenvector index and the state index are mixed. The transpose reading (state k → the eigenvector with the largest component on row k) is what the dimensions would call for. With N_states=2 (3x3 matrix) the two readings coincide often enough that 2-state runs are correct; with N_states=3 they do not.
Why the walk must actually run. With the flat state first, the guard at src/cipsi_utils/pt2_omp.irp.f:279 (N_det <= max(4,N_states) .or. pt2_N_teeth < 2) sends the whole run deterministic (WARNING: no comb can be built, no sample table), and all three PT2s are correct. The bug needs the stochastic path (comb buildable on the first state).
Controls.
- Duplicate-state control, all three states comb-buildable (states [2,3,2] of the same base): printed +14187.5 / -14147.8 / -0.39638 where -0.7869 is expected for both duplicated states. The failed comb build is not required; and a corrupted state's value can be small (~2x off), not only ~1e4.
- Same 3-state run with
do_diag = .False.forced (one-line toggle of the commented assignment atselection.irp.f:813): printed -0.78682(3) / -0.8656(3) / -0.81739625(0) — the healthy stochastic values, with state 3's fallback matching the deterministic one. This attributes the corruption to thedo_diagpost-processing. - In the corrupt run, the sample table's Variance/Norm² per state (2.6462/0.30354 and 2.667/0.3899) are bit-identical to the healthy 2-state run, and the generator blocks are identical; only PT2 moves. Variance and overlap are accumulated before the post-processing, so the error is confined to
e_pert.
Separate observation (not this defect). Failed apply_holes/apply_particles leave a stale determinant in place; the diag_H_mat_elem_fock fallback then yields an invalid e_pert that is still accumulated into pt2_data, and minilists behave as multisets.
No fix proposed here.
Activity
scemama commentedon Nov 26, 2026
Fix ready on two branches:
760b177a)ef086467, cherry-pick, identical hunk)The bug (as diagnosed in the issue): in
fill_buffer_$DOUBLE'sdo_diagblock, afterDSYEVthe eigenvectors sit inpt2_matrixby columns (column j = eigenvector ofeigvalues(j)). The old code tookiwork(j) = maxloc(pt2_matrix, DIM=1)— the dominant row of eigenvector j — and then usediwork(k)as an eigenvalue index for state k, mixing eigenvector and state indices. For N_states ≥ 3 a state can be assigned the external-determinant eigenvalue (≈Hii + E_shift − E0), giving the O(1e4) Ha values reported here. For N_states = 2 the two readings coincide when the dominant-row map is an involution, which is why 2-state runs looked healthy. The fix reads each row: state k takes the eigenvalue of the eigenvector whose largest component is in row k. One hunk, F90 only, no declaration change.Verification (Ampere, 3-state + 2-state matrix on both arms,
pt2with OMP_NUM_THREADS=1, QP_NTHREADS_PT2=2, pt2_relative_error=5e-2): fixture = 3-state, 3500-det, 128-MO wavefunction with state order (2,3,1) (the 3322-det fixture from this issue was not preserved as a standalone EZFIO; a truncated wavefunction at the same scale was reconstructed). Final per-state PT2, Ha:Buggy vs fixed stochastic agree with the deterministic run to 4.2e-4 Ha; Variance/Norm² of the buggy run match the fixed run to ~1e-14 (the walk is upstream of the corrupted post-processing, as noted here); the 2-state buggy control run is uncorrupted (−0.702037 / −0.664221), consistent with the bug needing N_states ≥ 3. Both arms agree to ~1e-8 on every value.
The "separate observation" in this issue (stale determinant after a failed
apply_holes/apply_particles, thediag_H_mat_elem_fockfallback still accumulating intopt2_data) is out of scope for this fix and will be tracked separately.cipsi: assign each state its own eigenvector's eigenvalue in do_diag
cipsi: assign each state its own eigenvector's eigenvalue in do_diag