Skip to content

fix: synthetic positions fallback in test mode and PYAUTO_SMALL_DATASETS - #479

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/positions-test-mode-fallback
Apr 29, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/positions-test-mode-fallback

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Fixes a ValueError: zero-size array to reduction operation fmax in Result.positions_likelihood_from when PYAUTO_TEST_MODE=2 produces unphysical mass models that back-trace to empty / NaN image-plane positions. Also collapses the os.environ.pop("PYAUTO_SMALL_DATASETS") workaround that simulator scripts use around PointSolver.solve by short-circuiting the solver itself when small-datasets mode is on.

Closes #477.

API Changes

No public API signature changes. Two test-mode-only behavior additions, both gated on env vars and inert in production:

  • Result.positions_likelihood_from now substitutes [(1.0, 0.0), (-1.0, 0.0)] when PYAUTO_TEST_MODE is set and the resolved positions are empty / NaN / inf.
  • PointSolver.solve now short-circuits to [(1.0, 0.0), (0.0, 1.0)] when PYAUTO_SMALL_DATASETS=1 is set, skipping the triangle-tiling solve.

Outside test mode / smoke-test mode neither branch is reached. See full details below.

Test Plan

  • New unit test test__positions_likelihood_from__test_mode_fallback exercises the empty-positions path with PYAUTO_TEST_MODE=2.
  • Existing test_autolens/analysis/test_result.py and test_autolens/point/triangles/ suites still pass (21 tests).
  • Manual smoke: PYAUTO_TEST_MODE=2 python scripts/imaging/features/pixelization/delaunay.py no longer crashes at the original result.py:333 error site (a separate downstream border_relocator.py:450 bug surfaces, tracked separately).
  • PointSolver short-circuit is exercised by every simulator integration script run with PYAUTO_SMALL_DATASETS=1 — workspace cleanup PR will remove the os.environ.pop workarounds.
Full API Changes (for automation & release notes)

Removed

  • None

Added

  • None (no new public symbols)

Renamed

  • None

Changed Signature

  • None

Changed Behaviour

  • autolens.analysis.result.Result.positions_likelihood_from — when PYAUTO_TEST_MODE is set (any non-zero value) and the resolved positions array is empty (shape[0] < 2), or contains NaN, or contains inf, substitutes the synthetic pair [(1.0, 0.0), (-1.0, 0.0)] and emits a single logger.warning before computing the threshold. Outside test mode no change.
  • autolens.point.solver.point_solver.PointSolver.solve — when PYAUTO_SMALL_DATASETS=1 is set, returns aa.Grid2DIrregular(values=[(1.0, 0.0), (0.0, 1.0)]) immediately, skipping super().solve_triangles(...) and downstream filtering. Outside small-datasets mode no change.

Migration

  • Workspace simulator scripts that currently wrap PointSolver.solve with os.environ.pop("PYAUTO_SMALL_DATASETS", None) / restore can now delete that workaround. A follow-up workspace PR removes it from scripts/group/simulator.py, scripts/group/features/multi_gaussian_expansion/simulator.py, and scripts/group/features/no_lens_light/simulator.py.

🤖 Generated with Claude Code

- Result.positions_likelihood_from: when PYAUTO_TEST_MODE is active and the
  resolved positions are empty / contain NaN / contain inf, substitute
  [(1.0, 0.0), (-1.0, 0.0)] so the threshold and PositionsLH still build.
  Outside test mode the behaviour is unchanged.
- PointSolver.solve: when PYAUTO_SMALL_DATASETS=1, return [(1.0, 0.0),
  (0.0, 1.0)] immediately and skip the triangle-tiling solve. Lets simulator
  scripts drop their os.environ.pop("PYAUTO_SMALL_DATASETS") workarounds.
- Adds one unit test for the test-mode fallback path.

Closes #477.
@Jammy2211

Copy link
Copy Markdown
Collaborator Author

Workspace PR: PyAutoLabs/autolens_workspace#102

@Jammy2211
Jammy2211 merged commit 24837a3 into main Apr 29, 2026
5 checks passed
@Jammy2211
Jammy2211 deleted the feature/positions-test-mode-fallback branch April 29, 2026 07:23
@Jammy2211 Jammy2211 removed the pending-release PR queued for the next release build label Sep 4, 2026
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: synthetic positions fallback in test mode and PYAUTO_SMALL_DATASETS

1 participant