Repository navigation
Description
Overview
Follow-up to #1777 / #1779. Model.tree_flatten now carries a model's direct priors and TuplePrior attributes, but it still drops fixed non-prior attributes on the model, such as a fixed sky level. tree_unflatten rebuilds the model without them, so making an instance from the rebuilt model falls back to a prior-config lookup for the missing attribute, which a config-less class does not have.
Plan approved by the human on 2026-11-18 ("Do the small follow up after prm"), so the start_dev approval pause is skipped.
Plan
- Carry the model's fixed direct attributes (not priors,
TuplePriors or child models) intree_flatten's aux data. - Restore them in
tree_unflatten. - Extend
test_autofit/mapper/test_model_pytree_tuple_prior.pywith instance round-trips for cases (a)-(c), asserting the fixed value survives and the rebuilt model gives the same instance as the original.
Detailed implementation plan
Affected Repositories
- PyAutoFit (primary)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoFit | main | clean |
Suggested branch: feature/model-pytree-fixed-attributes
Implementation Steps
- In
autofit/mapper/prior_model/prior_model.py,Model.tree_flatten: collect direct__dict__attributes that are not priors,TuplePriors orAbstractPriorModels (skippingcls,idand private names) and add them to the aux data. Model.tree_unflatten: set those attributes on the rebuilt model.- Add instance round-trip tests for cases (a)-(c) to
test_autofit/mapper/test_model_pytree_tuple_prior.py.
Key Files
autofit/mapper/prior_model/prior_model.py-Model.tree_flatten/tree_unflattentest_autofit/mapper/test_model_pytree_tuple_prior.py- the fix: Model.tree_flatten handles zero direct priors and keeps TuplePrior children #1779 tests
Original Prompt
Click to expand starting prompt
Model pytree round-trip drops fixed non-prior attributes (e.g. a fixed sky level)
Type: bug
Target: PyAutoFit
Repos:
- PyAutoFit
Difficulty: small
Autonomy: safe
Priority: medium
Status: formalised
Consequence: glance
Witness: afterautofit.jax.register_model, aModelof aDatasetModel-shaped class withgrid_offsetfree and a FIXED scalar attribute (e.g. a fixed sky level) round-trips throughjax.tree_util.tree_flatten/tree_unflattenwith the fixed value preserved, andinstance_from_prior_medians()(orinstance_from_vector) on the rebuilt model succeeds without looking up prior config for the fixed attribute and returns the same instance as the original model
Review-minutes: 5
Unattended: ready
Lane: any
Follow-up to PyAutoFit#1777 / PR #1779 (merged 2026-11-18; record
complete/2026/11/dataset-model-free-grid-offset-pytree-roundtrip.md). Human request,
verbatim: "Do the small follow up after prm".
#1779 made Model.tree_flatten carry direct priors and TuplePrior attributes as pytree
children, but fixed non-prior attributes on the Model (a float or other constant set on
the model, e.g. a fixed sky level) are not carried in the aux data. tree_unflatten
therefore rebuilds the model without them, and making an instance from the rebuilt model
in case (b) of test_autofit/mapper/test_model_pytree_tuple_prior.py falls back to a
prior-config lookup for the missing attribute (which a config-less class does not have).
Fix: carry the Model's fixed (non-prior, non-TuplePrior) direct attributes in
tree_flatten's aux data and restore them in tree_unflatten
(autofit/mapper/prior_model/prior_model.py); extend the #1779 test file with an
instance round-trip for cases (a)-(c) asserting the fixed value survives. Out of scope:
nested child models beyond what the existing flatten already recurses into.
Activity
Jammy2211 commentedon Nov 18, 2026
Library PR Created
PR: #1781 (label
pending-release)Plan was approved by the human on 2026-11-18 ("Do the small follow up after prm"), so the start_dev approval pause was skipped.
ConfigException(background_sky_level) when making an instance from the rebuilt model; (c) passed. After: all three match the original model.Tier glance; stopped at PR-open. Next: human /prm.
Jammy2211 commentedon Nov 18, 2026
Shipped in #1781 (merged
3ba1e6c3, 2026-11-18).Model.tree_flattencarries fixed direct attributes (e.g. a fixed sky level) in the aux data andtree_unflattenrestores them, so instances from a round-tripped model match the original (instance_from_prior_medians/instance_from_vector, cases a-c). CI GREEN; pytree tests 190 passed; autofit + autogalaxy smoke passed. Model and search identifiers checked unchanged against pre-#1778 main for five models. Pending release.