Repository navigation
Description
Overview
Add a family of standalone "multipole" light profiles (SersicMultipole, GaussianMultipole) that perturb the eccentric radius by Fourier components at orders m=3 and m=4. Originates from a Slack discussion with Aris who prototyped SersicPert; this issue lands the production version with a parameter API unified with EllipseMultipole / PowerLawMultipole. JAX support is non-negotiable from day one (xp=np threaded throughout). Future generalisation — a wrapper multipole that can perturb any radial profile, and unification with the ellipse-fitting multipole + planned galaxies= API — is out of scope here and will land in a separate z_features tracker once these baseline profiles ship and have test coverage.
Plan
- Add
SersicMultipoleandGaussianMultipoleas standalone bundled profiles (base profile + multipole perturbation in one class) — the only viable composition pattern because the multipole effect is multiplicative ongrid_radii, not additive on image. - Parameter API:
multipole_3_comps=(c, s)andmultipole_4_comps=(c, s)tuples, matching the(k_m, φ_m)convention used byEllipseMultipoleandPowerLawMultipole. Defaults(0.0, 0.0)make the class reduce numerically to its base profile. - Thread
xp=npend-to-end (perturbation, radii, image eval) so the profiles work underjax.jitandvmapfrom the first commit. Validate via vmap, not jit-on-concrete, per the PyAutoGalaxy CLAUDE.md guidance. - Expose at
ag.lp.SersicMultipole/ag.lp.GaussianMultipole. Register matching priors in bothautogalaxy_workspaceandautolens_workspace, and ship a workspace modeling example. - Document explicitly that this is the "elliptical multipole" flavour (perturbation rides on the already-elliptical
grid_radii) — same physics as Aris's prototype, distinct from the polar-frame perturbation inEllipseMultipole.
Detailed implementation plan
Affected Repositories
- PyAutoGalaxy (primary, library)
- autogalaxy_workspace (workspace follow-up: priors + example)
- autolens_workspace (workspace follow-up: priors mirror so lens galaxy modeling can use the new profiles)
Work Classification
Both — library first, workspace follows after library PR merges.
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoGalaxy | main | clean |
| ./autogalaxy_workspace | main | clean |
| ./autolens_workspace | main | clean |
Suggested branch: feature/multipole-light-profiles
Worktree root: ~/Code/PyAutoLabs-wt/multipole-light-profiles/ (created later by /start_library)
Implementation Steps
Phase 1 — Library (PyAutoGalaxy)
- New file
autogalaxy/profiles/light/standard/multipole.pycontainingSersicMultipole(AbstractSersic, LightProfile)andGaussianMultipole(Gaussian). - Constructor signature (Sersic example):
centre=(0.0, 0.0), ell_comps=(0.0, 0.0), intensity=0.1, effective_radius=0.6, sersic_index=4.0, multipole_3_comps=(0.0, 0.0), multipole_4_comps=(0.0, 0.0) - Shared helper
_perturbed_radii_from(grid, xp=np):- Call
self.eccentric_radii_grid_from(grid, xp=xp). theta = xp.arctan2(grid.array[:, 0], grid.array[:, 1]).- Apply
1 + Σ_m (c_m·cos(mθ) + s_m·sin(mθ))for m=3 and m=4. - Floor with
xp.maximum(perturbed, 1e-8)to prevent Sersic blow-up.
- Call
- Override
image_2d_from(grid, xp=np, operated_only=None, **kwargs)with the canonical decorator stack@aa.over_sample / @aa.grid_dec.to_array / @check_operated_only / @aa.grid_dec.transform; body returnsself.image_2d_via_radii_from(perturbed_radii, xp=xp), reusing the parent's analytic profile unchanged. - Expose via
autogalaxy/profiles/light/standard/__init__.pyand the top-levelautogalaxy/__init__.pysoag.lp.SersicMultipoleresolves. - No mutation of existing
Sersic/Gaussian— pure additive change. - Threading discipline (from
PyAutoGalaxy/CLAUDE.md): everyself.X(...)andconvert.X(...)call inside_perturbed_radii_fromandimage_2d_frommust passxp=xp. Don't rely on@propertyfor tracer-flowing values; convert to a method if needed.
Phase 2 — Tests (PyAutoGalaxy)
- New file
test_autogalaxy/profiles/light/standard/test_multipole.py:- Zero-perturbation parity —
SersicMultipole(..., multipole_3_comps=(0,0), multipole_4_comps=(0,0)).image_2d_from(grid)equalsSersic(...).image_2d_from(grid)to machine precision. Same for Gaussian. - m=4 fourfold symmetry — with
ell_comps=(0,0)and onlymultipole_4_comps=(c, 0), rotating the image by 90° leaves it unchanged. - m=3 threefold symmetry — analogous, 120° rotation.
- Centre translation —
centre=(y0, x0)shifts the image, verifying@transformis wired correctly. - Finite, non-negative — image is finite everywhere and non-negative where the base Sersic was non-negative.
- Zero-perturbation parity —
- Per the no-JAX-in-unit-tests memo, the unit tests stay numpy-only. JAX coverage is added in workspace_test in Phase 4.
Phase 3 — Workspace priors & example (autogalaxy_workspace, after library PR merges)
autogalaxy_workspace/config/priors/light/standard/sersic_multipole.yamlandgaussian_multipole.yaml: copy the corresponding Sersic/Gaussian prior, add Gaussian priors for the four multipole components (mean=0.0, sigma=0.05, matching the mass-multipole prior shape).autogalaxy_workspace/scripts/imaging/modeling/features/multipole_light.py: tutorial-style modeling script showing a single-galaxy fit withSersicMultipole(m=4)boxiness. Tutorial prose → Opus per the model-split rule. Also generate the notebook.- Add to
autogalaxy_workspace_test/scripts/if a regression script is appropriate for this feature.
Phase 4 — autolens_workspace mirror
- Mirror the priors yaml into
autolens_workspace/config/priors/light/standard/so lens-galaxy modeling can use the new profiles without a workspace config override. - Add a lens-modeling example to
autolens_workspace/scripts/imaging/modeling/features/multipole_light.pyif scope allows — otherwise defer to a follow-up.
Key Files
PyAutoGalaxy/autogalaxy/profiles/light/standard/multipole.py— newPyAutoGalaxy/autogalaxy/profiles/light/standard/__init__.py— exportsPyAutoGalaxy/autogalaxy/__init__.py—ag.lp.*surfacePyAutoGalaxy/test_autogalaxy/profiles/light/standard/test_multipole.py— new testsautogalaxy_workspace/config/priors/light/standard/sersic_multipole.yamlandgaussian_multipole.yaml— workspace priorsautogalaxy_workspace/scripts/imaging/modeling/features/multipole_light.py— workspace exampleautolens_workspace/config/priors/light/standard/*.yaml— lens workspace priors
Out of scope (deferred to future z_features tracker)
- Generalising multipoles into a standalone perturbation that wraps any
LightProfile(the "Gaussian + m1 + m3 + m4" anti-pattern Jam wants to avoid long-term). - Unifying with the ellipse-fitting multipole API.
- Migrating Ellipse model composition toward a
galaxies=API.
These three are motivated by the same wrapper construct and belong together in a follow-up z_features/multipole_light_unification.md tracker, opened once the standalone profiles have test coverage and a workspace example to validate against.
Original Prompt
Click to expand starting prompt
This is a conversation I had with Aris about implmeenting multipole light profiles, read it and then work it into
a plan.
Note that I would be keen for us to make its API unified with ellipse multipole light profiles,w hich are now
fully support in JAX, so that light profiles multipole for galaxies can easily be extended to have
multiple multipoles without each individual light profile being defined as a specific combination.
Think hard, do deep research and come up with a plan for z_features:
Aris [11:24 AM]
I have created a few new light profiles
Sersic + m3 + m4
Gaussian + m3 + m4
Should I open a autogalaxy issue and put them there so that if you want you can just paste them in?
I havent actually tried to implement it but I am assuming it is straightforward to make a (Gaussian + m=3,4) MGE model?
Jam [11:27 AM]
Yeah if you put an issue up I'll get Claude to do it.
[11:28 AM]Do they mirror mass profile multiples in so far that they are just the image of the mulitpole (e.g. mass is just deflections) or are they the whole image kf the swrsic and gaussian?
Aris [11:32 AM]
The amplitudes should mirror what we get from multipole mass models but the implementation logic is different.
For light profiles you perturb the grid_radii (the logic is similar to the perturbed ellipses from ellipse fitting) so the profile is evaluated at different positions.
Jam [11:34 AM]
Ah right let's just implement them as standalone light profiles for now then, and future work can generalise multiples to be an extension of light profiles so we avoid Gaussian + m1 + m3 + m4 and the like
[11:35 AM]Albeit that'll br a brief follow up claude issue provided we have a few good test cases in place
[11:36 AM]Maybe I can unify the API with ellipse fitting
Aris [11:36 AM]
class SersicPert(AbstractSersic, LightProfile):
"""
A Sersic light profile with m=3 and m=4 Fourier perturbations.
The eccentric radius is perturbed as:
r_perturbed = r * (
1
+ m3_0 * cos(3θ)
+ m3_1 * sin(3θ)
+ m4_0 * cos(4θ)
+ m4_1 * sin(4θ)
)
where:
- r is the eccentric radius
- θ is the polar angle in the profile frame
"""
def __init__(
self,
centre: Tuple[float, float] = (0.0, 0.0),
ell_comps: Tuple[float, float] = (0.0, 0.0),
intensity: float = 0.1,
effective_radius: float = 0.6,
sersic_index: float = 4.0,
m3_0: float = 0.0,
m3_1: float = 0.0,
m4_0: float = 0.0,
m4_1: float = 0.0,
):
super().__init__(
centre=centre,
ell_comps=ell_comps,
intensity=intensity,
effective_radius=effective_radius,
sersic_index=sersic_index,
)
self.m3_0 = m3_0
self.m3_1 = m3_1
self.m4_0 = m4_0
self.m4_1 = m4_1
@property
def m3_amplitude(self):
return (self.m3_0**2 + self.m3_1**2) ** 0.5
@property
def m3_phi(self):
return np.arctan2(
self.m3_1,
self.m3_0,
) / 3.0
@property
def m4_amplitude(self):
return (self.m4_0**2 + self.m4_1**2) ** 0.5
@property
def m4_phi(self):
return np.arctan2(
self.m4_1,
self.m4_0,
) / 4.0
def perturbed_radii_from(
self,
grid,
xp=np,
**kwargs,
):
"""
Returns Fourier-perturbed eccentric radii.
"""
# IMPORTANT:
# Extract raw backend array for JAX compatibility
grid_array = grid.array
y = grid_array[:, 0]
x = grid_array[:, 1]
grid_radii = self.eccentric_radii_grid_from(
grid=grid,
xp=xp,
**kwargs,
)
# grid_radii may also be an AA wrapper
if hasattr(grid_radii, "array"):
grid_radii = grid_radii.array
theta = xp.arctan2(y, x)
perturbation = (
1.0
+ self.m3_0 * xp.cos(3.0 * theta)
+ self.m3_1 * xp.sin(3.0 * theta)
+ self.m4_0 * xp.cos(4.0 * theta)
+ self.m4_1 * xp.sin(4.0 * theta)
)
perturbed_radii = grid_radii * perturbation
perturbed_radii = xp.maximum(
perturbed_radii,
1e-8,
)
return perturbed_radii
def image_2d_via_radii_from(
self,
grid_radii,
xp=np,
**kwargs,
):
"""
Returns the Sersic image evaluated at input radii.
"""
return self._intensity * xp.exp(
-self.sersic_constant
* (
(grid_radii / self.effective_radius)
** (1.0 / self.sersic_index)
- 1.0
)
)
@aa.over_sample
@aa.grid_dec.to_array
@check_operated_only
@aa.grid_dec.transform
def image_2d_from(
self,
grid: aa.type.Grid2DLike,
xp=np,
operated_only: Optional[bool] = None,
**kwargs,
) -> aa.Array2D:
"""
Returns the 2D image of the perturbed Sersic profile.
"""
perturbed_radii = self.perturbed_radii_from(
grid=grid,
xp=xp,
**kwargs,
)
return self.image_2d_via_radii_from(
grid_radii=perturbed_radii,
xp=xp,
**kwargs,
)chatgpt didnt use ell_comps for the parameters but this is a super easy fix, should I just put it like that
Jam [11:37 AM]
Does this work for elliptical multiples then?
[11:37 AM]And do we have code for elliptical multiples of ellipse fitting?
Aris [11:37 AM]
so for the light profiles, because you are perturbing the grid_radii, the perturbation follows the ellipticity of the grid (edited)
Jam [11:37 AM]
Put it up like that but leave a note on ell comps
Aris [11:37 AM]
so this is more like a elliptical multipole
[11:38 AM]so the ellipse fitting as well is more like "elliptical multipoles" (edited)
Jam [11:39 AM]
Isn't our ellipse fitting multiples code still spherical like? Anyway there is a logical way to unify these image light profiles with ellipse fitting include that.
[11:39 AM]I am JAX ING ellipse fitting this week for Sam so it's good timing all round haha
Aris [11:42 AM]
If I understand this correctly the ellipse fitting is more like elliptical mass model multipoles because the perturbation we are adding is applied directly to an already ellptical path. The Paugnet paper actually discussed this specifically referencing out m1 paper
Activity
Jammy2211 commentedon May 18, 2026
Library PR Created — 2026-05-18
PR
Status
Workspace changes needed. Next:
/start_workspaceto add priors and a modeling example inautogalaxy_workspace(and mirror the priors intoautolens_workspace).API Changes
Two new public classes added to
ag.lp, both pure additive:ag.lp.SersicMultipole— Sersic with m=3 and m=4 Fourier perturbations on the eccentric radiusag.lp.GaussianMultipole— Gaussian with m=3 and m=4 Fourier perturbations on the eccentric radiusBoth default to no perturbation (machine-precision parity with
ag.lp.Sersic/ag.lp.Gaussian), so no existing scripts break.Jammy2211 commentedon May 18, 2026
Update — 2026-05-18
Scope adjustment
Workspace priors + modeling example are deferred to a separate follow-up prompt. This issue's library work is complete once PRs #420 and PyAutoLens#515 merge.
Additional commits on PR #420
35f7b2c7—docs(api): listSersicMultipoleandGaussianMultipolein the autosummaryCompanion PR
Jammy2211 commentedon May 18, 2026
Shipped — 2026-05-18
PRs
Summary
ag.lp.SersicMultipoleandag.lp.GaussianMultipoleare now available — Sersic / Gaussian withmultipole_3_comps=(c, s)andmultipole_4_comps=(c, s)perturbations on the eccentric radius. Defaults are no-op, so they're a pure additive change to the public API. JAX-friendly (xp=npthreaded end-to-end). 12 new unit tests pass; fulltest_autogalaxy/suite green.Session Notes
EllipseMultipole/PowerLawMultipole(cos/sin tuples per order) rather than Aris's flatm3_0, m3_1, m4_0, m4_1prototype, per the Slack thread direction._LightProfileMultipoleMixinchosen over free-function or value-object composition. The leading underscore signals "throwaway scaffolding" — when thez_featuresgeneralisation lands (multipole as a wrapper around any radial profile, unified with the ellipse-fitting API), this mixin gets deleted.image_2d_via_radii_fromoverridden in both subclasses to accept a raw backend array; the perturbation step strips the autoarray wrapper, so the parent'sgrid_radii.arraycontract doesn't apply. Matches Aris's prototype.galaxies=migration) belongs in a separatez_features/multipole_light_unification.mdtracker — see PR feat(light): add SersicMultipole and GaussianMultipole profiles #420 body for scoping rationale.