Overview
Follow-up to the potential-correction port (#618). Three coupled legs plus a review deliverable: (1) the autolens_workspace_test smoke entry imaging/subhalo_recovery.py runs at 232s/224s against the 300s cap and flakes into timeout on slower runners; (2) the upstream author reports that at the SAME regularization parameters the recovered mass-perturbation signal differs between their original pure-Python code and the JAX-ported al.pc, beyond numerical error; (3) the author proposes a quantitative acceptance test — sample the potential-correction regularization hyper-params by Bayesian evidence for BOTH the single-step and the iterative method and require the input subhalo be recovered at the evidence-preferred params; (4) a judgment-tier algorithm double-check + code improvement report for the author.
The port history is suggestive of (2): the ported iterative engine cold-started to corr 0.032 and needed an x0 warm start from the one-shot solution (#630), and the port's Phase 5 concluded the author's stored demo iterative hyper-params were "miscalibrated" — if the original code recovers the signal at those same params, that is a real divergence in the iterative path, not miscalibration.
Plan
- Phase 1 — smoke timeout fix (autolens_workspace_test, standalone PR): profile where
imaging/subhalo_recovery.py's 232s goes, cut the dominant cost (dataset size / n_iter / source-pixel count) with re-calibrated assertion thresholds, target ~150s. Never weaken assertions to vacuity.
- Phase 2 — discrepancy reproduction + root cause: run the author's original code (
for_qiuhan_PT_jax tar, re-provided 2026-07-30) and al.pc side-by-side on the 200x200 demo at identical reg params; diff staged intermediates (mesh operators → reg matrix → curvature → solution → evidence → iterative trajectory) until the first divergence. Deliverable: parity certificate or localized bug + fix PR in PyAutoLens.
- Phase 3 — evidence-sampled end-to-end validation: sample
MaternKernel(coefficient, scale) via a PyAutoFit search over DpsiSrcInvAnalysis (one-shot evidence) and IterDpsiSrcInvAnalysis (converged Laplace evidence); assert subhalo recovery (corr, peak distance) at the evidence-preferred params. Wire the fixed-curvature fast evidence path into the analysis for tractable sampling; add the missing analysis.py unit tests.
- Phase 4 — algorithm review + code improvement report: full review of the single-step formulation (Cao et al. 2025) and the iterative method against the implementation; markdown report the author can review and selectively adopt.
Detailed implementation plan
Affected Repositories
- PyAutoLens (primary — potential bug fix, analysis fast-path glue, unit tests)
- autolens_workspace_test (smoke fix + evidence-sampling validation scripts)
Branch Survey
| Repository |
Current Branch |
Dirty? |
| ./PyAutoLens |
main |
clean |
| ./autolens_workspace_test |
main |
clean (⚠ feature/point-source-chi-squared-variants checked out in another task's worktree; files disjoint, pre-merge origin/main before PR) |
Suggested branch: feature/potential-correction-validation
Implementation Steps
- Phase 1: profile
autolens_workspace_test/scripts/imaging/subhalo_recovery.py (one-shot FitDpsiSrcImaging vs 5-iteration IterFitDpsiSrcImaging.solve_joint_optimization); reduce the dominant cost; re-calibrate corr/peak-dist thresholds at the reduced resolution; prove by smoke count 21/21 + local timing well under 300s.
- Phase 2: reference tree extracted from
for_qiuhan_PT_jax.tar (1).gz; stage-by-stage diff at identical MaternKernel params: PairRegularDpsiMesh operators (Hx/Hy, Hamiltonian), regularization_matrix_from, curvature, one-shot solution + log_evidence (fit.py:543), LM per-iteration state (damping mu*diag(H) at dense_util.py:390, gauge KKT at dense_util.py:396-407, cost dense_util.py:315, Laplace evidence dense_util.py:410 / iterative.py:553). Suspects: warm-start requirement, gauge projection, src-gradient evaluation position, logdet jitter (upstream commit 220c815).
- Phase 3: new validation script(s) in autolens_workspace_test composing
af.Model(al.pc.DpsiSrcPixelization) with free MaternKernel(coefficient, scale) (nu fixed) over the existing analyses (analysis.py:157, iterative.py:704); wire dense_util.log_evidence_from_fixed_curvature (dense_util.py:172) into DpsiSrcInvAnalysis; resolve the inconsistent instance contract between DpsiInvAnalysis (bare DpsiPixelization) and the joint analyses (DpsiSrcPixelization); add test_autolens/potential_correction/test_analysis.py. Full-size runs recorded as issue evidence; smoke-wire a reduced variant only if comfortably under the cap.
- Phase 4: review report covering evidence formulas (fit.py:194/543, dense_util.py:105/172/266/410), LM engine (iterative.py:383-545), gauge handling, SrcFactory gradient scheme — findings ranked, author-facing.
Key Files
autolens/potential_correction/{fit.py,iterative.py,dense_util.py,analysis.py,pixelization.py,mesh.py,src_factory.py} — the al.pc port under test
autolens_workspace_test/scripts/imaging/subhalo_recovery.py — flaky smoke entry (Phase 1)
autolens_workspace_test/scripts/{imaging,interferometer}/jax_likelihood/potential_correction.py — existing numeric-parity smokes (already green; Phase 2 extends beyond them to end-to-end trajectory parity)
Original Prompt
PyAutoMind: draft/bug/autolens/potential_correction_end_to_end_validation.md (includes the author's request verbatim; absorbs draft/bug/autolens/subhalo_recovery_iterative_dkappa_collapsed.md, whose specific collapse was fixed by #630).
Generated by the PyAutoLabs agent workflow.
Overview
Follow-up to the potential-correction port (#618). Three coupled legs plus a review deliverable: (1) the
autolens_workspace_testsmoke entryimaging/subhalo_recovery.pyruns at 232s/224s against the 300s cap and flakes into timeout on slower runners; (2) the upstream author reports that at the SAME regularization parameters the recovered mass-perturbation signal differs between their original pure-Python code and the JAX-portedal.pc, beyond numerical error; (3) the author proposes a quantitative acceptance test — sample the potential-correction regularization hyper-params by Bayesian evidence for BOTH the single-step and the iterative method and require the input subhalo be recovered at the evidence-preferred params; (4) a judgment-tier algorithm double-check + code improvement report for the author.The port history is suggestive of (2): the ported iterative engine cold-started to corr 0.032 and needed an x0 warm start from the one-shot solution (#630), and the port's Phase 5 concluded the author's stored demo iterative hyper-params were "miscalibrated" — if the original code recovers the signal at those same params, that is a real divergence in the iterative path, not miscalibration.
Plan
imaging/subhalo_recovery.py's 232s goes, cut the dominant cost (dataset size / n_iter / source-pixel count) with re-calibrated assertion thresholds, target ~150s. Never weaken assertions to vacuity.for_qiuhan_PT_jaxtar, re-provided 2026-07-30) andal.pcside-by-side on the 200x200 demo at identical reg params; diff staged intermediates (mesh operators → reg matrix → curvature → solution → evidence → iterative trajectory) until the first divergence. Deliverable: parity certificate or localized bug + fix PR in PyAutoLens.MaternKernel(coefficient, scale)via a PyAutoFit search overDpsiSrcInvAnalysis(one-shot evidence) andIterDpsiSrcInvAnalysis(converged Laplace evidence); assert subhalo recovery (corr, peak distance) at the evidence-preferred params. Wire the fixed-curvature fast evidence path into the analysis for tractable sampling; add the missinganalysis.pyunit tests.Detailed implementation plan
Affected Repositories
Branch Survey
Suggested branch:
feature/potential-correction-validationImplementation Steps
autolens_workspace_test/scripts/imaging/subhalo_recovery.py(one-shotFitDpsiSrcImagingvs 5-iterationIterFitDpsiSrcImaging.solve_joint_optimization); reduce the dominant cost; re-calibrate corr/peak-dist thresholds at the reduced resolution; prove by smoke count 21/21 + local timing well under 300s.for_qiuhan_PT_jax.tar (1).gz; stage-by-stage diff at identicalMaternKernelparams:PairRegularDpsiMeshoperators (Hx/Hy, Hamiltonian),regularization_matrix_from, curvature, one-shot solution +log_evidence(fit.py:543), LM per-iteration state (damping mu*diag(H) at dense_util.py:390, gauge KKT at dense_util.py:396-407, cost dense_util.py:315, Laplace evidence dense_util.py:410 / iterative.py:553). Suspects: warm-start requirement, gauge projection, src-gradient evaluation position, logdet jitter (upstream commit 220c815).af.Model(al.pc.DpsiSrcPixelization)with freeMaternKernel(coefficient, scale)(nu fixed) over the existing analyses (analysis.py:157, iterative.py:704); wiredense_util.log_evidence_from_fixed_curvature(dense_util.py:172) intoDpsiSrcInvAnalysis; resolve the inconsistent instance contract betweenDpsiInvAnalysis(bareDpsiPixelization) and the joint analyses (DpsiSrcPixelization); addtest_autolens/potential_correction/test_analysis.py. Full-size runs recorded as issue evidence; smoke-wire a reduced variant only if comfortably under the cap.Key Files
autolens/potential_correction/{fit.py,iterative.py,dense_util.py,analysis.py,pixelization.py,mesh.py,src_factory.py}— theal.pcport under testautolens_workspace_test/scripts/imaging/subhalo_recovery.py— flaky smoke entry (Phase 1)autolens_workspace_test/scripts/{imaging,interferometer}/jax_likelihood/potential_correction.py— existing numeric-parity smokes (already green; Phase 2 extends beyond them to end-to-end trajectory parity)Original Prompt
PyAutoMind:
draft/bug/autolens/potential_correction_end_to_end_validation.md(includes the author's request verbatim; absorbsdraft/bug/autolens/subhalo_recovery_iterative_dkappa_collapsed.md, whose specific collapse was fixed by #630).Generated by the PyAutoLabs agent workflow.