Repository navigation
fix: one M/L-gradient convention for SersicGradient and GaussianGradient - #726
Merged
Merged
Conversation
A positive mass_to_light_gradient now means the mass-to-light ratio falls outward for both profiles, M/L proportional to (R / R_pivot) ** -gradient. - SersicGradient: pivot exactly on the effective-radius ellipse (the gradient's argument carried an extra axis-ratio factor, so the pivot sat at R_e / q) in the convergence, CSE and MGE paths; pass xp through convergence_func. - GaussianGradient: flip the exponent sign and pivot exactly at mass_to_light_radius (drop the hard-coded 0.01 arcsec softening). - cse_settings_from: branch-free on mass_to_light_gradient so a free gradient runs under jax.jit (it raised TracerBoolConversionError). - Docstrings state the convention; tests of the pivot, the sign and jit with a free gradient; q < 1 reference values regenerated from an independent Keeton integral. Closes #725 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Found by the review legs: the traced gradient reached np.exp. The remaining jit failure of convergence_2d_from (an ArrayIrregular radius into jnp.exp) is shared with plain Sersic and predates this branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 tasks 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 #725.
SersicGradientandGaussianGradientnow share one mass-to-light gradient convention: a positivemass_to_light_gradientmeans M/L falls outward, with M/L ∝ (R / R_pivot)^(−gradient).SersicGradientnow pivots exactly on the effective-radius ellipse. Before, the gradient's argument carried an extra axis-ratio factor, so M/L equalledmass_to_light_ratioat R_e/q instead. The fix covers the convergence, CSE and MGE paths.GaussianGradienthad its exponent sign flipped. It now pivots exactly atmass_to_light_radius, with no+0.01softening.cse_settings_fromis now branch-free on the gradient, so a free (traced) gradient runs underjax.jit. Before, it raisedTracerBoolConversionError.SersicGradient.convergence_2d_from/convergence_funcnow passxpthrough.lmp/lmp_linearwrappers now state the convention.Reproduced on
main(055509e) before the change, and re-run on this branch:jax.jitdeflections, traced gradientGaussianGradientwith a non-zero gradient reverses direction: the same value now gives the opposite radial trend. Flip the sign of stored or fixed gradients to keep old behaviour (the prior is symmetric, −1..1).SersicGradientwith q < 1 and a non-zero gradient changes its normalisation by a factor q^gradient. The radial shape is unchanged.SersicGradient(gradient > 0.5) now uses 50 CSEs / 80 sample points everywhere, the maximum of the old per-index values, so shapes are static under jit. Deflections agree with an independent integral to ~2e-6 in the tests.Decision taken (one, flagged)
GaussianGradient, so M/L equalsmass_to_light_ratio_baseexactly atsigma == mass_to_light_radius, as the prompt's "explicit reference radius" asks.(sigma + 0.01) / mass_to_light_radius. That bounds M/L as σ→0 for a positive gradient, but moves the pivot off the named radius.sed -i 's|(sigma / self.mass_to_light_radius)|((sigma + 0.01) / self.mass_to_light_radius)|' autogalaxy/profiles/mass/stellar/gaussian_gradient.py, then update the5.0 / 3.0test value.API Changes
No public names were added, removed or renamed (public-names CLEAN), and no signatures or defaults changed. Two numerical outputs change:
GaussianGradientwith a non-zero gradient (the sign convention), andSersicGradientwith q < 1 and a non-zero gradient (the pivot).Full API Changes (for automation & release notes)
Changed behaviour
ag.mp.GaussianGradient/ag.lmp.GaussianGradient/ag.lmp_linear.GaussianGradient:mass_to_light_ratio = base * (sigma / mass_to_light_radius) ** -mass_to_light_gradient. It was** +gradientwithsigma + 0.01.ag.mp.SersicGradient(and its Sph / lmp / Exponential variants):kappa = M/L * (R / R_e) ** -gradient * I(R). It was(q R / R_e).Migration
GaussianGradient(mass_to_light_gradient=g)→GaussianGradient(mass_to_light_gradient=-g)reproduces the old trend, apart from the 0.01 softening.Test Plan
mass_to_light_radius; jit likelihood with a traced gradient matches numpy at 0.2 and 1.0, covering both sides of the 0.5 threshold. Control: all 9 changed or new tests fail onmain.scripts/misc/mass_via_integral/sersic_gradient.pyfails on this branch until the paired workspace PR, fix: SersicGradient integral reference uses the R_e-ellipse pivot autolens_workspace_test#368, lands.Follow-ups (out of scope, not fixed here)
convergence_2d_fromis not jittable for any Sersic stellar profile, plainSersicincluded, onmaintoo: the@to_arrayArrayIrregularradius goes intojnp.exp. Deflections, the likelihood path, do jit.SersicGradient.decompose_convergence_via_mgecalls a method,_decompose_convergence_via_mge, that does not exist, so it is dead code. Its formula was corrected for consistency.Validation checklist (--auto run — plan was not pre-approved)
xpfollow-up commit from review.convergence_2d_from) → fixed in 83e3f21 → CLEAN, with claim dispositions basis-cited · adversary (Fable, a different model) CLEAN: witness survived (M/L on ellipse 1 ± 2e-16; both fall outward; jit + grad run, matching numpy/FD) · Heart scoped dev verdict GREEN (shown: manifest drift ×2, release rehearsal stale — the launch ack)Generated by the PyAutoLabs agent workflow.
🤖 Generated with Claude Code