Skip to content

feat: add lazy JAX pytree registration helpers to autoconf - #93

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/imaging-mge-pytree-migration
Apr 16, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/imaging-mge-pytree-migration

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Add two lazy helpers to autoconf.jax_wrapper — register_pytree_node_class(cls) and register_pytree_node(nodetype, flatten_func, unflatten_func) — that defer the jax.tree_util import to call time and no-op if JAX is not installed.

These unblock autofit.jax.enable_pytrees() (PyAutoFit PR) which needs to register PyAutoFit model classes as JAX pytree nodes without forcing a JAX import on every import autofit.

API Changes

Additive only. Two new public helpers on autoconf.jax_wrapper:

  • register_pytree_node_class(cls) — lazy equivalent of jax.tree_util.register_pytree_node_class
  • register_pytree_node(nodetype, flatten_func, unflatten_func) — lazy equivalent of jax.tree_util.register_pytree_node

Both no-op if JAX is missing. See full details below.

Test Plan

  • pytest test_autoconf/ passes (71 tests)
  • Callers in PyAutoFit (autofit.jax.enable_pytrees) import and use both helpers successfully
Full API Changes (for automation & release notes)

Added

  • autoconf.jax_wrapper.register_pytree_node_class(cls) — registers cls with jax.tree_util when JAX is present; returns cls unchanged otherwise.
  • autoconf.jax_wrapper.register_pytree_node(nodetype, flatten_func, unflatten_func) — registers a non-decoratable class; returns None when JAX is missing.

Removed / Renamed / Changed Signature / Changed Behaviour

None.

Migration

None. Existing callers of autoconf.jax_wrapper are unaffected.

🤖 Generated with Claude Code

…istration

Library code can now register classes as JAX pytree nodes without forcing
jax.tree_util to import at module load. Both helpers no-op if JAX is missing,
so they're safe to call from code paths that may run without JAX installed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Jammy2211

Copy link
Copy Markdown
Collaborator Author

Workspace PR: PyAutoLabs/autolens_workspace_developer#11

@Jammy2211
Jammy2211 merged commit 6566f84 into main Apr 16, 2026
4 checks passed
@Jammy2211
Jammy2211 deleted the feature/imaging-mge-pytree-migration branch April 16, 2026 20:55
@Jammy2211 Jammy2211 removed the pending-release PR queued for the next release build label Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant