Skip to content

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

Closed

Description

@Jammy2211

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_gradient means 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 at mass_to_light_radius (drop the hard-coded 0.01 arcsec softening).
  • Make cse_settings_from branch-free so a traced gradient runs under jax.jit, and pass xp through SersicGradient.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 (GaussianGradient with a gradient flips sign, SersicGradient with 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-taken PR 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

  1. autogalaxy/profiles/mass/stellar/sersic_gradient.py
    • convergence_func: (grid_radius / R_e) ** -gradient (was (q * grid_radius / R_e)), pass xp to image_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.
  2. autogalaxy/profiles/mass/stellar/gaussian_gradient.py: M/L = base * (sigma / mass_to_light_radius) ** -gradient; docstring rewritten to match.
  3. autogalaxy/profiles/mass/stellar/sersic.py::cse_settings_from: compute both the gradient and the standard ranges with xp.where/xp.minimum, select with xp.where(gradient > 0.5, ...); freeze total_cses/sample_points to 50/80 on both paths (static shapes under jit, the existing maximum).
  4. 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.jit of 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).
  5. 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.py
  • autogalaxy/profiles/mass/stellar/gaussian_gradient.py
  • autogalaxy/profiles/mass/stellar/sersic.py
  • test_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

  1. Jammy2211 commented on Nov 18, 2026

    @Jammy2211
    CollaboratorAuthor

    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).

  2. Jammy2211 commented on Nov 19, 2026

    @Jammy2211
    CollaboratorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions