Analysing SCF convergence
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} \varepsilon^\dagger \qquad \text{with} \qquad \varepsilon^\dagger = (1-\chi_0 K).\]
where $α$ is the damping $P^{-1}$ is the mixing preconditioner (e.g. KerkerMixing
, LdosMixing
) and $\varepsilon^\dagger$ is the dielectric operator.
We thus investigate the largest and smallest eigenvalues of $(P^{-1} \varepsilon^\dagger)$ and $\varepsilon^\dagger$. The ratio of largest to smallest eigenvalue of this operator is the condition number
\[\kappa = \frac{\lambda_\text{max}}{\lambda_\text{min}},\]
which can be related to the rate of convergence of the SCF. The smaller the condition number, the faster the convergence. For more details on SCF methods, see Self-consistent field methods.
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.73133031618 -0.88 13.0 335ms
2 -36.42009523858 + -0.51 -1.24 1.0 84.3ms
3 +118.2191351500 + 2.19 0.04 20.0 331ms
4 -34.74806639702 2.18 -0.79 11.0 286ms
5 -28.63622804896 + 0.79 -0.59 4.0 163ms
6 -33.22547826755 0.66 -0.75 5.0 157ms
7 -36.67017599734 0.54 -1.49 4.0 144ms
8 -36.71859963174 -1.31 -1.61 2.0 114ms
9 -36.73921804473 -1.69 -1.88 2.0 107ms
10 -36.74069048726 -2.83 -2.07 1.0 91.8ms
11 -36.73471810230 + -2.22 -1.99 2.0 116ms
12 -36.74090047777 -2.21 -2.32 1.0 89.7ms
13 -36.74192953116 -2.99 -2.49 2.0 101ms
14 -36.74218846349 -3.59 -2.65 2.0 102ms
15 -36.73957423706 + -2.58 -2.27 3.0 124ms
16 -36.73216941270 + -2.13 -2.03 3.0 138ms
17 -36.73956914099 -2.13 -2.31 3.0 131ms
18 -36.73837231744 + -2.92 -2.25 3.0 272ms
19 -36.74222260588 -2.41 -2.80 3.0 723ms
20 -36.74247358960 -3.60 -3.40 2.0 105ms
21 -36.74246821350 + -5.27 -3.22 2.0 124ms
22 -36.74246667769 + -5.81 -3.44 2.0 117ms
23 -36.74247988153 -4.88 -3.94 2.0 110ms
24 -36.74247877965 + -5.96 -3.75 3.0 156ms
25 -36.74248015523 -5.86 -4.11 2.0 105ms
26 -36.74248028094 -6.90 -4.20 1.0 90.1ms
27 -36.74248057966 -6.52 -4.49 1.0 90.5ms
28 -36.74248013804 + -6.35 -4.16 3.0 141ms
29 -36.74248062439 -6.31 -4.71 3.0 123ms
30 -36.74248066718 -7.37 -5.05 2.0 101ms
31 -36.74248065509 + -7.92 -4.90 2.0 122ms
32 -36.74248067161 -7.78 -5.43 2.0 107ms
33 -36.74248067259 -9.01 -5.83 1.0 90.2ms
34 -36.74248067253 + -10.22 -5.83 3.0 134ms
35 -36.74248067264 -9.96 -6.13 2.0 109ms
36 -36.74248067268 -10.34 -6.60 2.0 105ms
37 -36.74248067266 + -10.76 -6.28 3.0 136ms
38 -36.74248067268 -10.75 -6.59 3.0 123ms
39 -36.74248067263 + -10.33 -6.20 3.0 132ms
40 -36.74248067268 -10.33 -6.86 3.0 131ms
41 -36.74248067268 -12.66 -7.02 2.0 108ms
42 -36.74248067267 + -11.07 -6.57 3.0 129ms
43 -36.74248067268 -11.28 -6.77 3.0 142ms
44 -36.74248067268 -11.43 -7.40 3.0 116ms
45 -36.74248067268 + -Inf -7.48 2.0 125ms
46 -36.74248067268 + -12.79 -7.23 2.0 117ms
47 -36.74248067268 -12.66 -7.92 2.0 104ms
48 -36.74248067268 + -13.55 -7.67 3.0 135ms
49 -36.74248067268 -13.67 -7.96 2.0 108ms
50 -36.74248067268 + -14.15 -8.15 2.0 107ms
51 -36.74248067268 -13.85 -8.03 3.0 127ms
52 -36.74248067268 + -Inf -8.55 2.0 105ms
53 -36.74248067268 + -13.85 -8.88 2.0 126ms
54 -36.74248067268 -13.85 -8.92 2.0 109ms
55 -36.74248067268 + -14.15 -8.36 3.0 132ms
56 -36.74248067268 + -Inf -9.11 3.0 132ms
57 -36.74248067268 -13.85 -9.44 2.0 98.8ms
58 -36.74248067268 + -14.15 -9.50 2.0 126ms
59 -36.74248067268 + -14.15 -9.71 2.0 106ms
60 -36.74248067268 -13.85 -9.96 1.0 93.2ms
61 -36.74248067268 + -13.85 -9.78 2.0 115ms
62 -36.74248067268 -14.15 -10.21 3.0 127ms
63 -36.74248067268 + -Inf -10.15 2.0 125ms
64 -36.74248067268 + -Inf -10.11 2.0 108ms
65 -36.74248067268 + -Inf -10.92 2.0 105ms
66 -36.74248067268 + -13.85 -10.87 4.0 158ms
67 -36.74248067268 -13.85 -10.99 2.0 108ms
68 -36.74248067268 + -Inf -11.51 2.0 101ms
69 -36.74248067268 + -14.15 -11.52 3.0 136ms
70 -36.74248067268 -14.15 -11.16 3.0 140ms
71 -36.74248067268 + -Inf -11.71 3.0 133ms
72 -36.74248067268 + -13.85 -12.15 2.0 108ms
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.73184560852 -0.88 13.0 339ms
2 -36.73923742493 -2.13 -1.36 1.0 86.9ms
3 -36.73847073581 + -3.12 -1.62 3.0 120ms
4 -36.74216175635 -2.43 -2.25 1.0 91.2ms
5 -36.74210843615 + -4.27 -2.45 4.0 131ms
6 -36.74235748851 -3.60 -2.36 4.0 108ms
7 -36.74240194936 -4.35 -2.75 1.0 92.8ms
8 -36.74247444801 -4.14 -3.17 1.0 92.9ms
9 -36.74247858298 -5.38 -3.47 3.0 107ms
10 -36.74248010905 -5.82 -3.78 3.0 113ms
11 -36.74248038258 -6.56 -4.10 6.0 131ms
12 -36.74248065771 -6.56 -4.53 2.0 105ms
13 -36.74248067023 -7.90 -5.00 3.0 139ms
14 -36.74248067161 -8.86 -5.27 1.0 92.3ms
15 -36.74248067260 -9.00 -5.80 3.0 123ms
16 -36.74248067267 -10.13 -5.98 3.0 137ms
17 -36.74248067265 + -10.72 -6.07 2.0 101ms
18 -36.74248067268 -10.62 -6.47 2.0 104ms
19 -36.74248067268 -11.28 -6.90 2.0 128ms
20 -36.74248067268 -12.60 -7.12 2.0 98.1ms
21 -36.74248067268 -14.15 -7.38 2.0 129ms
22 -36.74248067268 -13.37 -7.65 2.0 101ms
23 -36.74248067268 + -14.15 -7.88 1.0 95.7ms
24 -36.74248067268 -14.15 -8.26 2.0 110ms
25 -36.74248067268 + -Inf -8.42 3.0 133ms
26 -36.74248067268 + -13.85 -8.76 2.0 97.9ms
27 -36.74248067268 -14.15 -8.92 3.0 116ms
28 -36.74248067268 -14.15 -9.11 2.0 101ms
29 -36.74248067268 + -Inf -9.26 2.0 128ms
30 -36.74248067268 + -Inf -9.68 1.0 93.0ms
31 -36.74248067268 + -Inf -9.93 3.0 136ms
32 -36.74248067268 + -Inf -10.18 1.0 96.7ms
33 -36.74248067268 + -14.15 -10.99 2.0 128ms
34 -36.74248067268 -14.15 -11.27 4.0 148ms
35 -36.74248067268 + -Inf -11.44 3.0 109ms
36 -36.74248067268 + -Inf -11.75 2.0 98.0ms
37 -36.74248067268 + -Inf -12.12 5.0 120ms
Given this scfres_Al
we construct functions representing $\varepsilon^\dagger$ 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))
44.02448939188343
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.24421154609604
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))
Clearly the charge-sloshing mode is no longer dominating.
The largest eigenvalue is now
maximum(real.(λ_Kerker))
4.723586294004415
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} \varepsilon^\dagger$ 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:
- For metals the conditioning of the dielectric matrix increases steeply with system size.
- The Kerker preconditioner tames this and makes SCFs on large metallic systems feasible by keeping the condition number of order 1.
- For insulating systems the best approach is to not use any mixing.
- The ideal mixing strongly depends on the dielectric properties of system which is studied (metal versus insulator versus semiconductor).