JohanSchott / impurityModel

Calculate many-body states of an impurity Anderson model and spectra (e.g. XPS, XAS, RIXS, NIXS)
MIT License
22 stars 2 forks source link

Make Lanczos algorithm more robust #24

Open JohanSchott opened 2 years ago

JohanSchott commented 2 years ago

The Lanczos algorithm may suffer from numerical instability, see discussion in e.g. https://en.wikipedia.org/wiki/Lanczos_algorithm. The generous unit-test tolerances indicate numerical round-off errors are indeed present (compared the same code on Mac OS X and Ubuntu). Until now, the errors I have seen have been smaller than the physics of interest. But it is good to be aware of this numerical instability issue, in particular if very subtle features are of interest.

In https://en.wikipedia.org/wiki/Lanczos_algorithm, a few ideas and references are provided of how to improve the numerical stability of the Lanczos algorithm, that might be relevant for this repository.

johanjoensson commented 2 months ago

I have done some investigation of a few methods.

  1. Using blocks of vectors for the Lanczos method, instead of a single vector. This is useful if we want to calculate offdiagonal elements in the Greens function. Numerically, this increases stability a bit as well.
  2. Partial reorthogonalization is probably the best compromise between computational cost and numerical accuracy, link to old paper
  3. Full reorthogonalization is easy to implement, but veeeery computationally expensive.

In general, all methods that adds some orthogonalization-step to the method will require that we save all the Krylov vectors we generate. This increases the memory footprint of the calculation quite a bit. In my experience, the Greens function does not converge faster when we add orthogonalization. I have not actually looked at the numerical accuracy of the resulting Greens function though.

JohanSchott commented 2 months ago

Restarting the algorithm after a certain number of iterations seems to be a popular approach, e.g. Thick-Restart Lanczos method: https://zenodo.org/records/1236144

JohanSchott commented 2 months ago

Not sure how big this issue is.

johanjoensson commented 1 month ago

No, I am not sure that this will actually help with calculating the Greens function. The restarted methods work by focusing on certain eigenvalues/eigenvectors. If what you want is just certain eigenvalues/eigenvectors this is great, but for the Greens function to converge quickly, what eigenvalues should we focus on?

JohanSchott commented 1 month ago

I don't know. Perhaps it's not suitable for calculating Green's functions.

johanjoensson commented 1 month ago

The way we calculate Greens functions relies on the tridiagonalization of the Hamiltonian. With restarted methods I think we replace the tridiagonal structure with something different, but maybe there is a clever way to calculate the Greens function (we only need one element of the inverse of the Hamiltonian).

JohanSchott commented 1 month ago

When I quickly read about restarted methods I agree it does seem the matrix is not tridiagonal. So probably the three implementation ideas you outlined above are more promising.