fix: soft-fail jax_zero_contour callers in lens_calc to NaN/[]#465
Merged
Conversation
Replace ModuleNotFoundError re-raise in einstein_radius_jit_from and
_critical_curve_list_via_zero_contour with one-time-per-process warning
+ sentinel return (float('nan') / []). Backstop for the
default-enabled effective_einstein_radius latent in PyAutoLens, which
previously killed the post-fit metric write of converged searches on
venvs without jax_zero_contour. Mirrors the _maybe_magzero_warn pattern
from PyAutoLens #557.
Closes #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
When
jax_zero_contourisn't installed, two methods inautogalaxy/operate/lens_calc.pypreviously re-raisedModuleNotFoundError. Because PyAutoLens'seffective_einstein_radiuslatent (default-enabled) calls one of them, this crashed the post-fit metric write of any otherwise-converged JAX search on a venv without the optional dep — surfaced onautolens_profilingjob 322552. Same default-config-crashes-by-default failure shape as the magzero family that PyAutoLens #557 fixed; this is the parallel fix for the optional-dependency family.This PR adds the backstop soft-fail — return NaN / empty list with one warning per process per feature. PyAutoLens will get a caller-side fallback to the NumPy
einstein_radius_frompath in a sibling PR so users keep a real Einstein radius value; the backstop here protects any other direct caller.Closes #464
API Changes
Behaviour change (no signature change): when
jax_zero_contouris not installed,einstein_radius_jit_fromnow returnsfloat('nan')(was:ModuleNotFoundError), and the publictangential_critical_curve_list_via_zero_contour_from/radial_critical_curve_list_via_zero_contour_from(via the private_critical_curve_list_via_zero_contour) now return[](was:ModuleNotFoundError). Onelogger.warningper process per feature. New private helper_maybe_optional_dep_warnand module-level set_OPTIONAL_DEP_WARNED. No imports removed.See full details below.
Test Plan
pytest test_autogalaxy/operate/test_deflections.py— 34 pass including 3 new soft-fail tests.einstein_radius_jit_fromreturning NaN;tangential_critical_curve_list_via_zero_contour_fromreturning[].Full API Changes (for automation & release notes)
Added
autogalaxy.operate.lens_calc._maybe_optional_dep_warn(import_name, feature_name) -> bool— private helper, returns True (and warns once per process per feature) when the optional dep is missing.autogalaxy.operate.lens_calc._OPTIONAL_DEP_WARNED: set— module-level dedup set used by the helper.Changed Behaviour
LensCalc.einstein_radius_jit_from(...)— whenjax_zero_contouris missing, returnsfloat('nan')instead of raisingModuleNotFoundError. Signature unchanged.LensCalc.tangential_critical_curve_list_via_zero_contour_from(...)— whenjax_zero_contouris missing, returns[]instead of raising. Signature unchanged.LensCalc.radial_critical_curve_list_via_zero_contour_from(...)— same.LensCalc._critical_curve_list_via_zero_contour(...)— soft-fail point shared by both public sibling methods.Migration
None — callers that previously caught
ModuleNotFoundErrorfrom these methods will no longer see the exception. Callers that didn't catch it (the common case) now silently get a sentinel value and a one-time warning instead of a search-killing traceback.🤖 Generated with Claude Code