Fix remove_svd_gauge_dependence! for rank-deficient SVDs - #286
Merged
Merged
Conversation
Co-authored-by: Lukas Devos <ldevos98@gmail.com>
leburgel
force-pushed
the
lb/fix_svd_gauge_rank
branch
from
October 1, 2026 06:24
d9b5795 to
5afca7c
Compare
lkdvos
approved these changes
Oct 1, 2026
Jutho
reviewed
Oct 1, 2026
| if size(ΔU, 2) > r | ||
| if r < length(Sdiag) # rank-deficient case, no stable information can be extracted from extra columns of U | ||
| zero!(ΔU[:, (r + 1):end]) | ||
| zero!(view(ΔU, :, (r + 1):size(ΔU, 2))) |
Jutho
reviewed
Oct 1, 2026
| gaugepart = mul!(U₁' * ΔU₁, Vᴴ₁, ΔVᴴ₁', true, true) | ||
| gaugepart = project_antihermitian!(gaugepart) | ||
| gaugepart[abs.(transpose(Sdiag) .- Sdiag) .>= degeneracy_atol] .= 0 | ||
| gaugepart[abs.(transpose(view(Sdiag, 1:r)) .- view(Sdiag, 1:r)) .>= degeneracy_atol] .= 0 |
Member
There was a problem hiding this comment.
We could have had an S₁ = view(Sdiag, 1:r) definition and use this here, but it's fine like this.
Codecov Report❌ Patch coverage is
🚀 New features to boost your workflow:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When some singular values are below
rank_atol(r < length(S)),remove_svd_gauge_dependence!has two bugs:gaugepartis onlyr × r, so the function throws aBoundsError.ΔU(rows ofΔVᴴ) beyondrare meant to be zeroed, butzero!(ΔU[:, (r + 1):end])zeroes a copy. The first bug has kept this one from surfacing.This PR builds the mask from
Sdiag[1:r]and zeroes views. The full-rank case is unchanged.Reproducer
On
main:With only the mask fixed, the rank-deficient part is not zeroed:
With this PR:
I have a small regression test I could add, but that would be another instance of testing pullback-related things directly like the test added in #282, so I didn't add it right away. Let me know if this would be good to add anyway.