Skip to content

test: cross-validate multi-plane ray tracing against independent oracles (#714) - #715

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/multi-plane-cross-validation
Aug 29, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/multi-plane-cross-validation

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Multi-plane ray tracing (tracer_util.traced_grid_2d_list_from and its final-plane-normalised scaling factors) was previously validated only against itself or pinned literals produced by the same code — PyAutoLens#480 survived four months in exactly this machinery. This PR adds test_autolens/lens/test_multi_plane_cross_validation.py: genuinely independent oracles that share no code with tracer_util or LensCalc, and cross-validation tests asserting the implementation agrees with the published formalism (Schneider, Ehlers & Falco 1992 §9.1 eqs 9.6/9.7b; Narayan & Bartelmann 1996 eqs 55/60; McCully et al. 2014 Jacobian recursion). Phase 1 of #714 (library); the workspace-guide extension is phase 2, filed as a follow-up prompt.

Oracles: astropy Planck15 angular-diameter distances for β_ij (our hand-rolled cosmology matches to 2.1e-7 worst case; all six Planck15 parameters identical); the SEF recursion written from the paper using each galaxy's single-plane deflections; central-difference ray-traced Jacobian with μ = 1/det J (h-stable 1e-4…1e-7); the McCully Jacobian recursion. β-dependent quantities are asserted twice — astropy β at rtol 1e-6 (whole chain incl. cosmology) and the project's own β at 1e-10 (ray-tracing algebra and plane ordering at full precision); β-free quantities hold at 1e-10.

Coverage: degenerate reductions (all mass in one plane → single-plane analytic result; β limits 1/0; a deflector at plane j leaves the mapping to j unchanged; explicit three-plane longhand), the analytic two-aligned-SIS arm (closed-form positions and double-Einstein-ring radii), and a general four-plane elliptical case for every plane j: traced positions, deflections_between_planes_from, magnification against both Jacobian oracles, convergence and shear.

Finding (recorded, not loosened): the NumPy LensCalc._hessian_via_richardson hardcoded 0.01" step reproduces the #480 control-arm defect digit for digit on the #480 fixture (rays pass ~3.5e-4" from a singular isothermal centre): μ at the last plane = −0.006945, −0.002209, 0.001391, 0.002457 vs ray-traced Jacobian 0.045084, 0.010990, −0.086019, −0.011175 (matches the JAX autodiff recorded in #480) — 102–122% off with the sign flipped on all four points, while the same route agrees to 1.3e-8 at the intermediate plane. Pinned as xfail(strict=True) referencing draft/bug/autogalaxy/lenscalc_numpy_hessian_step_is_too_coarse.md, so the fix will XPASS and force removal. No library source is modified and no tolerance was widened.

API Changes

None — test-only change. No public API added, removed or modified.
See full details below.

Test Plan

  • pytest test_autolens/lens/test_multi_plane_cross_validation.py -q → 16 passed, 1 xfailed (strict)
  • pytest test_autolens/lens test_autolens/point -q → 268 passed, 1 xfailed (baseline 252 passed; nothing pre-existing changed)
  • Full test_autolens/ suite green in CI
Full API Changes (for automation & release notes)

Removed

  • none

Added

  • none (test module only: test_autolens/lens/test_multi_plane_cross_validation.py)

Migration

  • none

Closes #714 (phase 1).

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WzKP1RJKhPrtFmsHSm6EEA

…les (#714)

Multi-plane ray tracing was validated only against itself or against literals
produced by the same code. This adds a test module whose oracles share no code
with `tracer_util`: astropy Planck15 angular diameter distances for the scaling
factors, the SEF 1992 recursion written from the paper, a central-difference
Jacobian of theta -> beta_j, and the McCully et al. 2014 Jacobian recursion.

Covers the degenerate reductions (all mass in one plane, beta=1 / beta=0, a
deflector at plane j, the longhand three-plane formula), an analytic
two-aligned-SIS arm with its double Einstein ring radii, and a general
four-plane elliptical case checked plane by plane for traced positions,
`deflections_between_planes_from`, magnification, convergence and shear.

The module docstring states the formalism from the papers and the two
convention traps: `deflections_between_planes_from` is a final-plane-scaled
difference of positions, not a deflection; and truncating a tracer to planes
<= j changes every beta (the 1.86-vs-27.9 example from #480).

The known `LensCalc._hessian_via_richardson` step-size defect reproduces
exactly on the #480 configuration and is pinned as a strict xfail rather than
absorbed by a tolerance.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzKP1RJKhPrtFmsHSm6EEA
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Aug 29, 2026
@Jammy2211
Jammy2211 merged commit 9e89bd7 into main Aug 29, 2026
3 checks passed
@Jammy2211
Jammy2211 deleted the feature/multi-plane-cross-validation branch August 29, 2026 18:08
@Jammy2211 Jammy2211 removed the pending-release PR queued for the next release build label Sep 4, 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.

test: cross-validate multi-plane ray tracing against independent oracles (phase 1)

1 participant