Skip to content

Expose the swept factor graph on EPResult for the EP state figure (#1620) - #1621

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/model-figures-rollout-autofit
Sep 13, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/model-figures-rollout-autofit

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Phase 6a of the model-figures rollout (issue #1620) puts the model figure beside every model.info in autofit_workspace and HowToFit, including the EP state figure after an expectation-propagation run. Doing that from a workspace script exposed one gap: FactorGraphModel.optimise(...) builds its EPOptimiser, and so the factor graph it sweeps, internally, and returned only the history and the mean field. af.EPPlotter(kind="state") needs the optimiser's own graph, because the EP history is keyed by its factor objects and FactorGraphModel.graph builds a fresh graph, renaming prior factors, on every access.

EPResult now carries factor_graph, the swept graph, so the high-level form is one line:

result = factor_graph.optimise(optimiser=laplace, paths=paths, ep_history=af.EPHistory(kl_tol=0.05))
af.EPPlotter(result.factor_graph, ep_history=result.ep_history).figure(kind="state")

docs/features/graphical.md ("Seeing the EP run") shows that form beside the existing optimiser form. The two workspace PRs on the same-named branch consume it.

Opened under Heart RED release validation FAILED (stage integrate) (unrelated autolens integrate scripts) with explicit human authorisation on 2026-09-13; merge stays human via /prm.

API Changes

Additive only. EPResult.__init__ gains a trailing keyword factor_graph=None and stores it as EPResult.factor_graph; optimise() populates it. Nothing removed, renamed or made required.
See full details below.

Test Plan

  • test_autofit/graphical/test_ep_result_factor_graph.py (new, 4 tests): result.factor_graph is set after optimise, is a fresh DeclarativeFactorGraph distinct from FactorGraphModel.graph (whose PriorFactor names differ), the state figure renders from it with no absent factor, and EPResult(...) without the keyword still constructs.
  • test_autofit/graphical/gaussian/test_declarative.py: the StubEPOptimiser double gains factor_graph = None so the stub matches the real optimiser's surface.
  • Full test_autofit: 2847 passed / 2 skipped (baseline 2843 + 4 new).
  • Sphinx warning count 30 == docs/sphinx_warning_baseline.txt.
  • black / pyflakes clean on touched files (abstract.py carries pre-existing black drift outside this hunk, left as is).
Full API Changes (for automation & release notes)

Added

  • autofit.graphical.declarative.result.EPResult.factor_graph — the DeclarativeFactorGraph the EP optimiser swept; EPResult(..., factor_graph=None) keyword, populated by AbstractDeclarativeFactor.optimise().

Changed Behaviour

  • AbstractDeclarativeFactor.optimise() passes factor_graph=opt.factor_graph into the returned EPResult. No change to the history or mean field it returns.

Migration

  • None required. To draw the EP state figure after a high-level run: af.EPPlotter(result.factor_graph, ep_history=result.ep_history).figure(kind="state").

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DLx38vS6F1M7K5LnpVbeZ7

factor_graph.optimise() builds its EPOptimiser (and so the graph it
sweeps) internally and returned only the history and mean field, so a
caller could not draw af.EPPlotter(kind="state") without private API:
the plotter needs the optimiser's own graph, because
FactorGraphModel.graph rebuilds and renames prior factors on every
access and the history is keyed by the swept one. EPResult now carries
factor_graph (additive, default None). Docs show the high-level form.

Refs #1620

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

Copy link
Copy Markdown
Collaborator Author

Workspace PRs: PyAutoLabs/autofit_workspace#154, PyAutoLabs/HowToFit#52 — merge this library PR first (library-first gate).

@Jammy2211
Jammy2211 merged commit c089d0f into main Sep 13, 2026
4 checks passed
@Jammy2211
Jammy2211 deleted the feature/model-figures-rollout-autofit branch September 13, 2026 11:36
@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