Skip to content

register FitPointDataset pytrees for jit(fit_from) - #458

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/fit-point-pytree
Apr 19, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/fit-point-pytree

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Enable jax.jit(analysis.fit_from)(instance) for AnalysisPoint so the returned FitPointDataset has a traced jax.Array log_likelihood matching the NumPy-path scalar — completing the point-source entry in the pytree PoC series.

API Changes

Adds a private _register_fit_point_pytrees classmethod on AnalysisPoint that registers FitPointDataset, Tracer, and the three FitPositions* classes as JAX pytrees. Called once from fit_from when use_jax=True. No public surface change.
See full details below.

Test Plan

  • python -m pytest test_autolens/point/ -x -q — 44 passed
  • python -m pytest test_autolens/analysis/ test_autolens/lens/ -x -q — 113 passed
  • autolens_workspace_test/scripts/jax_likelihood_functions/point_source/point_pytree.py passes round-trip
Full API Changes (for automation & release notes)

Added

  • autolens.point.model.analysis.AnalysisPoint._register_fit_point_pytrees() — classmethod; idempotent. Registers:
    • FitPointDataset — no_flatten=("dataset", "solver", "fit_positions_cls")
    • Tracer — no_flatten=("cosmology",)
    • FitPositionsImagePairAll — no_flatten=("solver", "name", "use_jax", "_data", "_noise_map")
    • FitPositionsImagePairRepeat — same no_flatten
    • FitPositionsImagePair — same no_flatten

Changed Behaviour

  • AnalysisPoint.fit_from(instance) now calls _register_fit_point_pytrees() once when self._use_jax is True, enabling the returned FitPointDataset to be traced through jax.jit.

Notes

  • ps.Point / ps.PointFlux are not registered here — autofit.jax.pytrees.register_model(model) already handles them and would duplicate-register if called a second time.
  • _data / _noise_map ride as aux because the observed positions come from the on-disk PointDataset and are per-analysis constants.

🤖 Generated with Claude Code

Adds _register_fit_point_pytrees to AnalysisPoint so
jax.jit(analysis.fit_from)(instance) returns a FitPointDataset whose
log_likelihood is a traced jax.Array matching the NumPy scalar.

Registers:
  - FitPointDataset             no_flatten=(dataset, solver, fit_positions_cls)
  - Tracer                      no_flatten=(cosmology,)
  - FitPositionsImagePairAll    no_flatten=(solver, name, use_jax, _data, _noise_map)
  - FitPositionsImagePairRepeat same
  - FitPositionsImagePair       same

dataset/solver are per-analysis constants; observed data/noise ride as aux.
ps.Point / ps.PointFlux are handled by autofit.jax.pytrees.register_model.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Apr 19, 2026
@Jammy2211
Jammy2211 merged commit 6f720c6 into main Apr 19, 2026
5 checks passed
@Jammy2211

Copy link
Copy Markdown
Collaborator Author

Workspace PR: PyAutoLabs/autolens_workspace_test#40

@Jammy2211
Jammy2211 deleted the feature/fit-point-pytree branch April 19, 2026 21:29
@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