Skip to content

[BUG REPORT] Use per-root shift in the Davidson preconditioner #3398

Open

Description

@avanelst-ibm

The preconditioner shift in ‎pyscf/lib/linalg_helper.pymust be the eigenvalue estimate of the root currently being corrected (e[k]), not a fixed reference like the ground-state energy (e[0]). The diagonal preconditioner approximates the correction equation (H - e_k) t = -r_k for root k, so the shift is intrinsically tied to that root's own eigenvalue, not a free parameter. This PR corrects precond(xt[k], e[0], x0[k]) to precond(xt[k], e[k], x0[k]) so each root is corrected using its own shift.

Activity

  1. added a commit that references this issue on Aug 16, 2026
    62d9250
  2. JustinKyleKirkland commented on Aug 16, 2026

    @JustinKyleKirkland
    Contributor

    I implemented this and tested it fairly hard, and I want to report the result here rather than push the patch, because the uniform e[0] shift turns out to be load bearing in a way the correction equation argument does not capture. I opened #3402 for the change and have closed it in favor of this writeup.

    The report is right about convergence rate

    Preconditioning each root with its own shift does converge faster, consistently. Comparing two builds of linalg_helper.py differing only in that line:

    test set e[0] e[k]
    36 symmetric problems, 4 to 12 roots, well separated spectra 2181 products 1258 products, faster in 36/36
    36 symmetric problems, near-degenerate and strongly coupled 11524 products, 2 unconverged 11182 products, 1 unconverged, faster in 25/36
    20 non-symmetric problems via davidson_nosym1 641 products 410 products, faster in 20/20
    FCI N2/STO-3G, 4 roots 123 contractions 105 contractions
    EOM-EE-CCSD and EOM-IP-CCSD, 4 roots 36 and 27 products 35 and 26 products

    Eigenvalues agreed to convergence tolerance in all of those, so on the metric of "products needed to converge the roots you found", the per-root shift wins.

    But it changes which roots you find

    That metric assumes the solver converges to the correct lowest nroots in the first place. It does not always, and the shift is part of what decides. Running the full test suite gives 66 failures, 65 in pyscf/adc through davidson_nosym1 and 1 in pyscf/mcpdft through davidson1. Two of them are not tolerance noise, and they point in opposite directions.

    EA-ADC(2)-x on N2 / aug-cc-pVDZ, where the per-root shift is better. At nroots=8 both variants return the same spectrum. At nroots=4:

    nroots=4  e[0] shift: [0.09530653 0.12388331 0.13656938 0.13656938]
    nroots=4  e[k] shift: [0.08396417 0.09530653 0.12388331 0.13656938]
    nroots=8  both:       [0.08396417 0.08396417 0.09530653 0.12388331 0.13656938 0.13656938 0.18350472 0.21434253]
    

    The current solver misses the true lowest, doubly degenerate root at 0.08396 and returns roots 3 through 6. The value 0.0953 asserted as e[0] in pyscf/adc/test/test_radc/test_ea_N2.py::test_ea_adc2x is the third eigenvalue, not the first.

    CVS-IP-ADC(2)-x on the same system with ncvs=2, where the per-root shift is worse. Again both agree at nroots=6:

    nroots=3  e[0] shift: [15.10850838 15.11180785 15.7452561 ]   p = [1.516e+00 1.514e+00 3.0e-07]
    nroots=3  e[k] shift: [15.10850838 15.11180786 15.8470819 ]   p = [1.516e+00 1.514e+00 6.4e-03]
    nroots=6  both:       [15.10850838 15.11180786 15.7452561  15.7452561  15.82092866 15.82092866]
    

    Here the per-root shift returns 15.847 in third place, which is not among the lowest six at all, and reports it with nonzero intensity where the genuine third root is dark.

    Why I think this happens

    A uniform e[0] shift biases every correction vector toward the bottom of the spectrum, which acts as a crude regularizer keeping the block near the lowest roots. Per-root shifts make each correction more aggressive toward that root's own current estimate, which converges faster but lets the block drift off the lowest-nroots set when the spectrum is dense or degenerate and nroots is small. So the two shifts are optimizing different things: e[k] optimizes the rate at which the roots you have converge, e[0] optimizes the odds that the roots you have are the right ones.

    Separately, dgeev1 should keep e[0] regardless of what is decided for the other two. It solves A c = e B c but preconditions with diag(A) - e, modeling A - e*I rather than A - e_k*B, so a per-root shift amplifies that mismatch: over 20 random generalized problems at max_cycle=300, type=1 held at 20/20 converged while type=2 fell from 18/20 to 12/20. Making that solver per-root really means fixing its preconditioner first.

    Suggested resolution

    Given that a straight switch moves 66 reference values across two modules, and that at least one case selects a worse root set, this looks like a maintainer call rather than a patch. The option I would suggest is a __config__ toggle defaulting to the current behavior, in the style of the SORT_EIG_BY_SIMILARITY, PROJECT_OUT_CONV_EIGS and FOLLOW_STATE flags already at the top of that module, so that callers who know their spectrum is well separated can opt into the faster shift. I am happy to put that together if it would be useful, or to leave it here if the conclusion is that the current default is correct as is.

    Worth noting independently of the outcome: pyscf/tdscf/_lr_eig.py lines 201 and 429 carry the same precond(xk, e[0]) pattern, and pyscf/adc/test/test_radc/test_ea_N2.py::test_ea_adc2x appears to be asserting a spectrum that is missing its two lowest roots, which may be worth a look on its own.

  3. jeanwsr commented on Aug 16, 2026

    @jeanwsr
    Collaborator

    Adding an option for the shift looks good. And looks like some of the current ADC tests are wrong due to insufficient number of roots, they should be fixed.

  4. avanelst-ibm commented on Aug 16, 2026

    @avanelst-ibm
    Author

    Thanks for running such thorough experiments. I agree this could break down when roots are degenerate. A better approach might be to use the energy of the last converged root, similar to how it's done in the Dice solver. There, the algorithm tracks a single "active" root at a time, it follows one root, and once its residual drops below the convergence tolerance, the shift switches to target the next root's energy. You can see the implementation here: https://github.com/sanshar/Dice/blob/master/SHCI/Davidson.cpp

    One thing that might be interesting to add is a shift_mode parameter:

    shift_mode : {'ground', 'active', 'per_root'}

    to control which energy shift / Ritz value estimate is used in the diagonal preconditioner:

    • 'ground' (default): always use e[0] (the original shift).
    • 'active': use e[k0], where k0 is the index of the lowest root that has not yet converged in the current cycle. This is the strategy used in the Dice implementation of Davidson.
    • 'per_root': use each residual's own e[k].

    'ground' and 'active' are more conservative and robust to poor initialization and degenerate cases, while 'per_root' can converge significantly faster when the eigenvalues are well separated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions