qadence
qadence copied to clipboard
[Performance] Better routine for top-k eigenvalues
Torch routines to calculate top-k eigenvalues are not efficient / non-existent. The eigenvalues
function in qadence.utils
was converting the full tensor to numpy and using eigs from scipy, but this was more expensive than simply using torch.linalg.eigvals
for the full spectrum and then taking the top-k, so now that is what it is doing. Possibly we can squeeze further gains by using torch.linalg.eigvalsh
, but in my quick tests it was not clear if it was better.
This problem has been noticed by other people. For example here is an attempt at solving it: https://github.com/rfeinman/Torch-ARPACK
Could be worth trying to integrate the above, or we might need to consider writing our own solution for this if we value this routine. It should exploit the matrices being Hermitian.