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 SymmetricEigen Routine #1210

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

CattleProdigy
Copy link
Contributor

@CattleProdigy CattleProdigy commented Feb 21, 2023

I've got some proposed fixes to address the issue referenced below.

The bug itself is in the the subdim=2 special case. As best as I can tell, in that block we try to simply replace the unreduced block by its diagonalization, with the eigenvectors (called basis in the code) serving a similar role as a Givens rotation does in the Implicit-Shift QR part of the algorithm. The eigenvector / eigenvalue correspondence is mismatched. Unfortunately, upon fixing that I find the proptests break regularly. The results are correct but not to within the specified threshold. I should also note that the proptests are also failing on dev though you have to run it a few times to see a failure.
There was nothing in theory wrong with the existing calculation, but it has numerical issues. In the SVD version of this algorithm, a special 2x2 SVD implementation is used which avoid catastrophic cancellation. I adjusted the subdim=2 case to similarly select the eigenvector which bests avoid cancellation.

I'm not sure if there's a better way to salvage the subdim=2 case or if there's any advantage to doing so. In any case, I ultimately just removed it and let the Implicit-Shift QR part handle everything. That passes the test case from the user who reported the issue and proptest passes (100s of times without failing). FWIW the implementation in Eigen doesn't seem to have this special case.

For feedback:

  • Do we want to keep the user-submitted test case?
  • Do we want to try to keep the part I removed?

Addresses #1109

@CattleProdigy CattleProdigy marked this pull request as draft February 21, 2023 15:04
@CattleProdigy CattleProdigy force-pushed the sym-eig-fix branch 2 times, most recently from 1d64d61 to 15cfd50 Compare February 21, 2023 15:27
@Andlon
Copy link
Sponsor Collaborator

Andlon commented Mar 6, 2023

I haven't yet had time to review this, but I also don't know the specific motivation for the subdim = 2 special case. @sebcrozet, would you be able to comment on the motivation for this? Is it e.g. significantly faster in some cases important to you?

@Andlon
Copy link
Sponsor Collaborator

Andlon commented Mar 6, 2023

@CattleProdigy: as I said on Discord, thank you so much for looking into this! I hope to be able to review soon, but in the meantime I'll try to answer one more of your questions. I think we definitely want to keep all user-submitted test cases in the test suite, with a clear reference to the issue in question, e.g. symmetric_eigen_regression_issue_1109() or similar (in a way that aligns with the current naming conventions for the other SymmetricEigen tests, I haven't looked it up).

@CattleProdigy
Copy link
Contributor Author

@CattleProdigy: as I said on Discord, thank you so much for looking into this! I hope to be able to review soon, but in the meantime I'll try to answer one more of your questions. I think we definitely want to keep all user-submitted test cases in the test suite, with a clear reference to the issue in question, e.g. symmetric_eigen_regression_issue_1109() or similar (in a way that aligns with the current naming conventions for the other SymmetricEigen tests, I haven't looked it up).

I've updated the name of the test and the docstrings to match the other issue/regression tests

@CattleProdigy CattleProdigy marked this pull request as ready for review June 9, 2023 13:49
@CattleProdigy CattleProdigy changed the title RFC: Fix SymmetricEigen Routine Fix SymmetricEigen Routine Jul 21, 2023
@CattleProdigy
Copy link
Contributor Author

@Andlon @sebcrozet

I've decided to adopt the solution that disrupts the code the least: maintaining the subdim=2 case. I synced my branch with dev. It passes the regression test and the linalg::eigen proptests. It should be ready to review and merge.

@Andlon
Copy link
Sponsor Collaborator

Andlon commented Aug 1, 2023

Thanks for working on this @CattleProdigy, this is really great. I am not at all familiar with the code here, so given the subtlety of eigenvalue routines, I don't feel quite comfortable merging it right away, although of course the passing tests give great confidence to the solution here. Still, @sebcrozet, I think you were the original author of these routines, would you be able to take a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants