Skip to content

feat: model figures phase 2 — matplotlib renderer + opt-in model.png (#1613) - #1614

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/model-figures-renderer
Sep 11, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/model-figures-renderer

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Phase 2 of the model-figures epic (issue #1613; phase 1 was #1606). Draws the phase-1 GraphSpec as a pure-matplotlib containment figure: the figure is the map (which component owns which parameter, what is shared, fixed, related, constrained, missing), model.info stays the legend (priors and values). One vocabulary at every scale: white component cards with name-first pills, dashed plates badged N components for repeated siblings, a blue shared across group / ↗ owner badge with links routed through a dedicated gutter, cream relation pills carrying their defining expression, dashed orange assert … labels with both operands, a red missing state, 2D tags on tuples, redshift = 0.5 as a card subtitle, a one-line legend and a footer with defined counts (16 unique sampled scalars · 63 fixed leaf slots · 6 shared priors (unique variables, not references) · 2 plates standing for 60 components).

Text size is fixed; scalability comes from collapsing content and a width budget (default 14 in at 100 dpi) that wraps top-level cards in declaration order, never masonry. Zero new dependencies; graphviz deliberately not adopted. af.VisualiseGraph untouched.

Per-search output: model.png beside model.info, behind a new output.yaml key model_figure (default false). The key is read strictly, absent → off, because should_output's fallback to default: true would otherwise switch the figure on in every config that has not added the key yet. A render failure is logged and never raised, so a figure bug cannot kill a fit. model_graph is not reused (it gates graphical-model text, #1264).

Acceptance renders (structural doubles of the lens models until phase 3 renders the real PyAutoLens classes) are committed as evidence under docs/images/model_figures/ with make_figures.py; the three cookbook docs pages embed them.

Evidence renders
MGE 2×30 + pixelized: 11 components, two 30 components plates split on ell_comps, areas_factor · missing, footer 16 unique sampled scalars mge
Group scale: 8 extra galaxies as one plate, per-galaxy centre · fixed, varies by member, independent priors group
Shared + relation + assertion together composite

API Changes

Added af.ModelPlotter (new autofit.model_figure package) and a new, default-off output.yaml key model_figure. No existing symbol removed, renamed or changed. See full details below.

Test Plan

  • test_autofit/model_figure 76 passed, test_autofit/graph_spec 52 passed (the matplotlib-purity test for autofit.graph_spec still green), test_autofit/non_linear/paths/test_model_figure_output.py 9 passed — serial.
  • Full test_autofit suite green in the worktree before commit (counts in the ship report).
  • Every committed PNG ≤ 1400 px wide (max 1121); font sizes identical across the toy Gaussian and group-scale layouts (asserted).
  • Layout dict byte-identical across two builds and across a subprocess; PNG bytes identical across two in-process saves.
  • model_figure: true writes model.png beside model.info; false and absent write nothing; renderer failure leaves model.info intact and raises nothing.
  • Sphinx docs build: 30 warnings, equal to docs/sphinx_warning_baseline.txt.
  • CI: lib-tests 3.12 / 3.13 + no-jax leg, docs.
Full API Changes (for automation & release notes)

Added

  • autofit.model_figure.ModelPlotter(model, analysis=None, solved_paths=()) — exported as af.ModelPlotter.
  • ModelPlotter.figure(path=None, filename="model", format="show", detail="names", collapse=True, max_depth=None, show_fixed=True, width=14.0) -> matplotlib.figure.Figure — format ∈ show|png|svg|pdf (mirrors autofit.plot.output_figure); path is a directory.
  • ModelPlotter.spec(), .presentation(...), .layout(...) — the three layers, for tests and tooling.
  • autofit.model_figure.presentation.build_presentation, autofit.model_figure.layout.build_layout / Style, autofit.model_figure.render.draw / save — layer entry points (semi-public).
  • output.yaml key model_figure: false — writes model.png beside model.info per search when true; read strictly (absent → off), unlike every other output key.
  • autofit.non_linear.paths.directory._model_figure_enabled() — private helper.

Changed Behaviour

  • DirectoryPaths._save_model_info additionally writes model.png when model_figure is true and visualisation is not skipped by test mode; any exception is logged at INFO and swallowed.

Migration

  • None required. To switch the figure on for a workspace add model_figure: true to its config/output.yaml.

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

https://claude.ai/code/session_0178yLU9v19GtACcRPFggjGa

Phase 2 of the model-figures epic. A pure-matplotlib containment figure
drawn over the phase-1 GraphSpec: name-first pills inside component cards,
plates for repeated siblings ("N components"), sharing as a blue badge with
gutter links, relation pills showing their expression, dashed assertion
labels, missing/solved states, a one-line legend and a defined-count
footer. Text size is fixed; scalability comes from collapse and a width
budget that wraps top-level cards in declaration order.

- autofit/model_figure/{presentation,layout,render,plotter}.py, exported
  as af.ModelPlotter(model).figure(path=None, filename="model",
  format="show|png|svg|pdf", detail="names|priors", collapse=True,
  max_depth=None, show_fixed=True, width=14.0)
- DirectoryPaths._save_model_info writes model.png beside model.info when
  the NEW output.yaml key `model_figure` is true. The key is read strictly
  (absent -> off) so it cannot switch on in configs that lack it; a render
  failure is logged and never raised.
- 85 new tests (vocabulary rules, width budget, fixed text size,
  declaration order, determinism, file output, config gate).
- Acceptance renders committed under docs/images/model_figures/ with the
  script that regenerates them; figures embedded in the model,
  multi_level_model and multiple_datasets cookbook docs.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0178yLU9v19GtACcRPFggjGa
@Jammy2211

Copy link
Copy Markdown
Collaborator Author

Workspace PR: PyAutoLabs/autofit_workspace#152

@Jammy2211
Jammy2211 merged commit 707820b into main Sep 11, 2026
4 checks passed
@Jammy2211
Jammy2211 deleted the feature/model-figures-renderer branch September 11, 2026 14:06
@Jammy2211 Jammy2211 removed the pending-release PR queued for the next release build label Sep 26, 2026
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