Repository navigation
fix: tolerate a class already registered as a JAX pytree elsewhere (#693) - #702
Merged
Merged
Conversation
Building a JAX Fitness registers Galaxy via autofit.jax.register_model; autolens.jax.register_tracer_classes then reaches register_instance_pytree for the same class and JAX raised "Duplicate custom PyTreeDef type registration for Galaxy". Both autoarray registration helpers now keep the existing registration and record the class as registered; any other ValueError still raises. Fixes #693 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
Author
|
Workspace smoke ( |
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
Building a JAX
FitnessregistersGalaxyas a pytree throughautofit.jax.register_model. A laterautolens.jax.register_tracer_classesin the same process then reachesautoarray.abstract_ndarray.register_instance_pytree(Galaxy), and JAX raisedValueError: Duplicate custom PyTreeDef type registration for Galaxy. Both autoarray registration helpers now go through_register_pytree_node_once. If JAX reports a duplicate registration, the helper keeps the existing one, so the first route wins (autofit already does the same in reverse). Any otherValueErrorstill raises.Fixes #693. The work was done by a shift worker that crashed on 2026-11-14 before pushing. This session resumed it and rebased it onto current
main.API Changes
None — internal changes only.
register_instance_pytreeand_register_as_pytreeno longer raise when another route has already registered the class.See full details below.
Test Plan
pytest test_autoarray: 2461 passed (rebased ontoe81c6e16)test_autoarray/test_abstract_ndarray_pytree_duplicate.py: duplicate error tolerated on both helpers; any otherValueErrorstill raises (NumPy-only, stubbed JAX call)register_model(af.Collection(lens=af.Model(ag.Galaxy, mass=ag.mp.Isothermal))), thenregister_tracer_classes(tracer), thenjax.tree_util.tree_leaves(tracer). Control onmain: raisesDuplicate custom PyTreeDef type registration for Galaxy. This branch: passes.test_analysis_point_gradient_mode.py,test_static_lattice_jax.py,test_solver_spurious_core.pyin one session): 32 passed. These also pass onmain, because the gradient-mode test does not registerGalaxythroughregister_model, so the direct reproduction above is the real control.readiness --dev --repos PyAutoArray: GREEN. Non-blocking reasons shown: manifest drift (end-at-deliverable blocks: 46 mismatches; generated hooks: 2 mismatches vsPyAutoMind/repos.yaml); release validation incomplete (no rehearsal for current source).Full API Changes (for automation & release notes)
Added
autoarray.abstract_ndarray._register_pytree_node_once(cls, flatten, unflatten): private helper. Registers withjax.tree_utiland ignores JAX's duplicate-registrationValueError.Changed Behaviour
autoarray.abstract_ndarray.register_instance_pytree(cls, no_flatten=()): no longer raises whenclsis already registered by another route (e.g.autofit.jax.register_model); the existing registration is kept.autoarray.abstract_ndarray._register_as_pytree(cls): same.Generated by the PyAutoLabs agent workflow.
🤖 Generated with Claude Code