Repository navigation
Description
Overview
Add a stage-by-stage jax.value_and_grad probe for the MGE interferometer likelihood pipeline, mirroring the shipped imaging/mge_gradients.py which already reports 9/9 PASS on main. The interferometer path uses NUFFT/DFT transformers, complex intermediates, and visibilities-space NNLS — any silent gradient regression there would go undiagnosed today. A per-stage probe isolates the break point immediately.
This is Phase 1 of 2. Phase 2 (pixelization gradient probe) will follow as a separate issue / PR once this ships.
Plan
- Create
jax_profiling/interferometer/mge_gradients.pymodelled on the imaging MGE gradients script's structure and PASS/FAIL/ERROR output. - Probe ten stages: ray-trace → transformer-blurred lens light → profile-subtracted visibilities → transformed mapping matrix → data vector D → curvature F → regularization H → NNLS reconstruction → mapped reconstructed visibilities → full
jax.value_and_grad(AnalysisInterferometer.log_likelihood). - Include
_diagnose_kappa-style sweep whereverjaxnnls.solve_nnls_primalis invoked directly, so any NNLS NaN regression reports the safetarget_kappavalue for interferometer curvature matrices. - Reuse the dataset-auto-simulate +
Fitnessconstruction pattern proven byinterferometer/mge.py. - Follow PR fix: interferometer profiling scripts resolve dataset paths from workspace root #18's path convention (
Path("jax_profiling") / "interferometer" / "dataset" / ...); scripts run from workspace root. - Target 10/10 PASS on
main.
Detailed implementation plan
Affected Repositories
- autolens_workspace_developer (primary)
Work Classification
Workspace
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| autolens_workspace_developer | main | untracked local re-run artifacts only, no blocker |
Suggested branch: feature/interferometer-mge-gradients
Worktree root: ~/Code/PyAutoLabs-wt/interferometer-mge-gradients/ (created later by /start_workspace)
Implementation Steps
- Create
jax_profiling/interferometer/mge_gradients.py, modelled onjax_profiling/imaging/mge_gradients.py(787 lines). - Adapt blurring stage to use
al.TransformerDFTinstead ofConvolver; D/F become visibilities-space. Stage 4 (transformed mapping matrix) and stage 5 (D) are the interferometer-specific checkpoints; the rest of the pipeline is shared with imaging. _diagnose_kappasweep around any directjaxnnls.solve_nnls_primalcall (imaging empirically needs ≥1e-2; interferometer may need a different value — the probe reports it).- Follow dataset-path convention from PR fix: interferometer profiling scripts resolve dataset paths from workspace root #18:
dataset_path = Path(\"jax_profiling\") / \"interferometer\" / \"dataset\" / \"interferometer\" / instrument. - Run the probe; confirm 10/10 PASS before shipping. If a stage fails, file a separate issue rather than hack around it (per prompt guidance).
Key Files
jax_profiling/interferometer/mge_gradients.py— new
Prerequisites (already on main)
- PyAutoFit#1222 — TuplePrior pytree registration
- PyAutoArray#279 — Jacobi preconditioning of NNLS curvature matrix
- PyAutoArray#282 —
nnls_target_kappa=1.0e-2config default
Original Prompt
Click to expand starting prompt
JAX Gradient Testing: Interferometer
Context
autolens_workspace_developer/jax_profiling/imaging/mge_gradients.py
and pixelization_gradients.py are step-by-step
jax.value_and_grad probes that walk the imaging likelihood
pipeline (ray-trace → blurred image → profile-subtract → mapping
matrix → D → F → H → NNLS → mapped reconstruction → full
Fitness.call) and report PASS / FAIL / ERROR at each stage with
a gradient-norm diagnostic.
These scripts have been the primary tool for isolating JAX
gradient bugs — they caught the NNLS NaN that PR #279 fixed, the
rectangular-interpolator gradient explosion that PR #281 fixed,
and the NNLS target_kappa NaN that PR #282 fixed.
There is no equivalent probe for the interferometer pipeline.
The interferometer likelihood uses a different kernel path
(transformer_nufft / sparse Fourier operator, visibilities-space
NNLS) whose gradient health is not yet characterised, and any future
NaN regression there would go undiagnosed.
Pytree infrastructure (already shipped — assume present)
These probes exercise the full pytree approach:
jax.value_and_grad(AnalysisInterferometer.log_likelihood) with all
priors flowing as pytree leaves. Three library-level pieces that make
this work have already landed on main:
- PyAutoFit#1222 —
TuplePriorregistered as a JAX pytree. On a
typical Isothermal+Shear+MGE model this lifts live JAX-leaf count
from 3 to 167, so the probe actually differentiates through the
whole model instead of a handful of free floats. - PyAutoArray#279 — Jacobi preconditioning of the NNLS curvature
matrix. - PyAutoArray#282 —
nnls_target_kappa=1.0e-2config default
(jaxnnls's own1e-3default produces NaN in the relaxed-KKT
backward pass on real MGE pipelines even with Jacobi
preconditioning).
For reference, the imaging mge_gradients.py and
pixelization_gradients.py now report 9/9 PASS on main with this
stack. The interferometer probes should aim for the same outcome.
Task
Create
autolens_workspace_developer/jax_profiling/interferometer/pixelization_gradients.py
and mge_gradients.py, modelled directly on their imaging
counterparts.
Minimum stages to probe:
- Ray-trace interferometer grid (pixelization grid).
- Blurred (`transformer`-applied) lens-light image.
- Profile-subtracted visibilities.
- Transformed mapping matrix (mapper → FFT/NUFFT).
- Data vector D in visibilities space.
- Curvature matrix F.
- Regularization matrix H.
- NNLS reconstruction.
- Mapped reconstructed visibilities.
- Full pipeline via `Fitness.call` and
`jax.value_and_grad(AnalysisInterferometer.log_likelihood)`.
Each stage wraps a closure in `jax.value_and_grad`, prints gradient
norm / finite-fraction / non-zero count, and classifies the stage
as PASS / FAIL / ERROR. Final summary table identical to the
imaging version. Target outcome: 9/9 or 10/10 PASS.
Include an `_diagnose_kappa`-style loop at any stage that exercises
`jaxnnls.solve_nnls_primal` directly, so that if the NNLS NaN
regresses the probe can tell us which `target_kappa` value is safe
for the interferometer curvature matrix (imaging empirically needs
≥1e-2; interferometer may need a different value).
Why this matters
The interferometer path has more moving parts that can silently
kill gradients (NUFFT gridding tables, complex-valued intermediate
arrays, sparse visibility operators). Without a probe we will only
learn about regressions when a downstream fit produces all-zero or
NaN gradients and fails mysteriously. A stage-by-stage probe
isolates the break point immediately.
Dependencies
- `interferometer_jax_profiling.md` covers the forward-only
profiling scripts. This gradients probe assumes those exist (so
the dataset auto-simulate + `Fitness` construction pattern is
already proven). - If the interferometer profiling scripts are not yet in place,
this task is blocked on that one.
Activity
Jammy2211 commentedon Apr 18, 2026
Shipped: PyAutoArray #283 + #284 (kappa=1.0e-11), workspace_developer #20 (interferometer MGE gradient profiling + regression assertions), workspace_test #28 (likelihood baselines updated). Workspace_test CI was reproducibly failing despite the library fix being on main; merged via admin with a deferral note — will be resurfaced by the upcoming test overhaul / next release if still present.