Repository navigation
Description
Overview
Phase 6a of the model-figures epic: the PyAutoFit surfaces cut of the phase 6 rollout map. Every script and tutorial in autofit_workspace and HowToFit that prints model.info should show af.ModelPlotter(model).figure() beside it, and both expectation-propagation scripts should draw the phase-5 EP state figure. Drawing that state figure after the high-level FactorGraphModel.optimise(...) is impossible today without a private API, so the task is library-first: one small additive change to EPResult, then two workspace PRs.
Plan
- Library (PyAutoFit): expose the swept graph as
EPResult.factor_graph(additive, defaultNone), passed through fromFactorGraphModel.optimise, with a test and a docs example. - autofit_workspace: a figure beside every bare
model.info— 28 bare sites across 9 scripts. - HowToFit: the same across 8 tutorials — 14 bare sites, tutorial register.
- EP: state figure +
visualise_interval=1in both EP scripts, plus the missingmodel_figurekey inHowToFit/config/output.yaml. - Notebooks + catalogue regenerated per each repo's own convention.
- Ship library-first:
ship_library(PyAutoFit PR) →ship_workspace(two workspace PRs behind the library-first gate).
Detailed implementation plan
Affected Repositories
- PyAutoFit (primary)
- autofit_workspace
- HowToFit
Work Classification: Both (library first)
Worktree root: ~/Code/PyAutoLabs-wt/model-figures-rollout-autofit/
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoFit | main | clean |
| ./autofit_workspace | main | clean |
| ./HowToFit | main | clean |
Suggested branch: feature/model-figures-rollout-autofit (same name in all three so workspace smoke CI checks out the same-named library branch)
1. Library: expose the swept graph on EPResult (PyAutoFit)
autofit/graphical/declarative/result.py:EPResult.__init__(..., factor_graph=None)storingself.factor_graph— docstring: "the factor graph the optimiser actually swept; pass it toaf.EPPlotter(neverFactorGraphModel.graph, which rebuilds)". Additive, defaultNone.autofit/graphical/declarative/abstract.py:210-214: passfactor_graph=opt.factor_graph.- Test in
test_autofit/graphical/(next to existing EP result/optimise tests; fixturestest_factor_failure_recovery.make_two_variable_approxor the declarative doubles): afteroptimise(...),result.factor_graph isthe optimiser's graph andaf.EPPlotter(result.factor_graph, ep_history=result.ep_history).figure(kind="state", path=tmp, format="png")writes a file with no factor readingabsent. docs/features/graphical.md"Seeing the EP run": add the high-level formaf.EPPlotter(result.factor_graph, ep_history=result.ep_history).figure(kind="state")beside the existing optimiser form; Sphinx warnings must stay at baseline 30.- Ship:
ship_library→ PR (pending-release). Black on touched files only (black 25.1 reformats 263 files on main). Fulltest_autofitmust pass (2843 at phase 5).
2. Workspace: figure beside every bare model.info (autofit_workspace, HowToFit)
Pattern (verbatim from phases 2/4, e.g. autofit_workspace/scripts/cookbooks/model.py:235-244, HowToFit/.../tutorial_2_graphical_model.py:217-235): print(x.info) → blank line → """ prose """ → af.ModelPlotter(x).figure(). The prose opens with the fixed map/legend sentence the first time it appears in a script, then one short paragraph on what this figure shows that the info cannot (which parameters are fixed/shared/related/asserted, plates, what changed since the previous figure). Later sites in the same script use 1-3 lines of prose. Default figure() settings (format "show" → inline in notebooks, commits no asset). No try/except in scripts; a guard belongs in the library.
Coverage rule (the prompt's acceptance is a grep: a figure call beside every model.info occurrence): add one at every bare site, with these explicit exceptions recorded in the completion record:
autofit_workspace/scripts/cookbooks/result.py:406— indentedprint(model.info)inside the aggregator loop: one figure after the loop for the last loaded model, prose says the three are identical in structure.result*.info/samples.infolines are not model prints (not counted).- Where a print re-shows an unchanged structure after a prior/value-only edit (e.g.
cookbooks/model.py:109vs the priors block), the figure still goes in, prose one line: "the map is unchanged; only the legend moved" — that contrast is the teaching point.
autofit_workspace sites (census, file: line numbers of bare prints): cookbooks/model.py 109, 352, 394, 486, 501, 584, 588, 612, 660, 680, 738, 803 (12 bare of 16); cookbooks/multi_level_model.py 99, 354; features/model_comparison.py 124, 206, 289; features/search_chaining.py 157, 232, 305, 497, 533 (prior-passing is the best figure case: show the passed priors as the same map with a changed legend); features/search_grid_search.py 129; searches/start_point.py 125, 148; overview/overview_1_the_basics.py 222, 235, 549 (global_prior_model), 718; cookbooks/result.py 406 (loop exception). cookbooks/model.py:814-816 already carries the once-per-script wrap-up note about model_figure: true → keep it single.
HowToFit sites: chapter_1_introduction/tutorial_1_models.py 234, 381, 394, 486 (highest priority — the composition tutorial; teach the map/legend idea here in full tutorial register); tutorial_3_non_linear_search.py 265; tutorial_4_why_modeling_is_hard.py 309, 551, 661, 757 (x5 Gaussian: plate 5 components); tutorial_7_the_details.py 271; tutorial_optional_bayesian_formalism.py 271; chapter_3_graphical_models/tutorial_3_graphical_benefits.py 352 (global_prior_model); tutorial_5_expectation_propagation.py 221 (global_prior_model, plus EP below).
EP rollout (the phase-5 flag)
autofit_workspace/scripts/features/expectation_propagation.py: at thefactor_graphcomposition (before the low-level dissection) addprint(factor_graph.global_prior_model.info)+af.ModelPlotter(factor_graph.global_prior_model).figure()(the structure map; the factor-graph view itself needs the swept graph, so it comes after the fit). In thefactor_graph.optimise(...)call (:303-309) addvisualise_interval=1(flows through**kwargstoEPOptimiser.run, default 100, so withmax_steps=5the state PNG otherwise refreshes once). After the call add prose +af.EPPlotter(factor_graph_result.factor_graph, ep_history=factor_graph_result.ep_history).figure(kind="state"), reading the figure: factor status, update age, confirmed reverted updates; then extend the existing__Output Folder__prose withgraph_model.png/graph_state.png(written per tick whenconfig/output.yamlmodel_figure: true).HowToFit/scripts/chapter_3_graphical_models/tutorial_5_expectation_propagation.py: figure beside:221,visualise_interval=1on:263-264, EPPlotter state figure + tutorial-register prose after the fit, output-folder bullets for the two PNGs. Leavetutorial_optional_hierarchical_ep.pyalone (its optimise is commented out by design).HowToFit/config/output.yaml: addmodel_figure: falsewith the same two-line comment asautofit_workspace/config/output.yaml:106-108— today the key is absent there, so the prose pointer would be false.- Under CI the
LaplaceOptimiserEP loop runs real sweeps even inPYAUTO_TEST_MODE(not aNonLinearSearch), andEPState.from_historyrenders an empty history asabsentrather than raising — so the inline state figure is safe in smoke; verify by the headless runs below.
Notebooks + catalogue
Per repo convention (both AGENTS.md): from the repo root, PYTHONPATH=../PyAutoHands/autohands python3 ../PyAutoHands/autohands/generate.py autofit / ... howtofit (the worktree's activate.sh sets cwd/paths). Commit only the touched scripts' .ipynb twins plus llms-full.txt / workspace_index.json if the flow rewrites them; never sweep in other scripts' pre-existing drift. HowToFit: confirm tutorial_8_scientific_workflow.ipynb still has zero code cells.
Verification
- PyAutoFit: new test + full
pytest test_autofit/in the worktree;black --checkon touched files; sphinx build warning count == 30. - Every touched script runs headless from its repo root under the smoke env profile (
PYAUTO_TEST_MODE=1 PYAUTO_SKIP_FIT_OUTPUT=1 PYAUTO_SKIP_VISUALIZATION=1 PYAUTO_SKIP_CHECKS=1,MPLBACKEND=Agg,MPLCONFIGDIR=/tmp/matplotlib,NUMBA_CACHE_DIR=/tmp/numba_cache,PYTHONPATHpointing at the worktree PyAutoFit so the newEPResult.factor_graphresolves;PYAUTO_SKIP_API_GATE=1for the branch-only symbol) — exit 0, no traceback. HowToFit smoke runs every tutorial; autofit_workspace smoke allowlist coversoverview_1,cookbooks/{model,result,samples,latent_variables}andsearches/*— run the EP and features scripts locally anyway. pyauto-heart smokegrades against the canonical checkout, so the EP scripts must be run headless against the worktree PyAutoFit explicitly (phase-2 trap).- Notebooks regenerated; navigator catalogue current;
git statusshows only intended twins. - Ship order:
ship_library(PyAutoFit PR) →ship_workspace(autofit_workspace PR, HowToFit PR; both bodies link the library PR; library-first gate) →/prmover the three, then Mind record + follow-up: the rollout map's next cut is (b) PyAutoLens surfaces.
Original Prompt
Click to expand starting prompt
# Model figures phase 6a — PyAutoFit surfaces (autofit_workspace + HowToFit, incl. the EP state figure)
Type: feature
Target: workspaces
Repos:
- PyAutoFit
- autofit_workspace
- HowToFit
Themes:
- visualization
- notebooks
Difficulty: medium
Autonomy: supervised
Priority: normal
Status: formalised
Consequence: judge
Review-minutes: 30
Unattended: ready
Epic: model-figures
Phase: 6a
Filed: 2026-09-13
This is sub-task **(a)** cut from the rollout map
`draft/feature/workspaces/model_figures_6_rollout.md`, which orders one sub-task at a
time and never bundles two repos' rollouts into one PR. The map's bullet, verbatim:
"**(a) PyAutoFit surfaces** — `autofit_workspace` cookbooks and `features/`, the
`howtofit` scripts and the HowToFit chapters. The graphical-models chapter waits for
phase 4." Phase 4 has shipped, so that chapter is in scope here.
## Context
The `model-figures` epic (phases 1-5 shipped, phase 5 merged as PyAutoFit#1619) gives
every model a figure: `af.ModelPlotter(model).figure()` for the structure, and for
expectation propagation `af.EPPlotter(...)` plus per-run `graph_model.png` /
`graph_state.png`. Census (read-only, 2026-09-13): `autofit_workspace/scripts/` has
**28 bare** `print(<model>.info)` sites across 9 scripts; `HowToFit/scripts/` has **14
bare** sites across 8 tutorials. Neither EP script draws a figure.
**API gap found:** `FactorGraphModel.optimise(...)`
(`PyAutoFit/autofit/graphical/declarative/abstract.py:172-214`) builds the swept graph
inside `_make_ep_optimiser` and returns an `EPResult` (`declarative/result.py:57`)
carrying only `ep_history`, `declarative_factor`, `updated_ep_mean_field`.
`EPPlotter(kind="state")` must receive **the optimiser's own factor graph** (history is
keyed by its factor objects; `FactorGraphModel.graph` rebuilds and renames on every
access — `docs/features/graphical.md:288-292` says so). So a workspace script cannot
draw the state figure after the high-level `optimise` without a private API. The fix
belongs in the library, once: `EPResult.factor_graph` (additive, default `None`), passed
through from `abstract.py:210-214`, with a test and a `docs/features/graphical.md`
"Seeing the EP run" high-level form.
## Coverage rule
Acceptance is a grep: a figure call beside every `model.info` occurrence. Add one at
**every** bare site, with these exceptions recorded in the completion record:
- `autofit_workspace/scripts/cookbooks/result.py:406` — indented `print(model.info)`
inside the aggregator loop: one figure **after** the loop for the last loaded model,
prose says the three are identical in structure.
- `result*.info` / `samples.info` lines are not model prints (not counted).
- Where a print re-shows an **unchanged structure** after a prior/value-only edit (e.g.
`cookbooks/model.py:109`), the figure still goes in, prose one line: "the map is
unchanged; only the legend moved" — that contrast is the teaching point.
Pattern (verbatim from phases 2/4): `print(x.info)` → blank line → `"""` prose `"""` →
`af.ModelPlotter(x).figure()`. The prose opens with the fixed map/legend sentence the
first time it appears in a script, then one short paragraph on what the figure shows
that the info cannot. Default `figure()` settings. No `try/except` in scripts; a guard
belongs in the library.
## EP rollout (the phase-5 flag)
- `autofit_workspace/scripts/features/expectation_propagation.py`: at the `factor_graph`
composition add `print(factor_graph.global_prior_model.info)` +
`af.ModelPlotter(factor_graph.global_prior_model).figure()`. Add `visualise_interval=1`
to the `factor_graph.optimise(...)` call (`:303-309`; default 100, so with
`max_steps=5` the state PNG otherwise refreshes once). After the call add prose +
`af.EPPlotter(factor_graph_result.factor_graph,
ep_history=factor_graph_result.ep_history).figure(kind="state")`, reading the figure
(factor status, update age, confirmed reverted updates); extend the `__Output Folder__`
prose with `graph_model.png` / `graph_state.png`.
- `HowToFit/scripts/chapter_3_graphical_models/tutorial_5_expectation_propagation.py`:
figure beside `:221`, `visualise_interval=1` on `:263-264`, EPPlotter state figure +
tutorial-register prose after the fit, output-folder bullets for the two PNGs. Leave
`tutorial_optional_hierarchical_ep.py` alone (its optimise is commented out by design).
- `HowToFit/config/output.yaml`: add `model_figure: false` with the same two-line comment
as `autofit_workspace/config/output.yaml:106-108` — today the key is absent there, so
the prose pointer would be false.
- Under CI the `LaplaceOptimiser` EP loop runs real sweeps even in `PYAUTO_TEST_MODE`, and
`EPState.from_history` renders an empty history as `absent` rather than raising — so the
inline state figure is safe in smoke.
## Notebooks + catalogue
Per repo convention (both AGENTS.md): from the repo root,
`PYTHONPATH=../PyAutoHands/autohands python3 ../PyAutoHands/autohands/generate.py autofit`
/ `... howtofit`. Commit **only** the touched scripts' `.ipynb` twins plus
`llms-full.txt` / `workspace_index.json` if the flow rewrites them; never sweep in other
scripts' pre-existing drift. HowToFit: confirm `tutorial_8_scientific_workflow.ipynb`
still has zero code cells.
## Verification
- PyAutoFit: new test + full `pytest test_autofit/`; `black --check` on touched files;
sphinx build warning count == 30.
- Every touched script runs headless from its repo root under the smoke env profile
(`PYAUTO_TEST_MODE=1 PYAUTO_SKIP_FIT_OUTPUT=1 PYAUTO_SKIP_VISUALIZATION=1
PYAUTO_SKIP_CHECKS=1`, `MPLBACKEND=Agg`, `MPLCONFIGDIR=/tmp/matplotlib`,
`NUMBA_CACHE_DIR=/tmp/numba_cache`, `PYTHONPATH` pointing at the worktree PyAutoFit so
the new `EPResult.factor_graph` resolves; `PYAUTO_SKIP_API_GATE=1` for the branch-only
symbol) — exit 0, no traceback. HowToFit smoke runs *every* tutorial;
autofit_workspace's allowlist is narrower, so run the EP and `features/` scripts
locally anyway. `pyauto-heart smoke` grades against the canonical checkout, so run the
EP scripts against the worktree PyAutoFit explicitly (phase-2 trap).
- Notebooks regenerated; navigator catalogue current; `git status` shows only intended
twins.
- Ship order: `ship_library` (PyAutoFit PR) → `ship_workspace` (autofit_workspace PR,
HowToFit PR; both bodies link the library PR; library-first gate) → `/prm` over the
three, then Mind record + follow-up: the map's next cut is **(b) PyAutoLens surfaces**.(PyAutoMind/draft/feature/workspaces/model_figures_6a_autofit_surfaces.md, moved to active/ on issue.)
Activity
Jammy2211 commentedon Sep 13, 2026
Library PR Created
#1621
API changes (additive only):
EPResult.factor_graph— theDeclarativeFactorGraphthe EP optimiser actually swept, soaf.EPPlotter(result.factor_graph, ep_history=result.ep_history).figure(kind="state")works after a high-levelfactor_graph.optimise(...)run.EPResult.__init__gains a trailing keywordfactor_graph=None;AbstractDeclarativeFactor.optimise()populates it fromopt.factor_graph.docs/features/graphical.md("Seeing the EP run") documents the new form.Opened under Heart RED
release validation FAILED (stage integrate)with human authorisation 2026-09-13; merge stays human via /prm.Next: /start_workspace (autofit_workspace + HowToFit on the same-named branch, in flight).
Jammy2211 commentedon Sep 13, 2026
Workspace PRs Created
af.ModelPlotterfigures + 1af.EPPlotter(kind="state")across 9 scripts (cookbooks, features, searches, overview), notebooks regenerated.af.ModelPlotterfigures + 1af.EPPlotter(kind="state")across 7 tutorials, plus themodel_figurekey inconfig/output.yaml; notebooks regenerated.EPResult.factor_graph) — merge first (library-first gate); both workspace PRs' EP scripts import it.Smoke, run locally from each repo root under the smoke env profile: autofit_workspace 8 scripts + 2 notebooks PASS (exit 0); HowToFit 18 scripts PASS (exit 0).
All three PRs were opened under Heart RED
release validation FAILED (stage integrate)(unrelated autolens integrate scripts) with explicit human authorisation on 2026-09-13. Merge stays human.Next:
/prmover PyAutoFit#1621 → autofit_workspace#154 → HowToFit#52 once CI is green.Pre-existing defect found while writing tutorial 5's prose, out of scope here and to be filed as its own prompt:
scripts/chapter_3_graphical_models/tutorial_5_expectation_propagation.pycreatescentre_shared_priorbut never assigns it to any model, so despite the prose nocentreis actually shared across the datasets. The new figure prose describes only what the map actually shows.Merge pull request #1621 from PyAutoLabs/feature/model-figures-rollou…
Jammy2211 commentedon Sep 13, 2026
Shipped
Phase 6a of the model-figures epic — figures beside every
model.infoacross the AutoFit surfaces.PRs merged
c089d0fb38519e0daa49160725fdce704c0653b98ef02275f74aa0e6e04c78d04c7bef92a75bd9e670bfcfa189944dfe39008d500392c50b3e3c629cWhat shipped
EPResult.factor_graph, so an EP result can hand its factor graph straight to the plotter (the surface the EP state figure needs).ModelPlottercall sites + 1EPPlotteracross 9 scripts; notebooks regenerated.ModelPlotter+ 1EPPlotteracross 7 tutorials, plus themodel_figureconfig key; notebooks regenerated.CI — PyAutoFit: Docs (docs-build) + Tests (nojax, 3.12, 3.13) green. autofit_workspace: Navigator Check (3 jobs) + Smoke Tests (changes, 3.12, 3.13) green. HowToFit: Navigator Check (3) + Tutorials Complete + Smoke Tests (3) green.
Pending release — PyAutoFit#1621 is merged but unpublished; the
EPResult.factor_graphsurface reaches users at the next PyAutoFit release.Follow-ups
draft/bug/howtofit/tutorial_5_ep_shared_centre_never_assigned.md.draft/feature/workspaces/model_figures_6_rollout.md).