Skip to content

AD rules for (anti-) hermitian projection#174

Merged
lkdvos merged 15 commits intomainfrom
hermitian
Feb 27, 2026
Merged

AD rules for (anti-) hermitian projection#174
lkdvos merged 15 commits intomainfrom
hermitian

Conversation

@lkdvos
Copy link
Member

@lkdvos lkdvos commented Feb 17, 2026

Fixes #99.

Requires #175.

I played around a bit with also implementing the project_isometric, but since that was taking more significant changes (possibly writing an actual sylvester equation solver), I will leave that for a follow-up.
Also, I'm not actually smart enough for Enzyme rules, so will also ignore that for now. (Additionally I'm not sure we need them in that case, so don't want to pollute this PR)

@lkdvos lkdvos requested review from Jutho and kshyatt February 17, 2026 15:20
@codecov
Copy link

codecov bot commented Feb 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
ext/MatrixAlgebraKitChainRulesCoreExt.jl 83.33% <100.00%> (+1.19%) ⬆️
...gebraKitMooncakeExt/MatrixAlgebraKitMooncakeExt.jl 64.31% <100.00%> (+1.73%) ⬆️
src/implementations/projections.jl 96.42% <100.00%> (ø)
src/pullbacks/polar.jl 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

lkdvos and others added 9 commits February 26, 2026 10:32
Guard `C .+= ΔP` with `!iszerotangent(ΔP)` in both
`left_polar_pullback!` and `right_polar_pullback!` to handle
the case where ΔP is `nothing`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace LAPACK trsyl!-based solver with a direct eigendecomposition
approach when both arguments are the same Hermitian matrix (as in polar
pullbacks). This avoids LAPACKException(1) for close eigenvalues.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add rrules/pullbacks for `project_hermitian!`, `project_antihermitian!`,
and `project_isometric!` directly in each AD backend extension
(ChainRulesCore, Enzyme, Mooncake). The hermitian/antihermitian
pullbacks are self-adjoint, while the isometric pullback delegates to
`left_polar_pullback!` with zero ΔP.

Includes test utilities and tests for all three backends.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kshyatt
Copy link
Member

kshyatt commented Feb 26, 2026

AD rules yet no Enzyme 🥺 ? Or would you like me to add those?

@lkdvos
Copy link
Member Author

lkdvos commented Feb 26, 2026

See comment in the PR body about Enzyme 😉

@kshyatt
Copy link
Member

kshyatt commented Feb 26, 2026

OK well, I can certainly add them if you like, but if we don't need them yet, can of course happen later

@lkdvos
Copy link
Member Author

lkdvos commented Feb 26, 2026

The thing is that for Enzyme I would actually be quite interested to see if they can generate better rules than we can manually write, since this is somewhat of the promise of that system (maybe?), and also I really just was to lazy to actually go and investigate, since I basically mostly needed the chainrules ones since that simply errors without.

@lkdvos lkdvos enabled auto-merge (squash) February 26, 2026 19:41
@lkdvos lkdvos requested review from Jutho and kshyatt February 27, 2026 13:26
@kshyatt
Copy link
Member

kshyatt commented Feb 27, 2026

Looks good to me, feel free to just say "no" to my comment

@lkdvos lkdvos merged commit 295a354 into main Feb 27, 2026
10 checks passed
@lkdvos lkdvos deleted the hermitian branch February 27, 2026 15:46
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.

[AD] rrules for project_(anti)hermitian

3 participants