Repository navigation
fix: plot_grid drops highlighted indexes outside the grid (small datasets) - #706
Merged
Merged
Conversation
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>
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
plot_grid(indexes=...)raisedIndexErrorwhen a highlighted index lay outside the grid. HowToLenschapter_1_introduction/tutorial_2_ray_tracing.pypicks indexes for its 101x101 grid, andPYAUTO_SMALL_DATASETS=1caps that grid to 256 points, so the tutorial crashed.plot_gridnow 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_gridnow 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=intwould silently turn a boolean-mask group into indexes 0 and 1. The branch instead keeps the input dtype and converts a boolean group withnp.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-mismatchIndexError. 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. Newtest_autoarray/plot/test_grid.pycovers 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 onmainwithIndexError: index 5118 is out of bounds for axis 0 with size 16.scripts/chapter_1_introduction/tutorial_2_ray_tracing.pyexits 0 withPYAUTO_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.pyauto-heart smoke --targeted) on HEAD f575552 picked 7 scripts, all PASS: autogalaxyimaging/fit.py,guides/galaxies.py; autolensimaging/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_testpoint_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 withnp.flatnonzero.Validation checklist (--auto run — plan was not pre-approved)
/prmis the adversaryFollow-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