Skip to content

feat: graph_spec — semantic model extraction (model-figures phase 1) - #1606

Merged
Jammy2211 merged 3 commits into
mainfrom
feature/model-figures-graph-spec
Sep 11, 2026
Merged

Jammy2211 merged 3 commits into
mainfrom
feature/model-figures-graph-spec

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Phase 1 of the model-figures epic (PyAutoMind draft/feature/autofit/model_figures_epic.md): the semantic extraction layer every later figure renders over. A new autofit/graph_spec.py turns any AbstractPriorModel into a frozen, JSON-stable nesting tree — ComponentNodes in declaration order, one ParamRow per parameter slot carrying independent properties (sampling status free|fixed|solved|missing, sharing as prior id + path occurrences, dimensionality with per-slot tuple components, provenance with relation expressions), plus SharedEdge / RelationEdge / AssertionEdge, a model.info path index and reconciling counts. Sibling components collapse into plates by rules R1 (class tree + prior configuration) and R2 (split by cross-member shared priors) under the review's safety condition (sharing, relations, assertions and exceptions must match), grouping over the existing find_groups.

It draws nothing and imports no matplotlib (asserted by a test). af.VisualiseGraph is untouched. Closes #1605.

API Changes

Added only — af.GraphSpec (with GraphSpec.from_model(model, analysis=None, collapse=True, solved_paths=())) and the alias af.graph_spec_from(model, **kwargs), plus the dataclasses ComponentNode, ParamRow, PlateInfo, Provenance, SharedEdge, RelationEdge, AssertionEdge in autofit.graph_spec. No existing symbol changed.
See full details below.

Test Plan

  • python -m pytest test_autofit/graph_spec — 18-construct catalogue, collapse rules (R1 / R2 / safety condition / fixed tuple rows / Model(int) rows), determinism (byte-identical to_dict() across runs and id resets), matplotlib-purity subprocess check, and the three lens acceptance models as structural doubles.
  • python -m pytest test_autofit/ — full suite green locally (serial; test_prior_bounds_1489.py::TestEmceeContainment failed once on the first run and passed on re-run — a stochastic sampler test untouched by this diff).
  • CI matrix (3.12 / 3.13) green.

Acceptance cases vs the epic's targets

The three lens models are structural doubles of today's autolens_workspace scripts (autofit may not import autolens; phase 3 re-runs these on the real classes). Structural invariants are asserted unconditionally; where a faithful double cannot reproduce one of the epic's prototype numbers, the measured value is pinned with an # epic target: N -- measured M comment.

Model Epic target Measured on the double Structural invariants
(a) simple lens 8 raw nodes / 48 info lines → 6 boxes, 13 rows 8 / 47 → 6 boxes, 17 rows (redshift rows and both intensity rows counted) declaration order bulge, mass, shear
(b) MGE 2×30 + pixelized source 73 / 178 → 11 components, two ×30 plates on ell_comps, shared 60,60,30,30,30,30, 16 unique sampled scalars, areas_factor missing 72 / 173 (today's Delaunay has no pixels Model(int)) → 11 boxes, two ×30 plates split on ell_comps, shared 60/60/30/30/30/30, 16 unique sampled scalars, areas_factor = missing all met; sigma recorded as varies_by_member
(e) group scale, 8 extra galaxies 166 / 418 → 15 components, 41 sampled, 22 shared, 291 fixed slots 33 / 199 → 9 boxes, 69 sampled, 0 shared, 77 fixed slots (today's group/modeling.py composition shares no priors between galaxies and is far smaller than the prototype's model) 8 extra galaxies collapse into one plate 0 - 7, per-galaxy fixed centre tuples present and varies_by_member, nothing fixed dropped

Determinism: every acceptance extraction run twice is byte-identical.

Full API Changes (for automation & release notes)

Added

  • autofit.GraphSpec — frozen dataclass; GraphSpec.from_model(model, analysis=None, collapse=True, solved_paths=()), to_dict(), components(), node(path), rows(), row(path); fields root, shared, relations, assertions, path_index, counts.
  • autofit.graph_spec_from(model, **kwargs) — alias for GraphSpec.from_model.
  • autofit.graph_spec.ComponentNode, ParamRow, PlateInfo, Provenance, SharedEdge, RelationEdge, AssertionEdge — the spec's record types.

Migration

  • None. Purely additive.

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UJ9stuFNR4e9BF5GXsqvfv


Generated by Claude Code

…, part 1)

Pure extraction of a model's structure into frozen dataclasses: component
nesting tree, ParamRow as independent properties (sampling / sharing /
dimensionality / provenance), shared / relation / assertion edges, a
model.info path index and reconciling counts. No drawing, no matplotlib.
Tests cover the 18-construct catalogue and determinism. Collapse rules
land in the next commit.

Refs #1605

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UJ9stuFNR4e9BF5GXsqvfv
…figures phase 1, part 2)

Sibling Model components collapse into plates by class tree + prior
configuration (R1), split by cross-member shared priors (R2) under the
review's safety condition (sharing, relations, assertions and exceptions
must match across members). Plates group over find_groups so their keys
read as model.info prints them, and the path index records where the
figure's partition is finer than model.info's. Sharing now counts direct
occurrences only, so a relation operand is related, not shared.

Acceptance: the epic's three lens models as structural doubles mirroring
the workspace scripts (autofit may not import autolens). The MGE case
meets every epic invariant; the group-scale double is today's smaller
script composition, so its counts are pinned as measured and annotated.

Refs #1605

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UJ9stuFNR4e9BF5GXsqvfv
An unset optional attribute such as Basis(regularization=None) is not a
parameter slot and model.info prints nothing for it, so emitting a row
marked in_model_info=True broke the correspondence contract.

Refs #1605

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UJ9stuFNR4e9BF5GXsqvfv
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Sep 10, 2026 — with Claude
@Jammy2211
Jammy2211 merged commit e331e33 into main Sep 11, 2026
4 checks passed
@Jammy2211
Jammy2211 deleted the feature/model-figures-graph-spec branch September 11, 2026 00:53
@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.

feat: graph_spec — semantic model extraction (model-figures phase 1)

2 participants