Repository navigation
fix: Model.tree_flatten handles zero direct priors and keeps TuplePrior children - #1779
Merged
Merged
Conversation
…or children Model.tree_flatten built its pytree from direct_prior_tuples alone, so a Model with no direct priors (a DatasetModel shape, whose grid_offset priors sit under a TuplePrior) raised "not enough values to unpack", and a model with a free TuplePrior plus a scalar lost the tuple priors on round-trip. - Model.tree_flatten carries direct priors and direct TuplePrior attributes as children, and returns empty children when there are none. - TuplePrior gains tree_flatten/tree_unflatten (prior members as children, fixed members in aux) and is registered in enable_pytrees. - New round-trip test over a DatasetModel-shaped Model: prior_count 0, 2, 3 survives tree_flatten/tree_unflatten. Closes #1777 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1777.
Model.tree_flattenbuilt its pytree fromdirect_prior_tuplesalone. Two things went wrong because of that:Modelwith no direct priors (theDatasetModelshape, whosegrid_offsetpriors sit under aTuplePrior) raisedValueError: not enough values to unpack (expected 2, got 0).TuplePriorplus a free scalar lost the tuple priors on round-trip.This is a latent fix. No search depends on it today, because
Fitnesscloses over the model.Before / after on a
DatasetModel-shaped model, afterautofit.jax.register_model:API Changes
No public API is removed or renamed.
TuplePriorgains thetree_flatten/tree_unflattenpair that the other prior classes already have, andenable_pytrees()now registersTuplePrioras a JAX pytree node.Model.tree_flattenchildren now include directTuplePriorattributes.See full details below.
Test Plan
test_autofit/mapper/test_model_pytree_tuple_prior.py: round-trip for cases (a)/(b)/(c), asserting prior_count 0/2/3 and that the rebuiltgrid_offsetis aTuplePrior, plus a directTuplePriorround-trip with mixed free and fixed members. Without the source change, 3 of the 4 tests fail.test_autofit: 4295 passed, 2 skipped, 1 xfailed.pyauto-heart smoke autofit autogalaxy --root <task worktree>): 26/26 PASS, includingautogalaxy_workspace/scripts/multi_dataset/start_here.py(JAX FactorGraph).Out of scope, noted on the issue and not changed here:
Model.tree_flattenstill omits direct child models and fixed constants.tree_unflattenre-creates them from the class defaults or prior config, so a fixed scalar can trigger a config lookup on the rebuilt model.Collection.tree_flattenhas the same empty-zipunpack when the collection is empty.Full API Changes (for automation & release notes)
Added
autofit.mapper.prior.tuple_prior.TuplePrior.tree_flatten(): prior members become the children; their names and the fixed members go in the aux data.TuplePrior.tree_unflatten(aux_data, children)(classmethod).autofit.jax.enable_pytrees()registersTuplePrior.Changed
Model.tree_flatten()children = direct priors + directTuplePriorattributes. A model with neither returns empty children instead of raising.Generated by the PyAutoLabs agent workflow.
🤖 Generated with Claude Code