Skip to content

feat: lazily JIT-cache fit_for_visualization when flag set - #1229

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/mge-jit-visualization
Apr 19, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/mge-jit-visualization

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Replace the pass-through stub in Analysis.fit_for_visualization with a lazy jax.jit cache. With use_jax_for_visualization=True, the first call compiles self.fit_from and stores it on the instance as _jitted_fit_from; subsequent calls reuse the compiled function. Default behaviour (flag off) is unchanged — this is a controlled opt-in ahead of the remaining Fit* pytree registrations.

API Changes

Analysis.fit_for_visualization now lazily constructs and caches jax.jit(self.fit_from) on the instance when use_jax_for_visualization=True. Flag-off behaviour and all public signatures are unchanged. See full details below.

Test Plan

  • test_autofit/analysis/test_use_jax_for_visualization.py updated to exercise both the JIT path (asserts _jitted_fit_from is created on first call and reused on second) and the no-flag path
  • Full test_autofit/ suite passes (1232 tests)
  • End-to-end validated via modeling_visualization_jit.py in the linked workspace PR: 7.6× speedup compile → cached, Nautilus live-search fires the JIT path and writes subplot_fit.png
Full API Changes (for automation & release notes)

Changed Behaviour

  • Analysis.fit_for_visualization(instance) — when use_jax_for_visualization=True on the instance, lazily constructs jax.jit(self.fit_from) on the first call, caches it as self._jitted_fit_from, and returns the compiled function's output for every subsequent call. Falls back to plain self.fit_from(instance) when the flag is off.

Added (internal)

  • Analysis._jitted_fit_from — lazy-initialized attribute; None until the first fit_for_visualization call with the flag on.

Migration

No migration needed for flag-off callers (the default). Callers that set use_jax_for_visualization=True now get a JIT-compiled fit_from — their Fit* return type and all nested types must be pytree-registered or the compile will error. See admin_jammy/prompt/autolens/fit_*_pytree_*.md for the variant matrix.

🤖 Generated with Claude Code

Replace the pass-through stub in Analysis.fit_for_visualization with a
lazy jax.jit cache on the instance. With use_jax_for_visualization=True,
the first call compiles self.fit_from and stores it as _jitted_fit_from;
subsequent calls reuse it. Flag defaults to False so no existing fit is
affected until its Fit* return type has been pytree-audited.

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

Copy link
Copy Markdown
Collaborator Author

Workspace PR: PyAutoLabs/autolens_workspace_test#33

@Jammy2211
Jammy2211 merged commit 324bee5 into main Apr 19, 2026
3 checks passed
@Jammy2211
Jammy2211 deleted the feature/mge-jit-visualization branch April 19, 2026 13:39
@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