fix(jax): defensive pytree dedup in imaging/interferometer analyses#561
Merged
Conversation
Same defense as PyAutoGalaxy companion PR — but additionally cross-populates ``Tracer`` from autofit's ``_REGISTERED_INSTANCE_CLASSES`` since lens models always carry one, making ``Tracer`` a regular source of duplicate-registration when both the autofit walker and the analysis registration path run. Triggered by ``multi/start_here.py`` in autogalaxy_workspace during the 2026.5.29.2 release; same `ValueError: Duplicate custom PyTreeDef type registration for DatasetModel` would surface here as soon as a multi-dataset lens model gets fit. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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
Same defensive pattern as the PyAutoGalaxy companion PR — additionally cross-populates `Tracer` from autofit's `_REGISTERED_INSTANCE_CLASSES` since lens models always carry one, making `Tracer` a regular source of duplicate-registration whenever both the autofit walker and the analysis registration path run.
Repro
Same root cause as autogalaxy companion (multi/start_here.py in autogalaxy_workspace during the 2026.5.29.2 release):
```
ValueError: Duplicate custom PyTreeDef type registration for
<class 'autoarray.dataset.dataset_model.DatasetModel'>.
```
The autolens analyses register the same class set plus `Tracer`. Once `autofit.jax.pytrees.register_model` walks a lens model, both `DatasetModel` and `Tracer` get registered via autofit's path — neither set lands in autoarray's `_pytree_registered_classes`, so the next `fit_from` call's registration step asks JAX to register them again.
Fix
For both `imaging/model/analysis.py` and `interferometer/model/analysis.py`:
Paired with
Test plan
🤖 Generated with Claude Code