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.73309729706 -0.88 11.0 797ms
2 -36.65947204154 + -1.13 -1.48 1.0 183ms
3 +25.85660519199 + 1.80 -0.16 8.0 113ms
4 -36.54479882008 1.80 -1.07 6.0 102ms
5 -36.54226767109 + -2.60 -1.35 3.0 70.0ms
6 -35.43367344353 + 0.04 -1.01 4.0 94.4ms
7 -36.71052127765 0.11 -1.71 3.0 72.5ms
8 -36.73475095156 -1.62 -1.99 1.0 46.5ms
9 -36.74121877141 -2.19 -2.07 2.0 69.4ms
10 -36.74184284099 -3.20 -2.26 2.0 54.4ms
11 -36.74119751615 + -3.19 -2.28 2.0 64.5ms
12 -36.74197652704 -3.11 -2.53 2.0 53.7ms
13 -36.74244492238 -3.33 -2.91 1.0 53.6ms
14 -36.74247119199 -4.58 -2.98 3.0 69.5ms
15 -36.74075607712 + -2.77 -2.41 3.0 73.0ms
16 -36.74246100161 -2.77 -3.31 3.0 67.7ms
17 -36.74247529795 -4.84 -3.55 2.0 61.2ms
18 -36.74218408922 + -3.54 -2.83 4.0 78.4ms
19 -36.74247745801 -3.53 -3.57 3.0 79.2ms
20 -36.74247704372 + -6.38 -3.72 2.0 61.3ms
21 -36.74247972762 -5.57 -3.90 3.0 60.9ms
22 -36.74248037864 -6.19 -4.27 2.0 57.5ms
23 -36.74247941835 + -6.02 -3.93 3.0 68.6ms
24 -36.74248066465 -5.90 -4.71 3.0 70.7ms
25 -36.74248065613 + -8.07 -4.78 2.0 55.7ms
26 -36.74248067221 -7.79 -5.39 2.0 60.8ms
27 -36.74248067171 + -9.30 -5.32 3.0 69.2ms
28 -36.74248066757 + -8.38 -5.18 3.0 73.4ms
29 -36.74248067220 -8.33 -5.47 3.0 63.4ms
30 -36.74248067214 + -10.21 -5.68 2.0 62.1ms
31 -36.74248067016 + -8.70 -5.36 3.0 81.6ms
32 -36.74248067260 -8.61 -5.87 3.0 74.3ms
33 -36.74248067265 -10.37 -6.08 2.0 55.1ms
34 -36.74248067263 + -10.80 -6.13 2.0 70.2ms
35 -36.74248067255 + -10.09 -5.95 2.0 60.0ms
36 -36.74248067268 -9.89 -6.55 2.0 61.5ms
37 -36.74248067267 + -11.28 -6.58 3.0 75.2ms
38 -36.74248067268 -11.07 -7.12 2.0 62.6ms
39 -36.74248067268 + -12.75 -7.16 3.0 71.4ms
40 -36.74248067268 -12.73 -7.29 2.0 58.5ms
41 -36.74248067268 -12.59 -7.78 2.0 56.4ms
42 -36.74248067268 + -Inf -7.86 3.0 75.2ms
43 -36.74248067268 + -13.07 -7.46 3.0 65.4ms
44 -36.74248067268 -13.07 -8.13 3.0 73.5ms
45 -36.74248067268 + -Inf -8.32 2.0 57.0ms
46 -36.74248067268 + -13.45 -7.72 3.0 162ms
47 -36.74248067268 -13.30 -8.57 3.0 74.8ms
48 -36.74248067268 + -14.15 -8.43 2.0 782ms
49 -36.74248067268 + -Inf -8.23 3.0 66.7ms
50 -36.74248067268 -14.15 -8.63 2.0 66.2ms
51 -36.74248067268 + -Inf -8.29 3.0 89.4ms
52 -36.74248067268 + -Inf -8.49 2.0 52.2ms
53 -36.74248067268 + -Inf -8.67 2.0 64.5ms
54 -36.74248067268 + -14.15 -8.92 2.0 55.4ms
55 -36.74248067268 -14.15 -8.98 2.0 55.2ms
56 -36.74248067268 + -14.15 -9.67 1.0 49.1ms
57 -36.74248067268 + -14.15 -9.29 3.0 74.1ms
58 -36.74248067268 -13.85 -9.54 3.0 91.3ms
59 -36.74248067268 + -Inf -9.17 4.0 92.3ms
60 -36.74248067268 + -Inf -10.09 3.0 111ms
61 -36.74248067268 + -Inf -10.24 2.0 77.8ms
62 -36.74248067268 + -Inf -10.22 2.0 73.0ms
63 -36.74248067268 + -13.85 -10.72 2.0 62.1ms
64 -36.74248067268 + -Inf -10.54 3.0 84.1ms
65 -36.74248067268 + -Inf -10.72 1.0 49.7ms
66 -36.74248067268 + -Inf -10.84 1.0 49.1ms
67 -36.74248067268 -13.85 -11.12 3.0 62.8ms
68 -36.74248067268 + -Inf -11.32 2.0 56.2ms
69 -36.74248067268 + -14.15 -11.53 2.0 57.9ms
70 -36.74248067268 + -14.15 -11.56 2.0 69.2ms
71 -36.74248067268 -14.15 -12.13 1.0 53.6ms
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.73186446933 -0.88 10.0 551ms
2 -36.73977431891 -2.10 -1.37 1.0 404ms
3 -36.74117310244 -2.85 -1.93 6.0 64.3ms
4 -36.74167777712 -3.30 -1.92 2.0 88.6ms
5 -36.74244980359 -3.11 -2.65 1.0 47.4ms
6 -36.74242375447 + -4.58 -2.53 3.0 63.7ms
7 -36.74246577617 -4.38 -2.80 1.0 47.4ms
8 -36.74247995209 -4.85 -3.55 1.0 47.5ms
9 -36.74248010021 -6.83 -3.50 4.0 93.2ms
10 -36.74248052526 -6.37 -3.74 1.0 48.2ms
11 -36.74248064668 -6.92 -4.24 1.0 47.7ms
12 -36.74248066610 -7.71 -4.74 3.0 69.3ms
13 -36.74248067211 -8.22 -5.18 4.0 71.3ms
14 -36.74248067193 + -9.75 -5.36 5.0 60.1ms
15 -36.74248067264 -9.15 -5.84 2.0 70.3ms
16 -36.74248067268 -10.40 -6.31 2.0 51.7ms
17 -36.74248067268 -11.45 -6.55 3.0 73.1ms
18 -36.74248067268 -11.90 -6.98 2.0 50.8ms
19 -36.74248067268 -12.85 -7.18 3.0 72.7ms
20 -36.74248067268 -13.37 -7.80 2.0 48.8ms
21 -36.74248067268 + -14.15 -7.96 4.0 77.5ms
22 -36.74248067268 + -Inf -8.50 2.0 56.6ms
23 -36.74248067268 -14.15 -8.50 4.0 69.5ms
24 -36.74248067268 -14.15 -8.72 1.0 53.4ms
25 -36.74248067268 + -Inf -9.16 2.0 50.4ms
26 -36.74248067268 + -14.15 -9.48 4.0 70.0ms
27 -36.74248067268 + -Inf -9.77 5.0 57.4ms
28 -36.74248067268 -14.15 -10.23 2.0 70.8ms
29 -36.74248067268 + -13.85 -10.47 1.0 52.9ms
30 -36.74248067268 + -Inf -10.67 2.0 50.4ms
31 -36.74248067268 -13.85 -11.06 1.0 53.2ms
32 -36.74248067268 + -14.15 -11.32 3.0 67.9ms
33 -36.74248067268 -14.15 -11.67 2.0 55.8ms
34 -36.74248067268 + -14.15 -12.00 3.0 61.0ms
35 -36.74248067268 + -14.15 -12.20 3.0 72.3ms
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
endepsilon (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.02448899551031The smallest eigenvalue is a bit more tricky to obtain, so we will just assume
λ_Simple_min = 0.9520.952This makes the condition number around 30:
cond_Simple = λ_Simple_max / λ_Simple_min46.24421112973772This 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.723582819596549Since 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).