Skip to content

fix: install autofit's lazily-imported deps in the Colab setup cell - #63

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/colab-workshop-dep-stopgap
Sep 15, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/colab-workshop-dep-stopgap

Conversation

@Jammy2211

Copy link
Copy Markdown
Contributor

Why

HowToFit chapter 1 tutorial 5 died on Colab with ModuleNotFoundError: No module named 'corner' — after a 2000-step emcee search had already run to completion, in the results update that follows it.

The Colab bootstrap (autonerves/setup_colab.py) installs the stack with --no-deps, so any dependency Colab does not itself preinstall must be named in its hand-maintained _SHARED_EXTRAS list or it never lands. Four autofit dependencies are missing from that list, and all four are imported lazily — inside a function rather than at module scope — so import autofit succeeds, the model builds, the search runs, and the notebook dies partway through:

Package Imported in Kills
corner corner_cornerpy every post-fit corner plot — the reported failure
optax MultiStartAdam / MultiStartProdigy gradient MAP tutorials
xxhash graphical/EP factor hashing graphical-model tutorials
blackjax BlackJAXNUTS NUTS tutorials

Workspace smoke runs at PYAUTO_TEST_MODE=2, which bypasses the sampler entirely, so these imports are never reached and the scripts pass green while being unrunnable by a reader.

What this does

Adds a second pip install to the Colab setup cell, inside the else: branch so it only ever runs on Colab, never on a local install. Verified structurally: each cell was parsed with ast and the install confirmed to sit in the Try node's orelse body — 100/100 across the three repos.

--no-deps is required and deliberate: installing blackjax or optax with dependencies would let pip reinstall or downgrade Colab's GPU-enabled jax and break every GPU runtime.

Only these four packages are installed. The anesthetic, nautilus-sampler and dill pins are deliberately left alone — those are separate questions, and changing an already-working package here would be unnecessary risk.

This is a stopgap

The real fix is PyAutoLabs/PyAutoNerves#167, which adds all four to _SHARED_EXTRAS. Because the setup cell runs pip install autonerves --no-deps unpinned at run time, that release fixes every published notebook retroactively — including tag-pinned ones — with no notebook change at all.

This PR exists because the Colab badge links point at release tags, not main, so a notebook edit alone cannot reach an attendee clicking a README badge. It is belt-and-braces for a workshop running today, and it is harmless once the release lands: the extra install becomes a no-op ("Requirement already satisfied").

Remove once autonerves > 2026.9.15.1 is released.

Verification

  • Changed-file counts exactly match the notebooks carrying a setup cell.
  • Pure insertion — zero deletions, zero files outside notebooks/ touched.
  • ast.parse clean on every modified cell; JSON valid and cell counts unchanged in all.
  • No double insertions; the patch is idempotent.
  • Notebook serialisation round-trips byte-identically (ensure_ascii=True, no trailing newline), so there is no formatting churn.

🤖 Generated with Claude Code

The Colab bootstrap installs the stack with `--no-deps`, so any dependency
Colab does not itself preinstall must be named in autonerves' `_SHARED_EXTRAS`
or it never lands. Four autofit dependencies are missing from that list, and
all four are imported lazily — inside a function rather than at module scope —
so `import autofit` succeeds, the search runs to completion, and the notebook
dies partway through:

  corner   - `corner_cornerpy`; kills the post-fit corner plot
  optax    - MultiStartAdam / MultiStartProdigy
  xxhash   - graphical/EP factor hashing
  blackjax - BlackJAXNUTS

Reported against HowToFit chapter 1 tutorial 5, which died on Colab with
`ModuleNotFoundError: No module named 'corner'` after a 2000-step emcee search
had already finished.

This is a stopgap: the real fix is PyAutoNerves#167, which adds all four to
`_SHARED_EXTRAS`. Until that is released, the setup cell installs them itself
so the notebooks are self-sufficient. `--no-deps` is required — installing
blackjax or optax with dependencies would let pip downgrade Colab's
GPU-enabled jax.

Remove once autonerves > 2026.9.15.1 is released.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Jammy2211
Jammy2211 merged commit 1b85e12 into main Sep 15, 2026
6 checks passed
@Jammy2211
Jammy2211 deleted the feature/colab-workshop-dep-stopgap branch September 15, 2026 07:23
Jammy2211 pushed a commit that referenced this pull request Sep 15, 2026
…dencies-frmvth

fix: point Colab links at main so the #63 dependency stopgap reaches readers
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.

1 participant