Density noise: mix the perturbed states per quantum number

Aperta
#73 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp, hpc, python

Direzione di ricerca

Start with mix_noise_density in src/qops/renorm_bs.cpp, then read NoiseSource in include/qops/renorm_bs.hpp and the tuning paths in include/qops/config.hpp, src/qops/config.cpp, and src/qops/bindings_qops.cpp. Implement and verify the mode 2 behavior in both host and device paths, including deterministic results, conserved (N, 2Sz), and the specified density trace; run the noise tests in tests/python. Compare results at one and two MPI ranks before choosing how to combine channels.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

🤖 AI text below 🤖

Carries forward the plan of #66, which is closed in favour of this issue. Related: #15, #24, #65.

Where it stands

  • Cost. #66 measured the density half of the noise on the host at 22-54 % of a noisy sweep
    (H16/H24 STO-3G). Since cea717f the noise channels' transforms and densities run as device GEMM
    batches (same switch as the decimation's density build, DMRG_QOPS_GPU_DENSE). Measure again
    before deciding anything on cost.
  • Quality, the open part. Over 25 cell/bond-dimension pairs with FCI references, our density
    noise (noise_jitter=0) ended more than 0.1 mHa worse than its noiseless run in 7 cases, block2's
    ReducedPerturbativeCollected in 2. The per-quantum-number mix below is the proposed fix.
  • noise_jitter from #24 runs the density half alone, which is what the A/B below needs.
  • Step 2 now has to go into both paths of mix_noise_density (src/qops/renorm_bs.cpp): the host
    channels and the device batches.
  • Spin-adapted runs (sym='su2') have no noise yet.
  • The jitter half has its own proposed fix in #24 (jitter only a solve that accepted its guess in
    one Davidson iteration); it is separate from this plan.
How today's density half differs (from #66)
  • Operators. Ours are the old block's operators (cre/des, S, A, B, H), with the dot index untouched. The reference applies the operators of the enlarged block (block ⊗ dot).
  • How channels combine. Ours builds one density per operator. The reference first sums the perturbed states that share a quantum number (at most 13 in SZ) and builds one density each.
  • Scaling. Ours scales the whole sum once to λ·tr ρ, so large operators (H, the integral-weighted S) dominate. The reference normalizes each perturbed state first, then the set.
Plan (from #66)
  1. The switch. Add a noise_density tuning key and DMRG_NOISE_DENSITY env var next to noise_jitter (include/qops/config.hpp, src/qops/config.cpp, apply_tuning in src/qops/bindings_qops.cpp). Values:

    • −1/1: today's per-operator mix (the default);
    • 2: the per-quantum-number mix;
    • 0: density half off, which allows a jitter-only run and completes the A/B.

    Carry the mode in NoiseSource (include/qops/renorm_bs.hpp), set where noise_ops fills it (src/qops/dmrg_qops.cpp, sys and env decimation). Document it in docs/api.md.

  2. Per-quantum-number mix, in mix_noise_density (src/qops/renorm_bs.cpp).

    • Keep the per-operator transform w = (O ⊗ 1)Ψ.
    • Add w into one perturbed state per ΔQ = q(bra sector) − q(ket sector), keyed by (ΔQ, dot index, row start, column start).
    • Normalize each state, then scale the set to λ·⟨Ψ|Ψ⟩.
    • Build the ≤13 densities with the existing sector-grouped accumulation.

    That cuts the density builds from one per operator to at most 13; the transforms stay one per operator. Keep it deterministic: fixed operator and ΔQ order, and the same parallel pattern.

    Open for MPI: the channels are split by owner. Either reduce the densities as now, which makes the result depend on the rank count, or allreduce the ≤13 states, which is rank-independent and moves about 13×|Ψ| per bond. Decide after np=1 vs np=2.

  3. Enlarged-block operators, only if 1-2 leave a gap to the reference. Add the dot's own operators and the block × dot terms. grow_renorm_bs already builds them in dot-transfer-block form O_ab (include/qops/qops.hpp). Apply them to Ψ's dot slices instead of projecting them.

  4. Optional: move the noise transforms and densities to the GPU. Done on main (cea717f): the per-operator transforms and sector densities run as device GEMM batches.

Tests and benchmark (from #66)

Tests, in tests/python:

  • noise_density=1 is bit-identical to today.
  • noise_density=0 with noise_jitter=0 is bit-identical to the noiseless run.
  • noise_density=2 is bit-identical at 1/4/8 threads, stays in the target (N, 2Sz), and the added density has trace λ·tr ρ.
  • The existing noise gates stay green.

The benchmark is not a gate and goes to #65. It reruns the 25-pair table above (cold and CISD starts, noise_density 0/1/2 × jitter on/off) and the H16/H24 cost. The scheme is worth keeping if:

  • mode 2 is worse than noiseless no more often than the reference;
  • dec/noise drops by roughly the operator count over 13 on its density part;
  • the H24 noisy sweep comes clearly closer to a quiet one.

Refs #15, #24, #65.

The noise mechanisms note (noise-mechanisms.md from #24/#66, moved out of the repository)

The two noise mechanisms, and how they compare to block2

Written 2026-08-27 while investigating issue #15. Companion to the noise_jitter switch added in
PR #24. Read this before changing anything about noise.

Summary

A noise sweep in this engine perturbs the run in two independent places. They are not two
versions of the same idea. They fix different problems, and only one of them exists in block2's
default settings.

half what it does block2 name in block2 by default?
density enrichment mixes extra directions into the density matrix, so different states survive truncation Perturbative yes
guess jitter adds small offsets to the Davidson starting guess, so the solve moves Wavefunction no

The density half is White's density-matrix perturbation. The jitter is not.

Issue #15 is caused by the jitter. Every escape the noise feature buys is also caused by the
jitter. That is the whole tension.

What the two halves are, in this code

Density enrichment — mix_noise_density, src/qops/renorm_bs.cpp:305. Before each
decimation:

rho  <-  rho + lambda * sum_O (O Psi)(O Psi)^T / trace

O runs over the operators of the block being absorbed: cre, des, S, A, B, H
(collected in noise_ops, src/qops/dmrg_qops.cpp:2145). These are the operators that live at
the bond, so the injected directions point along directions the Hamiltonian actually couples.

It has the form of White's 2005 correction and of block2's perturbative noise, but it is not the
same scheme. Three differences, read from both codes:

  • Operators. Ours are the old block's, and the dot index is left untouched. White's are the
    system block's operators in H = Σ A_i ⊗ B_i, and block2 applies its MPO's left operators on
    the enlarged block (block ⊗ dot).
  • How channels combine. Ours builds one density per operator. block2's default (Reduced)
    first sums the perturbed states that share a quantum number, at most 13 in SZ, and builds one
    density each.
  • Scaling. Ours scales the whole sum once to λ·tr ρ, so the large operators (H, the
    integral-weighted S) dominate. block2 normalizes each perturbed state first, then the set.

The cost differs with the second point: one density build per operator here, at most 13 there.

Guess jitter — solve_bond, src/qops/dmrg_qops.cpp:760. After the transported guess is
canonicalized and before the Davidson runs, every element of every existing block gets a
hash-derived offset scaled to lambda times the guess norm.

It only writes into blocks that already exist, so N and 2Sz are strictly conserved. It is not
"off-symmetry" noise. What it does not conserve is S-squared, and in this engine nothing else does
either — the sector is (N, 2Sz) only, by design. That is how a schedule can walk a singlet run
into a quintet.

How they map to block2 and to White

block2's NoiseTypes enum (read from the installed pyblock2):

Wavefunction    1     random noise on the wavefunction
DensityMatrix   2     random noise on the density matrix
Perturbative    4     White's perturbative noise
Reduced         8     |
Unscaled       16     |  evaluation and memory variants of Perturbative,
Collected      32     |  same underlying math
LowMem         64     |
MidMem        128     |

pyblock2/driver/core.py:4622 sets the default when the caller does not:

if noise_type is None:
    noise_type = "ReducedPerturbativeCollected"

So block2's default is a density perturbation, and nothing else. Wavefunction noise exists there
but is not switched on unless you ask for it. It is not quite our jitter either: it perturbs the
solved state before the split, with norm √noise, where ours perturbs the Davidson guess before
the solve, with norm about λ/√3.

tuning={'noise_jitter': 0} runs our density half alone. That is the same kind of mechanism as
block2's default, not the same one (see above), and they do not behave the same:

density noise vs its own noiseless run, 25 cell/M pairs worse better worst
ours, cold start 7 5 +42.5 mHa
ours, ci_guess='cisd' 5 3 +9.4 mHa
block2 default, SZ 2 8 +0.65 mHa

Exact FCI references, the schedule below, 30 sweeps, a change of more than 0.1 mHa counted
(2026-09-25, on this tree). Ours also costs more: 40-54% of a noisy sweep on H24 at M = 1000.
The follow-up is the density-noise PR.

What we measured

All runs single-threaded, fixed integrals, on a busy box (correctness numbers only, no timings).
Probes are in the gitignored local/: probe_noise_jitter_ab.py and
probe_noise_jitter_escape.py.

The bug cell — N2/cc-pVDZ CAS(10,10) at r = 2.0, M = 64, plain compute(), schedule
[1e-3]*4 + [1e-4]*2 + [1e-5]*2:

run E - E(exact) S^2 sweeps
no noise +3.365e-03 0.00 19, converged
both halves +2.929e-02 6.00 28, converged
density only +4.498e-03 0.00 30, not converged
density only, repeated same bits 0.00
jitter forced on +2.929e-02 6.00 same as default

The cells the feature was written for (issue #5):

cell no noise both halves density only
OH 6-31G CAS(6,7), bd 16 / 24 / 40 +2.641e-03, stuck reaches CASCI +2.641e-03, same as no noise
OH, bd 32 / 48 (already fine) CASCI CASCI CASCI
OH, bd 12 +1.696e-01, third eigenstate +3.3e-05 +1.696e-01, same as no noise
O2 STO-3G CAS(8,6), bd 8 +2.211e-01, second eigenstate +2.9e-03 +2.211e-01, same as no noise

Measured on main 552ef65 plus this branch (2026-09-24). The trapped OH rungs moved since #5:
bd 24 now traps and bd 32 does not.

On the trapped cells the density half matches the no-noise run (to 5e-10 at bd 12, which
truncates). It does nothing at all. A truncated cell such as N2 STO-3G bd 8 is not in this table:
there the schedule lands above or below the no-noise run depending on the orbital order and the
integral bytes (#15).

Why the density half cannot fix the OH trap

The OH trap has dw = 0. Nothing is discarded, so the kept basis is already the complete one.

A density-side noise can only change which states survive truncation. Where nothing is
truncated, there is nothing for it to change. The kept set is the same set with or without it, so
the run is identical.

This is not an implementation gap and it is not fixable by copying block2 more closely. It is what
a density-side noise is.

The consequence: the two halves cover different failure modes, and neither covers both.

truncation active lossless bond (dw = 0)
density (White / block2) works — changes what is kept powerless
jitter (wavefunction side) works, and also picks a basin — the #15 bug the only thing that can move the solve

Prediction, not yet measured: block2 with its default noise cannot escape the OH trap either.
Worth running, because the issue's cross-check only ever ran block2 on the cell where our noise
misbehaves — never on the cells where our noise is the thing that works.

What block2 does when a run is stuck

  1. Spin adaptation (SU2), its default. A wrong-spin fixed point is unreachable, so the worst
    version of this problem cannot happen. We cannot copy this: SZ only, by design.
  2. NoiseTypes.Wavefunction. The same idea as our jitter. Available, not default.
  3. Bond-dimension ramps with noise schedules. Standard practice, and it works while truncation
    is still active.
  4. A random or different starting MPS. Re-rolls the basin rather than escaping it.
  5. Orbital reordering. Changes the landscape so the trap may not exist in the new ordering. We
    have this too.

So block2's practical answer to "stuck" is mostly to make the wrong-spin case impossible up front,
plus re-rolling the start. It has no better escape than ours for a lossless trap. It has a stronger
constraint that stops the bad case from arising.

That is the reason the fix here is not "become more like block2". The jitter does something their
default cannot do. It just needs to stop firing when it is not needed.

Options

  1. Gate the jitter on a stalled solve. Apply it only when the Davidson finished in one
    iteration, which means it accepted the transported guess unchanged. That is exactly the
    lossless-trap case, and it excludes every solve that was already moving — which is where the
    basin flipping happens. Both Davidson paths already report the iteration count
    (g_bond_dav_iters, gpu_davidson_last_iters()) and both already share the residual across
    ranks, so the decision is safe under MPI.
  2. Make the jitter multiplicative. v += amp * |v| * xi instead of v += amp * xi. It still
    breaks a zero residual, but it cannot put weight into a configuration that has none, so it
    cannot manufacture quintet character. One-line change, easy to compare against option 1.
  3. Keep-the-best guard. Noise makes a run non-monotonic. Remembering the best clean sweep would
    have made issue #15 report +3.4e-03 instead of +2.9e-02, whatever the noise did along the way.
    Generic protection, independent of which noise is used.
  4. S-squared penalty — checked and parked. It cannot be folded into the integrals: the
    S+ S- terms are not spin-diagonal per index, so g2e_ab cannot express them. It needs a real
    S-squared operator inside the engine. Out of proportion to the problem for now.

Open experiments

  • block2 on our trapped cells. Partly measured (2026-09-25). block2 starts from a random
    MPS, and that start does not fall into the O2 bd 8 or OH bd 12 traps at all (0.000 and
    +0.035 mHa noiseless). On OH bd 8 its default noise stays near the trap (+2.749 → +2.723 mHa)
    where our jitter escapes (+0.084). The OH band (bd 16 / 24 / 40) is not run yet.
  • Noise against different starting points. Measured for the cold start, ci_guess='cisd'
    and a random dense CI vector (2026-09-25, same 25 pairs as the table above). Noiseless runs
    ending more than 10 mHa above the best run: CISD 1, cold 9, random CI 12. CISD removes the
    traps: O2 bd 8 +221.081 → 0.000, OH bd 12 +169.593 → +0.011, and #15's quintet (a singlet at
    +10.6 / +3.4 mHa at M = 32 / 64). The guess that a CISD trial could be more trap-prone was
    wrong on these cells. project() and restart() are not in this run.

Status

  • The switch exists: DMRG_NOISE_JITTER / tuning={'noise_jitter': 0}. Default unchanged, both
    halves on. See the gate table in docs/api.md.
  • Container suite: 87/87 with the switch in place.
  • No fix yet. Issue #15 stays open.
Lingua principale
C++
Stelle
3
Fork
0
Merge medio
2g 8h
PR unite (30g)
31

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Algorithmiq/exa-dmrg

Tutte le issue di Algorithmiq/exa-dmrg

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.