-
Notifications
You must be signed in to change notification settings - Fork 61
A couple missing zero-derivs and an inplace rrule for svd_trunc #448
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
Open
kshyatt
wants to merge
3
commits into
main
Choose a base branch
from
ksh/svd_trunc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,11 @@ using MatrixAlgebraKit: remove_qr_gauge_dependence!, remove_lq_gauge_dependence! | |
| using Mooncake | ||
| using Random | ||
|
|
||
| function call_and_zero!(f!, A, alg) | ||
| F′ = f!(A, alg) | ||
| MatrixAlgebraKit.zero!(A) | ||
| return F′ | ||
| end | ||
|
|
||
| mode = Mooncake.ReverseMode | ||
| rng = Random.default_rng() | ||
|
|
@@ -18,7 +23,6 @@ eltypes = (Float64, ComplexF64) | |
| @timedtestset "Mooncake - Factorizations: $(TensorKit.type_repr(sectortype(eltype(V)))) ($T)" for V in spacelist, T in eltypes | ||
| atol = default_tol(T) | ||
| rtol = default_tol(T) | ||
|
|
||
| @timedtestset "QR" begin | ||
| A = randn(T, V[1] ⊗ V[2] ← V[1] ⊗ V[2]) | ||
|
|
||
|
|
@@ -29,8 +33,7 @@ eltypes = (Float64, ComplexF64) | |
| ΔQR = Mooncake.randn_tangent(rng, QR) | ||
| remove_qr_gauge_dependence!(ΔQR..., A, QR...) | ||
| Mooncake.TestUtils.test_rule(rng, qr_full, A; output_tangent = ΔQR, atol, rtol, mode, is_primitive = false) | ||
| # TODO: | ||
| # Mooncake.TestUtils.test_rule(rng, qr_null, A; atol, rtol, mode, is_primitive = false) | ||
| #Mooncake.TestUtils.test_rule(rng, qr_null, A; atol, rtol, mode, is_primitive = false) | ||
|
|
||
| A = randn(T, V[1] ⊗ V[2] ⊗ V[3] ← (V[4] ⊗ V[5])') | ||
|
|
||
|
|
@@ -41,34 +44,31 @@ eltypes = (Float64, ComplexF64) | |
| ΔQR = Mooncake.randn_tangent(rng, QR) | ||
| remove_qr_gauge_dependence!(ΔQR..., A, QR...) | ||
| Mooncake.TestUtils.test_rule(rng, qr_full, A; output_tangent = ΔQR, atol, rtol, mode, is_primitive = false) | ||
| # TODO: | ||
| # Mooncake.TestUtils.test_rule(rng, qr_null, A; atol, rtol, mode, is_primitive = false) | ||
| #Mooncake.TestUtils.test_rule(rng, qr_null, A; atol, rtol, mode, is_primitive = false) | ||
| end | ||
|
|
||
| @timedtestset "LQ" begin | ||
| A = randn(T, V[1] ⊗ V[2] ← V[1] ⊗ V[2]) | ||
|
|
||
| Mooncake.TestUtils.test_rule(rng, lq_compact, A; atol, rtol, mode, is_primitive = false) | ||
|
|
||
| # qr_full/qr_null requires being careful with gauges | ||
| # lq_full/lq_null requires being careful with gauges | ||
| LQ = lq_full(A) | ||
| ΔLQ = Mooncake.randn_tangent(rng, LQ) | ||
| remove_lq_gauge_dependence!(ΔLQ..., A, LQ...) | ||
| Mooncake.TestUtils.test_rule(rng, lq_full, A; output_tangent = ΔLQ, atol, rtol, mode, is_primitive = false) | ||
| # TODO: | ||
| # Mooncake.TestUtils.test_rule(rng, lq_null, A; atol, rtol, mode, is_primitive = false) | ||
| #Mooncake.TestUtils.test_rule(rng, lq_null, A; atol, rtol, mode, is_primitive = false) | ||
|
|
||
| A = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])') | ||
|
|
||
| Mooncake.TestUtils.test_rule(rng, lq_compact, A; atol, rtol, mode, is_primitive = false) | ||
|
|
||
| # qr_full/qr_null requires being careful with gauges | ||
| # lq_full/lq_null requires being careful with gauges | ||
| LQ = lq_full(A) | ||
| ΔLQ = Mooncake.randn_tangent(rng, LQ) | ||
| remove_lq_gauge_dependence!(ΔLQ..., A, LQ...) | ||
| Mooncake.TestUtils.test_rule(rng, lq_full, A; output_tangent = ΔLQ, atol, rtol, mode, is_primitive = false) | ||
| # TODO: | ||
| # Mooncake.TestUtils.test_rule(rng, lq_null, A; atol, rtol, mode, is_primitive = false) | ||
| #Mooncake.TestUtils.test_rule(rng, lq_null, A; atol, rtol, mode, is_primitive = false) | ||
| end | ||
|
|
||
| @timedtestset "Eigenvalue decomposition" begin | ||
|
|
@@ -88,7 +88,7 @@ eltypes = (Float64, ComplexF64) | |
|
|
||
| @timedtestset "Singular value decomposition" begin | ||
| for t in (randn(T, V[1] ← V[1]), randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])')) | ||
| USVᴴ = svd_compact(t) | ||
| #=USVᴴ = svd_compact(t) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we know why the non-truncated version is not working? |
||
| ΔUSVᴴ = Mooncake.randn_tangent(rng, USVᴴ) | ||
| remove_svd_gauge_dependence!(ΔUSVᴴ[1], ΔUSVᴴ[3], USVᴴ...) | ||
| Mooncake.TestUtils.test_rule(rng, svd_compact, t; output_tangent = ΔUSVᴴ, atol, rtol, mode, is_primitive = false) | ||
|
|
@@ -97,14 +97,23 @@ eltypes = (Float64, ComplexF64) | |
| ΔUSVᴴ = Mooncake.randn_tangent(rng, USVᴴ) | ||
| remove_svd_gauge_dependence!(ΔUSVᴴ[1], ΔUSVᴴ[3], USVᴴ...) | ||
| Mooncake.TestUtils.test_rule(rng, svd_full, t; output_tangent = ΔUSVᴴ, atol, rtol, mode, is_primitive = false) | ||
|
|
||
| =# | ||
| V_trunc = spacetype(t)(c => min(size(b)...) ÷ 2 for (c, b) in blocks(t)) | ||
| trunc = truncspace(V_trunc) | ||
| alg = MatrixAlgebraKit.select_algorithm(svd_trunc, t, nothing; trunc) | ||
| USVᴴtrunc = svd_trunc(t, alg) | ||
| ΔUSVᴴtrunc = (Mooncake.randn_tangent(rng, Base.front(USVᴴtrunc))..., zero(last(USVᴴtrunc))) | ||
| remove_svd_gauge_dependence!(ΔUSVᴴtrunc[1], ΔUSVᴴtrunc[3], Base.front(USVᴴtrunc)...) | ||
| Mooncake.TestUtils.test_rule(rng, svd_trunc, t, alg; output_tangent = ΔUSVᴴtrunc, atol, rtol, mode) | ||
|
|
||
| V_trunc = spacetype(t)(c => min(size(b)...) ÷ 2 for (c, b) in blocks(t)) | ||
| trunc = truncspace(V_trunc) | ||
| USVᴴ = svd_compact(t) | ||
| alg = MatrixAlgebraKit.select_algorithm(svd_trunc, t, nothing; trunc) | ||
| USVᴴtrunc = svd_trunc(t, alg) | ||
| ΔUSVᴴtrunc = (Mooncake.randn_tangent(rng, Base.front(USVᴴtrunc))..., zero(last(USVᴴtrunc))) | ||
| remove_svd_gauge_dependence!(ΔUSVᴴtrunc[1], ΔUSVᴴtrunc[3], Base.front(USVᴴtrunc)...) | ||
| Mooncake.TestUtils.test_rule(rng, call_and_zero!, svd_trunc!, t, alg; output_tangent = ΔUSVᴴtrunc, atol, rtol, mode, is_primitive = false) | ||
| end | ||
| end | ||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot we have the
svd_truncrules here, and don't actually remember why we needed that. (Did I do this? Does my memory still work? Are we even real?)Is this not the same as the MatrixAlgebraKit implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You added them lmao
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But yeah I think it should be, let me try removing this and just falling into MAKtopia