feat: potential_correction subpackage — gravitational imaging (phase 3)#621
Merged
Conversation
Adds autolens/potential_correction/ (exported as al.pc): the dpsi mesh paired to the data grid, FitDpsiImaging (dpsi-only inversion of an image residual), FitDpsiSrcImaging (joint source+dpsi inversion with full covariance), source factories, af.Analysis classes with evidence likelihoods, anchor-point rescaling and fit visualizations. Builds on the PyAutoArray operators (phase 1, #390) and PyAutoGalaxy input mass profiles (phase 2, #505). NumPy/numba only; JAX fast paths and the iterative LM engine follow as phase 4. Ported from the potential_correction package of Cao et al. 2025 (https://github.com/caoxiaoyue/lensing_potential_correction); cite via https://github.com/caoxiaoyue/potential_correction_paper. Phase 3 of #618. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Jul 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 3 of porting the gravitational-imaging (potential correction) technique into the PyAuto stack (#618): the technique itself, as a new
autolens/potential_correction/subpackage (exported asal.pc, mirroring theautolens/weakprecedent). It provides the δψ mesh paired to the data grid, the δψ-only linear inversion of an image residual (FitDpsiImaging), the joint source+δψ inversion with full covariance (FitDpsiSrcImaging), source factories (analytic + pixelized-ITP),af.Analysisclasses for evidence-based hyper-parameter sampling, anchor-point rescaling (Suyu's scheme) and the multi-panel fit visualizations.Ported from Cao et al. 2025's
potential_correctionpackage — from the author's updated 2026 tree (modern API:Tracer(galaxies=…),apply_over_sampling,aa.Settings, currentAdaptImages), with the numpy evidence formulation of the published GitHub version (https://github.com/caoxiaoyue/lensing_potential_correction). All modules cite it and https://github.com/caoxiaoyue/potential_correction_paper. NumPy/numba only — the JAX fast paths (jax_opskernels) and the iterative LM correction engine (IterFitDpsiSrcImaging) follow as Phase 4.Builds on Phase 1 (PyAutoArray#390: mask derivative operators, coarse-mesh interpolation,
CurvatureMask/FourthOrderMaskregularizations) and Phase 2 (PyAutoGalaxy#505: input pixelized mass profiles).Notable port improvements over the original:
DpsiLinearObjadapter lets every regularization build the δψ regularization matrix through the standardregularization_matrix_from(linear_obj=…)interface (mask-based schemes read.mask, kernel schemes read.source_plane_mesh_grid) — replacing the original's isinstance dispatch and its bespokecovariance_regclasses (autoarray's existingGaussianKernel/ExponentialKernel/MaternKernelare used instead).try/except-swallowingrescaled_dpsifallback is replaced by an explicit anchor-validity check; failed joint inversions return a logged penalty likelihood rather than a printed traceback.arc_mask_fromis reimplemented onscipy.ndimage(8-connectivity), dropping the original's scikit-image dependency; no new dependencies are introduced.jnpcoercions).API Changes
Added only — nothing removed or changed. One new subpackage
autolens.potential_correction, exported asal.pc: mesh (RegularDpsiMesh,PairRegularDpsiMesh), pixelizations (DpsiPixelization,DpsiSrcPixelization,DpsiLinearObj), source factories (SrcFactory,AnalyticSrcFactory,PixSrcFactoryITP), fits (FitDpsiImaging,FitDpsiSrcImaging), analyses (DpsiInvAnalysis,DpsiSrcInvAnalysis), plusal.pc.utilandal.pc.visualize.See full details below.
Test Plan
DpsiLinearObjworking through both mask-based and kernel regularizations, mesh pairing (partition of unity, linear-function exactness, divisibility/sparsity errors), and end-to-end finite evidence for bothFitDpsiImagingand the jointFitDpsiSrcImagingon the realmasked_imaging_7x7fixture (real inversion, current API).test_autolenssuite run before commit (execution contract).Full API Changes (for automation & release notes)
Added
al.pc.RegularDpsiMesh(factor=1)— the δψ-mesh model component (coarsening factor).al.pc.PairRegularDpsiMesh(mask, pixel_scale, dpsi_factor=2)— pairs the δψ mesh to the data grid: cleaned masks, coarse binning, bilinear δψ→data interpolation matrix, sparse 1st/2nd derivative operators of both grids.al.pc.DpsiPixelization(mesh, regularization)/al.pc.DpsiSrcPixelization(dpsi_pixelization, src_pixelization)— model components sampled by the analyses.al.pc.DpsiLinearObj(mask, points)— linear-object adapter through which anyAbstractRegularizationbuilds the δψ regularization matrix.al.pc.SrcFactory/AnalyticSrcFactory(source_galaxy)/PixSrcFactoryITP(points, values)— source brightness + gradient evaluation (Delaunay-ITP variant; per-point cross sizes from Voronoi cell areas, with a scipy fallback whenaa.Mesh2DVoronoiis unavailable).al.pc.FitDpsiImaging(...)— δψ-only linear inversion of an image residual;log_evidence,solve_dpsi,rescaled_dpsi.al.pc.FitDpsiSrcImaging(...)— joint source+δψ inversion (block mapping matrix[F_src | −B·D_s·D_ψ], block-diagonal regularization);log_evidence,solve_src_dpsi,best_fit_source/best_fit_dpsi,draw_random_solutions,rescaled_dpsi.al.pc.DpsiInvAnalysis/al.pc.DpsiSrcInvAnalysis—af.Analysisclasses with evidence likelihoods (failed inversions → logged −1e8 penalty) and fit visualization.al.pc.util—gradient_points_from,source_gradient_from,source_gradient_matrix_from,dpsi_gradient_matrix_from,psf_matrix_from,inverse_covariance_matrix_from,log_det_mat,dpsi_rescale_factors_from,split_cross_from,arc_mask_from.al.pc.visualize—imshow_masked_data,show_image_irregular(_interpolate),show_fit_dpsi,show_fit_dpsi_src.docs/api/potential_correction.rst+ docs index entry.Migration
Generated by the PyAutoLabs agent workflow.