Skip to content

fix: effective_einstein_radius falls back to NumPy when jax_zero_contour missing - #558

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/optional-dep-latents-soft-fail
May 28, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/optional-dep-latents-soft-fail

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

effective_einstein_radius (default-enabled in autolens/config/latent.yaml) crashes the post-fit metric write of converged JAX searches when jax_zero_contour isn't installed — same surfacing context as PyAutoLabs/PyAutoGalaxy#464. The PyAutoGalaxy backstop returns NaN; this PR adds the caller-side fallback so the user keeps a real Einstein radius value: when the dep is missing on the JAX path, route to the existing NumPy LensCalc.einstein_radius_from(grid) branch with one fallback warning per process.

Related to PyAutoLabs/PyAutoGalaxy#464.

API Changes

Behaviour change (no signature change): on the JAX path (xp is not np), effective_einstein_radius now detects whether jax_zero_contour is importable. If yes — unchanged JIT path. If no — falls through to the existing NumPy einstein_radius_from(grid) branch with a one-time-per-process warning. NumPy callers are unaffected. New private helper _jax_zero_contour_available and module-level flag _JAX_ZERO_CONTOUR_FALLBACK_WARNED.

See full details below.

Test Plan

  • pytest test_autolens/analysis/test_latent.py — 24 pass including 1 new fallback test asserting the JAX path routes to the NumPy spy when jax_zero_contour is mocked missing.
Full API Changes (for automation & release notes)

Added

  • autolens.analysis.latent._jax_zero_contour_available() -> bool — private helper, returns True if jax_zero_contour is importable; False (with one warning per process) otherwise.
  • autolens.analysis.latent._JAX_ZERO_CONTOUR_FALLBACK_WARNED: bool — module-level dedup flag for the fallback warning.

Changed Behaviour

  • autolens.analysis.latent.effective_einstein_radius(fit, magzero, xp=np) — on the JAX path, when jax_zero_contour is missing, falls through to the existing NumPy LensCalc.einstein_radius_from(grid=fit.dataset.grids.lp) branch with a one-time warning instead of raising. Signature unchanged. NumPy callers unaffected.

Migration

None.

🤖 Generated with Claude Code

…our missing

Add caller-side fallback to the NumPy einstein_radius_from(grid) path
when xp is not np but jax_zero_contour isn't installed, with one
fallback warning per process. User keeps a real Einstein radius value
instead of NaN. Sibling to PyAutoGalaxy backstop in #464.
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label May 28, 2026
@Jammy2211
Jammy2211 merged commit 709f7d1 into main May 28, 2026
6 checks passed
@Jammy2211
Jammy2211 deleted the feature/optional-dep-latents-soft-fail branch May 28, 2026 14:35
@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