fix: effective_einstein_radius falls back to NumPy when jax_zero_contour missing#558
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
effective_einstein_radius(default-enabled inautolens/config/latent.yaml) crashes the post-fit metric write of converged JAX searches whenjax_zero_contourisn'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 NumPyLensCalc.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_radiusnow detects whetherjax_zero_contouris importable. If yes — unchanged JIT path. If no — falls through to the existing NumPyeinstein_radius_from(grid)branch with a one-time-per-process warning. NumPy callers are unaffected. New private helper_jax_zero_contour_availableand 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 whenjax_zero_contouris mocked missing.Full API Changes (for automation & release notes)
Added
autolens.analysis.latent._jax_zero_contour_available() -> bool— private helper, returns True ifjax_zero_contouris 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, whenjax_zero_contouris missing, falls through to the existing NumPyLensCalc.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