Skip to content

fix: galaxies_to_halo_arrays raises on max_n overflow, accepts max_n=None - #870

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/substructure-halo-arrays-overflow
Nov 19, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/substructure-halo-arrays-overflow

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

galaxies_to_halo_arrays used to drop halos silently when a plane held more than max_n of them. The negative-convergence sheets are still computed for the full population, so the simulated image lost mass and nothing reported it. Measured on main a79a6b2: a 1e6 M☉ line of sight dropped 3,708 of 10,389 halos at max_n=1000.

The fix changes three things:

  • Overflow raises. An integer max_n that any plane exceeds raises a ValueError naming each overflowing plane (index, redshift, halo count) and the max_n needed.
  • max_n=None sizes the arrays. The arrays are sized to the fullest plane. In los_realizations_to_arrays that is the fullest plane across the whole batch, so every realisation shares a shape. An overflow there is prefixed with the realisation index.
  • New helper. halo_counts_per_plane_from lets callers pick max_n up front.

Callers that pass an integer max_n large enough for every plane get identical arrays.

Closes #869

Workspace

autolens_workspace's los_halos/simulator_jax.py used a fixed max_n=200. With its own settings, the fullest plane holds 323–377 halos on every seed it draws (42, 100–107), so the example was silently dropping halos and would raise after this change. The companion workspace PR switches it to max_n=None.

Sibling

#868 (LOSSampler colossus) touches los.py and test_los.py only. It has no overlap with this diff.

Checks

  • Reproduced on main first: 5 halos on one plane with max_n=3 kept 3 and raised nothing.
  • Tests: test_autolens/lens/test_substructure_util.py, 10 passed (5 new; the witness is test__galaxies_to_halo_arrays__raises_when_a_plane_overflows_max_n and …__max_n_none_sizes_to_fullest_plane_and_keeps_every_halo).
  • Targeted smoke: no curated script references the change, so the import check ran: autolens guides/galaxies.py PASS.
  • Review: independent review, CLEAN.

🤖 Generated with Claude Code

…None

A plane holding more halos than max_n used to drop the extras silently,
while the negative-convergence sheets still removed their mass. Now an
overflow raises a ValueError naming each plane, its count and the max_n
needed, and max_n=None sizes the arrays to the fullest plane (across the
whole batch in los_realizations_to_arrays). Adds
halo_counts_per_plane_from.

Closes #869

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

fix: galaxies_to_halo_arrays silently drops halos beyond max_n

1 participant