Repository navigation
Description
Overview
FitPositionsSource defaults to the scalar "magnification" source-plane weighting, |β̂−c|² μ²/σ². Near critical curves this under-weights radial noise by about |μ|. On the point_source true model, the source χ² is 10,023, against 4.25 image-plane and 5.41 with "jacobian".
The "jacobian" weighting is the Gravity.jl source-plane likelihood (Lombardi 2024, Eq. 46). It is also the "proper" mode in Lenstool's code (forme 8). The current "magnification" normalisation is 1-D and model-dependent, so it rewards high μ, and it matches no Lenstool code path.
This issue does three things:
- makes
"jacobian"the default; - corrects the
"magnification"normalisation; - fixes the workspace Lenstool example, which is really an image-plane fit.
Plan
- Default
FitPositionsSource.weightingto"jacobian".FitPositionsSourceSolvedalready defaults to it. - Keep
"magnification"as an opt-in in both classes. Give it the model-independent 2-D normalisation log((2π)²σ⁴), i.e. Eq. 46 with B ≈ μ²Θ, and document its radial bias. - Rewrite the docstrings with citations: Gravity.jl Eqs. 46/58, Keeton 2001 Eq. 10, Jullo 2007 Eq. 10, Lenstool
forme 8. - Re-derive the pinned test values, and add a test that the true model ranks first on an anisotropic, near-critical mock.
- Workspace updates are part of this task. They follow the library PR (library first) and explain the new default:
- What
"jacobian"means: each source-plane residual is measured in the image-plane noise ellipse, so it is still a distance from the points to the source. - Why it is the default: it is Gravity.jl Eq. 46, it stays robust near critical curves, and it costs nothing extra over μ.
- When to opt into
"magnification", and its radial bias. - Where: this goes in
point_source/fit.py,point_source/modeling.py,guides/point_source_pairing.pyandcluster/likelihood_function.py. The Lenstool example is also pointed at the image-plane fit, because the Mahler input usesforme -1.
- What
- Re-measure the pinned values in autolens_workspace_test.
- Add an autolens_profiling rerun note later, once the
cluster-pointsolver-robust-settingsclaim is released. - Add a release note: results from source-plane χ² fits will change.
Tier: judge — merge mode: human /prm
Detailed implementation plan
Affected Repositories
- PyAutoLens (primary)
- autolens_workspace
- autolens_workspace_test
- autolens_profiling (rerun note only, deferred)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoLens | main | clean |
| ./autolens_workspace | main | 1 untracked/dirty file (unrelated) |
| ./autolens_workspace_test | main | — |
| ./autolens_profiling | main | claimed by cluster-pointsolver-robust-settings |
Suggested branch: feature/positions-source-jacobian-default
Implementation Steps
autolens/point/fit/positions/source/separations.py:37: setweighting = "jacobian".noise_normalization(:201-214): both weightings return Σ log((2π)² σ⁴).- Update the class docstrings.
FitPositionsSourceSolved(same file,:224-313)- Confirm the
"magnification"branch uses the same normalisation, and thatmarginalization_termuses B = Σ μ²Θ. - Update the docstrings (
autolens/point/fit/solved.py:105-110says "near-critical tangential limit").
- Confirm the
- Tests,
test_autolens/point/fit/positions/source/test_separations.py- The
:88default assertion. - Re-derive tests 1 and 2:
noise_normalizationandlog_likelihood(no mass);chi_squared_map(IsothermalSph). - Add an anisotropic near-critical mock where the true model must outrank perturbed models under
"jacobian".
- The
- Other tests:
test_fit_dataset.py:68(−12.9947298).test_solved.py:87,346.plot/test_source_plane_panel.py:19-32,215: the default now draws the A·σ ellipse, not the σ/|μ| circle.test_positions_panel.py:177,224andtest_fit_point_plots.py:88.
- autolens_workspace (in this task, after the library PR). Each script explains the default: what jacobian is, why it is the default, and when to use magnification.
scripts/point_source/fit.py:420andmarkdown/point_source/fit.md:495.scripts/point_source/modeling.py:388,426.scripts/guides/point_source_pairing.py:119,144.scripts/cluster/likelihood_function.py:10.scripts/cluster/lenstool/modeling.py:34-37andREADME.md:30(+ notebook copies): switch to the image-plane fit class, citingforme -1.
- autolens_workspace_test
- Re-measure the literals in
scripts/point_source/jax_likelihood/source_plane.py(−331481.2598 vmap, −331481.2651 eager). - Re-check the assertions in
scripts/cluster/likelihood_sanity.py. - Update the description in
scripts/AGENTS.md:173.
- Re-measure the literals in
- autolens_profiling (deferred): a note in
wiki/campaigns/point_source_source_plane.mdsaying that plain-lane timings and logL values predate the default switch.
Key Files
autolens/point/fit/positions/source/separations.py: the weighting and normalisation.autolens/point/fit/solved.py: the precision tensor helpers.autolens/point/plot/source_plane_panel.py: readsfit.weighting(circle vs ellipse).
References
- Lombardi 2024, arXiv:2406.15280, §5.1:
- Eq. 46: log P = Σ[½ log|Θᵢ/2π| − ½ δᵀBᵢδ], with Bᵢ = Aᵢ⁻ᵀΘᵢAᵢ⁻¹.
- Eqs. 54–58: the marginalised source.
- Jullo et al. 2007, arXiv:0706.0048, Eq. 10: the scalar μ² form.
- Lenstool 8.10.1
src/o_chi.cchi2_src():forme 8/13is the tensor form; the scalar modes use |μ|.- Normalisation: log(4π²/det W).
- This was read from a personal mirror, not the official repo.
- Keeton 2001, astro-ph/0102340, Eq. 10.
Original Prompt
Click to expand starting prompt
FitPositionsSource default "magnification" weighting mis-maps near-critical noise: check against Gravity.jl, consider defaulting…
Type: bug
Target: PyAutoLens
Repos:
- PyAutoLens
- autolens_profiling
- autolens_visualization
- autolens_workspace
- HowToLens
Difficulty: too-large
Autonomy: human-required
Priority: high
Memory: reading-queue.md; wiki/lensing/sources/lens-modeling-methods.md; wiki/lensing/sources/dark-matter-substructure.md
Status: formalised
Consequence: judge
Review-minutes: 25
Unattended: never
@PyAutoLens @autolens_workspace @autolens_profiling
Request (human, 2026-10-21)
intake an issue on the bug thing, have the issue check against the gravity.jl paper
Finding (2026-10-21, while prototyping the source-plane fit panel)
FitPositionsSource (autolens/point/fit/positions/source/separations.py:174-177) defaults to weighting = "magnification":
- χ²ᵢ = |β̂ᵢ − c|² · μᵢ² / σᵢ², i.e. an isotropic source-plane noise radius of σ/|μ|.
- The true source-plane footprint of image-plane noise σ is the ellipse σ·AAᵀ. For an isothermal lens its radial semi-axis stays σ, so the scalar convention under-states radial noise by ~|μ| on near-critical images.
Numbers on the autolens_visualization point_source true model (σ = 5 mas, μ = 6.7/69/47/102):
| Model | Image-pair χ² | Default source χ² (σ/|μ|) | Source χ², weighting="jacobian" |
|---|---|---|---|
| True model | 4.25 | 10,023 | 5.41 |
| R_E + 0.01″ | 53 | 167,321 | 120 |
| Lens centre x + 0.005″ | 6,243 | 20,364 | 6,012 |
On the multi-plane cluster true model, point_0's default source χ² is 81.8 (jacobian 4.46).
The jacobian weighting tracks the image-plane χ² ordering; the default does not.
Prior work (do not redo)
complete/2026/07/point-source-chi-squared-variants.mdimplemented the Lombardi 2024 (arXiv:2406.15280, Gravity.jl: Fast and accurate gravitational lens modeling in Julia, A&A 690, A346) solved likelihoods and addedweighting = "jacobian"|"magnification".- Its benchmark (profiling#99) already found the scalar-μ² source plane "catastrophically biased" (truth −33788 vs wrong models −110 on a μ=367 image), with the tensor weighting as the fix.
FitPositionsSourceSolveddefaults to "jacobian".FitPositionsSourcekept "magnification", apparently for Lenstool-style comparability.
Scope
- Check against the Gravity.jl paper (full text): its source-plane χ² definition, weighting, and normalisation / log-det terms. Confirm exactly what our "jacobian" implements (precision Wᵢ = Aᵢ⁻ᵀΘᵢAᵢ⁻¹, observed-plane normalisation) and whether "magnification" corresponds to any convention the paper endorses. Quote the equations.
- Decide the default (human decision): switch
FitPositionsSourceto "jacobian", keep "magnification" with a loud docstring/warning, or deprecate it. Weigh backwards compatibility: existing results, the Lenstool comparisons, and the workspace/HowToLens text that describes the μ² weighting. - If switching:
- library change plus tests (truth ranks first on an anisotropic mock)
- workspace and tutorial prose updates
- an autolens_profiling/inference rerun note
- a changelog/release-note line, since this changes source-χ² modelling results
- Cross-check with the new source-plane fit panel, which draws both the σ/|μ| circle and the A·σ ellipse. Prototypes are in
/mnt/c/Users/Jammy/Science/scratch/eyes/autolens/source_plane_prototype/.
Findings (2026-10-21, start_dev session: paper + Lenstool source check)
Gravity.jl (Lombardi 2024, arXiv:2406.15280, §5.1):
- Eq. 46: log P = Σ[½ log|Θᵢ/2π| − ½ (β̂ᵢ−β)ᵀ Bᵢ (β̂ᵢ−β)], with Bᵢ = Aᵢ⁻ᵀ Θᵢ Aᵢ⁻¹. The normalisation is image-plane only and model-independent.
- Eqs. 49, 54–58: precision-weighted β̄ and analytic marginalisation of the source, adding −½ log|B/2π|.
- No scalar-μ² approximation is discussed. Lenstool is mentioned only for timing and for agreement on lensing quantities.
- Our
"jacobian"equals Eq. 46 for the free centre.FitPositionsSourceSolvedequals Eq. 58.
Lenstool:
- Paper. Jullo et al. 2007 (arXiv:0706.0048), Eq. 10, writes the scalar form |β−⟨β⟩|² μ²/σ². It gives no source-plane normalisation.
- Code. Lenstool 8.10.1
src/o_chi.cchi2_src(), read from the mirror github.com/tomresseguier/lenstool-perso (not the official CRAL repo). The source-plane mode is selected byimage.forme:forme 8/13("the proper way"): (A⁻¹δ)ᵀ W (A⁻¹δ). This is the same as Gravity.jl Bᵢ and Keeton 2001 Eq. 10.- Scalar modes: weight by |μ|/σ², or by a system-averaged det A. These are not μ²/σ².
- Default
forme -1: an image-plane fit. - Every source-plane mode adds log(4π²/det W). This is model-independent only in
forme 8/13. - The centre is a plain or √μ-weighted mean, and the source is never marginalised.
- Gravity.jl vs Lenstool. The two codes do not disagree: our
"jacobian"with its normalisation equals Lenstoolforme 8for circular errors. - Our
"magnification". It matches Jullo's Eq. 10 chi² but no Lenstool code path. Its normalisation Σ log(2πσ²/μ²) is 1-D and model-dependent (it rewards high μ) and matches no Lenstool mode. - The workspace Lenstool example is mislabelled. The Mahler SMACS0723 ICLv2
input.parusesforme -1, an image-plane fit. Soautolens_workspace/scripts/cluster/lenstool/modeling.py:34-37is wrong to map it toFitPositionsSourcewith the "scalar μ² convention".
Decisions (human, 2026-10-21)
- Keep two weightings × two centres. Weighting is
"jacobian"or"magnification". Centre is free (FitPositionsSource) or solved (FitPositionsSourceSolved). There is no separate barycentre option: Solved already gives the optimal centre, and a Lenstool-only reproduction is not wanted. - Default to
"jacobian"in both classes. ForFitPositionsSourcethis is a new default;FitPositionsSourceSolvedalready uses it. - Fix
"magnification". Make it Eq. 46 with B ≈ μ²Θ, i.e. give it the model-independent 2-D normalisation log((2π)²σ⁴) in both classes. Document its radial-direction bias near critical curves. - Fix the workspace Lenstool example and its README: point them at the image-plane fit.
- Defer the autolens_profiling rerun note until the
cluster-pointsolver-robust-settingsclaim is released. - Tier judge → human /prm.
Activity
Jammy2211 commentedon Oct 21, 2026
Library PR created: #792 (
pending-release).The PR does three things:
jacobiantheFitPositionsSourcedefault;magnificationweighting the model-independent 2-D normalisation;FitPositionsSourceSolvedvalues unchanged.test_autolensgives 911 passed. Source-plane χ² and log-likelihood values fromFitPositionsSourcechange.Next: /start_workspace for autolens_workspace and autolens_workspace_test. That covers prose explaining the default, the Lenstool example fix (it uses
forme -1, so it is an image-plane fit), and re-measuring the pinned values injax_likelihood/source_plane.py. The autolens_profiling note is deferred until its claim is released.Jammy2211 commentedon Oct 21, 2026
Shipped — 2026-10-21
Merged:
pending-release):FitPositionsSourcedefaults to"jacobian"; the"magnification"weighting is an opt-in with the model-independent 2-D normalisation.guides/point_source_pairing.pyexplains the default. Thelikelihood_functionwalkthrough is rewritten to the jacobian form. The Lenstool example now usesFitPositionsImagePairRepeat, because the Mahler fit isforme -1.source_plane.pyis re-pinned from −331481.26 to −104.67. This is fully accounted for: the normalisation change gives +2.11, and the rest is χ² dropping from 662,993 to 244.Re-filed separately:
cluster/likelihood_function.pydisagrees with the library (manual 26.2 vs library −1.5e5), and inlikelihood_sanity.pypoint_0's images trace up to ~7″ from the truth.