Skip to content

fix: normalise the four hand-rolled auto-simulate guards onto should_simulate - #463

Merged
Jammy2211 merged 1 commit into
mainfrom
claude/autolens-guard-small-datasets-jaqyxv
Aug 3, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
claude/autolens-guard-small-datasets-jaqyxv

Conversation

@Jammy2211

@Jammy2211 Jammy2211 commented Aug 3, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #462. Follow-up left open by choice from #455 / #460.

What changed

Four scripts guarded their auto-simulate step by hand instead of calling al.util.dataset.should_simulate, which the other 249 sites use:

Script Before After
scripts/cluster/likelihood_function.py not (dataset_path / "data.fits").exists() or not (dataset_path / "mass.csv").exists() should_simulate(...) or not (dataset_path / "mass.csv").exists()
scripts/interferometer/features/pixelization/many_visibilities_preparation.py not (dataset_path / "data.fits").exists() should_simulate(...)
scripts/imaging/features/advanced/subhalo/sensitivity/slam_source_parametric.py not dataset_Path().exists() should_simulate(...)
scripts/imaging/features/advanced/subhalo/sensitivity/slam_source_pixelized.py not dataset_Path().exists() should_simulate(...)

The two idioms are not equivalent. Under PYAUTO_SMALL_DATASETS=1 (a config/build/profile_smoke.yaml default) should_simulate deletes the dataset so the simulator rebuilds it at reduced resolution; a bare .exists() check reuses whatever is on disk. The four scripts therefore read a full-resolution dataset left by an earlier uncapped run inside a run that is meant to be capped.

cluster/likelihood_function.py also reads the truth-model CSVs, so its stricter mass.csv clause is kept rather than dropped. should_simulate is evaluated first so its rebuild side-effect always runs before or short-circuits.

The failure mode is silent, not loud

The prompt (and this PR's first draft) predicted a shape-mismatch crash. Measured, it is quieter and worse. Controlled run of cluster/likelihood_function.py under the capped profile, with a stale (1000, 1000) dataset on disk, pre-change vs post-change — the only variable is whether the dataset gets rebuilt:

pre-change post-change
dataset after run (1000, 1000) — reused (16, 16) — rebuilt
image-plane log likelihood -2.3951e+07 1.7518e+01
library image-plane log likelihood -3.1784e+07 1.7518e+01
script's own Match (rtol=1e-2) False True
process exit 0 0

So a capped run silently computed on full-resolution data, the script's hand-rolled likelihood disagreed with the library's by ~33%, its own consistency check reported False — and it exited 0 anyway, so nothing surfaced it. A teaching script demonstrating a wrong result while reporting success. Running from an empty dataset dir gives Match (rtol=1e-2): True, confirming the stale dataset is the cause.

Two of the four never worked at all

slam_source_parametric.py and slam_source_pixelized.py guarded on dataset_Path() — an undefined name — so they raised NameError whenever the dataset was absent. Confirmed before/after on a clean checkout:

BEFORE: NameError: name 'dataset_Path' is not defined. Did you mean: 'dataset_path'?   (line 876)
AFTER:  runs 98 lines further, to line 974

Nobody noticed because config/build/no_run.yaml excludes every sensitivity script, and none of the four is in smoke_tests.txt — so the premise that they "currently pass smoke" was wrong; they were never run.

Both still fail further down on pre-existing, unrelated stale-API faults — 'Model' object has no attribute 'centre' (parametric) and module 'autolens' has no attribute 'MapperValued' (pixelized). Those are the standing no_run reason and are out of scope; this PR strictly improves both and does not claim to fix them.

Verification

Capped profile (PYAUTO_TEST_MODE=2 PYAUTO_SMALL_DATASETS=1 + the rest of profile_smoke.yaml), from an empty dataset dir and from a stale full-resolution one:

Script Case A (absent dir) Case B (stale full-res)
cluster/likelihood_function.py exit 0, 13.7s, Match (rtol=1e-2): True exit 0, 11.8s, (1000,1000) → (16,16), Match: True
interferometer/.../many_visibilities_preparation.py exit 0, 22.0s exit 0, 18.3s, rebuilt (data.fits md5 2d36bc69… → ee334711…)
subhalo/sensitivity/slam_source_parametric.py guard fires, dataset simulated, reaches line 974 (was NameError at 876) n/a — no_run
subhalo/sensitivity/slam_source_pixelized.py guard fires, dataset simulated n/a — no_run

Guard semantics isolated old-vs-new:

PYAUTO_SMALL_DATASETS=0   stale full-res -> old=False  new=False   (identical; uncapped runs unaffected)
PYAUTO_SMALL_DATASETS=1   stale full-res -> old=False  new=True    (old reuses full-res; new deletes + rebuilds)

Uncapped behaviour is unchanged, so the prompt's "can only make them slower" caution applies only to capped runs, where rebuilding is the point — and both timed cases are 12–22s.

Also run: scripts/check_sizes.sh (clean) and the full run_smoke.py suite.

Scope note

Growing should_simulate an optional required_files=[...] argument (a PyAutoArray change) is not done — only 1 of 249 call sites needs a stricter check, so a library API for a single caller is not yet earned. Recorded on #462 rather than silently dropped.

A sweep confirms the class is now closed: no hand-rolled auto-simulate guards remain. The other .exists() checks in scripts/ are deliberately different and were left alone — a FileNotFoundError for the committed SDP.81 dataset (interferometer/start_here.py), a path fallback (guides/hpc/example_cpu_and_gpu.py), and secondary-artifact guards (positions.json, point_dataset_*.json) that correctly sit after a primary should_simulate call (converting those would rmtree the dataset twice).

Notebooks

Regenerated via PyAutoHands; exactly the four corresponding .ipynb files changed, diffs confined to the guard lines. Navigator catalogue (llms-full.txt, workspace_index.json) unchanged.

…simulate

Four scripts guarded their auto-simulate step by hand instead of calling
`al.util.dataset.should_simulate`, which the other 249 sites use. The two are
not equivalent: under `PYAUTO_SMALL_DATASETS=1` (a `profile_smoke.yaml`
default) `should_simulate` deletes the dataset so the simulator rebuilds it at
the reduced resolution, whereas a bare `.exists()` check reuses whatever is on
disk. The four scripts would therefore read a full-resolution dataset left by
an earlier uncapped run inside a run that is meant to be capped — the exact
shape mismatch `should_simulate` was written to prevent.

Verified on `cluster/likelihood_function.py` with a stale 1000x1000 dataset on
disk: capped run now rebuilds it to 16x16 and exits 0.

`cluster/likelihood_function.py` also reads the truth-model CSVs, so its
stricter `mass.csv` clause is kept alongside `should_simulate` rather than
dropped; `should_simulate` is evaluated first so its rebuild always runs.

Two of the four never worked at all: `slam_source_parametric.py` and
`slam_source_pixelized.py` guarded on `dataset_Path()`, an undefined name, so
they raised `NameError` whenever the dataset was absent. Both are `no_run` in
`config/build/no_run.yaml`, which is why CI never caught it.

Notebooks regenerated; navigator catalogue unchanged.

Closes #462
@Jammy2211
Jammy2211 merged commit 4e396f1 into main Aug 3, 2026
5 checks passed
@Jammy2211
Jammy2211 deleted the claude/autolens-guard-small-datasets-jaqyxv branch August 25, 2026 18:56
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.

Normalise the four hand-rolled auto-simulate guards onto should_simulate

2 participants