Skip to content

docs: stored Chapter 2 fit results so HowToLens tutorials skip sampling - #134

Merged
Jammy2211 merged 8 commits into
mainfrom
feature/howtolens-stored-results
Nov 11, 2026
Merged

Jammy2211 merged 8 commits into
mainfrom
feature/howtolens-stored-results

Conversation

@Jammy2211

@Jammy2211 Jammy2211 commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

HowToLens now ships the completed output of every Chapter 2 search from Tutorial 2 onwards. When a reader runs a tutorial, PyAutoFit finds the stored result, prints Fit Already Completed: skipping non-linear search and loads it in seconds, so the chapter can be worked through without waiting tens of minutes per search. The tutorials say this is deliberate and print the real run time of each stored fit. Tutorial 1 stays the reader's one live search.

Closes #130 (phase 1: Chapter 2; Chapters 3-4, the optional chapter and the other HowTo series follow).

What is stored: ten fits from real runs (test mode off) on RAL at the released 2026.11.9.1 libraries, about 5.5 MB in total. Each keeps only what PyAutoFit needs to rebuild the result, with samples.csv thinned to 10 equal-weight draws (~40-200 KB per fit). Two fits whose corner plots the text asks readers to interpret keep 1,000 draws: Tutorial 2 and Tutorial 6's second search. Tutorial 2 keeps a fuller, illustrated folder (3.9 MB, minus the corner-plot PNGs) because it walks the reader through the output tree.

Tooling: .github/scripts/stored_results.py

  • harvest <root> copies completed real runs into output/howtolens/chapter_2, keeping the minimal files and thinning samples (valid shapes only, always the best one).
  • check runs Tutorials 2-6 with test mode off and any real sampling refused. It currently passes for all five.

CI: new .github/workflows/stored_results.yml runs check against the released libraries (pip install -r requirements.txt, test mode off) on PRs, on main and daily. Library releases never push to this repo, so the daily run is what turns HowToLens red if a release moves a stored fit's identifier.

AGENTS.md documents how to refresh the store.

Decisions to review

  1. Tutorial 3 live points. Real runs showed the settings in the current text don't work on this 20-parameter model. Nautilus's default n_points_min is n_dim + 50 = 70.

    • Less thorough: 21 → 50. 21 crashed Nautilus every time (LinAlgError while building its first bounds).
    • Prior tuning: 75 → 150. 75 stalled (no new bound for 68,000 calls); 100 reached a poor fit.
    • Reduced complexity: 75 → 300. 75 and 150 reached a poor fit, and 200 stalled. At 300 it now matches the thorough search, so that comparison isolates the effect of linking. The text now says that simplifying the model didn't remove the need for a thorough search here.
  2. seed=1 on every Tutorial 2/3 Nautilus search, explained in the text. Unseeded, Tutorial 2's 200-live-point fit reached the right solution on the laptop but a poor one on RAL (log Z −42,262 vs +3,322). With seed 1 and seed 2, every search ends where its lesson needs it:

    Search log Z
    Tutorial 2 +3,322
    Prior tuning +3,336
    Reduced complexity +3,340
    More thorough +3,322
    Less thorough −59,734 (fails, as intended)
  3. Simulators use noise_seed=1, so every reader simulates the exact data the stored fits describe. Noise was random before.

  4. Tutorial 1 is not stored. Its search has no name, so it writes no output; it takes about 4 minutes live.

Known rough edges

  • A warning on the less-thorough fit. Loading it prints a WARNING that its best sample "cannot be reconstructed as a model instance", then falls back. That failed search put 99% of its weight on source elliptical components with magnitude ≥ 1, which the sampler scored but the model can't rebuild. This is a library bug, to be filed separately; the stored data is kept as the search produced it.
  • Extra files beside each stored folder. Loading a stored fit writes a .zip and status files there. They're gitignored, so readers' git status stays clean.
  • Possible hang for readers who rerun. Anyone who deletes a stored folder and reruns a JAX tutorial on CPU with jaxlib 0.11.2 may hit the known XLA:CPU deadlock (it hit Tutorials 4 and 6 on RAL). This is tracked in PyAutoNerves#213.

Heart RED override (development only)

Heart was RED at ship time for reasons outside HowToLens:

  • autocti_workspace: Smoke Tests failure on main
  • manifest drift: organism-map blocks (generated) — 7 mismatch(es) vs PyAutoMind/repos.yaml
  • PyAutoArray: open PR 7d old
  • PyAutoMind: open PR 7d old
  • release validation incomplete: no rehearsal for current source

The live human authorized this PR in the session: "yes override, open the PR". Full record on #130: #130 (comment). This PR does not fix any of those reasons. Merge needs a separate human /prm and every required check green.

Scripts Changed

  • scripts/chapter_2_lens_modeling/tutorial_1_non_linear_search.py: notes that this is the one live search.
  • scripts/chapter_2_lens_modeling/tutorial_2_practicalities.py: __Stored Results__ section, seed=1 with an explanation (including that this fit can fail unseeded), and a print of the recorded run time.
  • scripts/chapter_2_lens_modeling/tutorial_3_why_modeling_is_hard.py: n_live 21→50, 75→150 and 75→300; seed=1 on all searches; matching text and live-points table.
  • scripts/chapter_2_lens_modeling/tutorial_4_linear_profiles.py, tutorial_5_data_and_likelihoods.py, tutorial_6_search_chaining.py: one-line stored-result notes.
  • scripts/simulator/lens_sersic.py, no_lens_light__mass_sis.py, lens_extra_galaxy.py: noise_seed=1.
  • .github/scripts/stored_results.py (new), .github/workflows/stored_results.yml (new), AGENTS.md, output/howtolens/chapter_2/ (stored fits, force-added), and regenerated notebooks.

Test Plan

  • python .github/scripts/stored_results.py check: OK for Tutorials 2-6.
  • Tutorial 3 run as a reader: all five searches load, and the comparison tables print the expected log likelihoods and recorded times.
  • Smoke (test mode, profile_smoke.yaml), local: scripts/simulator all PASS; Chapter 2 Tutorials 2 and 4–7 PASS. Tutorials 1 and 3 hit the 300 s cap while the laptop was saturated (load average 8.5–9.3 on 8 cores). Rerun individually under the same environment, they PASS (24 s and 45 s). Exact-head CI smoke is authoritative.
  • CI green, including the new stored_results job.

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

Jammy2211 and others added 8 commits November 10, 2026 12:12
…orial notes

Adds .github/scripts/stored_results.py (harvest + check), seeds the three
Chapter 2 simulators so every reader simulates the data the stored fits
describe, and explains in Tutorials 1-6 that later fits load stored results.
Stored outputs follow from the RAL regeneration run.

Refs #130

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
n_live=21 on the 20-parameter model crashes Nautilus while it builds its
first bounds (numpy LinAlgError: Matrix is not positive definite): 4/4 runs
(3 laptop + RAL 414812), and n_live=30 crashed 1/2. n_live=40 (4/4) and 50
(2/2) ran past the window where every crash occurred. The prose now explains
that 21 is accepted but too few points for Nautilus to build its bounds.

Refs #130

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nverge

Real RAL runs showed these 20-parameter fits are seed-sensitive at the
tutorial live-point counts: tutorial 2 (n_live=200) reached the right solution
on the laptop but a poor one (log Z -42,262 vs +3,322) on RAL. With seed=1 and
seed=2 every search lands where its lesson needs it:

- tutorial 2 reference n_live=200: +3,322 (both seeds)
- prior tuning 75 -> 150: 75 stalled (no new bound for 68k calls), 100 reached
  a poor fit (-4,831), 150 gives +3,336 (both seeds)
- reduced complexity 75 -> 300: 75 and 150 reached poor fits, 200 stalled
  (both seeds), 300 gives +3,340 (both seeds) and now matches the thorough
  search, so that comparison isolates the effect of linking
- more thorough n_live=300: +3,322 (both seeds)

Every chapter 2 tutorial 2/3 search now uses seed=1, explained in the prose.
stored_results.py check now removes the setup folders a refused search writes.

Refs #130

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ten fits from RAL runs at the released 2026.11.9.1 libraries, harvested by
.github/scripts/stored_results.py: tutorial 2's illustrated folder (3.9 MB,
1,000 samples) and minimal ~40-200 KB folders for every other search.
stored_results.py check passes for tutorials 2-6 (no search samples).

harvest now keeps only samples the model can rebuild (elliptical components
inside the unit circle) and always the best of them: tutorial 3's failed
less-thorough fit puts 99% of its weight on invalid source shapes, and with
only invalid rows PyAutoFit cannot rebuild any result. search.summary is
optional, since not every completed search writes one.

Refs #130

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…esults in AGENTS.md

Refs #130

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…seeded

Same-seed reruns were shown to give the same outcome on one cluster, not the
same path on every computer. Tutorial 2's 200-live-point fit failed in 1 of 4
real runs without a seed; say so and point to Why Modeling Is Hard.

Refs #130

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Runs .github/scripts/stored_results.py check with test mode off after
pip install -r requirements.txt, so a library release that moves a stored
fit's identifier turns HowToLens red instead of silently sending readers back
to sampling. Daily schedule because library releases never push here.
check now prints the last 20 lines of a failing tutorial.

Refs #130

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jammy2211
Jammy2211 merged commit 653c483 into main Nov 11, 2026
9 checks passed
@Jammy2211
Jammy2211 deleted the feature/howtolens-stored-results branch November 11, 2026 09:19
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.

docs: ship stored fit results so HowToLens tutorials skip sampling

1 participant