You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG REPORT] Use per-root shift in the Davidson preconditioner #3398
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.
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:
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:
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.
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.
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.
Activity
Use the per-root eigenvalue as the Davidson preconditioner shift
JustinKyleKirkland commentedon Aug 16, 2026
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.pydiffering only in that line:e[0]e[k]davidson_nosym1Eigenvalues 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
nrootsin the first place. It does not always, and the shift is part of what decides. Running the full test suite gives 66 failures, 65 inpyscf/adcthroughdavidson_nosym1and 1 inpyscf/mcpdftthroughdavidson1. 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=8both variants return the same spectrum. Atnroots=4: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]inpyscf/adc/test/test_radc/test_ea_N2.py::test_ea_adc2xis 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 atnroots=6: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-nrootsset when the spectrum is dense or degenerate andnrootsis 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,
dgeev1should keepe[0]regardless of what is decided for the other two. It solvesA c = e B cbut preconditions withdiag(A) - e, modelingA - e*Irather thanA - e_k*B, so a per-root shift amplifies that mismatch: over 20 random generalized problems atmax_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 theSORT_EIG_BY_SIMILARITY,PROJECT_OUT_CONV_EIGSandFOLLOW_STATEflags 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.pylines 201 and 429 carry the sameprecond(xk, e[0])pattern, andpyscf/adc/test/test_radc/test_ea_N2.py::test_ea_adc2xappears to be asserting a spectrum that is missing its two lowest roots, which may be worth a look on its own.jeanwsr commentedon Aug 16, 2026
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.
avanelst-ibm commentedon Aug 16, 2026
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_modeparameter:to control which energy shift / Ritz value estimate is used in the diagonal preconditioner:
'ground'(default): always usee[0](the original shift).'active': usee[k0], wherek0is 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 owne[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.