feat: warn when no light lies behind any mass (#532 phase 4) - #697
Merged
Conversation
Discharges phase 4 of the @rhayes777 API audit. He was asked on #532 whether a warning on z_lens > z_source would be noise in a real multi-plane setup and did not answer, so the question is settled by construction instead: the warning ships behind its own filterable category, so a user for whom it IS noise silences it with one filter rather than living with it. warnings.filterwarnings("ignore", category=MultiPlaneRedshiftWarning) It is a warning and NEVER an error. Multi-plane ray tracing genuinely supports geometries that look inverted under two-plane "lens and source" naming, so a flagged configuration may be exactly what the user intended. The rule is deliberately narrow: it fires only when NO lensable thing lies behind ANY mass, across more than one redshift plane — i.e. nothing in the tracer can be lensed at all. Mass at z=1.0 with light at both 0.5 and 1.5 is a real multi-plane system and stays quiet, because some of its light IS lensed. Building this surfaced three false-positive classes, all now regression-tested: - A source reconstructed by a Pixelization carries no LightProfile. Counting only light profiles fired on every pixelized-source test in the suite — core usage. - A point source carries neither light profile nor pixelization. - An entirely empty galaxy is a scaffold (a model being composed, a source not yet filled in); warning at someone mid-construction is unhelpful. Hence LENSABLE_CLS = (LightProfile, Pixelization, Point, PointSolved), plus a stand-down when a galaxy is empty. Evidence this matters: before those fixes the warning fired in ~10 existing legitimate tests; it now fires in none. The suite's warning count is back to its pre-change baseline of 18. Tracer-safe: redshifts can be free model parameters, so only concrete redshifts are compared and a traced redshift makes the check skip rather than coerce a traced boolean. Tests: 532 passed (+13 on this branch), zero regressions.
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.
Discharges phase 4, the last open item of the @rhayes777 API audit epic PyAutoArray#415. With this merged the whole campaign is done.
The question this answers
@rhayes777 was asked on #532 whether warning on
z_lens > z_sourcewould be noise in a real multi-plane setup. He did not answer in 12 days. Rather than hold indefinitely or drop it, the question is settled by construction: the warning ships behind its own filterable category, so a user for whom it is noise silences exactly it, and nothing else:It is a warning and never an error. Multi-plane ray tracing genuinely supports geometries that look inverted under two-plane "lens and source" naming, so a flagged configuration may be exactly what the user meant. The existing test asserting an inverted tracer still evaluates to a finite image is kept and extended.
The rule is deliberately narrow
It fires only when no lensable thing lies behind any mass, across more than one redshift plane — i.e. nothing in the tracer can be lensed at all. A system with mass at
z=1.0and light at both0.5and1.5is a real multi-plane configuration and stays quiet, because some of its light is lensed.Three false-positive classes found while building this
This is the part worth reviewing, because the first version was wrong and the test suite caught it:
LightProfileat allal.Galaxy(redshift=1.0)with nothing in it — a model being composedCounting only
LightProfilemade the warning fire in ~10 existing legitimate tests, including every pixelized-source case — core PyAutoLens usage, and precisely the noise the reporter asked about. HenceLENSABLE_CLS = (LightProfile, Pixelization, Point, PointSolved)plus the empty-galaxy stand-down.Evidence it is now quiet: the warning fires in zero tests outside its own regression module, and the suite's total warning count is back to its pre-change baseline of 18 (it peaked at 44 with the naive rule).
I'd also flag: my first implementation silently swallowed an
AttributeErrorfrom a wrong class reference (ag.MassProfiledoes not exist), so the warning never fired at all and every check looked like it passed. Caught by testing the reported case explicitly rather than trusting a green suite. The broadexceptis gone.API Changes
autolens.lens.tracer.MultiPlaneRedshiftWarning, aUserWarningsubclass.autolens.lens.tracer.LENSABLE_CLS.Tracer safety
Redshifts can be free model parameters (a traced subhalo redshift under
jax.jit), so only concrete redshifts are compared and a traced redshift makes the check skip rather than coerce a traced boolean — the sameis_concrete_scalargate used across the rest of the audit work. Pinned by a test using a stand-in whose__bool__raises.Test Plan
532 passed, 1 skipped(+13 on this branch). Zero regressions.Generated by Claude Code