Repository navigation
Conversation
…ht-hand side (stein_rtol) instead of degeneracy_atol Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
... and 14 files with indirect coverage changes 🚀 New features to boost your workflow:
|
| degeneracy_atol::Real = default_pullback_rank_atol(DV[1]), | ||
| gauge_atol::Real = default_pullback_gauge_atol(ΔDV[2]) | ||
| gauge_atol::Real = default_pullback_gauge_atol(ΔDV[2]), | ||
| complement_rtol::Real = eps(real(eltype(ΔA)))^(3 / 4) |
There was a problem hiding this comment.
It is somewhat inconsistent that we use a relative tolerance for this tolerance, whereas we use an absolute tolerance for all the other parameters.
So I would suggest complement_atol, with a default value that scales with the size of the adjoints, i.e. complement_atol::Real = default_pullback_gauge_atol(ΔDV...), or with new default_pullback_complement_atol definition that is similar to default_pullback_gauge_atol.
The advantage of that approach is that, we could have that X₀ is very small, because the adjoints are of that nature that they are completely captured in the current subspace. So it could be that e.g. ΔD and ΔV are order 1, but that the resulting X₀ is small. It then doesn't make much sense to compute the series so that X is converged very precisely relative to the size of X₀.
There was a problem hiding this comment.
That being said, I do agree that the previous atol passed to acccelartive_smith_iteration was completely wrong, since that was degeneracy_atol, with scales with the size of the primal values (i.e. D in this case) and not with the size of the adjoints. The only reasonable previous choice would have been gauge_atol, but a new parameter is certainly fine.
There was a problem hiding this comment.
I checked explicitly, and the case where X₀ did require one or two more doublings than actually needed when using the relative tolerance. Switching to an absolute difference fixes this. The issue with choosing the default similar to default_pullback_gauge_atol(ΔDV...) is that the terms in the series scale like ΔA, not like ΔV. So this choice would reintroduce the issues that arise when scaling A.
I added complement_atol with a new default_pullback_complement_atol, built from cotangents that actually scale like ΔA (ΔD and ΔV ./ D for the eigh case, and ΔS, ΔU ./ S and ΔVᴴ ./ S for the SVD case). I also chose to multiply with eps^(3/4) * x rather than eps(x)^(3/4) like the other defaults. eps(x)^(3/4) only grows like x^(3/4), so the tolerance would still drift slightly with the scale of A.
| default_pullback_gauge_atol(A) = iszerotangent(A) ? 0 : eps(norm(A, Inf))^(3 / 4) | ||
| function default_pullback_gauge_atol(A, As...) | ||
| As′ = filter(!iszerotangent, (A, As...)) | ||
| return isempty(As′) ? 0 : eps(norm(As′, Inf))^(3 / 4) |
There was a problem hiding this comment.
Not related to this change, but because of how norm works in Julia (i.e. the recursive norm( list, Inf) does not apply norm(x, Inf) on the elements x in list, but just norm(x). Hence, I would suggest to change this to
eps(maximum(y->norm(y, Inf), As′))
| x = zero(real(float(eltype(d)))) | ||
| iszerotangent(ΔD) || (x = max(x, norm(ΔD, Inf))) | ||
| iszerotangent(ΔV) || (x = max(x, norm(ΔV ./ transpose(d), Inf))) | ||
| return eps(typeof(x))^(3 / 4) * x |
There was a problem hiding this comment.
It seems this is different from eps(x)^(3 / 4), so if this is better, we should probably use it consistently in the other default_..._atol functions as well. Also, the behavior to divide by ΔV by D, is that something that 🤖 would also recommend for the default_pullback_gauge_atol?
There was a problem hiding this comment.
Yes, I was just checking the same thing. The gauge tolerance default actually used to look like eps(T)^(3/4) * max(n, 1), which is nicely linear in the norm. This was changed in #92 to resolve some accuracy issues, but I think it's better to switch back to multiplying the norm with eps(T)^(3/4).
svd_trunc_pullback!,eigh_trunc_pullback!andeig_trunc_pullback!stop the Smith series for the part outside the kept vectors once its terms drop belowdegeneracy_atol. That tolerance scales like the singular values or eigenvalues, while the terms scale likeΔA, i.e. inversely with them. The result therefore depends on the scale ofA: forAscaled by 2^20 or more, the series stops after too few terms andΔAis off by 1e-3 (svd, eigh) up to 2e-1 (eig) on the reproducer below.This PR adds a keyword
complement_atolto the three pullbacks. Its default,default_pullback_complement_atol, iseps(T)^(3/4)times the largest entry of the cotangents that scale likeΔA:ΔDandΔV ./ transpose(D)(eig, eigh), orΔS,ΔU ./ transpose(S)andΔVᴴ ./ S(svd). The pullbacks then scale exactly withA, with errors of 1e-15 (eig: 5e-12) at every scale.Reproducer
c ΔA(c A)against the full pullback atA, withca power of two so the factors scale exactly (ΔS / cforc A), for spectra with kept values in [1, 10] and discarded ones at most 0.5 (mainagainst this PR, Julia 1.12):🤖 Generated with Claude Code