-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix: SVD fallback exception from numba compiled function #238
Conversation
Thanks for the PR, Looks good to me! Seems like the underlying bug is a bit of a problem though - is it only occasionally? |
Based on a search today, I've read the convergence issue with threads appear across other users with OpenBLAS, even prompting some Julia wrapper packages (and outright exclusion of GESDD by some), as well as a variety of other such cases. I think it just crops up enough to be noticeable with the decomposition used by GESDD in practice --- for the case we encountered it was only appearing using some matrices having very high condition numbers. I think having the fallback as structured (ie fast-path through numba, fallback to GESVD in scipy) is likely the best option. Otherwise, not sure if there's something that can be recommended on the OpenBLAS side, since this is mentioned elsewhere. I'll try gather some info on whether it is just x86_64 (how I hit the issue), whether MacOS M1+ is affected, and whether conda-shipped numpy (with MKL) is affected too. |
Thanks @jcmgray for merging this PR so quickly! As @mlxd mentioned, we are developing a new PennyLane device based on |
I can mint a release soon! My only hesitation is currently not all tests are passing due to some cryptic 'fatal exception' on the windows github CI, but I don't think its something related to |
Thanks @jcmgray I may be completely wrong, but it could be worth trying to set the env var |
Thanks for the tips @mlxd, I'll give those a try. |
Moving the windows CI to openblas indeed seems to have fixed it. |
Details:
PennyLane has a new device (
default.tensor
) which can use quimb under the hood for the MPS and TN implementations. Currently, we observed a failure mode with a given circuit with the MPS backend:For the above, and when setting OMP_NUM_THREADS to any value except that exact physical cores, we see the GESDD SVD method fail to converge (a known issue for others with LAPACK GESDD calls). This should be caught by the
quimb/tensor/decomp.py::svd_truncated_numpy
function, which checks for a numpy-raisedLinAlgError
, and if so falls back to the GESVD implementation. However, when numba compiles thesvd_truncated_numba
function, the raised error is no longer aLinAlgError
, but the more generalValueError
, causing the fallback to fail.This PR replaces the
LinAlgError
check with aValueError
check, which should catch both cases due to the error hierarchy(https://numpy.org/doc/stable/reference/generated/numpy.linalg.LinAlgError.html).
With the above change, we are successfully able to run our given circuit. If keeping both error types is preferred, I'll be happy to readd the LinAlgError type back in.