Repository navigation
Description
Overview
substructure_util.galaxies_to_halo_arrays pads each plane's halos into a fixed (n_planes, max_n, n_params) array. When a plane holds more than max_n halos it drops the extras silently, while the negative-convergence sheets are still computed for the full population. The simulated image loses halos and mass is no longer conserved. A 1e6 M☉ line of sight measured on main a79a6b2 dropped 3,708 of 10,389 halos at max_n=1000. los_realizations_to_arrays inherits the same problem.
Reproduced on main before the fix: 5 NFWTruncatedSph halos on one plane with max_n=3 → 3 kept, no error.
Plan
- Count the halos on each plane before packing.
- With an integer
max_nthat any plane exceeds, raise aValueErrornaming each overflowing plane (index, redshift, count) and themax_nneeded. - Accept
max_n=None: size the arrays to the fullest plane (inlos_realizations_to_arrays, the fullest plane across the batch, so every realisation shares a shape). - Add a public helper
halo_counts_per_plane_fromso callers can choosemax_nup front. - Add the witness tests; check whether the
los_halos/simulator_jax.pyexample's fixedmax_n=200overflows with its own settings and update it only if it does. - Tier + merge mode: effective level: supervised; merge mode: auto-merge on green if the Witness passes after a merge slot
Detailed implementation plan
Affected repositories
- PyAutoLens (primary)
- autolens_workspace (only if
simulator_jax.py'smax_n=200can overflow)
Branch
feature/substructure-halo-arrays-overflow; worktree ~/Code/PyAutoLabs-wt/substructure-halo-arrays-overflow/.
Steps
autolens/lens/substructure_util.py: addhalo_counts_per_plane_from(galaxies, plane_redshifts, profile_cls)and a_check_max_nthat raises.galaxies_to_halo_arrayschecks before packing and resolvesmax_n=Nonetomax(counts, 1). Theif slot < max_nsilent skip is removed.los_realizations_to_arrays:max_n=None→ fullest plane across all realisations; on overflow, prefix the error with the realisation index.test_autolens/lens/test_substructure_util.py: overflow raises with plane + count;Nonekeeps every halo; exactmax_nis accepted; batchNone; batch overflow names the realisation.
Key files
autolens/lens/substructure_util.pytest_autolens/lens/test_substructure_util.pyautolens_workspace/scripts/imaging/features/advanced/los_halos/simulator_jax.py(conditional)
Sibling in flight: PyAutoLens#868 / autolens_workspace#681 (LOSSampler colossus) touch los.py and the same workspace script, but not these functions.
Source: PyAutoMind draft/bug/autolens/substructure_util_galaxies_to_halo_arrays_drops.md (shift 2026-11-19-pm).
Activity
Jammy2211 commentedon Nov 19, 2026
Shipped
Merged in #870 and PyAutoLabs/autolens_workspace#682 (2026-11-19, /prm, merged unchanged).
galaxies_to_halo_arrays/los_realizations_to_arraysraise a ValueError on overflow instead of dropping halos, andmax_n=Nonesizes to the fullest plane; the workspace example usesmax_n=None(1100/1100 halos kept). Witness 10 passed (4 fail on main). Independent adversary (Fable 5.2): CLEAN. Follow-up already filed: jax.grad NaN with zero-padded slots (pre-existing).Not yet released (pending-release). Record: PyAutoMind complete/2026/11/substructure-halo-arrays-overflow.md