Repository navigation
test: cross-validate multi-plane ray tracing against independent oracles (#714) - #715
Merged
Merged
Conversation
…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
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
Multi-plane ray tracing (
tracer_util.traced_grid_2d_list_fromand 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 addstest_autolens/lens/test_multi_plane_cross_validation.py: genuinely independent oracles that share no code withtracer_utilorLensCalc, 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
Planck15angular-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_richardsonhardcoded 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 asxfail(strict=True)referencingdraft/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)test_autolens/suite green in CIFull API Changes (for automation & release notes)
Removed
Added
test_autolens/lens/test_multi_plane_cross_validation.py)Migration
Closes #714 (phase 1).
Generated by the PyAutoLabs agent workflow.
🤖 Generated with Claude Code
https://claude.ai/code/session_01WzKP1RJKhPrtFmsHSm6EEA