Skip to content

fix: one M/L-gradient convention for SersicGradient and GaussianGradient - #726

Merged
Jammy2211 merged 2 commits into
mainfrom
feature/stellar-ml-gradient-conventions
Nov 19, 2026
Merged

Jammy2211 merged 2 commits into
mainfrom
feature/stellar-ml-gradient-conventions

Conversation

@Jammy2211

@Jammy2211 Jammy2211 commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Closes #725. SersicGradient and GaussianGradient now share one mass-to-light gradient convention: a positive mass_to_light_gradient means M/L falls outward, with M/L ∝ (R / R_pivot)^(−gradient).

  • SersicGradient now pivots exactly on the effective-radius ellipse. Before, the gradient's argument carried an extra axis-ratio factor, so M/L equalled mass_to_light_ratio at R_e/q instead. The fix covers the convergence, CSE and MGE paths.
  • GaussianGradient had its exponent sign flipped. It now pivots exactly at mass_to_light_radius, with no +0.01 softening.
  • cse_settings_from is now branch-free on the gradient, so a free (traced) gradient runs under jax.jit. Before, it raised TracerBoolConversionError.
  • SersicGradient.convergence_2d_from/convergence_func now pass xp through.
  • Docstrings on the mass profiles and the lmp / lmp_linear wrappers now state the convention.

Reproduced on main (055509e) before the change, and re-run on this branch:

check main branch
q=0.6, M/L on R_e ellipse (input 2.0) 3.333 (= 2/q) 2.0
SersicGradient M/L at r = 0.5, 2.0 (gradient +1) 2.0, 0.5 2.0, 0.5
GaussianGradient M/L at σ = 0.5, 2.0 (gradient +1) 0.51, 2.01 2.0, 0.5
jax.jit deflections, traced gradient TracerBoolConversionError runs

⚠️ Behaviour change for existing users (release notes)

  • GaussianGradient with 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).
  • SersicGradient with q < 1 and a non-zero gradient changes its normalisation by a factor q^gradient. The radial shape is unchanged.
  • Steep-gradient 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)

  • Decision: I dropped the hard-coded 0.01 arcsec softening in GaussianGradient, so M/L equals mass_to_light_ratio_base exactly at sigma == mass_to_light_radius, as the prompt's "explicit reference radius" asks.
  • Rejected alternative: keep (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.
  • Consequence: with a positive gradient, M/L diverges as σ→0. The Gaussian light is already singular there.
  • Revert: 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 the 5.0 / 3.0 test value.

API Changes

No public names were added, removed or renamed (public-names CLEAN), and no signatures or defaults changed. Two numerical outputs change: GaussianGradient with a non-zero gradient (the sign convention), and SersicGradient with 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 ** +gradient with sigma + 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

  • Full PyAutoGalaxy suite: 1554 passed.
  • PyAutoLens suite on the branch: 1032 passed, 1 xfailed.
  • New and updated tests: pivot on the R_e ellipse at q=0.6 for gradients −1, 0.5 and 1.5; both profiles fall outward with the same power law; Gaussian pivot at 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 on main.
  • The q<1 CSE reference values come from an independent Keeton integral. Control: the same integral reproduces the old reference values to 1e-6 when given the old formula.
  • Smoke (autogalaxy, autolens, autolens_test): autogalaxy + autolens + autolens_test 99 passed, 0 failed
  • autolens_workspace_test scripts/misc/mass_via_integral/sersic_gradient.py fails 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_from is not jittable for any Sersic stellar profile, plain Sersic included, on main too: the @to_array ArrayIrregular radius goes into jnp.exp. Deflections, the likelihood path, do jit.
  • SersicGradient.decompose_convergence_via_mge calls a method, _decompose_convergence_via_mge, that does not exist, so it is dead code. Its formula was corrected for consistency.
  • The CSE settings switch at gradient = 0.5, so the likelihood has a small step there (adversary: χ² jumps ~470 between 0.5 and 0.5001). This predates the branch.
  • Negative gradient at high Sersic index (Γ=−0.6, n=4.5) has ~2–3% CSE deflection error against the integral. The standard-path settings are unchanged, so this probably predates the branch.

Validation checklist (--auto run — plan was not pre-approved)

  • Effective level: supervised (header: supervised, cap: bug → supervised); shift 2026-11-18-pm2
  • Plan: on the issue (fix: one M/L-gradient convention for SersicGradient and GaussianGradient #725), written at start. Since then I added the paired workspace PR and the xp follow-up commit from review.
  • Gate: tests 1554 PyAutoGalaxy + 1032 PyAutoLens · smoke autogalaxy + autolens + autolens_test 99 passed, 0 failed · review FINDINGS (xp not passed in 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)
  • Human: plan sound in hindsight?
  • Human: diff matches plan (no scope creep)?
  • Human: merge, amend, or reject — then log the outcome

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

Jammy2211 and others added 2 commits November 18, 2026 20:08
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>
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Nov 18, 2026
@Jammy2211 Jammy2211 added the decision-taken Autonomous run took a flagged decision label Nov 18, 2026
@Jammy2211
Jammy2211 merged commit b923217 into main Nov 19, 2026
5 checks passed
@Jammy2211
Jammy2211 deleted the feature/stellar-ml-gradient-conventions branch November 19, 2026 08:19
@pyautolabs-bot pyautolabs-bot Bot removed the pending-release PR queued for the next release build label Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

decision-taken Autonomous run took a flagged decision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: one M/L-gradient convention for SersicGradient and GaussianGradient

1 participant