Skip to content
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

Fix compatibility issues with SciPy 1.14 #13358

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jakelishman
Copy link
Member

@jakelishman jakelishman commented Oct 22, 2024

Summary

The main change here is that SciPy 1.14 on macOS now uses the system Accelerate rather than a bundled OpenBLAS by default. These have different characteristics for several LAPACK drivers, which caused numerical instability in our test suite. Fundamentally, these problems existed before; it was always possible to switch out the BLAS/LAPACK implementation that SciPy used, but in practice, the vast majority of users (and our CI) use the system defaults.

The modification to Operator.power to shift the branch cut was suggested by Lev. As a side-effect of how it's implemented, it fixes an issue with Operator.power on non-unitary matrices, which Sasha had been looking at.

The modification to the Choi-to-Kraus conversion reverts back from a Schur-based decomposition to an eigh-based one. This was noted in a code comment that it was causing instability, and tracing the git history through to fdd5603 (gh-3884) suggests that this was around the time of Scipy 1.1 to 1.3, with OpenBLASes around 0.3.6. The bundled version of OpenBLAS with SciPy 1.13 was 0.3.27, so several releases on. If eigh problems re-appear, we can look at changing the decomposition back to something else, but the current eigh seems to be more stable than the Schur form for a wider range of inputs now.

Details and comments

Let's see what happens in the full test matrix, especially Windows (which iirc is usually the source of eigh problems). It worked with both SciPy 1.13 and 1.14 on my Intel Mac.

Fix #12655
Fix #13305
Fix #13307

This should hopefully unblock #13309.

This obsoletes the bugfix of #13319 as a side-effect of solving #13305, but the additional method / keyword argument to power there is still likely very useful (though will need adapting to use the same technique as here).

The main change here is that SciPy 1.14 on macOS now uses the system
Accelerate rather than a bundled OpenBLAS by default.  These have
different characteristics for several LAPACK drivers, which caused
numerical instability in our test suite.  Fundamentally, these problems
existed before; it was always possible to switch out the BLAS/LAPACK
implementation that SciPy used, but in practice, the vast majority of
users (and our CI) use the system defaults.

The modification to `Operator.power` to shift the branch cut was
suggested by Lev.  As a side-effect of how it's implemented, it fixes
an issue with `Operator.power` on non-unitary matrices, which Sasha had
been looking at.

The modification to the Choi-to-Kraus conversion reverts back from a
Schur-based decomposition to an `eigh`-based one.  This was noted in a
code comment that it was causing instability, and tracing the git
history through to fdd5603 (Qiskitgh-3884) suggests that this was around
the time of Scipy 1.1 to 1.3, with OpenBLASes around 0.3.6.  The bundled
version of OpenBLAS with SciPy 1.13 was 0.3.27, so several releases on.
If `eigh` problems re-appear, we can look at changing the decomposition
back to something else, but the current `eigh` seems to be more stable
than the Schur form for a wider range of inputs now.

Co-authored-by: Lev S. Bishop <[email protected]>
Co-authored-by: Alexander Ivrii <[email protected]>
@jakelishman jakelishman added Changelog: Bugfix Include in the "Fixed" section of the changelog mod: quantum info Related to the Quantum Info module (States & Operators) labels Oct 22, 2024
@jakelishman jakelishman added this to the 1.3.0 milestone Oct 22, 2024
@jakelishman jakelishman requested a review from a team as a code owner October 22, 2024 17:29
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

@coveralls
Copy link

Pull Request Test Coverage Report for Build 11465405675

Details

  • 9 of 9 (100.0%) changed or added relevant lines in 2 files are covered.
  • 22 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.02%) to 88.635%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 4 91.98%
crates/qasm2/src/parse.rs 18 96.69%
Totals Coverage Status
Change from base Build 11461474832: -0.02%
Covered Lines: 74567
Relevant Lines: 84128

💛 - Coveralls

Copy link
Member

@levbishop levbishop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nice to explicitly test eigenvalues barely either side of the intended branch cut, but perhaps that would be a pain to write?

@jakelishman
Copy link
Member Author

I could adapt the exact same test, I think? We'd just need to take care not to couple the test to the particular choice of the rotation epsilon.

@levbishop
Copy link
Member

Yeah, it might get confusing though with the different epsilons involved. There's eps_bc that defines the intended position of the branch cut, eps_fp thats potential numerical imprecision during the test, and then eps_test that's how close the test comes either side of the branch cut. I guess you want eps_test > eps_fp and then check eigenvalues at eps_bc±eps_test away from the axis.

@jakelishman
Copy link
Member Author

I was hoping to make eps_bc an implementation detail and specifically avoid testing anything about its value, but actually, maybe we make it a keyword arg on Operator.power to allow the user to move it around? Then it's easier to test as well.

@levbishop
Copy link
Member

levbishop commented Oct 22, 2024

That seems in line with how we deal with other tolerance-ish things. I don't have a strong opinion.

@jakelishman
Copy link
Member Author

Seems like eigh remains unstable on macOS. I'll switch that Choi-to-Kraus conversion over to something else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog mod: quantum info Related to the Quantum Info module (States & Operators)
Projects
None yet
4 participants