The goal of this example is to explain the differing convergence behaviour of SCF algorithms depending on the choice of the mixing. For this we look at the eigenpairs of the Jacobian governing the SCF convergence, that is 1−αP−1ε†withε†=(1−χ0K).
KerkerMixing
, LdosMixing
)
and ε† is the dielectric operator.
We thus investigate the largest and smallest eigenvalues of (P−1ε†) and ε†. The ratio of largest to smallest eigenvalue of this operator is the condition number κ=λmaxλmin,
For our investigation we consider a crude aluminium setup:
using AtomsBuilder
using DFTK
system_Al = bulk(:Al; cubic=true) * (4, 1, 1)
FlexibleSystem(Al₁₆, periodicity = TTT): cell_vectors : [ 16.2 0 0; 0 4.05 0; 0 0 4.05]u"Å"
and we discretise:
using PseudoPotentialData
pseudopotentials = PseudoFamily("dojo.nc.sr.lda.v0_4_1.standard.upf")
model_Al = model_DFT(system_Al; functionals=LDA(), temperature=1e-3,
symmetries=false, pseudopotentials)
basis_Al = PlaneWaveBasis(model_Al; Ecut=7, kgrid=[1, 1, 1]);
On aluminium (a metal) already for moderate system sizes (like the 8 layers we consider here) the convergence without mixing / preconditioner is slow:
# Note: DFTK uses the self-adapting LdosMixing() by default, so to truly disable
# any preconditioning, we need to supply `mixing=SimpleMixing()` explicitly.
scfres_Al = self_consistent_field(basis_Al; tol=1e-12, mixing=SimpleMixing());
n Energy log10(ΔE) log10(Δρ) Diag Δtime --- --------------- --------- --------- ---- ------ 1 -36.73372409678 -0.88 11.0 480ms 2 -36.54927769127 + -0.73 -1.33 1.0 157ms 3 +61.16604959193 + 1.99 -0.06 22.0 379ms 4 -35.82323484490 1.99 -0.96 10.0 333ms 5 -25.75016816170 + 1.00 -0.54 5.0 185ms 6 -36.36466582549 1.03 -1.19 4.0 171ms 7 -36.69438399901 -0.48 -1.57 3.0 170ms 8 -36.71542333898 -1.68 -1.73 2.0 113ms 9 -36.73973626349 -1.61 -2.06 2.0 108ms 10 -36.73920968223 + -3.28 -2.06 3.0 131ms 11 -36.74133415779 -2.67 -2.28 2.0 110ms 12 -36.74137938893 -4.34 -2.30 2.0 118ms 13 -36.74152077867 -3.85 -2.42 1.0 99.0ms 14 -36.74221927551 -3.16 -2.62 1.0 98.8ms 15 -36.74132123693 + -3.05 -2.47 2.0 124ms 16 -36.73596244634 + -2.27 -2.11 3.0 174ms 17 -36.73736756507 -2.85 -2.21 3.0 157ms 18 -36.74144784101 -2.39 -2.53 3.0 146ms 19 -36.74150148859 -4.27 -2.50 3.0 147ms 20 -36.74244708404 -3.02 -2.94 2.0 118ms 21 -36.74247259177 -4.59 -3.09 2.0 136ms 22 -36.74251298891 -4.39 -3.68 2.0 117ms 23 -36.74251206447 + -6.03 -3.76 2.0 159ms 24 -36.74251434697 -5.64 -4.10 1.0 99.0ms 25 -36.74251450683 -6.80 -4.01 2.0 127ms 26 -36.74251455560 -7.31 -4.33 2.0 115ms 27 -36.74251474605 -6.72 -4.43 2.0 124ms 28 -36.74251453687 + -6.68 -4.36 2.0 127ms 29 -36.74251476405 -6.64 -4.97 2.0 117ms 30 -36.74251476752 -8.46 -5.13 3.0 147ms 31 -36.74251477028 -8.56 -5.20 3.0 178ms 32 -36.74251477111 -9.08 -5.33 1.0 95.7ms 33 -36.74251477251 -8.85 -5.66 2.0 117ms 34 -36.74251477235 + -9.79 -5.55 3.0 148ms 35 -36.74251477230 + -10.25 -5.56 3.0 139ms 36 -36.74251477302 -9.14 -6.29 2.0 117ms 37 -36.74251477290 + -9.91 -5.98 3.0 148ms 38 -36.74251477303 -9.89 -6.59 3.0 146ms 39 -36.74251477300 + -10.46 -6.15 3.0 176ms 40 -36.74251477303 -10.45 -6.60 3.0 135ms 41 -36.74251477304 -11.42 -6.98 2.0 117ms 42 -36.74251477304 -12.58 -7.06 3.0 147ms 43 -36.74251477304 -12.56 -7.12 1.0 98.3ms 44 -36.74251477304 -12.89 -7.36 2.0 117ms 45 -36.74251477304 -12.77 -7.77 1.0 98.4ms 46 -36.74251477304 + -12.87 -7.39 3.0 155ms 47 -36.74251477304 -13.30 -7.40 3.0 173ms 48 -36.74251477304 + -Inf -7.55 3.0 177ms 49 -36.74251477304 -13.15 -7.81 3.0 143ms 50 -36.74251477304 -13.67 -8.21 2.0 114ms 51 -36.74251477304 -14.15 -8.18 3.0 140ms 52 -36.74251477304 + -14.15 -8.16 2.0 115ms 53 -36.74251477304 + -Inf -8.22 3.0 123ms 54 -36.74251477304 -14.15 -8.28 2.0 149ms 55 -36.74251477304 + -Inf -8.90 1.0 99.3ms 56 -36.74251477304 + -Inf -8.68 3.0 156ms 57 -36.74251477304 + -Inf -8.67 2.0 119ms 58 -36.74251477304 + -Inf -9.29 2.0 117ms 59 -36.74251477304 + -13.85 -8.60 3.0 166ms 60 -36.74251477304 -14.15 -9.27 4.0 167ms 61 -36.74251477304 + -Inf -8.59 4.0 169ms 62 -36.74251477304 -14.15 -9.10 3.0 180ms 63 -36.74251477304 + -13.85 -9.24 2.0 129ms 64 -36.74251477304 -14.15 -10.09 2.0 114ms 65 -36.74251477304 -14.15 -9.70 4.0 176ms 66 -36.74251477304 + -13.85 -10.20 3.0 146ms 67 -36.74251477304 + -Inf -10.24 1.0 101ms 68 -36.74251477304 + -Inf -10.57 1.0 163ms 69 -36.74251477304 -14.15 -10.49 3.0 692ms 70 -36.74251477304 + -14.15 -10.76 2.0 115ms 71 -36.74251477304 + -Inf -10.80 2.0 115ms 72 -36.74251477304 -13.85 -10.98 2.0 108ms 73 -36.74251477304 + -13.85 -11.19 2.0 138ms 74 -36.74251477304 -13.85 -10.63 3.0 168ms 75 -36.74251477304 + -Inf -11.35 3.0 165ms 76 -36.74251477304 + -13.85 -11.02 3.0 161ms 77 -36.74251477304 -13.85 -11.74 3.0 159ms 78 -36.74251477304 + -14.15 -11.93 2.0 138ms 79 -36.74251477304 + -Inf -12.23 2.0 121ms
while when using the Kerker preconditioner it is much faster:
scfres_Al = self_consistent_field(basis_Al; tol=1e-12, mixing=KerkerMixing());
n Energy log10(ΔE) log10(Δρ) Diag Δtime --- --------------- --------- --------- ---- ------ 1 -36.73113129843 -0.88 11.0 412ms 2 -36.73922462098 -2.09 -1.36 1.0 657ms 3 -36.73897761884 + -3.61 -1.61 3.0 128ms 4 -36.74219400837 -2.49 -2.16 2.0 112ms 5 -36.74231044516 -3.93 -2.40 5.0 114ms 6 -36.74244084393 -3.88 -2.45 2.0 103ms 7 -36.74248499908 -4.36 -3.12 1.0 90.2ms 8 -36.74251177551 -4.57 -3.22 3.0 151ms 9 -36.74251295375 -5.93 -3.45 1.0 92.0ms 10 -36.74251418318 -5.91 -3.76 2.0 101ms 11 -36.74251471578 -6.27 -4.21 6.0 124ms 12 -36.74251476845 -7.28 -4.66 2.0 129ms 13 -36.74251476124 + -8.14 -4.66 2.0 107ms 14 -36.74251477267 -7.94 -5.35 1.0 96.0ms 15 -36.74251477297 -9.52 -5.53 3.0 140ms 16 -36.74251477301 -10.40 -5.71 2.0 98.3ms 17 -36.74251477292 + -10.04 -5.84 2.0 104ms 18 -36.74251477304 -9.95 -6.58 1.0 114ms 19 -36.74251477304 -12.10 -6.66 8.0 172ms 20 -36.74251477304 + -11.98 -6.82 1.0 95.9ms 21 -36.74251477304 -12.13 -7.08 2.0 131ms 22 -36.74251477304 -12.28 -7.57 2.0 106ms 23 -36.74251477304 + -14.15 -7.74 3.0 139ms 24 -36.74251477304 -14.15 -7.94 1.0 96.1ms 25 -36.74251477304 + -Inf -8.52 2.0 103ms 26 -36.74251477304 + -13.85 -8.41 3.0 143ms 27 -36.74251477304 -13.85 -8.65 1.0 112ms 28 -36.74251477304 + -13.85 -9.20 2.0 105ms 29 -36.74251477304 + -Inf -9.49 3.0 144ms 30 -36.74251477304 -13.85 -9.91 1.0 96.2ms 31 -36.74251477304 + -Inf -10.16 3.0 142ms 32 -36.74251477304 + -Inf -10.56 1.0 96.0ms 33 -36.74251477304 + -14.15 -10.86 2.0 111ms 34 -36.74251477304 + -Inf -11.31 3.0 128ms 35 -36.74251477304 + -Inf -11.36 2.0 131ms 36 -36.74251477304 -14.15 -11.80 2.0 104ms 37 -36.74251477304 + -14.15 -12.08 4.0 132ms
Given this scfres_Al
we construct functions representing
ε† and P−1:
# Function, which applies P^{-1} for the case of KerkerMixing
Pinv_Kerker(δρ) = DFTK.mix_density(KerkerMixing(), basis_Al, δρ)
# Function which applies ε† = 1 - χ0 K
function epsilon(δρ)
δV = apply_kernel(basis_Al, δρ; ρ=scfres_Al.ρ)
χ0δV = apply_χ0(scfres_Al, δV)
δρ - χ0δV
end
epsilon (generic function with 1 method)
With these functions available we can now compute the desired eigenvalues. For simplicity we only consider the first few largest ones.
using KrylovKit
λ_Simple, X_Simple = eigsolve(epsilon, randn(size(scfres_Al.ρ)), 3, :LM;
tol=1e-3, eager=true, verbosity=2)
λ_Simple_max = maximum(real.(λ_Simple))
┌ Info: Arnoldi eigsolve finished after 1 iterations: │ * 7 eigenvalues converged │ * norm of residuals = (8.18e-06, 2.11e-08, 6.48e-09, 1.67e-05, 9.36e-06, 2.68e-05, 2.73e-05) └ * number of operations = 15
44.02448779307413
The smallest eigenvalue is a bit more tricky to obtain, so we will just assume
λ_Simple_min = 0.952
0.952
This makes the condition number around 30:
cond_Simple = λ_Simple_max / λ_Simple_min
46.24420986667451
This does not sound large compared to the condition numbers you might know from linear systems.
However, this is sufficient to cause a notable slowdown, which would be even more pronounced if we did not use Anderson, since we also would need to drastically reduce the damping (try it!).
Having computed the eigenvalues of the dielectric matrix we can now also look at the eigenmodes, which are responsible for the bad convergence behaviour. The largest eigenmode for example:
using Statistics
using Plots
mode_xy = mean(real.(X_Simple[1]), dims=3)[:, :, 1, 1] # Average along z axis
heatmap(mode_xy', c=:RdBu_11, aspect_ratio=1, grid=false,
legend=false, clim=(-0.006, 0.006))
This mode can be physically interpreted as the reason why this SCF converges slowly. For example in this case it displays a displacement of electron density from the centre to the extremal parts of the unit cell. This phenomenon is called charge-sloshing.
We repeat the exercise for the Kerker-preconditioned dielectric operator:
λ_Kerker, X_Kerker = eigsolve(Pinv_Kerker ∘ epsilon,
randn(size(scfres_Al.ρ)), 3, :LM;
tol=1e-3, eager=true, verbosity=2)
mode_xy = mean(real.(X_Kerker[1]), dims=3)[:, :, 1, 1] # Average along z axis
heatmap(mode_xy', c=:RdBu_11, aspect_ratio=1, grid=false,
legend=false, clim=(-0.006, 0.006))
┌ Info: Arnoldi eigsolve finished after 1 iterations: │ * 3 eigenvalues converged │ * norm of residuals = (2.12e-04, 4.21e-04, 2.33e-04) └ * number of operations = 12
Clearly the charge-sloshing mode is no longer dominating.
The largest eigenvalue is now
maximum(real.(λ_Kerker))
4.7236110498662836
Since the smallest eigenvalue in this case remains of similar size (it is now
around 0.8), this implies that the conditioning improves noticeably when
KerkerMixing
is used.
Note: Since LdosMixing requires solving a linear system at each
application of P−1, determining the eigenvalues of
P−1ε† is slightly more expensive and thus not shown. The
results are similar to KerkerMixing
, however.
We could repeat the exercise for an insulating system (e.g. a Helium chain). In this case you would notice that the condition number without mixing is actually smaller than the condition number with Kerker mixing. In other words employing Kerker mixing makes the convergence worse. A closer investigation of the eigenvalues shows that Kerker mixing reduces the smallest eigenvalue of the dielectric operator this time, while keeping the largest value unchanged. Overall the conditioning thus workens.
Takeaways: