Skip to content

fix: add auto-simulate guards to unguarded dataset loads - #460

Merged
Jammy2211 merged 3 commits into
mainfrom
feature/missing-auto-simulate-guards
Aug 3, 2026
Merged

Jammy2211 merged 3 commits into
mainfrom
feature/missing-auto-simulate-guards

Conversation

@Jammy2211

@Jammy2211 Jammy2211 commented Aug 3, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #455

Summary

Fixes 3 of the 4 missing-dataset smoke failures from PyAutoHeart run 30790463134 (the 4th, group/data_preparation/start_here, is deleted by #456 — this branch is merged onto that). All three were reproduced on a clean checkout before any edit, and every paired simulator already existed — the fix is an auto-simulate guard in each case, nothing was missing.

A sweep then showed the failures were the tip of a class: dataset loads that reach from_fits with no guard pass smoke only because an earlier script in the run happens to simulate the same dataset first. Any of them run standalone in a clean checkout still break. After this branch, zero unguarded dataset loads remain in either repo.

Root cause shape

Two of the three failing scripts already carried a correct guard — for their first dataset. The load that failed was a second dataset further down the same file that nobody guarded. mask_irregular.py had no guard at all.

Scripts Changed

Script Change
scripts/imaging/data_preparation/manual/mask_irregular.py ★ guard → imaging/features/no_lens_light/simulator.py
scripts/multi_dataset/features/imaging_and_interferometer/modeling.py ★ guard on the 2nd (imaging) dataset → multi_dataset/simulator.py
scripts/guides/results/start_here.py guard → no_lens_light/simulator.py
scripts/guides/results/latent_variables.py guard → no_lens_light/simulator.py
scripts/imaging/data_preparation/start_here.py guard → imaging/simulator.py
scripts/imaging/data_preparation/examples/psf.py guard → imaging/simulator.py
scripts/imaging/features/linear_light_profiles/likelihood_function.py guard → imaging/simulator.py
scripts/imaging/features/pixelization/delaunay.py one guard at :932 — the 2nd unguarded block at :1041 is the same dataset later in the same linear script
scripts/imaging/data_preparation/gui/mask.py guard → no_lens_light/simulator.py
scripts/imaging/data_preparation/gui/positions.py guard → no_lens_light/simulator.py
scripts/imaging/data_preparation/gui/extra_galaxies_centres.py guard → extra_galaxies/simulator.py
scripts/imaging/data_preparation/gui/mask_extra_galaxies.py guard → extra_galaxies/simulator.py
scripts/imaging/data_preparation/gui/lens_light_centre.py repointed off the dead lens_sersic path + guard
scripts/guides/results/database/start_here.py three faults fixed — see below
scripts/guides/results/aggregator/queries.py stale prose only (lens_sersic → simple__no_lens_light, matching the code beneath)
config/build/no_run.yaml guides/results/database/start_here NEEDS_FIX entry removed

★ = one of the reported smoke failures.

The dead dataset/imaging/lens_sersic path

No simulator anywhere writes it. Three references: gui/lens_light_centre.py:32, guides/results/database/start_here.py:73, and aggregator/queries.py:60 (prose only — the code already queried simple__no_lens_light).

Repointing at dataset/multi_dataset/imaging/lens_sersic (the only real lens_sersic dataset) was rejected: it is multi-band with g_data.fits/g_psf.fits prefixes, so a plain from_fits(data_path=dataset_path / "data.fits") cannot load it. Both consumers now use dataset/imaging/simple, which scripts/imaging/simulator.py builds with a Sersic bulge on the lens galaxy (:184) — single-band imaging that genuinely has lens light, which is what a "click the lens light centre" GUI needs.

database/start_here.py drops the dead name rather than duplicating simple twice, which would give two identically-named database entries and defeat the guide's own point.

guides/results/database/start_here.py leaves no_run

Its NEEDS_FIX marker named one fault. It had three:

  1. Missing dataset → auto-simulate guard, inside the loop, dispatching per dataset name.
  2. Missing info.json → built inline. The sole producer, data_preparation/examples/optional/info.py, writes it for simple alone, so nothing wrote simple__no_lens_light/info.json in any run order, and it isn't shipped. The inline dict matches info.py's contents and a prose cross-reference to it is kept. Dead import json removed. No downstream key dependency — aggregator/data_fitting.py:76 reads agg.values("info") generically.
  3. Unbounded real search → n_like_max=300. The script declares ENV: real_search (so PYAUTO_TEST_MODE is unset and the sampler genuinely runs) but was the only such script in the workspace without a cap. Its four siblings in guides/results/ all use 300, and _quick_fit.py:16 documents the rationale: "hard-capped at n_like_max=300 likelihood evaluations rather than running to convergence… fast enough to fit inside the per-script CI timeout."

The invariant real_search ⟹ n_like_max now holds with zero exceptions — exactly 5 scripts declare real_search and use af.Nautilus, and all 5 carry a cap.

Runtime: unbounded (>9 min on one core, fit 1 of 2 not converging) → EXIT 0 in 245s.

Validation

Every changed script that can run, run under its real smoke env — built via autohands.env_config.build_env_for_script against config/build/profile_smoke.yaml, not hand-set variables. Those envs set PYAUTO_SMALL_DATASETS=1, which makes should_simulate rmtree and re-simulate, so every guard was genuinely exercised rather than skipped over pre-existing data.

Script Result
mask_irregular.py ★ PASS 8s
multi_dataset/.../modeling.py ★ PASS 20s
guides/results/database/start_here.py PASS 245s
guides/results/aggregator/queries.py PASS 68s
imaging/features/pixelization/delaunay.py PASS 24s
linear_light_profiles/likelihood_function.py PASS 11s
guides/results/start_here.py PASS 11s
data_preparation/examples/psf.py PASS 10s
guides/results/latent_variables.py PASS 9s
imaging/data_preparation/start_here.py PASS 9s

Not verified by execution: the 5 GUI scripts — they cannot run headless and are no_run. Their guards use the same idiom and are syntax- and import-checked, but were not executed.

Also: check_sizes.sh clean; all changed scripts compile; all import al; full generate.py autolens regeneration left workspace_index.json and llms-full.txt byte-identical (so no generated-index collision with #453 or #459).

Note on the reported evidence

The triage said NEEDS_FIX markers existed "for several start_here scripts". no_run.yaml carried 4 NEEDS_FIX entries, of which exactly one was dataset-related. imaging/data_preparation/start_here and guides/results/start_here were not in no_run — they were unguarded and passed only by run-ordering luck. Both are now guarded.

Ship gate

Heart red at ship time (2026-08-03T17:44:16Z). Shipped under the corrective-PR exception, human-authorized in session, scoped to the YELLOW reason "workspace validation not passing (19 failed, 1 timeout, cloud#30790463134: …)" — the run this task was filed from, 3 of whose failures this removes.

None of the three RED reasons relate to this change: "PyAutoFit: 1 commit(s) behind origin", "install verification FAILED (testpypi; checks D)" (chased by PyAutoLens#687), "release validation FAILED (stage integrate)" (chased by PyAutoFit#1442). The exception permits commit/push/PR-open only — merge and release stay human.

Follow-up filed (not in this PR)

Two guard idioms coexist and are not equivalent: should_simulate also deletes-and-rebuilds under PYAUTO_SMALL_DATASETS=1, while the hand-rolled not (dataset_path / "data.fits").exists() variants in 4 scripts do not — so those keep full-resolution data on disk in a capped run. Deliberately not folded in, since it is a behaviour change to scripts that currently pass. Prompt drafted in PyAutoMind.

🤖 Generated with Claude Code

Jammy2211 and others added 3 commits August 3, 2026 19:05
Fixes 3 of the 4 missing-dataset smoke failures from PyAutoHeart run
30790463134 (the 4th, group/data_preparation/start_here, is deleted by #456).
All three were reproduced on a clean checkout before any edit, and every
paired simulator already existed.

Two of the three already carried a correct guard for their FIRST dataset; the
load that failed was a SECOND dataset further down the same file that nobody
guarded. mask_irregular.py had no guard at all.

14 guards added across autolens_workspace, each dispatching to its existing
paired simulator. delaunay.py takes ONE guard at :932 — the second unguarded
block at :1041 resolves to the same dataset/imaging/simple later in the same
linear script.

Retires the dead dataset/imaging/lens_sersic path, which no simulator anywhere
writes. gui/lens_light_centre.py and guides/results/database/start_here.py are
repointed at dataset/imaging/simple (built by scripts/imaging/simulator.py with
a Sersic bulge on the lens galaxy). database/start_here DROPS the dead name
rather than duplicating `simple` twice, which would give two identically-named
database entries. queries.py:60 had stale prose naming lens_sersic while the
code beneath already queried simple__no_lens_light.

guides/results/database/start_here leaves no_run. It had THREE faults, not the
one its NEEDS_FIX marker named:
  1. missing dataset      -> auto-simulate guard (in the loop, per name)
  2. missing info.json    -> built inline; the sole producer, data_preparation/
     examples/optional/info.py, writes it for `simple` ALONE, so nothing wrote
     simple__no_lens_light/info.json in any run order. Dead `import json`
     removed. No downstream key dependency: aggregator/data_fitting.py:76
     reads agg.values("info") generically.
  3. unbounded real search -> n_like_max=300. It declares ENV: real_search (so
     PYAUTO_TEST_MODE is unset and the sampler genuinely runs) but was the ONLY
     such script in the workspace without a cap; its four siblings in
     guides/results/ all use 300. Invariant now holds with zero exceptions.
     Runtime: unbounded (>9min, not converging) -> EXIT 0 in 245s.

Verified under real smoke envs built via autohands.env_config.build_env_for_
script, not hand-set vars. PYAUTO_SMALL_DATASETS=1 makes should_simulate
rmtree and re-simulate, so every guard was genuinely exercised.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Aug 3, 2026
@Jammy2211
Jammy2211 merged commit f95b4fd into main Aug 3, 2026
6 of 8 checks passed
@Jammy2211
Jammy2211 deleted the feature/missing-auto-simulate-guards branch August 3, 2026 21:41
@Jammy2211 Jammy2211 removed the pending-release PR queued for the next release build label Oct 7, 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: add auto-simulate guards to unguarded dataset loads

1 participant