Repository navigation
feat: PointSolver residual_threshold (on by default) rejects singular-core candidates - #800
Merged
Merged
Conversation
…didates On r_core = 0 cluster members the deflection is discontinuous at the centre, so triangle containment passes with no root and the solver returns a spurious candidate (residual ~0.04", |mu| 0.1-0.3, which the magnification filter cannot remove). The new residual_threshold (default None, behaviour unchanged) masks candidates whose source-plane residual exceeds residual_threshold * pixel_scale_precision. It is a static-shape mask inside the custom-JVP primal and works eager, under jit and under vmap. Closes #799. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qy3Nc9rZwKHwQgPt8kMyeD
Human decision on #799/#800: the singular-core spurious candidate is common on cluster models, so the residual filter now defaults to 10 x pixel_scale_precision. Pass residual_threshold=None to disable. test_static_lattice_jax pins None because it counts triangle-step traces and the filter adds one trace of the padded candidates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qy3Nc9rZwKHwQgPt8kMyeD
1 task done
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
Closes #799. On cluster models whose member galaxies are
r_core = 0dPIEs,PointSolvercan return a candidate on a member's centre that is not an image. The deflection is discontinuous there, so the triangle around the centre traces onto a triangle inscribed in a circle of the member's Einstein radius. That traced triangle contains the source at every refinement step, with no root inside it.These candidates carry a lens-equation residual of about 0.04″, against a precision of 0.001″. The magnification filter cannot remove them: the host is near-critical (a saddle Jacobian) at the members, so |μ| there is 0.1–0.3.
This PR adds
residual_threshold, on by default at 10.0 (the human decided 2026-10-23 that the problem is common on cluster models). The solver drops any candidate whose source-plane residual |β(θ̂) − β| exceedsresidual_threshold × pixel_scale_precision. Passresidual_threshold=Noneto restore the old behaviour.Evidence (laptop, CPU fp64; diagnostic timings only). The candidates are those of the default solve after the magnification filter:
simple: 101 draws × 2 sources × 3 scales, plus stress draws 53/73/81 × 7 scalesRule chosen. k = 10 is 2.8× above the worst true residual and 3.85× below the smallest spurious one. The rejected alternative is a triangle-area consistency check, traced area × |μ| over image area. It separates the viz draws well, but true near-cusp candidates reach 1927 on it, so it would drop real images. The linearised |A⁻¹r| is also not used: A blows up next to a singular centre, so it would accept the core point.
Caveats:
jax.jitthe core point is removed and the output matches NumPy to 1e-10. This was checked on the four spurious cases.Cost of the default: one extra deflection of the padded candidate array (
MAX_CONTAINING_SIZErows) per solve, eager and jitted. That is small next to the triangle steps (e.g. 20 rows vs 11 859 at step 0 intest_static_lattice_jax).Default-on check: the full suite gives 952 passed, 1 xfailed. On the viz cluster draws,
simpleand the 1c/1d near-cusp fixtures, k = 10 changes outputs only by removing the 4 core points.API Changes
Adds a
residual_thresholdkeyword, default 10.0, toPointSolver/AbstractSolver, itsfor_gridandfor_limits_and_scaleconstructors, and its pytree round trip.display_solver_frompasses it on too.Behaviour change: by default, solves now drop candidates that do not satisfy the lens equation (residual > 10 ×
pixel_scale_precision). Passresidual_threshold=Noneto keep the old output.See full details below.
Test Plan
pytest test_autolens/: 952 passed, 1 xfailed (the existing ShapeSolver JAX xfail), with the default on.jax_likelihood/{image_plane,source_plane,fluxes_time_delays}.py,jax_grad/gradient.py,solver/padding_backend.py,visualization/visualization_jax.py.test_static_lattice_jaxpinsresidual_threshold=None: it counts the triangle-step traces, and the filter adds one.test_autolens/point/triangles/test_solver_spurious_core.py(11 tests). It uses a minimal fixture: a cored dPIE host plus oner_core = 0member (two planes). It checks:residual_threshold=Nonethe core point is returned, and the default (10.0) removes only that point;jitmatches NumPy, andvmapmatches scalar solves;value_and_gradof a solver-chained positions likelihood is exactly equal with the option on and off.Full API Changes (for automation & release notes)
Added
al.PointSolver(..., residual_threshold: Optional[float] = 10.0): rejects candidates with |β(θ̂) − β| >residual_threshold * pixel_scale_precision.al.PointSolver.for_grid(..., residual_threshold=10.0)andal.PointSolver.for_limits_and_scale(..., residual_threshold=10.0): forwarded to the constructor.AbstractSolver._filter_large_residual(...)(private): a static-shape NaN mask, applied inPointSolver._solve_arrayafter_filter_low_magnification, inside the custom-JVP primal only (implicit_diff.pyuntouched).display_solver_from: forwards the solver'sresidual_threshold(fallback 10.0).Migration
al.PointSolver.for_grid(grid=grid, pixel_scale_precision=0.001, residual_threshold=None).Generated by the PyAutoLabs agent workflow.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Qy3Nc9rZwKHwQgPt8kMyeD