Skip to content

Add the missing setup_notebook() line to 6 tutorial scripts - #70

Merged
Jammy2211 merged 1 commit into
mainfrom
claude/howto-setup-notebook-audit-dm2j9e
Aug 18, 2026
Merged

Add the missing setup_notebook() line to 6 tutorial scripts#70
Jammy2211 merged 1 commit into
mainfrom
claude/howto-setup-notebook-audit-dm2j9e

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

What

Adds the standard boilerplate line

# from autolens import setup_notebook; setup_notebook()

to the six scripts in this repo that never had it, and updates their generated notebooks to match.

Script Notebook
scripts/chapter_2_lens_modeling/tutorial_8_need_for_speed.py notebooks/chapter_2_lens_modeling/tutorial_8_need_for_speed.ipynb
scripts/chapter_2_lens_modeling/tutorial_11_slam.py notebooks/chapter_2_lens_modeling/tutorial_11_slam.ipynb
scripts/chapter_3_pixelizations/tutorial_9_model_fit.py notebooks/chapter_3_pixelizations/tutorial_9_model_fit.ipynb
scripts/simulator/lens_x2.py notebooks/simulator/lens_x2.ipynb
scripts/simulator/lens_x3.py notebooks/simulator/lens_x3.ipynb
start_here.py start_here.ipynb

Why

setup_notebook() chdir's to the workspace root and enables inline plotting. Without it, a tutorial that loads data by a relative path (or shells out to a simulator) fails when executed by nbconvert, which runs with CWD set to the notebook's own directory — it works interactively only if the user happens to launch jupyter from the repo root.

simulator/lens_x2.py and lens_x3.py are the load-bearing cases in this repo — both resolve dataset_path = Path("dataset", dataset_type, dataset_name) relative to CWD and write FITS output there, so their notebooks were relying on the user's launch directory. The other four are prose- or import-only and are a consistency fix.

Placement

Immediately after the module docstring, matching the sibling convention exactly (blank line, the commented call, blank line). The .py keeps the line commented; the notebook generator strips the # when it emits the code cell, which is what the notebook side of this diff shows.

For the three prose-only tutorials (tutorial_8_need_for_speed, tutorial_11_slam, tutorial_9_model_fit — each is a single module docstring with no code), this adds a small code cell to a notebook that previously had only the Colab setup cell. Happy to drop those three if you'd rather they stay pure markdown; the two simulators and start_here.py are the ones that matter.

Notebooks

Patched by hand rather than regenerated — PyAutoHands isn't available in the session that produced this. The edits reproduce the generator's output shape exactly (verified against already-correct sibling pairs in this repo, and json.dumps(nb, indent=1) round-trips the files byte-identically), so a real generate.py run should be a no-op. Worth confirming before merge if you want belt and braces.

Scope

One leg of a full audit of the setup_notebook line across the three HowTo repos and all five user-facing workspaces — 39 scripts missing it in total (HowToFit 3, HowToGalaxy 2, HowToLens 6, autofit_workspace 1, autogalaxy_workspace 5, autolens_workspace 22; autocti_workspace was already clean). autoreduce_workspace and every *_workspace_test / *_workspace_developer repo are deliberately excluded: none of them generates notebooks, so the convention doesn't apply there yet.

Tracked in PyAutoMind as howto-setup-notebook-audit.


Generated by Claude Code

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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0126SmBwHMzP4okcjhjPoLFZ
@Jammy2211
Jammy2211 merged commit e0fbdf6 into main Aug 18, 2026
7 checks passed
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.

2 participants