Repository navigation
Description
Overview
The mass-to-light gradient profiles SersicGradient and GaussianGradient disagree on what the gradient means, and neither matches its docstring. SersicGradient puts its pivot (where M/L equals mass_to_light_ratio) at R_e/q instead of on the effective-radius ellipse; GaussianGradient uses the opposite sign of exponent, so the same positive gradient makes M/L rise outward rather than fall, and pivots at sigma + 0.01. A free gradient also cannot be jitted: cse_settings_from branches in Python on mass_to_light_gradient > 0.5. Found while reading the code for the stars_dm_slope science project.
Reproduced on main (055509e) before any change:
q 0.6 M/L on R_e ellipse: 3.333 (expected 2.0) # = 2.0 / q
SersicGradient M/L at r=0.5, 2.0: [2.0, 0.5] # falls outward
GaussianGradient M/L at sigma=0.5, 2.0: [0.51, 2.01] # rises outward, same gradient
jit FAILED: TracerBoolConversionError # free gradient under jax.jit
Plan
- One convention for both profiles: a positive
mass_to_light_gradientmeans M/L falls outward, M/L ∝ (R / R_pivot)^(-gradient). SersicGradient: pivot exactly on the effective-radius ellipse (drop the extra axis-ratio factor) in the convergence, the CSE decomposition and the MGE decomposition.GaussianGradient: flip the exponent sign and pivot exactly atmass_to_light_radius(drop the hard-coded 0.01 arcsec softening).- Make
cse_settings_frombranch-free so a traced gradient runs underjax.jit, and passxpthroughSersicGradient.convergence_func. - Fix the docstrings to state the convention; regenerate the test reference values that encoded the old pivot; add tests of the pivot, the sign and jit with a free gradient.
- This changes results for existing users of both profiles (
GaussianGradientwith a gradient flips sign,SersicGradientwith q < 1 shifts its normalisation): flag in release notes. - Tier: glance. effective level: supervised; merge mode: auto-merge on green if the Witness passes after a merge slot — but a
decision-takenPR ends at PR-open for /prm.
Detailed implementation plan
Affected repositories
- PyAutoGalaxy (primary)
Work classification
Library (bug)
Branch survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoGalaxy | main | clean |
Suggested branch: feature/stellar-ml-gradient-conventions
Worktree root: ~/Code/PyAutoLabs-wt/stellar-ml-gradient-conventions/
Implementation steps
autogalaxy/profiles/mass/stellar/sersic_gradient.pyconvergence_func:(grid_radius / R_e) ** -gradient(was(q * grid_radius / R_e)), passxptoimage_2d_via_radii_from.decompose_convergence_via_cse:(r / scaled_effective_radius) ** -gradient(r is the elliptical radius,scaled_effective_radius = R_e/sqrt(q), so r/scaled = R_c/R_e matches the light).decompose_convergence_via_mge:(r / R_e) ** -gradient.- Docstring: formula, sign convention, pivot on the R_e ellipse.
autogalaxy/profiles/mass/stellar/gaussian_gradient.py:M/L = base * (sigma / mass_to_light_radius) ** -gradient; docstring rewritten to match.autogalaxy/profiles/mass/stellar/sersic.py::cse_settings_from: compute both the gradient and the standard ranges withxp.where/xp.minimum, select withxp.where(gradient > 0.5, ...); freezetotal_cses/sample_pointsto 50/80 on both paths (static shapes under jit, the existing maximum).- Tests (
test_autogalaxy/profiles/mass/stellar/test_sersic_gradient.py,test_gaussian_gradient.py):- pivot: q=0.6, M/L on the R_e ellipse equals
mass_to_light_ratio; - sign: same positive gradient → both profiles' M/L falls outward;
- jit:
jax.jitof a deflection/likelihood sum with a traced gradient runs and matches numpy; - regenerate the q<1 reference values (deflections from an independent numerical integral of the corrected convergence).
- pivot: q=0.6, M/L on the R_e ellipse equals
- Check other users of the gradient (basis, chaining_util, light-and-mass wrappers, fixtures) for sign assumptions.
Key files
autogalaxy/profiles/mass/stellar/sersic_gradient.pyautogalaxy/profiles/mass/stellar/gaussian_gradient.pyautogalaxy/profiles/mass/stellar/sersic.pytest_autogalaxy/profiles/mass/stellar/test_sersic_gradient.py,test_gaussian_gradient.py
Original prompt
PyAutoMind/active/stellar_m_l_gradient_profiles_sersicgradient_piv.md (from the stars_dm_slope parameterisation review, 2026-11-16, section 3).
Activity
Jammy2211 commentedon Nov 18, 2026
Library PR Created: #726 (decision-taken: 0.01 softening dropped; see PR). Paired workspace PR: PyAutoLabs/autolens_workspace_test#368 (merge after the library PR).
Gate: PyAutoGalaxy 1554 passed · PyAutoLens 1032 passed · smoke 99/0 · review FINDINGS→fixed→CLEAN · independent adversary (Fable) CLEAN · Heart scoped GREEN. Workspace impact: option (ii), one script in autolens_workspace_test; no autolens_workspace/autogalaxy_workspace change (prose is sign-neutral, priors symmetric). Ends at PR-open for /prm (supervised + decision-taken).
Jammy2211 commentedon Nov 19, 2026
Shipped: #726 (b923217) then PyAutoLabs/autolens_workspace_test#368 (3234b21b9), merged 2026-11-19T08:19Z by human /prm, as is. SersicGradient and GaussianGradient share one M/L-gradient convention (positive = falls outward); decision taken stands (GaussianGradient 0.01 softening dropped). Release notes: GaussianGradient with a non-zero gradient reverses its trend; SersicGradient with q<1 changes normalisation by q^gradient. Pending release.