-
Notifications
You must be signed in to change notification settings - Fork 5
AD rules for (anti-) hermitian projection #174
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
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
9d6bd03
Fix zero tangent guard in polar pullback
lkdvos eeaf9a9
Use eigendecomposition-based Sylvester solver for symmetric case
lkdvos e2dce34
Add AD rules for projection methods
lkdvos fda5129
simplify implementations
lkdvos 3e73c0c
remove enzyme
lkdvos 219040e
simplify chainrules tests
lkdvos 5d92319
simplify mooncake tests
lkdvos 3b282ea
revert changes
lkdvos f3bfc54
possibly fix implementation
lkdvos 89bed77
refactor projections tests
lkdvos b14a8f5
revert accidental deletion of projections file
lkdvos b318018
comment about copy/restoring A
lkdvos 0988f9f
test aliasing mooncake rules
lkdvos 426938b
test mooncake diagonal projections and fix oopsie
lkdvos 4254861
Test supplying a destination to projections
lkdvos 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
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 |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| using MatrixAlgebraKit | ||
| using Test | ||
| using LinearAlgebra: Diagonal | ||
| using CUDA, AMDGPU | ||
|
|
||
| BLASFloats = (Float32, ComplexF64) # full suite is too expensive on CI | ||
| GenericFloats = () | ||
| @isdefined(TestSuite) || include("../testsuite/TestSuite.jl") | ||
| using .TestSuite | ||
|
|
||
| is_buildkite = get(ENV, "BUILDKITE", "false") == "true" | ||
|
|
||
| m = 19 | ||
| for T in (BLASFloats..., GenericFloats...) | ||
| TestSuite.seed_rng!(123) | ||
| atol = rtol = m * m * TestSuite.precision(T) | ||
| if !is_buildkite | ||
| TestSuite.test_mooncake_projections(T, (m, m); atol, rtol) | ||
| TestSuite.test_mooncake_projections(Diagonal{T, Vector{T}}, (m, m); atol, rtol) | ||
| end | ||
| end |
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 |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| """ | ||
| test_mooncake_projections(T, sz; kwargs...) | ||
|
|
||
| Run all Mooncake AD tests for hermitian and anti-hermitian projections of element type `T` | ||
| and size `sz`. | ||
| """ | ||
| function test_mooncake_projections(T::Type, sz; kwargs...) | ||
| summary_str = testargs_summary(T, sz) | ||
| return @testset "Mooncake projection $summary_str" begin | ||
| test_mooncake_project_hermitian(T, sz; kwargs...) | ||
| test_mooncake_project_antihermitian(T, sz; kwargs...) | ||
| end | ||
| end | ||
|
|
||
| """ | ||
| test_mooncake_project_hermitian(T, sz; rng, atol, rtol) | ||
|
|
||
| Test the Mooncake reverse-mode AD rule for `project_hermitian` and its in-place variant. | ||
| """ | ||
| function test_mooncake_project_hermitian( | ||
| T, sz; | ||
| rng = Random.default_rng(), atol::Real = 0, rtol::Real = precision(T) | ||
| ) | ||
| return @testset "project_hermitian" begin | ||
| A = instantiate_matrix(T, sz) | ||
| B = instantiate_matrix(T, sz) | ||
| alg = MatrixAlgebraKit.select_algorithm(project_hermitian, A) | ||
| Mooncake.TestUtils.test_rule( | ||
| rng, project_hermitian, A, alg; | ||
| mode = Mooncake.ReverseMode, atol, rtol | ||
| ) | ||
| Mooncake.TestUtils.test_rule( | ||
| rng, project_hermitian!, A, A, alg; | ||
| mode = Mooncake.ReverseMode, atol, rtol | ||
| ) | ||
| Mooncake.TestUtils.test_rule( | ||
| rng, project_hermitian!, A, B, alg; | ||
| mode = Mooncake.ReverseMode, atol, rtol | ||
| ) | ||
| end | ||
| end | ||
|
|
||
| """ | ||
| test_mooncake_project_antihermitian(T, sz; rng, atol, rtol) | ||
|
|
||
| Test the Mooncake reverse-mode AD rule for `project_antihermitian` and its in-place variant. | ||
| """ | ||
| function test_mooncake_project_antihermitian( | ||
| T, sz; | ||
| rng = Random.default_rng(), atol::Real = 0, rtol::Real = precision(T) | ||
| ) | ||
| return @testset "project_antihermitian" begin | ||
| A = instantiate_matrix(T, sz) | ||
| B = instantiate_matrix(T, sz) | ||
| alg = MatrixAlgebraKit.select_algorithm(project_hermitian, A) | ||
| Mooncake.TestUtils.test_rule( | ||
| rng, project_antihermitian, A, alg; | ||
| mode = Mooncake.ReverseMode, atol, rtol | ||
| ) | ||
| Mooncake.TestUtils.test_rule( | ||
| rng, project_antihermitian!, A, A, alg; | ||
| mode = Mooncake.ReverseMode, atol, rtol | ||
| ) | ||
| Mooncake.TestUtils.test_rule( | ||
| rng, project_antihermitian!, A, B, alg; | ||
| mode = Mooncake.ReverseMode, atol, rtol | ||
| ) | ||
| end | ||
| end |
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
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.
Uh oh!
There was an error while loading. Please reload this page.