-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
YGate.power(1/2)
behaves differently with scipy 1.14 on macOS
#13305
Comments
YGate.power(1/2)
behaves differently with qiskit 1.2.4 on macOSYGate.power(1/2)
behaves differently with scipy 1.14 on macOS
Hmm, this is kind of weird - I don't think anything should have changed between the 1.2 series and Are you using the same versions of Scipy between the macOS 1.2.4 and main tests? Are they both running on the same processor? I can't reproduce on Intel macOS with scipy 1.13.1 |
Ah, I see you just updated to say it's a scipy 1.14 problem - thanks. |
I updated the description just now. I confirmed that it is due to scipy 1.14. |
Ok, so Scipy 1.14 started using Accelerate as its default BLAS on macOS. This is quite possibly the difference - it used OpenBLAS before. I need to look a little bit into where something's going wrong, because we want to return the principal square root. I'm hoping we weren't just doing that by chance previously. |
Thank you for investigating this issue so quickly. Using Accelerate is a big change. |
Ok, so digging a little into the Let's handle the immediate problem first: at the end of the day, the trouble is that Accelerate is finding that the eigenvalues of Now, an additional problem: the way >>> from qiskit.quantum_info import Operator
>>> import scipy.linalg
>>> # Not unitary.
>>> data = [[1, 1], [0, -1]]
>>> print(Operator(data).power(0.5).data)
[[1.000000e+00+0.j 0.000000e+00+0.j]
[0.000000e+00+0.j 6.123234e-17+1.j]]
>>> print(scipy.linalg.fractional_matrix_power(data, 0.5)))
[[1.00000000e+00+0.j 5.00000000e-01-0.5j]
[0.00000000e+00+0.j 4.93096709e-17+1.j ]] The ability to do fractional matrix powers of Unfortunately for us, |
Fwiw, while we're seeing the problem with Accelerate here with the default Scipy 1.14 wheels, in principle it can happen with any Scipy version if the user switches out the BLAS implementation it's built against. So pinning Scipy would just unfortunately squashing a single symptom. If we can't come up with a fix to this that at least makes it less surprisingly, I guess we'll at least need to heavily document in |
Thank you for your detailed investigation. I will report the issue of |
I reported it to scipy scipy/scipy#21687 |
Oh, I don't think it's a problem with the function per se - it's just one of these problems we have to deal with with imprecise numerical linear algebra. |
I reported only |
Imamichi-san: in case you didn't see it, #13358 includes the "fix" for this, which is that we've done some (slightly questionable) numerical trickery to shift the branch-cut point of the fraction-root function slightly away from the really common -1 point. It'll make roots of common operators reliable, at the cost that an operator that truly has an eigenvalue a very small rotation anticlockwise around from -1 might have its root put on the other side of the branch cut. That's controllable with |
Thank you for the fix and information, Jake. |
Environment
What is happening?
YGate.power(1/2)
behaves differently with scipy 1.14 on macOS compared with outcomes with other version and OS.How can we reproduce the issue?
macOS + qiskit 1.2.4 + scipy 1.14.1
macOS + qiskit 1.2.4 + scipy 1.14.0
macOS + qiskit 1.2.4 + scipy 1.13.1
RedHat 9.4 + qiskit 1.2.4 + scipy 1.14.1
What should happen?
Consistent outcomes regardless of scipy version
Any suggestions?
pin scipy version, e.g.,
scipy<1.14
for macOS?The text was updated successfully, but these errors were encountered: