Repository navigation
Description
Overview
Building a JAX Fitness registers the model's classes (including Galaxy) as JAX pytrees via autofit.jax.register_model. If the same process then calls autolens.jax.register_tracer_classes (the static-lattice / PointSolver JAX path), autoarray.abstract_ndarray.register_instance_pytree registers Galaxy a second time and JAX raises ValueError: Duplicate custom PyTreeDef type registration for Galaxy. PyAutoFit's side already tolerates the duplicate; autoarray's side does not. Found while shipping PyAutoFit#1649 / PyAutoLens#752, which worked around it with a subprocess.
Reproduced on main (PyAutoArray@102f0249, PyAutoFit@362ee746): build Fitness(model, AnalysisPoint(use_jax=True)), then register_tracer_classes(tracer) → the ValueError above, raised at autoarray/abstract_ndarray.py:136.
Plan
- Make autoarray's two registration helpers idempotent across registration routes: when JAX reports the class is already registered (by PyAutoFit or anyone else), record it as registered and return, as PyAutoFit's
register_modelalready does. - Only the duplicate-registration error is swallowed; any other error still raises.
- The first registration of a class wins (JAX has no unregister). Document that in the docstrings.
- Add a PyAutoArray unit test that registers a class through another route, then calls both helpers without error.
- Check the Witness: a JAX
Fitnessfor anAnalysisPointmodel, then the 16test_static_lattice_jax.pytests, all in one pytest process. - Tier: glance — merge mode: auto-merge on green if the Witness passes, post-merge summary
Detailed implementation plan
Affected repositories
- PyAutoArray (primary)
- PyAutoFit: no change needed.
register_model/enable_pytreesalready catch the duplicateValueError.
Work classification: Library
Branch survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| PyAutoArray | main | clean |
Suggested branch: feature/galaxy-duplicate-pytree-registration
Worktree root: ~/Code/PyAutoLabs-wt/galaxy-duplicate-pytree-registration/
Steps
autoarray/abstract_ndarray.py: add a small helper_register_pytree_node_once(cls, flatten, unflatten). It callsautonerves.jax_wrapper.register_pytree_node, catchesValueErrorwhose message contains"Duplicate custom PyTreeDef", and re-raises anything else. Both_register_as_pytreeandregister_instance_pytreeuse it and addclsto_pytree_registered_classeseither way.- Docstrings: say that a class registered first through another route (e.g.
autofit.jax.register_modelduring a JAXFitnessbuild) keeps that registration. test_autoarray/test_abstract_ndarray_pytree.py(or the existing pytree test module): register a throwaway class directly withjax.tree_util.register_pytree_node, thenregister_instance_pytree(cls)must not raise and must mark it registered; a non-duplicateValueErrorstill propagates.- Witness, in one process: build a JAX
Fitnessfor theAnalysisPointmodel fromtest_analysis_point_gradient_mode.py, then runtest_autolens/point/triangles/test_static_lattice_jax.py(16 tests). All must pass.
Not in scope: removing the subprocess workaround from PyAutoLens test_analysis_point_gradient_mode.py. That subprocess also serves as the GPU-run entry point, and PyAutoLens is not in this task's repos. Raise it as a follow-up.
Key files
autoarray/abstract_ndarray.py: registration helpers- test module under
test_autoarray/
Activity
Jammy2211 commentedon Nov 18, 2026
Library PR Created
Resumed the 2026-11-14 shift worker's unpushed fix and rebased it onto current
main. PR: #702pytest test_autoarray: 2461 passedregister_modelregistersGalaxy, thenregister_tracer_classes): raisesDuplicate custom PyTreeDef type registrationonmain, passes on the branchAPI changes: none (internal changes only). Workspace impact: none expected; the workspace smoke run is in progress. The merge is human (
/prm).Merge pull request #702 from PyAutoLabs/feature/galaxy-duplicate-pytr…
Jammy2211 commentedon Nov 18, 2026
Shipped
Merged in #702 (
5815019d).register_instance_pytreeand_register_as_pytreenow keep an existing JAX registration and no longer raiseDuplicate custom PyTreeDef type registration, so building a JAXFitnessand then callingregister_tracer_classesin the same process works.Evidence: autoarray 2461 passed; direct reproduction with real JAX (raises on old
main, passes on the branch); PyAutoLens static-lattice and point-gradient tests 32 passed; workspace smoke all passed (autocti not run: no GSL on the laptop); Heart dev gate GREEN. The fix reaches users in the next release (pending-release).