From 1ff2fa0ac7bd9f184cfab616a58fee3b16a5182b Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 18 Aug 2026 12:10:23 +0000 Subject: [PATCH] Add the missing setup_notebook() line to HowToLens tutorial scripts Every workspace/tutorial script opens with # from autolens import setup_notebook; setup_notebook() right after the module docstring; the line chdir's to the workspace root and enables inline plotting when the generated notebook is run. A handful of scripts never got it. Without it a tutorial that loads data by a relative path (or shells out to a simulator) fails under nbconvert, which runs with CWD set to the notebook's own directory, and works interactively only if the user happened to launch jupyter from the repo root. This is the full audit of every chapter in the repo (plus the root start_here.py): the missing line is added in the sibling convention's exact position and the generated notebooks are updated to match, uncommented, the way PyAutoHands emits them. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_0126SmBwHMzP4okcjhjPoLFZ --- .../chapter_2_lens_modeling/tutorial_11_slam.ipynb | 10 ++++++++++ .../tutorial_8_need_for_speed.ipynb | 10 ++++++++++ .../chapter_3_pixelizations/tutorial_9_model_fit.ipynb | 10 ++++++++++ notebooks/simulator/lens_x2.ipynb | 2 ++ notebooks/simulator/lens_x3.ipynb | 2 ++ scripts/chapter_2_lens_modeling/tutorial_11_slam.py | 2 ++ .../tutorial_8_need_for_speed.py | 2 ++ .../chapter_3_pixelizations/tutorial_9_model_fit.py | 2 ++ scripts/simulator/lens_x2.py | 2 ++ scripts/simulator/lens_x3.py | 2 ++ start_here.ipynb | 2 ++ start_here.py | 2 ++ 12 files changed, 48 insertions(+) diff --git a/notebooks/chapter_2_lens_modeling/tutorial_11_slam.ipynb b/notebooks/chapter_2_lens_modeling/tutorial_11_slam.ipynb index 2d92fdd..6cc672c 100644 --- a/notebooks/chapter_2_lens_modeling/tutorial_11_slam.ipynb +++ b/notebooks/chapter_2_lens_modeling/tutorial_11_slam.ipynb @@ -108,6 +108,16 @@ "\n", "_setup_colab.setup(\"howtolens\")" ] + }, + { + "cell_type": "code", + "metadata": {}, + "source": [ + "\n", + "from autolens import setup_notebook; setup_notebook()" + ], + "outputs": [], + "execution_count": null } ], "metadata": { diff --git a/notebooks/chapter_2_lens_modeling/tutorial_8_need_for_speed.ipynb b/notebooks/chapter_2_lens_modeling/tutorial_8_need_for_speed.ipynb index 08a77f8..d4608fa 100644 --- a/notebooks/chapter_2_lens_modeling/tutorial_8_need_for_speed.ipynb +++ b/notebooks/chapter_2_lens_modeling/tutorial_8_need_for_speed.ipynb @@ -203,6 +203,16 @@ "\n", "_setup_colab.setup(\"howtolens\")" ] + }, + { + "cell_type": "code", + "metadata": {}, + "source": [ + "\n", + "from autolens import setup_notebook; setup_notebook()" + ], + "outputs": [], + "execution_count": null } ], "metadata": { diff --git a/notebooks/chapter_3_pixelizations/tutorial_9_model_fit.ipynb b/notebooks/chapter_3_pixelizations/tutorial_9_model_fit.ipynb index 0e4f6ed..b1b201c 100644 --- a/notebooks/chapter_3_pixelizations/tutorial_9_model_fit.ipynb +++ b/notebooks/chapter_3_pixelizations/tutorial_9_model_fit.ipynb @@ -54,6 +54,16 @@ "\n", "_setup_colab.setup(\"howtolens\")" ] + }, + { + "cell_type": "code", + "metadata": {}, + "source": [ + "\n", + "from autolens import setup_notebook; setup_notebook()" + ], + "outputs": [], + "execution_count": null } ], "metadata": { diff --git a/notebooks/simulator/lens_x2.ipynb b/notebooks/simulator/lens_x2.ipynb index 99271d7..51ef62a 100644 --- a/notebooks/simulator/lens_x2.ipynb +++ b/notebooks/simulator/lens_x2.ipynb @@ -87,6 +87,8 @@ "cell_type": "code", "metadata": {}, "source": [ + "\n", + "from autolens import setup_notebook; setup_notebook()\n", "\n", "from pathlib import Path\n", "import autolens as al\n", diff --git a/notebooks/simulator/lens_x3.ipynb b/notebooks/simulator/lens_x3.ipynb index 5a031b3..b5d4b33 100644 --- a/notebooks/simulator/lens_x3.ipynb +++ b/notebooks/simulator/lens_x3.ipynb @@ -88,6 +88,8 @@ "cell_type": "code", "metadata": {}, "source": [ + "\n", + "from autolens import setup_notebook; setup_notebook()\n", "\n", "from pathlib import Path\n", "import autolens as al\n", diff --git a/scripts/chapter_2_lens_modeling/tutorial_11_slam.py b/scripts/chapter_2_lens_modeling/tutorial_11_slam.py index c8c3a1f..bb22d0d 100755 --- a/scripts/chapter_2_lens_modeling/tutorial_11_slam.py +++ b/scripts/chapter_2_lens_modeling/tutorial_11_slam.py @@ -65,3 +65,5 @@ This tutorial concludes the lens modeling chapter. In the next chapter, we introduce pixelizations, which reconstruct the source galaxy on a pixel-grid rather than with light profiles. """ + +# from autolens import setup_notebook; setup_notebook() diff --git a/scripts/chapter_2_lens_modeling/tutorial_8_need_for_speed.py b/scripts/chapter_2_lens_modeling/tutorial_8_need_for_speed.py index 72faed8..1a79fd6 100755 --- a/scripts/chapter_2_lens_modeling/tutorial_8_need_for_speed.py +++ b/scripts/chapter_2_lens_modeling/tutorial_8_need_for_speed.py @@ -160,3 +160,5 @@ passing (tutorial 10) reduce the number of evaluations needed to fit complex models, and the SLaM pipelines (tutorial 11) package these ideas into automated pipelines for fitting large samples of lenses. """ + +# from autolens import setup_notebook; setup_notebook() diff --git a/scripts/chapter_3_pixelizations/tutorial_9_model_fit.py b/scripts/chapter_3_pixelizations/tutorial_9_model_fit.py index 32c0ca4..c6b5206 100755 --- a/scripts/chapter_3_pixelizations/tutorial_9_model_fit.py +++ b/scripts/chapter_3_pixelizations/tutorial_9_model_fit.py @@ -11,3 +11,5 @@ Once complete, you can then move on to the next HowToLens tutorial and gain more insight into adaptive pixelizations. """ + +# from autolens import setup_notebook; setup_notebook() diff --git a/scripts/simulator/lens_x2.py b/scripts/simulator/lens_x2.py index 00d83ad..8eeb19a 100644 --- a/scripts/simulator/lens_x2.py +++ b/scripts/simulator/lens_x2.py @@ -40,6 +40,8 @@ If any code in this script is unclear, refer to the `autolens_workspace/*/imaging/simulator.ipynb` notebook. """ +# from autolens import setup_notebook; setup_notebook() + from pathlib import Path import autolens as al import autolens.plot as aplt diff --git a/scripts/simulator/lens_x3.py b/scripts/simulator/lens_x3.py index a778fef..b3df746 100644 --- a/scripts/simulator/lens_x3.py +++ b/scripts/simulator/lens_x3.py @@ -41,6 +41,8 @@ If any code in this script is unclear, refer to the `autolens_workspace/*/imaging/simulator.ipynb` notebook. """ +# from autolens import setup_notebook; setup_notebook() + from pathlib import Path import autolens as al import autolens.plot as aplt diff --git a/start_here.ipynb b/start_here.ipynb index 7f165a9..d54e79f 100644 --- a/start_here.ipynb +++ b/start_here.ipynb @@ -96,6 +96,8 @@ "cell_type": "code", "metadata": {}, "source": [ + "\n", + "from autolens import setup_notebook; setup_notebook()\n", "\n", "print(__doc__)\n" ], diff --git a/start_here.py b/start_here.py index 9e24317..bc718ff 100644 --- a/start_here.py +++ b/start_here.py @@ -49,4 +49,6 @@ Open `scripts/chapter_1_introduction/tutorial_0_visualization.py` (or the `.ipynb` equivalent) and start there. """ +# from autolens import setup_notebook; setup_notebook() + print(__doc__)