Fix NaN in spectral TV regularizer on flat maps (epsilon_tv=0)#311
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev-backend #311 +/- ##
============================================
Coverage 47.43% 47.44%
============================================
Files 55 55
Lines 26979 26984 +5
Branches 4599 4599
============================================
+ Hits 12798 12803 +5
Misses 12689 12689
Partials 1492 1492 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
achael
approved these changes
Jun 23, 2026
achael
left a comment
Owner
There was a problem hiding this comment.
looks good -- main still has default epsilon=1e-12, so I think we just need to cherry pick this into dev as well.
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.
What
reg_tv_spec/reggrad_tv_specproducedNaNon a flat spectral map whenepsilon_tv == 0(the default since #310). A flat coefficient map is exactly the multifrequency imaging start —add_const_mfinitialises a constant spectral index, so every neighbour difference is zero and the naivesqrt(0)leaves a0/0:Downstream this killed the optimizer: an HL Tau
mf_order=1run gaveJ: nanand reconstructed a flat blob instead of the disk. With the fix it converges tochi2_vis ~ 1and nxcorr 0.999 vs the exact v1.2.5 result.Fix
Double-
whereguard in both functions (autodiff-safe; a flat pixel gets gradient 0, not0/0). Minimal and self-contained — onlymultifreq_imager_utils.pyis touched, no new shared helper.Test
New
TestSpectralTVFlatMapFiniteintest_gradients.py: everytv_*spectral regularizer stays finite on a flat map atepsilon_tv=0, checked on both the NumPy analytic gradient andjax.gradof the value. The existing S5 FD-parity suite uses a structured map withepsilon_tv != 0, which is why it never caught this.Origin
Regression from #310, which flipped the
epsilon_tvdefault from1e-12to0. Backend-touching. May warrant a release cherry-pick like the #240stv_pol_gradfix.