Skip to content

fix: plot_grid drops highlighted indexes outside the grid (small datasets) - #706

Merged
Jammy2211 merged 3 commits into
mainfrom
feature/plot-grid-small-datasets-indexes
Nov 20, 2026
Merged

Jammy2211 merged 3 commits into
mainfrom
feature/plot-grid-small-datasets-indexes

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

plot_grid(indexes=...) raised IndexError when a highlighted index lay outside the grid. HowToLens chapter_1_introduction/tutorial_2_ray_tracing.py picks indexes for its 101x101 grid, and PYAUTO_SMALL_DATASETS=1 caps that grid to 256 points, so the tutorial crashed. plot_grid now drops out-of-range indexes and logs one INFO line with the count. A group with nothing left is skipped, and each surviving group keeps its own colour. Closes #705.

API Changes

None — internal changes only. plot_grid now tolerates out-of-range highlight indexes instead of raising. Its signature is unchanged and the new logger is module-private (_logger).
See full details below.

Decision taken (decide-and-flag)

Step 1 of the plan said "convert each group to an integer numpy array". The independent review showed that dtype=int would silently turn a boolean-mask group into indexes 0 and 1. The branch instead keeps the input dtype and converts a boolean group with np.flatnonzero, which matches how main behaves for full-length masks. Float indexes still raise, as on main. One side effect: a boolean mask shorter than the grid now highlights its set points instead of raising a length-mismatch IndexError. No caller in the libraries or tutorials passes masks; every caller passes integer lists.

Test Plan

  • python -m pytest -q -n 4 test_autoarray/plot: 72 passed. New test_autoarray/plot/test_grid.py covers in-range, partly out-of-range (with the log text), fully out-of-range and boolean-mask groups. Control: the out-of-range tests fail on main with IndexError: index 5118 is out of bounds for axis 0 with size 16.
  • Witness: HowToLens scripts/chapter_1_introduction/tutorial_2_ray_tracing.py exits 0 with PYAUTO_SMALL_DATASETS=1 (log: plot_grid: dropped 15 highlighted index(es) outside the 256-point grid.) and exits 0 without it. Before the fix, small mode exited 1 with the IndexError.
  • Targeted smoke (pyauto-heart smoke --targeted) on HEAD f575552 picked 7 scripts, all PASS: autogalaxy imaging/fit.py, guides/galaxies.py; autolens imaging/fit.py, multi_galaxy/fit.py, guides/galaxies.py, imaging/features/pixelization/delaunay.py, interferometer/features/pixelization/delaunay.py. An earlier run on the first commit also passed autolens_workspace_test point_source/jax_likelihood/solver_extent.py.
Full API Changes (for automation & release notes)

Changed Behaviour

  • autoarray.plot.plot_grid(indexes=...): indexes outside [-N, N) are dropped and logged at INFO; a group left empty is skipped; boolean-mask groups are converted with np.flatnonzero.

Validation checklist (--auto run — plan was not pre-approved)

  • Effective level: supervised (header: safe, cap: bug → supervised); shift worker 2026-11-20-am, ends at PR-open
  • Plan: on the issue (fix: plot_grid IndexError when highlighted indexes exceed the grid (small datasets) #705), written at start, unmodified since; the one deviation is flagged above
  • Gate: tests 72 passed (plot modules) + Witness pass both modes · smoke targeted 7/7 PASS · review CLEAN (independent Opus reviewer; its first pass returned one finding, the boolean-mask conversion, fixed in f575552, and the re-review was CLEAN; the surface listed no claims to falsify) · Heart dev-ship GREEN (scoped to PyAutoArray + dependants, refreshed 2026-11-20T08:43Z). Shown, non-blocking: PyAutoGalaxy/PyAutoLens 5 commits behind origin (local checkouts); manifest drift ×3 (in the shift's heart-ack)
  • No adversary pass (shift ruling S3): the close-out or /prm is the adversary
  • Human: plan sound in hindsight?
  • Human: diff matches plan (no scope creep)?
  • Human: merge, amend, or reject — then log the outcome

Follow-up suggested in the prompt, not done here: add tutorial_2 to a HowToLens smoke list.

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

Jammy2211 and others added 3 commits November 20, 2026 08:39
Tutorials pick highlight indexes for a full-size grid; under
PYAUTO_SMALL_DATASETS the grid is capped and plot_grid raised IndexError.
Out-of-range indexes are now dropped (logged once), and a group with none
left is skipped. Closes #705.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jammy2211 Jammy2211 added pending-release PR queued for the next release build decision-taken autonomous run took one flagged decision (AUTONOMY.md decide-and-flag) labels Nov 20, 2026
@Jammy2211
Jammy2211 merged commit 0f4e8a0 into main Nov 20, 2026
4 checks passed
@Jammy2211
Jammy2211 deleted the feature/plot-grid-small-datasets-indexes branch November 20, 2026 11:38
@pyautolabs-bot pyautolabs-bot Bot removed the pending-release PR queued for the next release build label Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

decision-taken autonomous run took one flagged decision (AUTONOMY.md decide-and-flag)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: plot_grid IndexError when highlighted indexes exceed the grid (small datasets)

1 participant