Repository navigation
Description
Overview
InversionImagingSparse.psf_weighted_data builds the data vector D from dataset.sparse_operator.weight_map, which is data / noise**2 baked from the original image when apply_sparse_operator ran. FitImaging hands the inversion a DatasetInterface whose data is the profile-subtracted image, but that subtracted data never reaches D. So any sparse-operator imaging fit with a regular light profile plus a pixelized source inverts the unsubtracted image: D is off by about 20x and chi-squared and log_evidence are badly wrong, all silently. Fits with no regular light profile are unaffected.
Plan
- Build
psf_weighted_datafrom the inversion's own (interface)dataandnoise_mapinstead of the operator's baked weight map. This matches what the numba sparse path already does. - Leave the operator's precomputed curvature terms alone. They depend only on the noise-map, which the fit does not change.
- Add a regression test with a regular light profile plus a pixelized source, built on an operator made from the original image. Sparse and dense inversions must agree on D, chi-squared and log_evidence to 1e-10. A no-profile control must stay unchanged.
- Interferometer sparse path: checked, and it does not share this seam. The interface carries an explicit
sparse_dirty_imageanddata_term, PyAutoGalaxy and PyAutoLensfit_interferometerpass the subtracted ones, and both readers in PyAutoArray (interferometer/sparse.py,inversion_interferometer_matrix_free_util.py) prefer them over the operator's cached values. No change there. - Tier: glance (declared). Merge mode for this session: human /prm, by maintainer instruction.
Detailed implementation plan
Affected Repositories
- PyAutoArray (primary)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoArray | main | clean |
Suggested branch: feature/sparse-inversion-subtracted-data
Note: PyAutoArray is also claimed in Mind by magnification-maps-wiring (PyAutoLens#818). By maintainer override, this task runs in parallel on its own branch. The diffs don't overlap (inversion/imaging/sparse.py).
Implementation Steps
autoarray/inversion/inversion/imaging/sparse.py—psf_weighted_data: build the native weight map fromself.data / self.noise_map**2. Scatter the slim values to native viamask.derive_indexes.native_for_slim, with zeros off-mask, using numpy or JAX throughself._xp. Then pass that map toinversion_imaging_util.psf_weighted_data_from.test_autoarray/inversion/inversion/imaging/— witness test: (a) sparse operator built from the original image, then the inversion run on aDatasetInterfacewith subtracted data. D, chi-squared and log_evidence must matchInversionImagingMappingto 1e-10. (b) Control with unmodified data stays equal.- Run the PyAutoArray unit suite plus the relevant autolens_workspace_test sparse/pixelization scripts.
Key Files
autoarray/inversion/inversion/imaging/sparse.py— seamautoarray/inversion/inversion/imaging/inversion_imaging_util.py—psf_weighted_data_from,ImagingSparseOperator.from_(bakesweight_map)autoarray/inversion/inversion/imaging_numba/sparse.py— reference: already usesself.dataautoarray/inversion/inversion/interferometer/sparse.py— checked, honourssparse_dirty_image
Original Prompt
Click to expand starting prompt
Mind prompt: draft/bug/autoarray/sparse_inversion_ignores_profile_subtracted_image.md (Priority: high, Consequence: glance, Witness: a regression test with a regular light profile + pixelized source where the sparse-operator and dense inversions agree on D, chi-squared and log_evidence to 1e-10).
Symptom. InversionImagingSparse.psf_weighted_data reads dataset.sparse_operator.weight_map, which is data / noise**2 baked at apply_sparse_operator time from the ORIGINAL image. FitImaging.galaxies_to_inversion swaps data for profile_subtracted_image in the DatasetInterface but passes the operator through unchanged, so the sparse data vector D never sees the subtraction.
Measured 2026-09-11 (400-px rectangular mesh, true-Sersic regular lens light + pixelized source):
| leg | inversion class | chi2 | log_evidence |
|---|---|---|---|
sparse (apply_sparse_operator) |
InversionImagingSparse |
154083 | −38713 |
| dense | InversionImagingMapping |
16239 | +31051 |
max|D_sparse − D_dense| / max|D_dense| = 19.8. The control with no regular light profile agrees to 2.2e-16, so all-linear models — and today's production GPU runs, which fit the plain dataset — are unaffected. Any apply_sparse_operator user with a regular lens light (SLaM after light[1] with the light fixed, foreground-subtracted fits) is silently wrong.
Fix. Build psf_weighted_data from the interface's (subtracted) data — rebuild or pass the subtracted weight map into the operator rather than reading the one baked from the original image — and add the regression test named in the witness. Check whether the interferometer sparse path has the same seam.
Activity
Jammy2211 commentedon Nov 8, 2026
Library PR created: #681
InversionImagingSparse.psf_weighted_datanow uses the inversion dataset's (profile-subtracted)data/noise_mapthrough a gather-only helper. A first scatter-based version reproducibly hung therectangular_mge.pyvmap likelihood on CPU, so it was replaced (details in the PR).jax.jit), and the no-profile control is unchanged. End-to-endal.FitImaging: sparse log_evidence goes from −69075 (main) to +277.98, matching dense to 1e-13.sparse_dirty_image/data_termare already passed by Galaxy and Lens and honoured in PyAutoArray.rectangular_mge_rtu.pyhangs in its vmap on main too, so that's pre-existing.magnification-maps-wiring(PyAutoLens#818). This task runs in parallel under an explicit human override given 2026-11-08 in session https://claude.ai/code/session_016nhQ8MFwfRFgwBVbYjP9Xd. The files don't overlap./prm. The declared tier is glance, but the maintainer asked to review every PR.Generated by Claude Code
Jammy2211 commentedon Nov 9, 2026
Shipped — 2026-11-09
/prmwith CI 3/3 legs green.pending-releaselabel on the PR).Generated by Claude Code