Skip to content

fix: galaxies_to_halo_arrays silently drops halos beyond max_n #869

Closed

Description

@Jammy2211

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_n that any plane exceeds, raise a ValueError naming each overflowing plane (index, redshift, count) and the max_n needed.
  • Accept max_n=None: size the arrays to the fullest plane (in los_realizations_to_arrays, the fullest plane across the batch, so every realisation shares a shape).
  • Add a public helper halo_counts_per_plane_from so callers can choose max_n up front.
  • Add the witness tests; check whether the los_halos/simulator_jax.py example's fixed max_n=200 overflows 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's max_n=200 can overflow)

Branch

feature/substructure-halo-arrays-overflow; worktree ~/Code/PyAutoLabs-wt/substructure-halo-arrays-overflow/.

Steps

  1. autolens/lens/substructure_util.py: add halo_counts_per_plane_from(galaxies, plane_redshifts, profile_cls) and a _check_max_n that raises. galaxies_to_halo_arrays checks before packing and resolves max_n=None to max(counts, 1). The if slot < max_n silent skip is removed.
  2. los_realizations_to_arrays: max_n=None → fullest plane across all realisations; on overflow, prefix the error with the realisation index.
  3. test_autolens/lens/test_substructure_util.py: overflow raises with plane + count; None keeps every halo; exact max_n is accepted; batch None; batch overflow names the realisation.

Key files

  • autolens/lens/substructure_util.py
  • test_autolens/lens/test_substructure_util.py
  • autolens_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

  1. Jammy2211 commented on Nov 19, 2026

    @Jammy2211
    CollaboratorAuthor

    Shipped

    Merged in #870 and PyAutoLabs/autolens_workspace#682 (2026-11-19, /prm, merged unchanged). galaxies_to_halo_arrays / los_realizations_to_arrays raise a ValueError on overflow instead of dropping halos, and max_n=None sizes to the fullest plane; the workspace example uses max_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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions