Add the missing setup_notebook() line to 6 tutorial scripts - #70
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
scripts/chapter_2_lens_modeling/tutorial_8_need_for_speed.pynotebooks/chapter_2_lens_modeling/tutorial_8_need_for_speed.ipynbscripts/chapter_2_lens_modeling/tutorial_11_slam.pynotebooks/chapter_2_lens_modeling/tutorial_11_slam.ipynbscripts/chapter_3_pixelizations/tutorial_9_model_fit.pynotebooks/chapter_3_pixelizations/tutorial_9_model_fit.ipynbscripts/simulator/lens_x2.pynotebooks/simulator/lens_x2.ipynbscripts/simulator/lens_x3.pynotebooks/simulator/lens_x3.ipynbstart_here.pystart_here.ipynbWhy
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.pyandlens_x3.pyare the load-bearing cases in this repo — both resolvedataset_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
.pykeeps 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 andstart_here.pyare 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 realgenerate.pyrun 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_notebookline 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_workspaceand every*_workspace_test/*_workspace_developerrepo 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