Repository navigation
fix: pad empty halo slots with benign params so substructure jax.grad is finite - #872
Merged
Merged
Conversation
… is finite galaxies_to_halo_arrays padded empty slots with zeros, so a padded NFWTruncatedSph slot had scale_radius = 0 and jax.grad through the multi-plane deflections was NaN whenever planes held different halo counts. Empty slots now hold the profile's `vmapped_padding_params` row (ones when it has none) behind a zero centre. Adds the witness test: 2 + 5 halos at max_n=8 give the same finite gradient as no padding, to 1e-10. Closes #871 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
galaxies_to_halo_arrayspadded empty halo slots with zeros. A paddedNFWTruncatedSphslot therefore hadscale_radius = 0, andjax.gradthrough the multi-plane substructure deflections was NaN whenever planes held different halo counts, which they always do.max_n=None(#870) did not help, because every plane below the fullest is still padded.Empty slots now hold a benign row: a zero centre followed by the profile's
vmapped_padding_params, or ones when the profile has none. The mask still zeroes the slot's deflection, and its gradient is now finite (and zero). The companion PyAutoGalaxy PR (PyAutoLabs/PyAutoGalaxy#738) makes the hook itself swap masked rows, and also fixes thecNFWSphNaN gradient. Either PR alone makes this PR's witness pass, so they can merge in either order.Closes #871
Tests (witness)
test__galaxies_to_halo_arrays__padded_slots_keep_multi_plane_gradients_finite: two planes with 2 and 5NFWTruncatedSphhalos are packed atmax_n=8.jax.gradof the summed multi-plane deflection, with respect to the grid and to every real halo's params, is finite and equals the no-padding gradient (each plane packed atmax_nequal to its own count) to 1e-10 in float64. The padded slots' gradients are exactly 0.test__galaxies_to_halo_arrays__empty_slots_hold_benign_padding.test_autolens/lens: 228 passed. The finitecNFWSphgradient half of the witness is tested in PyAutoGalaxy#738.Smoke
Targeted (
pyauto-heart smoke --targeted): autolensguides/using_jax.py,guides/misc/witt_wynne.pyPASS; autogalaxyguides/using_jax.pyPASS.Review
Independent review (Opus 5.5): CLEAN. It noted that, because this PR pads with the benign row, the hook's own handling of zero padding is tested only in PyAutoGalaxy#738.
🤖 Generated with Claude Code