From 8a138e0053e8850ee4a1ea41ea4a1441b92593a0 Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Mon, 3 Aug 2026 19:05:10 +0100 Subject: [PATCH 1/2] fix: add auto-simulate guards to unguarded dataset loads chapter_4_pixelizations/tutorial_3_inversions.py is one of the 4 missing-dataset smoke failures from PyAutoHeart run 30790463134 (FileNotFoundError on dataset/imaging/source_complex/data.fits), reproduced on a clean checkout before any edit. The script already carried a correct guard at L49 for its FIRST dataset (simple__no_lens_light); the source_complex block further down had none. Guarded against the existing scripts/simulator/source_complex.py. tutorial_5_borders.py gets the same treatment for dataset/imaging/ x2_lens_galaxies (scripts/simulator/lens_x2.py). It stays no_run for its unrelated mask reason, but the guard is correct either way. Verified: tutorial_3_inversions EXIT 0 in 19s under the real smoke env built via autohands.env_config.build_env_for_script. PYAUTO_SMALL_DATASETS=1 makes should_simulate rmtree and re-simulate, so the guard was genuinely exercised. tutorial_5_borders is not verified by execution (no_run). Co-Authored-By: Claude Opus 5 --- .../tutorial_3_inversions.py | 15 +++++++++++++++ .../chapter_4_pixelizations/tutorial_5_borders.py | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/scripts/chapter_4_pixelizations/tutorial_3_inversions.py b/scripts/chapter_4_pixelizations/tutorial_3_inversions.py index 5e18954..e473626 100644 --- a/scripts/chapter_4_pixelizations/tutorial_3_inversions.py +++ b/scripts/chapter_4_pixelizations/tutorial_3_inversions.py @@ -152,6 +152,21 @@ dataset_name = "source_complex" dataset_path = Path("dataset") / "imaging" / dataset_name +""" +__Dataset Auto-Simulation__ + +If the dataset does not already exist on your system, it will be created by running the corresponding +simulator script. This ensures that all example scripts can be run without manually simulating data first. +""" +if al.util.dataset.should_simulate(str(dataset_path)): + import subprocess + import sys + + subprocess.run( + [sys.executable, "scripts/simulator/source_complex.py"], + check=True, + ) + dataset = al.Imaging.from_fits( data_path=dataset_path / "data.fits", noise_map_path=dataset_path / "noise_map.fits", diff --git a/scripts/chapter_4_pixelizations/tutorial_5_borders.py b/scripts/chapter_4_pixelizations/tutorial_5_borders.py index 67b83bb..fc8904f 100644 --- a/scripts/chapter_4_pixelizations/tutorial_5_borders.py +++ b/scripts/chapter_4_pixelizations/tutorial_5_borders.py @@ -279,6 +279,21 @@ def perform_fit_with_source_galaxy_mask_and_border( dataset_name = "x2_lens_galaxies" dataset_path = Path("dataset") / "imaging" / dataset_name +""" +__Dataset Auto-Simulation__ + +If the dataset does not already exist on your system, it will be created by running the corresponding +simulator script. This ensures that all example scripts can be run without manually simulating data first. +""" +if al.util.dataset.should_simulate(str(dataset_path)): + import subprocess + import sys + + subprocess.run( + [sys.executable, "scripts/simulator/lens_x2.py"], + check=True, + ) + dataset = al.Imaging.from_fits( data_path=dataset_path / "data.fits", noise_map_path=dataset_path / "noise_map.fits", From e7b664b61d267a8989fe7d296848e9719620cdf5 Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Mon, 3 Aug 2026 19:18:24 +0100 Subject: [PATCH 2/2] docs: regenerate notebooks for auto-simulate guards Co-Authored-By: Claude Opus 5 --- .../tutorial_3_inversions.ipynb | 28 ++++++++++++++++++- .../tutorial_5_borders.ipynb | 28 ++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/notebooks/chapter_4_pixelizations/tutorial_3_inversions.ipynb b/notebooks/chapter_4_pixelizations/tutorial_3_inversions.ipynb index 39df2b6..78a6080 100644 --- a/notebooks/chapter_4_pixelizations/tutorial_3_inversions.ipynb +++ b/notebooks/chapter_4_pixelizations/tutorial_3_inversions.ipynb @@ -296,7 +296,33 @@ "metadata": {}, "source": [ "dataset_name = \"source_complex\"\n", - "dataset_path = Path(\"dataset\") / \"imaging\" / dataset_name\n", + "dataset_path = Path(\"dataset\") / \"imaging\" / dataset_name" + ], + "outputs": [], + "execution_count": null + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "__Dataset Auto-Simulation__\n", + "\n", + "If the dataset does not already exist on your system, it will be created by running the corresponding\n", + "simulator script. This ensures that all example scripts can be run without manually simulating data first." + ] + }, + { + "cell_type": "code", + "metadata": {}, + "source": [ + "if al.util.dataset.should_simulate(str(dataset_path)):\n", + " import subprocess\n", + " import sys\n", + "\n", + " subprocess.run(\n", + " [sys.executable, \"scripts/simulator/source_complex.py\"],\n", + " check=True,\n", + " )\n", "\n", "dataset = al.Imaging.from_fits(\n", " data_path=dataset_path / \"data.fits\",\n", diff --git a/notebooks/chapter_4_pixelizations/tutorial_5_borders.ipynb b/notebooks/chapter_4_pixelizations/tutorial_5_borders.ipynb index 9c35e81..440b2bb 100644 --- a/notebooks/chapter_4_pixelizations/tutorial_5_borders.ipynb +++ b/notebooks/chapter_4_pixelizations/tutorial_5_borders.ipynb @@ -444,7 +444,33 @@ "metadata": {}, "source": [ "dataset_name = \"x2_lens_galaxies\"\n", - "dataset_path = Path(\"dataset\") / \"imaging\" / dataset_name\n", + "dataset_path = Path(\"dataset\") / \"imaging\" / dataset_name" + ], + "outputs": [], + "execution_count": null + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "__Dataset Auto-Simulation__\n", + "\n", + "If the dataset does not already exist on your system, it will be created by running the corresponding\n", + "simulator script. This ensures that all example scripts can be run without manually simulating data first." + ] + }, + { + "cell_type": "code", + "metadata": {}, + "source": [ + "if al.util.dataset.should_simulate(str(dataset_path)):\n", + " import subprocess\n", + " import sys\n", + "\n", + " subprocess.run(\n", + " [sys.executable, \"scripts/simulator/lens_x2.py\"],\n", + " check=True,\n", + " )\n", "\n", "dataset = al.Imaging.from_fits(\n", " data_path=dataset_path / \"data.fits\",\n",