Repository navigation
Description
Overview
HowToLens tutorials make readers wait minutes for each non-linear search. This task ships small, git-tracked stored results so every search after the first loads instantly through PyAutoFit's existing "Fit Already Completed" path, and the tutorials say so and show the real run time. This is phase 1 (HowToLens chapter 2 plus the design gate); later phases cover chapter 3/4/optional and HowToFit/HowToGalaxy.
Plan
- Confirm the design: PyAutoFit already skips the search when an output folder holds
.completedand needs onlyfiles/samples_summary.json(samples.csvoptional). Check that the stored folders' identifiers stay stable across a release; if not, stop and file the PyAutoFit "bare result from disk" phase instead. - Add a regeneration script that runs every chapter 2 search for real, records its wall time, and writes a minimal tracked folder per search (full samples only where a tutorial reads
result.samples). - Keep tutorial 1's full output folder as the illustration of a real output directory.
- Update each chapter 2 search cell's prose: the result is loaded on purpose, here is what the real fit cost, and how to rerun it yourself.
- Add a check that runs outside test mode and fails if any chapter 2 search actually samples.
- Regenerate notebooks; smoke and CI green.
- Tier: judge — merge mode: human /prm.
Detailed implementation plan
Affected Repositories
- HowToLens (primary). PyAutoFit only if the design gate fails (separate phase).
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./lens/HowToLens | main (8aa7fa1) | clean |
Suggested branch: feature/howtolens-stored-results
Facts from the survey
NonLinearSearch.fit→paths.is_complete(.completedor a zip containing one) →result_via_completed_fit(autofit/non_linear/search/abstract_search.py), which loadssamples_summary.jsonand triessamples.csv(FileNotFoundError → samples=None).pre_fit_outputstill runs on a completed fit (visualize_before_fit), so measure its cost.- Test mode writes to
output/test_mode/..., so smoke runs never touch shipped results: the check must run with test mode off. .gitignoreignoresoutput/wholesale.- Chapter 2 searches (post-docs: implement approved Chapter 2 lessons 1–4 #113): t1 (1), t2 practicalities (1, reads samples), t3 why_modeling_is_hard (several; one reuses t2's
tutorial_2_practicalitiesfolder; reads samples), t4 linear_profiles + mge (2), t5 data_and_likelihoods (2), t6 search_chaining (2, reads samples).
Implementation Steps
- Design gate: run chapter 2 with test mode off in a scratch output dir; record per-search identifier, folder size, needed files and wall time; confirm the identifier is stable against a re-import and the current PyPI release. Report on the issue.
scripts/stored_results/generate.py(or similar): runs each search, keeps.completed,.identifier,files/{samples_summary,model,search,samples_info}.json, +samples.csvwhere needed, writes arun_times.jsonmanifest (search name → wall time, machine, library version)..gitignore: un-ignore the stored-result folders for chapter 2 only.- Tutorial prose: a short note at each search cell (from the manifest's times) and a one-paragraph explanation in tutorial 1/README.
- Check script (
scripts/stored_results/check.py): runs with test mode off and asserts every chapter 2 search logs "Fit Already Completed"; wire into CI or the smoke harness. - Regenerate notebooks + llms files; run smoke.
Key Files
scripts/chapter_2_lens_modeling/tutorial_*.py.gitignore,output/howtolens/chapter_2/...- PyAutoFit
autofit/non_linear/search/abstract_search.py,autofit/non_linear/paths/directory.py(read only)
Witness
Running every chapter 2 tutorial from a clean checkout with test mode off logs "Fit Already Completed: skipping non-linear search" for each search (zero searches sample); the tracked stored-results footprint is reported in MB.
Original Prompt
Click to expand starting prompt
HowTo series: ship stored fit results so notebooks run without sampling waits
Type: docs
Target: HowToLens
Repos:
- PyAutoFit
- HowToFit
- HowToGalaxy
- HowToLens
Difficulty: too-large
Autonomy: supervised
Priority: normal
Memory: wiki/lensing/sources/dark-matter-substructure.md; wiki/galaxies/sources/massive-ellipticals.md; wiki/galaxies/sources/cosmos-survey.md
Status: formalised
Consequence: glance
Witness: running every HowToLens tutorial that calls search.fit with a clean checkout logs "Fit Already Completed: skipping non-linear search" for each search (zero searches sample), and the tracked stored-results footprint is reported in MB.
Review-minutes: 3
Unattended: needs-slicing
Human idea (2026-11-01). Make HowToLens (then HowToFit, HowToGalaxy, other HowTo series) ship stored, lightweight fit results that PyAutoFit loads instantly, so readers complete notebooks uninterrupted.
Intent
- Every tutorial that runs a non-linear search (HowToLens: 14 scripts — chapter_2_lens_modeling tutorials 1–7, chapter_4_scaling_up_lensing tutorials 1–6, chapter_optional/tutorial_searches) loads a pre-computed result when the reader runs the cell; no sampling wait.
- Tutorials say clearly that this is intentional, and show the real run time that produced each stored result (keep search.summary / timing so readers see what the fit actually cost).
- The FIRST fit (ch2 tutorial 1) may ship its full output folder, for illustration of a real output directory; later fits use the lightweight store.
- Only a few cells and comments per tutorial change.
Survey already done (2026-11-01, read-only)
- PyAutoFit already skips the search when a fit is complete:
NonLinearSearch.fit->paths.is_complete(.completedfile or a zip holding one) ->result_via_completed_fit(fit/PyAutoFit/autofit/non_linear/search/abstract_search.py ~L330, ~L513), which needs onlyfiles/samples_summary.json(viapaths.load_samples_summary); fullsamples.csvis OPTIONAL (FileNotFoundError->samples=None). - So option (b) — PyAutoFit as-is, ship minimal
<output>/<path_prefix>/<name>/<identifier>/folders with.completed+files/samples_summary.json(+ model.json/search.json) — looks viable without a library change. - HowToLens
.gitignoreignoresoutput/wholesale; shipped results need a dedicated tracked location or un-ignore rule.
Open questions / risks for the plan
- Identifier fragility: the output folder is keyed by a hash of model + search settings (unique_tag); any prior/default-config/library change moves the hash and the stored result silently stops matching (fit reruns). Need a regeneration script + a CI/Heart staleness check (fail if a tutorial would actually sample).
- Which tutorials use
result.samples(corner plots, PDFs, errors from full samples — e.g. ch2 tutorial 7 results)? Those need samples.csv shipped, or rewriting to use samples_summary only. Measure on-disk size. pre_fit_outputstill runs (visualize_before_fit etc.) on a completed fit — check cost; consider whether output mode should skip it.- Option (a) fallback: a PyAutoFit "bare-bones result from disk" API (small json -> Result) only if (b) is too fragile or too big. Prefer (b).
- Where timing lives: samples_summary/search.summary already record time? Confirm and surface it in tutorial text.
- Colab/notebook path: stored results must be present in the Colab bootstrap clone too.
Suggested phasing
- P1 research: per-tutorial survey — files needed, sizes, samples.csv dependence, identifier stability across a release; decide (a) vs (b).
- P2 (only if (a)): PyAutoFit library change.
- P3 HowToLens chapter 2 rollout (generator script, stored results, tutorial prose + run-time display, staleness check).
- P4 HowToLens chapter 4 + optional.
- P5 other HowTo series (HowToFit, HowToGalaxy).
🤖 Generated with Claude Code
Activity
Jammy2211 commentedon Nov 6, 2026
Design-gate findings + decision (2026-11-06)
Load path confirmed. Ch2 tutorial 2 run for real (test mode off): search
Time To Run = 0:33:34(of whichVisualization Time = 1120 sfrom quick-update figures). Re-running the script then loggedFit Already Completed: skipping non-linear searchand printed the result ~54 s in (setup + JAX compile only). Tutorial 1 whole script: 250 s.Identifier. The output hash covers the model (class paths + priors) and the Nautilus
__identifier_fields__(n_live, n_update, enlarge_per_dim, …, seed), not n_batch or update frequencies. Stored results survive prose/cosmetic edits; they move if a profile class changes module, a default prior changes, or a Nautilus default changes → the staleness check is required.Size. Tutorial 2's completed folder is 22 MB;
files/samples.csvalone is 12 MB (14,534 rows);samples_summary.json28 KB,model.json12 KB.Decision (human): stored results must be lightweight; the goal is getting readers through the tutorials quickly.
samples.csv. Results load fromsamples_summary.json(+ model/search json,.completed).result.samples(ch2 t2, t3, t6): ship an extremely thinsamples.csv(order 10 equal-weight samples), enough for the cells to run. Check what corner plots/PDF cells do with ~10 samples and reword those cells if needed.Separate bug found:
aplt.corner_anesthetic(samples=result.samples)at tutorial_2_practicalities.py:453 ran 44+ minutes on the 20-parameter model (not hung: 400 axes, 190 2D-KDE panels, pandas shared-axis tick pass). Filed in Mind asdraft/bug/autofit/corner_anesthetic_takes_40_minutes_on_a.md; thin samples make it fast here, but the library default still needs fixing.Jammy2211 commentedon Nov 6, 2026
Correction to the comment above: thin samples do NOT fix the corner-plot slowness. With
samples.csvcut to 10 equal-weight rows (5 KB, loads fine:Fit Already Completed),corner_anestheticat tutorial_2_practicalities.py:453 still ran >14 min. The time goes into building 400 shared matplotlib axes and pandas' per-panelhandle_shared_axestick-label pass, independent of sample count. Bug prompt updated. Consequence for this task: until that bug is fixed, ch2 tutorial 2 (and any 20-parameter corner plot) needs a tutorial-side workaround, e.g. plotting a parameter subset.Jammy2211 commentedon Nov 10, 2026
Progress (2026-11-10)
Corner-plot fix PyAutoFit#1761 shipped in 2026.11.9.1. With it, tutorial 2 runs end to end in 36–48 s from its stored result (was >90 min).
Pushed
5051c33onfeature/howtolens-stored-results:.github/scripts/stored_results.py—harvest <full-output-root>copies the minimal set (.completed,.identifier,search.summary,files/{model,search,samples_info,samples_summary}.json, thinnedsamples.csv; ~72 KB per fit, verified byte-identical after a load so readers never see modified files) and the illustrated tutorial 2 folder (full minusimage/searchcorner PNGs, ~3.6 MB).checkruns tutorials 2–6 with test mode off andstart_resume_fitpatched to fail (68 s; verified OK for t2 and FAILED-with-folder for unstored t3–t6).lens_sersic,no_lens_light__mass_sis,lens_extra_galaxy:noise_seed=1(was random, -1), so every reader simulates the exact data the stored fits describe. Verified byte-identicaldata.fitsacross runs.__Stored Results__section + prints the recorded run time (result.samples.time); one-line pointers in tutorials 3–6. Tutorial 3's existing run-time table already reads recorded times.Decisions flagged for review:
name/path_prefix, so output is disabled by design (~4 min live). Tutorial 2 carries the illustrated full folder, since it is the tutorial that walks the output tree.tutorial_2_practicalitiesandtutorial_6_search_2, whose corner plots the prose asks readers to interpret (10 points would break that lesson). ~0.5 MB each.Next: regenerate tutorials 2–6 on RAL (
ralpartition, 5 jobs, t3 after t2, private checkout at tag 2026.11.9.1), harvest,git add -f, runcheck, regenerate notebooks, ship. Blocked on an interactive SSH login to RAL.Jammy2211 commentedon Nov 10, 2026
RAL regeneration running (private checkout at 2026.11.9.1, jobs t2 414811, t3 414812 after t2, t4 414813, t5 414814, t6 414818). Tutorial 6 hit the jaxlib 0.11.2 XLA:CPU deadlock at its first
MultiStartProdigyjit (0% CPU, no progress): resubmitted withXLA_FLAGS=--xla_cpu_multi_thread_eigen=false, now optimising normally. Reader risk to note in the PR: anyone who deletes the stored folder and reruns tutorial 6 on CPU with jaxlib 0.11.2 may hang the same way; the stored result avoids it by default.fix: tutorial 3 less-thorough search uses n_live=50, not 21
fix: seed chapter 2 Nautilus searches; tutorial 3 live points that co…
docs: add stored Chapter 2 fit results (tutorials 2-6)
Jammy2211 commentedon Nov 10, 2026
State at end of 2026-11-10 (resume here)
Branch
feature/howtolens-stored-resultsatc8fc19a.stored_results.py checkpasses for tutorials 2-6: every chapter 2 search loads a stored result. Stored total about 5.5 MB (tutorial 2's illustrated folder 3.9 MB).Tutorial changes made on this branch, for review:
n_live21 → 50. 21 crashed Nautilus every time (LinAlgError in its first bounds).seed=1on all tutorial 2/3 Nautilus searches. Unseeded, tutorial 2 (n_live=200) reached the right solution on the laptop but a poor one on RAL (log Z −42,262 vs +3,322).noise_seed=1.Found along the way:
draft/research/autonerves/jax_version_policy_and_the_recurring_xla.md.harvestworks around it by keeping valid rows only..zipand status files next to its folder. They're gitignored, so readers'git statusstays clean.Next: read tutorial 3's printed output once for fallback warnings; regenerate notebooks and llms files;
/ship_workspace; PR for human/prm; file the ell_comps bug via/intake.docs: regenerate chapter 2 and simulator notebooks; document stored r…
Jammy2211 commentedon Nov 11, 2026
Heart RED override: development only (2026-11-11)
Authorization (live human, this session, verbatim): "yes override, open the PR". This authorizes commit, push and PR-open for
feature/howtolens-stored-resultsonly. Merge stays separate: human/prmwith every required GitHub check green. No release.Heart verdict at ship time: RED (
pyauto-heart readiness). Exact reasons:autocti_workspace: Smoke Tests failure on mainmanifest drift: organism-map blocks (generated) — 7 mismatch(es) vs PyAutoMind/repos.yamlPyAutoArray: open PR 7d oldPyAutoMind: open PR 7d oldrelease validation incomplete: no rehearsal for current sourceNone involve HowToLens, and this branch does not claim to fix any of them.
Branch gates passed (head
a7aa184):stored_results.py check: OK for Tutorials 2-6 (no search samples).profile_smoke.yaml):scripts/simulatorall PASS;scripts/chapter_2_lens_modelingTutorials 2 and 4–7 PASS.mainruns them in 6.1 s and 7.3 s. The PR's exact-head CI smoke is the authoritative leg and must be green before merge.docs: soften seed reproducibility claims; note tutorial 2 can fail un…
ci: stored-results check against released libraries (PR, main, daily)
Jammy2211 commentedon Nov 11, 2026
Shipped
Merged in #134 (merge
653c48320, 2026-11-11). Phase 1 of the HowTo stored-results epic is complete.output/howtolens/chapter_2/(10 fits, ~5.5 MB); Tutorial 1 stays the reader's one live search..github/scripts/stored_results.py(harvest,check) and thestored_results.ymlCI job (PRs,main, daily), which passed against PyPI 2026.11.9.1 + jax 0.11.2.seed=1on Tutorial 2/3 searches; simulatorsnoise_seed=1./prmwith all 9 checks green.Follow-ups filed in Mind:
draft/docs/howtolens/howtolens_stored_results_phase_2_chapters_3.md.draft/feature/pyautoheart/release_validation_check_howto_stored_fit_result.md.draft/bug/autogalaxy/searches_score_elliptical_components_with_magnit.md.