Skip to content

Domain perturbation theory (new module domain_perturbation) - #431

Open
michelcaffarel-hub wants to merge 5 commits into
QuantumPackage:dev-stablefrom
michelcaffarel-hub:domain_perturbation
Open

michelcaffarel-hub wants to merge 5 commits into
QuantumPackage:dev-stablefrom
michelcaffarel-hub:domain_perturbation

Conversation

@michelcaffarel-hub

@michelcaffarel-hub michelcaffarel-hub commented Nov 25, 2026 •

Copy link
Copy Markdown

Domain perturbation theory (new module domain_perturbation)

New program domain_pert: perturbation theory derived from the Dyson equation with domains in the space of determinants, with the stored wave function as reference, for all the states, from order 2 to n_pert.

  • The reduced resolvent of the reference space is included, so the theory is complete for multideterminant references (it enters at order 4).

  • Orders are Rayleigh-Schrödinger orders: the Taylor expansions of the amplitudes in E - E_n are propagated with the walkers.

  • Stochastic evaluation with annihilation; n_walkers = 0 gives the exact sums for small systems.

  • Excited states are treated state by state (indefinite reduced resolvent, MINRES). No coupling between states.

  • Heat-bath sampling of the excitations (domain_heat_bath, default), which does not enumerate the connected determinants: needed for large systems.

  • Indexed on-the-fly evaluation of <l|H|Phi_n> (only the reference determinants that can be connected to l are visited): benzene with 6081 reference determinants, 210 s -> 85 s.

  • External determinants with a singular domain matrix are skipped with a warning.

  • Optional Chebyshev acceleration (domain_chebyshev): terms at the energy E_0+E_2, second order kept with weight 1, self-consistent energy; interval estimated from the moments or given by the user.

EZFIO parameters (domain_perturbation): n_pert, n_det_domain (maximum number of determinants in an external domain, 1 = singletons), n_walkers, n_replicas, exact_coupling, domain_heat_bath, domain_seed, domain_chebyshev, domain_cheb_auto, domain_cheb_min, domain_cheb_max; results domain_energy, domain_energy_error.

Validation

See the "Validation" section of src/domain_perturbation/README.rst. In short:

Test Result
H2O 6-31G all-electron, HF reference, singletons, orders 2-10 vs PySCF Epstein-Nesbet series < 6e-9 Ha
H2O STO-3G, FC, 31 dets, 3 states, orders 2-7, domains 1/4/20 vs dense code about 1e-8 Ha
H3 doublet cc-pVDZ, CIS reference, 3 states, orders 2-5, domains 1/6 vs dense code (QP integrals) 12 digits
E2, singletons, 110 dets vs EN PT2 of pt2 12 digits
Stochastic vs deterministic: 150 seeds x 20 replicas, 3 states, orders 2-7 no bias seen (largest deviation 2.1 sigma over 18 values); observed spread / quoted error between 0.87 and 1.17 (heat-bath mode)
Same seed with 1 and 20 threads identical to the displayed precision
Chebyshev, H2O 6-31G FC, HF reference, order 12 -76.119955298 (plain series -76.122465967, FCI -76.119955188)
Chebyshev, H2O 6-31G all-electron, 1089 dets, order 8 error 0.1 uHa (plain series 17 uHa)

New test: 50.domain_perturbation.bats (3 tests pass; run after 00.create.bats and the HF tests).

Known limitations

  • External domains are not spin-adapted; near-degenerate external determinants give large corrections (the smallest |H_jj - E_n| is printed).
  • For excited states the spectrum of the propagator can be complex: the Chebyshev series then diverges (third state of H3, CIS reference). A warning is printed.
  • On the small systems tested the stochastic mode can be slower than the exact one (1089 dets, order 8, 20 replicas of 1e6 walkers: 307 s against 47 s).
  • Deterministic mode with large domains is slow (OH cc-pVDZ, n_det_domain=4: 440 s).
  • Benzene cc-pVDZ FC, 1176 determinants, singletons: E2 agrees with the PT2 of pt2 within the error bars (1e-4 Ha); error 1.6e-3 Ha at order 3 in 8 minutes on 20 threads. The statistical error grows quickly with the order, and domains with more than one determinant are too slow to build for this system.
  • On AVX-512 machines, Fix infinite loop in get_excitation_degree_c with AVX-512 #432 (merged) is needed when N_int < 4.
  • The test suite of the other modules was not run.
  • The module contains one .f90 file, like cipsi_utils/selection_types.f90.

🤖 Generated with Claude Code

michelcaffarel-hub and others added 2 commits November 25, 2026 17:30
New program domain_pert: perturbation theory derived from the Dyson
equation with domains in the space of determinants, with the wave
function as reference, for all the states and up to order n_pert.
Stochastic evaluation with annihilation, exact evaluation for small
systems, and optional Chebyshev acceleration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* heat-bath sampling of the excitations (domain_heat_bath)
* with exact_coupling=False, the coupling vector is sampled for the first
  generation and its elements are computed on the fly for the scores
* better load balancing of the walkers of the reference space

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@scemama scemama left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Review — domain perturbation theory (new module domain_perturbation)

Reviewed on the Mini (macOS arm64, gfortran 16.2, config/gfortran_macos.cfg),
checked out on top of dev-stable 264d3e7, full ninja build: exit 0,
domain_pert links, OCaml tools rebuilt with the new EZFIO group.

The test suite 50.domain_perturbation.bats was reproduced in plain bash
(bats is not installed on the Mini): H3_2 HF ×2, H3_2 CIS 3 states ×3
(incl. Chebyshev), H4_1 HF ×2 exact + ×3 stochastic. As committed, the
suite cannot pass
— two blocking findings below.

Overall

Clean, well-structured addition that follows QP2 idioms (providers hoisted
before parallel regions, per-thread work arrays, the bitmask machinery reused
throughout). The sharded hash table with one OpenMP lock per shard is a sound
choice for the producer-consumer walker scheme, and the counter-based RNG with
per-chunk states gives reproducible, thread-independent streams — the right
choice for a stochastic method. Propagating Taylor jets of the amplitudes with
the walkers, and unifying the RS / BW / Chebyshev modes through the same
tables, is elegant. The README is exemplary: theory, validation against
independent codes, explicit limitations, programmer's view. MINRES with a
diagonal preconditioner for the indefinite reduced resolvent, state by state,
is the right tool.

Blocking findings

F1. The committed test reference values do not match the committed geometry

The bats test compares against hard-coded values
(e.g. H3_2 HF: -1.610273153311 at order 4, n_det_domain = 1), but
tests/input/h3_2.xyz (collinear H3, H at z = -0.74, 0, +0.74) has an HF
total energy of -0.302720866959 in cc-pvdz, as measured here. A
perturbative correction of -1.3 Ha is impossible, so the values cannot be the
PT expansion of this geometry. I also tried the classic equilateral H3 with
0.74 Å sides: order 4 gives -0.7142655, not -1.6102732. Corroborating: the
README says the CIS test uses a "CIS reference (30 determinants)", while the
committed geometry gives a 21-determinant CIS wave function. The 12-digit
values were evidently generated from a different (near-equilibrium) H3/H4
geometry. As committed, the test fails on any machine (measured: H3_2 HF →
NaN, H4_1 HF → 0.0063165 vs -2.0170464, CIS states off by 3.5 mHa to 5.2 Ha).
The reference values need to be regenerated from tests/input/h3_2.xyz /
h4_1.xyz — or the geometries fixed and documented.

F2. NaN when an external determinant is exactly degenerate with the state

On the committed (collinear) H3_2, there is an external determinant with
H_jj = E_0 exactly (mirror symmetry; the program prints
Smallest |H_jj - E_0| = 0.0). In domain_resolvent
(connected.irp.f:260-265), the singleton branch computes
g(1,0) = 1.d0/(hdiag - e_ref) with no guard: the division by zero produces
Inf/NaN which contaminates the energies (measured: E_2 finite, E_3 = NaN,
E_4 = NaN). The README's limitation note says such determinants "give large
corrections", but in practice the code returns NaN rather than a large
number. Suggestion: guard the denominator (a floor in the spirit of the 0.1 Ha
used in the MINRES preconditioner, or skip the determinant with a warning),
and consider the same for the nearly-singular dgetrf path
(connected.irp.f:276-278, which currently stops).

HPC opportunities (in decreasing order of expected impact)

H1. exact_coupling=True default forces exact enumeration and a large coupling table

domain_series.irp.f:230,183-199: with exact_coupling=True (the EZFIO
default), exact is forced even in stochastic mode: the coupling vector
v = Q H Phi_0 is obtained by full enumeration of the connected determinants
of every reference determinant, and stored in a dense table tv whose size is
the whole external space (the selector space of the pool, typically 10-100
times N_det). For a CIPSI pool of 10^4-10^5 determinants that is
10^6-10^7 entries, i.e. 10^2-10^3 MB (keys 32 B/entry with N_int = 2, plus
njet+1 doubles per entry, of which only order 0 is ever used — table_get
returns w(0,i)). The README says exact coupling is "possible only for small
systems", but there is no guard or warning. Suggestion: default
exact_coupling=False, or a loud warning / size estimate when it is combined
with a large pool.

H2. Per-step recomputation of each external domain and its factorization

domain_series.irp.f:82-124 calls domain_generation once per step
q = 0..n_pert-2; inside it, domain_build + domain_resolvent
(connected.irp.f:158-285) run for every external determinant j of the
table. But the domain of j (and the factorized nd×nd domain matrix A) depends
only on j, n_det_domain and the integrals — not on q. So the enumeration in
domain_connected, the build_fock_tmp call and the dgetrf are repeated
n_pert-1 times per replica for the same j. A cache persistent across the q
loop of domain_replica (keyed by j, storing the domain and the
factorization, or at least A and ipiv — e_ref is constant per state) would
remove a sizeable fraction of the per-step cost.

H3. The on-the-fly score recomputes <l|H|Phi_n> for every (j, l)

propagate.irp.f:311-322: with exact_coupling=False (the intended
large-system mode), for each external determinant j and each member l of its
domain, i_H_psi (slater_rules.irp.f:1035) is called — enumerating the
connections of l to the reference space plus a binary-search index lookup and
a matrix element per connection. But <l|H|Phi_n> depends only on l (and the
state), not on j, not on the step q, not on the replica; the same l recurs in
the domains of many j's, across steps. Suggestion: a per-state memo table
l → <l|H|Phi_n> (a det_table with njet = 0, or a plain hash), filled on
first need and reused for the whole state. This attacks the dominant
per-determinant cost of the large-system mode directly. (The in-tree
i_H_psi_minilist variant is not a substitute: it rebuilds the minilist of
each key on every call.)

H4. Reduced-resolvent MINRES: cold start per Taylor jet, no per-state statistics

reduced_resolvent.irp.f:169-188,71-153: domain_r0_jets performs
(njet+1) = (n_pert-2)/2+1 independent MINRES solves per call
(z_m = R(b_m - z_{m-1})), each started from z = 0, up to 1000 iterations,
each iteration being a full H_u_0_nstates_openmp matvec (the CIPSI H·u
cost). With n_pert = 10, n_replicas = 20: (n_pert-3) = 7 calls × 5 solves
per replica; each solve allocates 9 scratch arrays of N_det
(r1,r2,y,v,w,w1,w2,prec,q) and recomputes the preconditioner prec, which
is identical for all jets and steps of a state — hoist it. Levers, in order
of expected payoff:

  1. Warm start: the systems share the operator and the right-hand sides are
    related (b_m = d_m - z_{m-1}); starting MINRES from z_{m-1} should cut the
    iteration counts for m ≥ 1.
  2. Make the tolerance a parameter: the 1e-11 relative residual (:145) is
    far below the stochastic accuracy (quoted errors 1e-4..1e-3);
    1e-8..1e-9 would save iterations in stochastic mode.
  3. Report the iteration counts (per state, per order) to EZFIO: a non-
    converged solve currently only prints a warning to stdout (:148-150), so
    the user cannot tell which state/order stalled or how close it was.

The matvec itself reuses the CIPSI H·u (good); the transposes and
allocations in H_u_0_nstates_openmp are a small fraction of it.

H5. Per-thread work arrays sized by the global bound n_connected_max

propagate.irp.f:41,96,233,275-276: list(N_int,2,nlist) is allocated per
thread with nlist = n_connected_max — the worst-case number of connected
determinants over all determinants (connected.irp.f:3-29). For a large
active space (no = np = 50 per spin) that is ~10^6 entries, i.e.
150-300 MB of work arrays per thread (N_int = 2), while the actual connection
count of a given determinant is far smaller (and the 1e-12 threshold prunes
it further). The heat-bath path already uses nlist = 1 (:44), except in
domain_generation with domain_heat_bath and n_det_domain > 1
(:233-237), where the domain construction is still enumeration-based (the
README documents it as "too slow for large systems"); the array could be sized
from the actual no/nv of the determinant, which hb_prepare already computes,
or grown on demand. A silent RAM risk on 8 GB machines; a growable per-thread
list removes the ceiling.

H6. Shared hash table: per-thread tables would scale better

det_table_module.f90:121-150: every thread deposits into the shared table
under one omp lock per shard; shard_grow (:92-119) reallocates and
rehashes the whole shard under the lock. Deposit is the hottest operation of
the scheme; per-shard locks are the scalability ceiling. The standard fix:
per-thread tables (lock-free deposits, local growth) merged once at the end
of the generation. A deterministic merge order would also restore bit-exact
thread independence (point 1 below).

H7. diag_H_mat_elem computed twice per external determinant

propagate.irp.f:257 (importance pass, hd = diag - e_ref) and :299
(main loop): the same diag_H_mat_elem(key, N_int) — a Slater-rule diagonal,
O(mo_num) integral operations — is computed once in the importance pass and
again in the main loop. The importance pass already computes hd; store it
(a second array like imp) and reuse it. Trivial change.

H8. Heat-bath setup: two n⁴ integral passes, and a per-element ddot under Cholesky

heat_bath.irp.f:37-87 (hb_start, count) and :89-146 (hb_cum, fill)
each loop over all (ij)×(a,b) pairs calling get_two_e_integral — the
significant doubles are fetched twice; a single pass with per-pair dynamic
lists (the 1e-12 threshold leaves a small fraction of n⁴) would halve the
setup cost. More importantly, under do_ao_cholesky/do_mo_cholesky every
get_two_e_integral is a rank-R ddot (map_integrals.irp.f:250-266): the
setup becomes O(n⁴·R) scalar ddot's, cache-hostile and infeasible for large
systems. Two options: (a) document that the heat-bath mode wants the full MO
map (Cholesky off) and recommend it; (b) batch the (a,b) block of each (i,j)
pair as a GEMM over the Cholesky 3-index tensor (same flops, BLAS3
efficiency). Related: PROVIDE all_mo_integrals at the program level
(domain_pert.irp.f:15) forces the full MO integral map in memory (about
mo_num⁴ footprint) with no warning in the README.

H9. OMP schedule: per-determinant tasks with DYNAMIC(1)

propagate.irp.f:99,282: SCHEDULE(DYNAMIC,1) over one-external-determinant /
one-walker-chunk tasks. With ~10^6 tasks the per-iteration scheduling
overhead is not negligible, and chunk 1 gives poor granularity against the
per-task fixed costs (hb_prepare, domain_build, RNG warm-up). A chunk of
16-64 (the importance pass already uses DYNAMIC,4 at :254) should balance
better.

H10. Per-walker domain-membership test is a linear scan

propagate.irp.f:395-410 (domain_in_list), called per walker draw in the
heat-bath spawn path (:352) and per connected determinant (:362,377): a
linear scan comparing N_int×2 int8 words per domain member. Precompute
det_hash(dom_l) once per domain (nd cheap hashes) and reject with a single
int8 comparison before the full compare. Also: with n_det_domain = 1 the
domain is {j} and a drawn excitation is never j, so the call is pure overhead
— guard it with nd > 1.

H11. Per-replica allocation of (njet+1)×N_det arrays

domain_series.irp.f:69: d0, z, zphi are allocated (and zeroed) per
replica — n_replicas times (20 by default). For N_det = 10^6, njet = 4 that
is ~120 MB allocated and freed 20 times. Hoist the allocation to
domain_samples and pass it down. Trivial win.

H12. Structural opportunities (beyond this PR)

  • Multi-node: the module is OpenMP-only, while CIPSI distributes selection
    and PT2 over ZMQ (qp_run -s / qp_tunnel). A ZMQ slave for the walker
    generations (per-node table + global merge) would extend the method to the
    multi-node regime; the per-replica, per-chunk design is amenable.
  • GPU: the per-walker work (heat-bath draw + deposit) and the H·u matvec are
    the two natural kernel candidates (the gpu module / simple_gpu is already
    in the tree).
  • The Chebyshev mode is a real asset for large systems (0.1 µHa at order 8
    where the plain series gives 17 µHa, per the validation in the README) —
    worth keeping first-class.

Other points (robustness, documentation, portability)

  1. Bit-exact thread-independence. The per-walker RNG stream is
    thread-independent by construction (state = f(det_hash, seed, chunk)) —
    good. But table entries accumulate as s%w(:,i) = s%w(:,i) + w(:) under
    the lock (det_table_module.f90:143): the addition order depends on
    scheduling, so in deterministic mode (n_walkers = 0) the final energy is
    not bit-identical across thread counts, only close to display precision.
    The PR body's "identical with 1 and 20 threads" is better phrased
    "reproducible to displayed precision" (or verified at higher precision).
    A deterministic merge order (H6) would restore bit-exactness.
  2. Hard stop on a singular domain matrix (connected.irp.f:276-278):
    a nearly singular domain (external determinant nearly degenerate with the
    state — the documented limitation) aborts the whole run, including all
    other states. A warning + skip (or regularization) would be more robust
    (see F2).
  3. domain_hij_threshold is a hard-coded provider (1e-12), not an EZFIO
    keyword (connected.irp.f:31-38) — the integral screening cannot be tuned
    without a rebuild. It interacts with H8 (Cholesky roundoff ~1e-14×R may
    want a larger threshold). Consider an EZFIO parameter.
  4. domain_njet = max(2, domain_njet) in Chebyshev mode
    (propagate.irp.f:447): with n_pert < 6 the jet is silently widened to
    order 2 (cost impact). Worth a line in the README.
  5. README gaps: the all_mo_integrals memory footprint (H8) and the
    OpenMP-only / single-node scope.
  6. Minor: domain_spawn_d0 allocates the heat-bath per-thread arrays
    (pij, ptype, pcum, propagate.irp.f:97-98) even when the heat bath
    is not active; in inexact mode the coupling table tv
    (domain_series.irp.f:177) is allocated but never used.
  7. Test portability: the bats test uses qp reset -d, whose
    bin/qp_reset parses arguments with GNU getopt long options
    (getopt -o adhm -l all,dets,help,mos ...). macOS ships BSD getopt, which
    does not understand that syntax, and the test then fails with
    "EZIFIO directory not found" (reproduced here; works once GNU getopt from
    gnu-getopt is on PATH). Upstream CI (Linux) is unaffected, but the test
    cannot run as-is on a macOS box.

Things that look right (checked)

  • Exact mode (n_walkers = 0): exact enumeration, exact v table,
    Δ_2 = exact v^T s — consistent with the Epstein-Nesbet limit (the README
    validation against the pt2 program is the right check).
  • Jet propagation through the reduced resolvent, z_m = R(b_m - z_{m-1})
    (domain_r0_jets), matches the Dyson structure; the ordering in
    domain_replica (spawn the old z into the external part, then update z,
    domain_series.irp.f:110-119) is consistent step by step.
  • The reduced resolvent does not require the stored states to be complete:
    MINRES solves (e - PHP) z = q in the full reference space with the
    eigenvalue of state n replaced by -1 (domain_r0_matvec); near-
    degeneracies are clamped by the 0.1 Ha floor in the preconditioner (:96).
  • domain_build early-returns before building the Fock for
    n_det_domain = 1 (connected.irp.f:190); ties are broken by bit-string
    comparison (domain_lower), so the domain does not depend on the order of
    the determinants.
  • n_connected_max is a true global upper bound (singles + same-spin +
    opposite-spin doubles from the generator mask), so the pre-sized lists are
    safe.
  • The two-pass task counting in domain_spawn_d0 and the per-chunk seed
    offset are correct; the chunk random numbers depend only on the determinant
    and the chunk, as documented.
  • The jackknife error estimate includes the bias correction for products of
    averages of E_p (domain_series.irp.f:259-261,
    chebyshev.irp.f:201) — easy to miss, and it is there.
  • RELEASE_NOTES.org +1, NEED minimal (davidson_undressed, determinants,
    bitmask, mo_two_e_ints, hamiltonian) — both fine.

michelcaffarel-hub and others added 2 commits November 26, 2026 11:54
The elements of the coupling vector needed by the scores are computed by
visiting only the determinants of the reference which can be connected to
l (same beta string with doubly excited alpha strings, and alpha strings
at most singly excited), instead of a scan of the whole reference.
Benzene cc-pVDZ, 6081 determinants: 210 s -> 85 s, same results bit for
bit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* External determinants with a singular domain matrix (degenerate with the
  state) are skipped and counted, with a warning, instead of producing
  NaN or stopping (review F2).
* The test runs the SCF before the perturbation, so that it does not
  depend on the previous tests, and the tolerance of the deterministic
  test is 1e-5: the energies depend on the orbitals, e.g. on rotations of
  degenerate orbitals (review F1: the reference values are those obtained
  after the SCF of 10.hf.bats; without SCF E_0 = -0.3027 for H3_2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@scemama scemama left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Follow-up review — commits 3da8e16, 2c83ce7 (on top of the 2026-11-25 19:08 UTC review)

Rebuilt from the new head on the Mini (macOS arm64, gfortran 16.2,
config/gfortran_macos.cfg): full ninja PASS, including the new
h_phi.irp.f. The updated test suite was reproduced in plain bash (bats is
not installed on the Mini) with the same fixtures as last time.

F2 (singular domains) — fixed, well fixed

domain_resolvent now returns an ok flag: exact singularity (dgetrf
info ≠ 0, which used to be a hard stop) and near-singularity (any LU pivot
below 1e-8; for nd = 1, |H_jj − E_ref| < 1e-8) make the caller skip the
determinant, count it atomically in domain_n_singular, and the program
prints the count with a warning. Documented in the README. This is the right
shape of the fix. Two small residuals:

  • In deterministic mode (n_walkers = 0), skipping means the "exact" sum
    silently loses terms; the printed counter is the only signal. One line in
    the README ("in exact mode the result is then an approximation, with the
    number of dropped terms printed") would make that explicit.
  • domain_n_singular is a global provider accumulated over all states; the
    final warning is a global count, not per state. Cosmetic.

H3 (on-the-fly ⟨l|H|Φ_n⟩) — substantially addressed by h_phi.irp.f

The new domain_h_phi exploits the bilinear-matrix structure of the
reference (the same machinery the CIPSI selection uses): α-doubles (same β
string, α at Hamming distance exactly 4) are visited through
psi_bilinear_matrix_columns_loc, and everything else (at most a single per
spin, i.e. 0 < da+db ≤ 2 in excitation units, excluding (0,0)) through the
transposed rows. I checked the covered set: { (2,0), (1,0), (0,1), (1,1) }
is exactly the connection set of a 1+2-electron Hamiltonian; the two parts
are disjoint; i_H_j returns 0 for the not-actually-connected candidates.
domain_alpha_det (the O(N_det) index mapping) is computed once, domain_h_phi
is read-only over the shared providers, and all providers are hoisted above
the parallel region in domain_generation — clean. The per-candidate binary
search that i_H_psi performed is gone.

What remains: domain_generation is still called once per order step, so
domain_h_phi(l) is still re-evaluated for the same l at every q. A
per-state memo (l → value) would remove the last per-step repetition — the
same one-line idea as before, now worth less. Also, the part-2 outer scan is
O(N_det_alpha_unique) per l: negligible for an HF/CIS reference,
O(N_ref) per l for a large CIPSI reference (same asymptotic as before, no
regression).

F1 (test reference values) — withdrawn

The updated test runs the SCF to convergence first (the scf() helper,
n_it_scf_max 50, tolerance relaxed to 1e-5 with a comment that correctly
explains why: the perturbative energies depend on the orbitals, e.g. rotations
of degenerate orbitals, not only on E_HF). My earlier failure was not a
geometry/reference mismatch but unconverged orbitals in the fixture: the
qp create_ezfio SCF of 00.create.bats does not converge these
quasi-degenerate 3/4-center systems to the ground-state solution (I measured
E_0 = -0.3027209 for H3_2 instead of ≈ -1.6105 — a different SCF stationary
point — and comparable garbage for H4_1). Making the test self-contained is
the right fix.

The updated suite now passes end to end on the Mini (12/12, deterministic +
stochastic): H3_2 HF -1.6102726 / -1.6099589 (refs -1.6102732 / -1.6099594,
max diff 6e-7), H3_2 CIS 3 states to 4e-7 incl. Chebyshev, H4_1 HF
-2.017046423901 exact at displayed digits, stochastic runs within ~2.5 error
bars. Note that with converged orbitals the "Smallest |H_jj - E_0|" is
0.607 Ha (H3_2) and 0.086 Ha (H4_1) — the exact degeneracy behind my F2 NaN
was also an artifact of the wrong SCF root, so the skip is a genuine
robustness improvement rather than a fix for the committed test case.

Still open from the first review (untouched by these commits)

H1 (exact_coupling = True default), H2 (per-step domain_build/dgetrf
recomputation — the singular-domain skip does not remove it), H4 (cold-start
MINRES per Taylor jet, 1e-11 tolerance, no iteration statistics), H5
(n_connected_max-sized per-thread work arrays), H6 (shared table,
per-shard locks), H7 (diag_H_mat_elem computed twice), H8 (heat-bath
2×n⁴ integral passes, rank-R ddot under Cholesky), H9 (DYNAMIC(1)),
H10 (domain_in_list linear scan), H11 (per-replica N_det allocations),
H12 (multi-node/GPU outlook); robustness: bit-exact thread independence,
hard-coded domain_hij_threshold (and now domain_singular_threshold = 1e-8
in the same category — fine as a provider, but an EZFIO keyword would let the
user tune it), domain_njet = max(2, …) silent widening, README gaps
(all_mo_integrals footprint, OpenMP-only scope), and the BSD-getopt
portability of the bats test (it now calls qp reset --mos as well, same
issue on macOS).

Minor notes on the new code

  • The scf() helper's qp reset --mos before qp run scf is the right
    sequence (forces the AO→MO recompute); the tolerance comment is exactly
    what a future maintainer needs.
  • domain_beta_index lower-bounds on the (colliding) search key and then
    linear-scans for the exact string match — correct against hash collisions;
    the scan is O(1) in practice.
  • domain_n_singular warning wording ("Check the orbitals") is honest and
    helpful.

@michelcaffarel-hub

Copy link
Copy Markdown
Author

Thanks a lot for this very careful review. I pushed two commits (3da8e16, 2c83ce7).

F1 (reference values). The values are those of the regular test chain: h3_2.ezfio and h4_1.ezfio are created by 00.create.bats and their orbitals are converged by 10.hf.bats, whose reference energy for H3_2 is -1.558273529860, which is the E_0 of the test. Without the SCF step one gets exactly E_0 = -0.302720866959, the value you measured, and a determinant degenerate with the reference. The test now runs the SCF itself, so it no longer depends on the previous tests (checked from freshly created EZFIO directories). I also raised the tolerance of the deterministic test to 1e-5: rerunning the chain moves the order-4 energy of H3_2 by 5e-7, since the perturbative energies depend on the orbitals (rotations of degenerate orbitals of linear H3), not only on the HF energy.

F2 (NaN). Fixed: external determinants whose domain matrix has a pivot below 1e-8 are skipped and counted, with a warning that suggests checking the orbitals, instead of producing NaN or stopping.

H3. Done differently from the memo you suggest: <l|H|Phi_n> is now evaluated by visiting only the reference determinants that can be connected to l (same beta string for doubly excited alpha strings, scan of the alpha strings at most singly excited). On average only about 4 reference determinants are connected to an external one (benzene, 6081 determinants), and the run time went from 210 s to 85 s with bit-identical results. A memo table could still help on top of that.

Thread independence (point 1). Agreed: the stochastic streams are thread independent, but the accumulation order is not; I changed the PR description to "identical to the displayed precision".

The other suggestions (H1, H2, H4–H11 and the README points) are good; I will look at them, starting with the cheap ones (H7, H10, H11, the MINRES preconditioner and warm start).

* Without Chebyshev acceleration and for n_pert >= 4, the renormalized
  series E_n + rPT_p is printed, with
  rPT_p = sum_q Delta_q(E_n) / (1 - sum_q Delta_q'(E_n)), the
  self-consistent equation linearized around E_n (jackknife errors).
  For p = 2 and singletons it reproduces the rPT2 of the CIPSI programs
  (2e-8 Ha on H2O cc-pVDZ, 1407 determinants).
* New keyword domain_minres_tol (default 1e-8, was a hard-coded 1e-11)
  for the minimal residual method applying the reduced resolvent; the
  number of solutions and of iterations is printed for each state
  (review H4). Benzene cc-pVDZ, 20530 determinants: 18 -> 13 iterations,
  energies changed by 1e-11 Ha.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@scemama scemama left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Follow-up review — commit b8ead39 (renormalized series rPTn, MINRES tolerance)

On top of the 2026-11-26 review (which covered up to 2c83ce7). Rebuilt on
the Mini (macOS arm64, gfortran 16.2): full ninja PASS; the 12-test matrix
reproduced in plain bash, plus new cross-checks of the rPT values against
the pt2 and fci (CIPSI) programs in the same tree.

H4 (MINRES) — points 2 and 3 addressed

  • The tolerance is now the EZFIO keyword domain_minres_tol (default 1e-8,
    previously hard-coded 1e-11); the doc line states honestly that the
    resulting error is below the statistical one.
  • Per-state statistics in domain_minres_stat (number of solves, total and
    maximum iterations), reset per state in the driver and printed as
    "MINRES (reduced resolvent): N solutions, iterations: mean X, max Y". A
    solve that reaches itmax = 1000 is now visible from the output. Measured
    on the test matrix: the 3-state CIS runs (n_pert = 5) solve 4 reduced
    resolvent systems per state (n_pert−3 jet updates × (njet+1) jets), with
    mean 9.2–10.8 and max 10–11 iterations; the Chebyshev run (n_pert = 10)
    35 systems, mean 9.7–11.6, max 12. No solve is printed for the
    1-determinant references, where the reduced resolvent vanishes on the
    relevant subspace. Nothing is close to itmax.
  • What remains of H4: warm starts between the Taylor-jet solves (the
    right-hand sides are related, b_m = d_m − z_{m−1}), and the per-solve
    preconditioner recomputation plus the 9 scratch arrays of N_det.

New feature: the renormalized series rPTp — checked

domain_rpt_energies computes rPT_p = Σ_{q=2..p} Δ_q,0 / (1 − Σ Δ_q,1),
one Newton step of the self-consistent equation E = E_0 + Σ_q Δ_q(E). I
verified the structure: for p = 2, Δ_2,1 = −‖ψ_1‖_2, so
rPT_2 = Δ_2 / (1 + ‖ψ_1‖_2) — the rPT2 of the CIPSI programs, as the
README now states.

Numerical cross-check in this tree (H3_2, cc-pvdz, converged SCF,
n_det_domain = 1, n_pert = 4), against the pt2 program on the same EZFIO
directory (independent Slater-rule implementation, stochastic PT2 with
~1e-3 relative error):

quantity pt2 program domain_pert diff.
Δ_2 = E_2 -0.056940935 -0.057009552 6.9e-5 Ha
‖ψ_1‖_2 (overlap) 0.031420234 0.0315180 (derived) 1.0e-4
E_0 + rPT_2 -1.6134798683914386 -1.613541157057 6.1e-5 Ha

The differences are within the stochastic error of the pt2 program, so
the formula, the sign conventions and the jet bookkeeping are all
confirmed. (The fci CIPSI run on the same system gives
E + rPT2 = -1.6100315329431103, which is not comparable — it is
renormalized around the 473-determinant CIPSI pool, not the HF
determinant.)

Two further observations from the same runs:

  • The fci CIPSI state energy is -1.610031316671576, which reproduces the
    Chebyshev reference value of the bats test (-1.610031316672) to 1e-9 —
    an independent confirmation of the test chain's reference values.
  • The stochastic matrix results are bit-identical to the previous run
    (2c83ce7), so the code change left the RNG streams untouched, as
    advertised.

The rest of the implementation is consistent: jackknife error over the
replicas with per-replica rPT values and the same bias correction as E_p;
gated on n_pert ≥ 4 (njet ≥ 1) and RS mode only; zeroed otherwise; the
README documents the series and the p = 2 case. Three small points:

  • No guard on the denominator 1 − Σ Δ_q,1: for an excited state close to
    a level coalescence the rPT values can blow up or change sign silently
    (the self-consistent equation then has its solution moving). The three
    CIS test states are well behaved (rPT_5: -1.3115719 / -1.2064807 vs the
    RS sums -1.3118154 / -1.2066774, same limiting region, no divergence),
    but a warning when 1 − Σ Δ_q,1 is small or negative would make the
    output self-explanatory in the cases that matter.
  • The rPT values are printed but not written to EZFIO, so scripts cannot
    read them (the RS energies go through domain_energy). Minor.
  • The new feature is not exercised by the bats tests (they compare
    domain_energy, i.e. the RS series). A reference line or two for
    E_0 + rPT_2 would lock the feature in.

The promised cheap items (H7, H10, H11) are not in yet

The 13:46 comment announced "starting with the cheap ones (H7, H10, H11,
the MINRES preconditioner and warm start)"; this commit covers the MINRES
tolerance and statistics part. H7 (double diag_H_mat_elem),
H10 (domain_in_list linear scan), H11 (per-replica allocations) are
unchanged, as are H1, H2, the MINRES warm start, H5–H6 and H8–H9.

Test results

12/12 PASS, same reference values as before (the suite is unchanged). The
RS energies are identical at all displayed digits despite the MINRES
tolerance moving 1e-11 → 1e-8 (H3_2 HF d=1: -1.61027262070914; H4_1 HF
d=1: -2.017046423901, exact). The rPT table is printed for every RS run
with n_pert ≥ 4.

This branch has not been deployed

No deployments
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.

2 participants