Skip to content

Commit 819a286

Browse files
committed
Added scaling for DIIS mixing.
This improves the precision for inversions when the matrix elements are much bigger than 1.
1 parent c130134 commit 819a286

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

changes/orphan.5.fix.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
DIIS mixing now uses a scaling factor for inverse
2+
3+
This provides a better stability for the inversion
4+
algorithm when the metrics are much bigger
5+
than 1.

src/sisl/mixing/diis.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ def solve_lagrange(self) -> tuple[npt.NDArray[np.float64], npt.NDArray[np.float6
106106
B[j, i] = B[i, j]
107107

108108
# fill the rest of the matrix
109-
B[:, n_h] = 1.0
110-
B[n_h, :] = 1.0
109+
scale = B[:n_h, :n_h].max() - B[:n_h, :n_h].min()
110+
B[:, n_h] = scale
111+
B[n_h, :] = scale
111112
B[n_h, n_h] = 0.0
112113

113114
# Although B contains 1 and a number on the order of
@@ -124,7 +125,7 @@ def solve_lagrange(self) -> tuple[npt.NDArray[np.float64], npt.NDArray[np.float6
124125
# Is this because sym also implies positive definiteness?
125126
# However, these are matrices of order ~30, so we don't care
126127
c = solve_destroy(B, RHS, assume_a="sym")
127-
return c[:-1], -c[-1]
128+
return c[:-1] * scale, -c[-1] * scale**2
128129
except np.linalg.LinAlgError as e:
129130
# We have a LinalgError, this will take the last entry and
130131
# do a linear mixing.

0 commit comments

Comments
 (0)