Skip to content

feat: PointSolver residual_threshold (on by default) rejects singular-core candidates - #800

Merged
Jammy2211 merged 2 commits into
mainfrom
feature/point-solver-spurious-core
Oct 23, 2026
Merged

Jammy2211 merged 2 commits into
mainfrom
feature/point-solver-spurious-core

Conversation

@Jammy2211

@Jammy2211 Jammy2211 commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Closes #799. On cluster models whose member galaxies are r_core = 0 dPIEs, PointSolver can 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 |β(θ̂) − β| exceeds residual_threshold × pixel_scale_precision. Pass residual_threshold=None to restore the old behaviour.

Evidence (laptop, CPU fp64; diagnostic timings only). The candidates are those of the default solve after the magnification filter:

Dataset Worst true residual / precision Smallest spurious residual / precision Effect at k = 10
autolens_viz cluster: 17 draws × 2 sources × 7 scales (0.2–1.0″) 3.58 38.5 (4 core points: draws 9 and 16) removes 4/4; no other output changes (238 cases)
simple: 101 draws × 2 sources × 3 scales, plus stress draws 53/73/81 × 7 scales 2.21 none no change
1c/1d near-cusp fixtures (48 rows, precisions 1e-3/1e-4, 0–3 extra levels) 1.075 none all 48 rows bit-identical to the default

Rule 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:

  • Under jax.jit the core point is removed and the output matches NumPy to 1e-10. This was checked on the four spurious cases.
  • At a coarse precision (0.01) the cut becomes 0.1″, which is above these 0.04″ residuals.
  • A2744 was not tested.

Cost of the default: one extra deflection of the padded candidate array (MAX_CONTAINING_SIZE rows) per solve, eager and jitted. That is small next to the triangle steps (e.g. 20 rows vs 11 859 at step 0 in test_static_lattice_jax).

Default-on check: the full suite gives 952 passed, 1 xfailed. On the viz cluster draws, simple and the 1c/1d near-cusp fixtures, k = 10 changes outputs only by removing the 4 core points.

API Changes

Adds a residual_threshold keyword, default 10.0, to PointSolver / AbstractSolver, its for_grid and for_limits_and_scale constructors, and its pytree round trip. display_solver_from passes it on too.

Behaviour change: by default, solves now drop candidates that do not satisfy the lens equation (residual > 10 × pixel_scale_precision). Pass residual_threshold=None to 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.
  • Workspace smoke against this branch: autolens_workspace 41 scripts + 2 notebooks, autolens_workspace_test 37, euclid 9, HowToLens 50, all passed. autocti was not run: no GSL headers on the laptop, and it does not use PyAutoLens.
  • Real-solve workspace_test scripts (smoke short-circuits the solver), all passed: 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_jax pins residual_threshold=None: it counts the triangle-step traces, and the filter adds one.
  • New test_autolens/point/triangles/test_solver_spurious_core.py (11 tests). It uses a minimal fixture: a cored dPIE host plus one r_core = 0 member (two planes). It checks:
    • with residual_threshold=None the core point is returned, and the default (10.0) removes only that point;
    • a normal lens is identical with the option on and off;
    • the keyword threads through both constructors and the pytree;
    • jit matches NumPy, and vmap matches scalar solves;
    • value_and_grad of 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) and al.PointSolver.for_limits_and_scale(..., residual_threshold=10.0): forwarded to the constructor.
  • AbstractSolver._filter_large_residual(...) (private): a static-shape NaN mask, applied in PointSolver._solve_array after _filter_low_magnification, inside the custom-JVP primal only (implicit_diff.py untouched).
  • display_solver_from: forwards the solver's residual_threshold (fallback 10.0).

Migration

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Qy3Nc9rZwKHwQgPt8kMyeD

…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
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Oct 23, 2026
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
@Jammy2211 Jammy2211 changed the title feat: opt-in PointSolver residual_threshold rejects singular-core candidates feat: PointSolver residual_threshold (on by default) rejects singular-core candidates Oct 23, 2026
@Jammy2211
Jammy2211 merged commit 67e9f1f into main Oct 23, 2026
4 checks passed
@Jammy2211
Jammy2211 deleted the feature/point-solver-spurious-core branch October 23, 2026 21:23
@pyautolabs-bot pyautolabs-bot Bot removed the pending-release PR queued for the next release build label Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: PointSolver spurious candidates on r_core = 0 dPIE member cores

1 participant