Repository navigation
Description
Overview
Two earlier attempts to put zero_contour-based critical curves on the default visualization path were silently broken (2026-04-19 yaml flip revert, 2026-05-16 Euclid pipeline regression). A 2026-05-21 perf benchmark identified a third, independent issue: LensCalc._critical_curve_list_via_zero_contour rebuilds its closure + ZeroSolver on every call, busting the JIT cache and making every call cost ~10 s. With the closure cached, warm calls drop to ~66 ms — fast enough to be a default for any JIT'd likelihood function.
This task lands all three coupled fixes that the future Phase A config dispatch depends on: the perf bug, the broad-except that silently swallowed both prior failures, and the first __Visualization Sanity__ regression-net block.
Plan
- Cache
(f, solver)insideLensCalckeyed on(kind, pixel_scales, tol, max_newton)so subsequent_via_zero_contour_from()calls reuse JAX's compile cache. - Tighten the broad
except Exception:inPyAutoLens/autolens/imaging/plot/fit_imaging_plots.py:52so future regressions of this class fail loudly with a logged warning, not silently. - Add the first
__Visualization Sanity__block onautolens_workspace_test/scripts/imaging/modeling_visualization_jit.py— asserts non-empty critical curves, finite/positive Einstein radius, AND warm-call latency under 100 ms (regression net for the closure-cache-busting bug). - Verify via
/smoke_testagainsteuclid_strong_lens_modeling_pipelinethat the pipeline still runs cleanly. - NO config flip — that's the next sub-prompt (revised Phase A: context-aware dispatch).
- NO
z_projects/euclidedits — live science work, separate Phase B prompt targets the pipeline workspace.
Detailed implementation plan
Affected Repositories
- PyAutoGalaxy (primary — perf fix in
LensCalc) - PyAutoLens (broad-except tighten)
- autolens_workspace_test (Visualization Sanity pilot block)
Work Classification
Library (then workspace follow-up bundled into the same PR pair)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoGalaxy | main | clean |
| ./PyAutoLens | main | clean |
| ./autolens_workspace_test | main | dirty — pre-existing drift (README + dataset/build/*), unrelated to this task |
Suggested branch: feature/fast-viz-zero-contour-perf
Worktree root: ~/Code/PyAutoLabs-wt/fast-viz-zero-contour-perf/ (created later by /start_library)
Implementation Steps
- PyAutoGalaxy
autogalaxy/operate/lens_calc.py— in_critical_curve_list_via_zero_contour(around line 1121), introduceself._zero_contour_cache: dict(lazy init) keyed on(kind, pixel_scales, tol, max_newton). On cache hit, reuse the stored(f, solver). Unit test: two calls with same params reuse same(f, solver)identity; different params produce distinct entries. - PyAutoLens
autolens/imaging/plot/fit_imaging_plots.py:52— replace bareexcept Exception:withexcept (ModuleNotFoundError, ValueError):(silent — known recoverable) +except Exception as exc: logger.warning(..., exc_info=True)(loud — anything else). Unit test re-broadens to confirm the WARNING log fires. - autolens_workspace_test
scripts/imaging/modeling_visualization_jit.py— append a__Visualization Sanity__prose block following the same style as the existing__Likelihood Sanity__at line ~170. Three assertions:len(tangential_critical_curve_list) > 0,np.isfinite(er) and er > 0, and warm-call latency< 100 mson the second call.
Key Files
PyAutoGalaxy/autogalaxy/operate/lens_calc.py:1121-1178— perf cache fixPyAutoLens/autolens/imaging/plot/fit_imaging_plots.py:19-53— broad-except tightenautolens_workspace_test/scripts/imaging/modeling_visualization_jit.py— Sanity block
Out of scope (deferred to follow-up sub-prompts)
- Config flip / context-aware dispatch (revised Phase A)
- Latent migration in
euclid_strong_lens_modeling_pipeline/util.py:491(Phase B) - IPython
update_display(fig, display_id=...)wiring (Phase C) - Rollout of
__Visualization Sanity__across other dataset types (Phase D)
Original Prompt
Click to expand starting prompt
See PyAutoPrompt/issued/fast_viz_zero_contour_perf_fix.md for the verbatim authored prompt — the implementation steps above already mirror it. Key reference points kept inline for issue-time visibility:
-
April 2026 revert (PyAutoGalaxy commit
abd7b717):ZeroSolverraised inside model-fits and the exception was swallowed by the broadexcept Exception:atfit_imaging_plots.py:52— critical curves silently vanished on HPC runs. -
May 2026 revert (PyAutoFit PR #1280): same failure shape on Euclid pipeline; source-plane FITS files wrote all-zero, Einstein-radius posteriors collapsed to the full prior, nothing raised.
-
Perf benchmark (2026-05-21) on SIE + circular source:
Method First call Warm call marching_squares32 ms 32 ms zero_contour(current code)10300 ms 10300 ms zero_contour(reusedf/ solver)10679 ms 66 ms The closure cache-busting bug means every call rebuilds JAX's compile cache. Fix: cache
(f, solver)onLensCalckeyed on(kind, pixel_scales, tol, max_newton). Warm calls drop to ~66 ms. -
Out of scope (deferred sub-prompts): config flip, Euclid latent migration, IPython display wiring, Phase D rollout. The full out-of-scope list and reference memory entries live in the authored prompt file.
Activity
Jammy2211 commentedon May 21, 2026
Smoke Test Results — 2026-05-21
All 6 smoke tests passed across 1 workspace (
euclid_strong_lens_modeling_pipeline).Scripts:
start_here.py,scripts/initial_lens_model.py,scripts/full_model.py,scripts/lens_model_waveband.py,scripts/mge_lens_only.py,scripts/sersic_lens_model.py.Run against the
feature/fast-viz-zero-contour-perfworktree (PyAutoGalaxy LensCalc cache fix + PyAutoLens broad-except tighten).PYAUTO_TEST_MODE=2withPYAUTO_DISABLE_JAX=1per the workspace'sconfig/build/env_vars.yaml.PYAUTO_SKIP_WORKSPACE_VERSION_CHECK=1set to bypass a pre-existing workspace/library version mismatch (2026.5.14.2vs2026.5.21.1) unrelated to this task.Confirms no pipeline regression from the cache fix and broad-except tightening.
Jammy2211 commentedon May 21, 2026
Library PRs Created — 2026-05-21
PRs
Status
Library work shipped; workspace work pending. Next:
/ship_workspaceto add the__Visualization Sanity__block as a workspace PR onautolens_workspace_test. The Sanity block's perf assertion (< 100 mswarm call) depends on the PyAutoGalaxy cache fix being released, so the workspace PR will hold until #434 ships in a release.API Changes
LensCalc._zero_contour_cache: dict— new private attribute, transparently caches(f, ZeroSolver)across calls. No public surface._compute_critical_curve_lines— broadexcept Exceptiontightened:ModuleNotFoundError/ValueErrorstill silent, anything else logsWARNINGwithexc_info=True. Same return tuple.Verification
pytest test_autogalaxy/: 924 passed.pytest test_autolens/: 297 passed.euclid_strong_lens_modeling_pipelinesmoke (6 scripts): all PASS (see perf: cache zero_contour solver + viz sanity net (fast_viz A') #433 (comment)).Jammy2211 commentedon May 21, 2026
Shipped — 2026-05-21
PRs
Summary
Phase A′ of
z_features/fast_visualization.mddone.LensCalc._critical_curve_list_via_zero_contournow caches(f, ZeroSolver)keyed on(kind, pixel_scales, tol, max_newton)— warm CPU calls drop from ~10300 ms to ~67 ms (tangential) and ~68 ms (Einstein radius). The broadexceptin_compute_critical_curve_linesnow logsWARNINGwithexc_info=Truefor unexpected exceptions while keepingModuleNotFoundError/ValueErrorsilent (both are pre-handled upstream). First__Visualization Sanity__block lands onmodeling_visualization_jit.pywith curve-count + Einstein-radius + warm-call < 100 ms assertions to catch any future regression of either failure mode.Session Notes
JAX_DISABLE_JIT).autolens_workspace_test/scripts/jax_likelihood_functions/point_source/point.py(likelihood returns-1e99sentinel instead of-83.38) reproduces on canonicalmainand is out of scope for this task — separate prompt to follow.z_projects/euclid(live science, off-limits) toeuclid_strong_lens_modeling_pipeline/util.py:491where theeffective_einstein_radiuslatent is currently commented out and ready to re-enable; Phase C reduces to wiringIPython.display.update_display(fig, display_id=...)sinceBackgroundQuickUpdatealready exists in PyAutoFit (commit1fee93174).point.pyfailure above). The__Visualization Sanity__block runs in the build-server'srun_all_scripts.shrather than the smoke list, so its< 100 msperf assertion will start firing against the next released library.fix(viz): make _compute_critical_curve_lines failures loud, not silent