Skip to content

fix: soft-fail jax_zero_contour callers in lens_calc to NaN/[]#465

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

fix: soft-fail jax_zero_contour callers in lens_calc to NaN/[]#465
Jammy2211 merged 1 commit into
mainfrom
feature/optional-dep-latents-soft-fail

Conversation

@Jammy2211
Copy link
Copy Markdown
Collaborator

Summary

When jax_zero_contour isn't installed, two methods in autogalaxy/operate/lens_calc.py previously re-raised ModuleNotFoundError. Because PyAutoLens's effective_einstein_radius latent (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 on autolens_profiling job 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_from path 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_contour is not installed, einstein_radius_jit_from now returns float('nan') (was: ModuleNotFoundError), and the public tangential_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). One logger.warning per process per feature. New private helper _maybe_optional_dep_warn and 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.
  • Soft-fail tests cover: helper one-warning-per-process semantics; einstein_radius_jit_from returning NaN; tangential_critical_curve_list_via_zero_contour_from returning [].
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(...) — when jax_zero_contour is missing, returns float('nan') instead of raising ModuleNotFoundError. Signature unchanged.
  • LensCalc.tangential_critical_curve_list_via_zero_contour_from(...) — when jax_zero_contour is missing, returns [] instead of raising. Signature unchanged.
  • LensCalc.radial_critical_curve_list_via_zero_contour_from(...) — same.
  • Private LensCalc._critical_curve_list_via_zero_contour(...) — soft-fail point shared by both public sibling methods.

Migration

None — callers that previously caught ModuleNotFoundError from 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

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
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label May 28, 2026
@Jammy2211 Jammy2211 merged commit f08f6b2 into main May 28, 2026
6 checks passed
@Jammy2211 Jammy2211 deleted the feature/optional-dep-latents-soft-fail branch May 28, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pending-release PR queued for the next release build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: optional-dep latents fall back to NumPy, soft-fail to NaN

1 participant