This repository has been archived by the owner on Nov 7, 2024. It is now read-only.
Add fallback to gesvd if gedd LAPACK fails in numpy backend #962
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Solves: #896
Hi TN people!
Thank you very much for your work so far!
Much like in #896 users of our project OQuPy experience sometimes non-reproducible "SVD did not converge" errors. Very unpleasantly they occur more often with large tensors that are often the result of hours of computation time. I believe most (if not all) of these errors could be avoided by falling back to the _gesvd LAPACK routine in scipy.
Numpy uses the _gesdd LAPACK routine for performing SVDs. In a nutshell: _gesdd routine is for large matrices much faster then the _gesvd routine, but _gesvd is more stabil for badly conditioned matrices.
If one searches for "scipy gesdd SVD did not converge" one finds a lot of issues on github and stackoverflow and 90% of the conversation can be summarised as "I cannot reproduce your/my issue."
In this Issue, @pv (Pauli Virtranen) is pointing out:
However, when browsing through the dozens of issues, it seems that they are often resolve when using the _gesvd LAPACK routine (through scipy). Because _gesdd is mostly much faster I think it is reasonable to keep this as the default, but fall back to the _gesvd routine if the _gesdd fails. This is also done in the TeNPy package here.
Following the Zen of Python: "Errors should never pass silently.", I've added a warning to the fall back to gesdd.
Unfortunately, I don't know how to test it, because I don't know how to construct a matrix that will fail reliably with gesdd.