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

Add rules for Symmetric/Hermitian eigen and svd #323

Merged
merged 65 commits into from
Jan 7, 2021

Conversation

sethaxen
Copy link
Member

@sethaxen sethaxen commented Dec 6, 2020

This PR adds frules for eigen! and eigvals! and rrules for eigen, eigvals, svd, and svdvals for Hermitian or real Symmetric inputs. The rules for the eigen functions are similar to those in #321 but are more efficient due to known types and unitary eigenvectors. The svd functions are added because their primals in base call mutating functions, which will miss the eigen rules, hence we don't need to add corresponding frules.

This PR will eventually also fix the normalization convention issue noted in #321, so it depends on that PR.

@codecov-io
Copy link

codecov-io commented Dec 6, 2020

Codecov Report

Merging #323 (d7a3f2d) into master (e11af5d) will decrease coverage by 13.08%.
The diff coverage is 73.14%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master     #323       +/-   ##
===========================================
- Coverage   97.64%   84.56%   -13.08%     
===========================================
  Files          18       18               
  Lines        1018     1017        -1     
===========================================
- Hits          994      860      -134     
- Misses         24      157      +133     
Impacted Files Coverage Δ
src/rulesets/LinearAlgebra/symmetric.jl 75.00% <72.15%> (-25.00%) ⬇️
src/rulesets/LinearAlgebra/factorization.jl 93.28% <75.86%> (-6.06%) ⬇️
src/rulesets/Base/evalpoly.jl 0.00% <0.00%> (-97.68%) ⬇️
src/rulesets/Base/utils.jl 0.00% <0.00%> (-80.00%) ⬇️
src/ChainRules.jl 66.66% <0.00%> (-33.34%) ⬇️
src/rulesets/Statistics/statistics.jl 66.66% <0.00%> (-23.34%) ⬇️
src/rulesets/LinearAlgebra/utils.jl 66.66% <0.00%> (-20.00%) ⬇️
src/rulesets/LinearAlgebra/structured.jl 92.04% <0.00%> (-6.84%) ⬇️
src/rulesets/LinearAlgebra/norm.jl 98.24% <0.00%> (-1.76%) ⬇️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e11af5d...d7a3f2d. Read the comment docs.

@sethaxen sethaxen closed this Jan 5, 2021
@sethaxen sethaxen reopened this Jan 5, 2021
@sethaxen
Copy link
Member Author

sethaxen commented Jan 5, 2021

In the interest of getting this merged, I have added I think sufficient comments and references. A later PR can always add more about phase/normalization conventions. @willtebbutt could you re-review?

@sethaxen
Copy link
Member Author

sethaxen commented Jan 5, 2021

The CI errors are unrelated to this PR and due to JuliaDiff/FiniteDifferences.jl#133.

@sethaxen sethaxen closed this Jan 7, 2021
@sethaxen sethaxen reopened this Jan 7, 2021
Copy link
Member

@willtebbutt willtebbutt left a comment

Choose a reason for hiding this comment

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

I'm not going to pretend that I follow the details of the implementations, but I'm satisfied that what is implemented has been tested properly, so I'm happy to approve.

I've requested a couple of additional bits of documentation in the test sets because I had to squint to figure out what was being tested in each block and, since this is a comparatively complicated new bit of code, I feel that signposting what's going on is quite important. Would you mind making similar readability improvements to all of the testsets that you've added?

test/rulesets/LinearAlgebra/symmetric.jl Outdated Show resolved Hide resolved
test/rulesets/LinearAlgebra/symmetric.jl Outdated Show resolved Hide resolved
@sethaxen
Copy link
Member Author

sethaxen commented Jan 7, 2021

Done! Thanks!

@sethaxen sethaxen merged commit 053a6c0 into JuliaDiff:master Jan 7, 2021
@sethaxen sethaxen deleted the symeig branch January 7, 2021 12:39
@sethaxen sethaxen restored the symeig branch January 7, 2021 12:42
sethaxen added a commit to sethaxen/ChainRules.jl that referenced this pull request Jan 7, 2021
bors bot added a commit to FluxML/Zygote.jl that referenced this pull request Jan 9, 2021
875: Remove eigen and eigvals adjoints for Symmetric/Hermitian r=DhairyaLGandhi a=sethaxen

JuliaDiff/ChainRules.jl#323 added rrules for `eigen` and `eigvals` for Symmetric/Hermitian matrices. This PR removes those rules from Zygote. Once the old tests pass, I'll remove them, since the rrules are more thoroughly tested.

Depends on JuliaRegistries/General#27508 is merged.

Co-authored-by: Seth Axen <[email protected]>
sethaxen added a commit that referenced this pull request Jan 14, 2021
* Add symmetric/hermitian eigendecomposition rules

* Add utility functions

* Add frules and rrules for sym/herm power series

* Add int pow rules

* Add sincos rules

* Remove unused function argument

* Fix and comment _nonzero

* Make methods and signatures less ambiguous

* Handle Zero() better

* Standardize notation

* Remove parens

* Update src/rulesets/LinearAlgebra/structured.jl

Co-authored-by: Nick Robinson <[email protected]>

* Fix for Julia 1.0

* Use correct variable and method name

* Accumulate in the triangle in the pullback

* Remove comment

* Add eigen and eigvals tests

* Remove outdated comment

* Clean up and make constraint functions faster

* Make outputs of int pow of Hermitian are Hermitian

* Fix typo in comment

* Test most power series functions

* Don't thunk tangents

* Make type-stable and use optimal threshold

* Split out symmetric/hermitian methods/tests

* Use correct pullback of hermitrization

* Stabilize eigenvector computation

* Test composed pullback

* Remove all eigendecomposition rules

Moved to #323

* Move to utilities section

* Move to utilities section

* Separate shared code into its own function

* Don't thunk

* Use correct function name

* Correctly broadcast

* Remove power rules

* Rename to matrix functions

* Remove pow tests

* Expand test suite

* Remove sincos rules for now

* Add references and comments

* Add _isindomain

* Refactor _matfun

Return cache and handle type-unstable case

* Add _matfun_frechet

* Broadcast instead of indexing

* Add comments and use indexing from paper

* Handle Zeros

* Contrain differentials according to primals

* Support all matrix functions

* Remove unused methods

* Support Symmetric{Complex}

* Add rules for sincos

* Make atanh rule type-stable

* Correctly test type-unstable functions

* Use correct denominator

* Add tests for almost-singular and low-rank matrices

* Remove out-dated comments

* Test alternate differentials

* Don't use only

* Remove _hermitrizeback!

* Don't use hasproperty, not in old Julia versions

* Reduce allocations

* simplify section name

* Simplify line

* Handle mixture of non-Zero and Zero

* Don't loop over unused functions

* Test against component frules instead of fd

* Test that rules produce same uplo as primal

* Apply suggestions from code review

Co-authored-by: Lyndon White <[email protected]>

* Reuse variable name

In this case it is type-stable

* Use bang bang convention for maybe-in-place

* Don't assume the wrapped matrix is mutable

* Replace hermitrize!

* Use diagind

* Remove handling of Zero differential

* Unify symbols

* Use hasproperty

* Load hasproperty from Compat

* Replace refs with one to Higham

* Add docstrings

* Update src/rulesets/LinearAlgebra/symmetric.jl

Co-authored-by: Lyndon White <[email protected]>

* Increment version number

* Use utility function

* Stabilize jvp Jacobian dimensions

* Don't use non-exported function

* Bump required ChainRulesCore

Co-authored-by: Nick Robinson <[email protected]>
Co-authored-by: Lyndon White <[email protected]>
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.

3 participants