refactor(light): split multipole module + add ag.lp_linear variants#421
Merged
Conversation
Refactors the multipole light profile module added in #420: - autogalaxy/profiles/light/standard/multipole.py is split into per-class modules: - _multipole_mixin.py — private, holds the shared _LightProfileMultipoleMixin - sersic_multipole.py — SersicMultipole - gaussian_multipole.py — GaussianMultipole - test_autogalaxy/profiles/light/standard/test_multipole.py is split into test_sersic_multipole.py + test_gaussian_multipole.py - standard/__init__.py updated to the two new imports Adds linear-light-profile counterparts: - autogalaxy/profiles/light/linear/sersic_multipole.py ag.lp_linear.SersicMultipole(lp.SersicMultipole, LightProfileLinear) hardcodes intensity=1.0 (solved via inversion) and drops intensity from the constructor signature. - autogalaxy/profiles/light/linear/gaussian_multipole.py — same pattern. - linear/__init__.py exports both. - test_autogalaxy/profiles/light/linear/test_sersic_multipole.py and test_gaussian_multipole.py cover: class identity (LightProfileLinear + the standard subclass), intensity-not-a-constructor-parameter, multipole_*_comps propagation, parity with the linear base profile at zero perturbation, and image parity with the standard variant at intensity=1.0. Docs: - docs/api/light.rst Linear [ag.lp_linear] section now lists SersicMultipole and GaussianMultipole. 895 unit tests pass. Follows up #418. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Follow-up to #420.
autogalaxy/profiles/light/standard/multipole.pyinto per-class modules (sersic_multipole.py,gaussian_multipole.py) with a shared private mixin in_multipole_mixin.py. Tests split correspondingly. Pure mechanical refactor — no behaviour change.ag.lp_linear.SersicMultipoleandag.lp_linear.GaussianMultipole— the linear-inversion counterparts of the standard variants. Each subclasses its standard counterpart +LightProfileLinear, hardcodingintensity=1.0(the inversion solves it). Docs autosummary updated under the Linear [ag.lp_linear] section.895 unit tests pass (10 new tests cover the linear variants and the split standard tests; previously 885 in main).
API Changes
Two new public classes added to
ag.lp_linear:ag.lp_linear.SersicMultipole— linear elliptical Sersic with m=3/m=4 multipole perturbationsag.lp_linear.GaussianMultipole— linear elliptical Gaussian with m=3/m=4 multipole perturbationsStandard classes (
ag.lp.SersicMultipole/ag.lp.GaussianMultipole) move frommultipole.pytosersic_multipole.py/gaussian_multipole.py— import paths viaag.lp.*are unchanged.See full details below.
Test Plan
python -m pytest test_autogalaxy/profiles/light/standard/test_sersic_multipole.py test_autogalaxy/profiles/light/standard/test_gaussian_multipole.py— 12 tests pass (split intact from feat(light): add SersicMultipole and GaussianMultipole profiles #420)python -m pytest test_autogalaxy/profiles/light/linear/test_sersic_multipole.py test_autogalaxy/profiles/light/linear/test_gaussian_multipole.py— 10 new tests passpython -m pytest test_autogalaxy/— 895 pass, no regressionsag.lp_linear.SersicMultipoleandag.lp_linear.GaussianMultipoleresolve via the standardag.lp_linear.*namespaceintensityis 1.0, constructor rejectsintensity=kwarg, multipole tuples propagate through to the image computationFull API Changes (for automation & release notes)
Added
ag.lp_linear.SersicMultipole(centre, ell_comps, effective_radius, sersic_index, multipole_3_comps=(0.0, 0.0), multipole_4_comps=(0.0, 0.0))— linear-inversion counterpart ofag.lp.SersicMultipole. Inherits from bothag.lp.SersicMultipoleandLightProfileLinear, soisinstance(profile, ag.lp.SersicMultipole)andisinstance(profile, LightProfileLinear)are both true.ag.lp_linear.GaussianMultipole(centre, ell_comps, sigma, multipole_3_comps=(0.0, 0.0), multipole_4_comps=(0.0, 0.0))— same for Gaussian.autogalaxy.profiles.light.standard._multipole_mixin._LightProfileMultipoleMixin— internal mixin module extracted from the old multipole.py. Leading underscore signals throwaway scaffolding.Removed
autogalaxy.profiles.light.standard.multipolemodule — split intosersic_multipole+gaussian_multipole+_multipole_mixin. The publicag.lp.SersicMultipoleandag.lp.GaussianMultipoleimport paths are unchanged.Renamed / Moved
autogalaxy.profiles.light.standard.multipole.SersicMultipole→autogalaxy.profiles.light.standard.sersic_multipole.SersicMultipole(publicag.lp.SersicMultipolepath unchanged).autogalaxy.profiles.light.standard.multipole.GaussianMultipole→autogalaxy.profiles.light.standard.gaussian_multipole.GaussianMultipole(publicag.lp.GaussianMultipolepath unchanged).Changed Signature
ag.lp_linearvariants intentionally drop theintensityconstructor argument (constructor raisesTypeErrorif passed), mirroring the standard linear pattern.Changed Behaviour
ag.lp.SersicMultipole/ag.lp.GaussianMultipolebehaviour unchanged.Migration
from autogalaxy.profiles.light.standard.multipole import SersicMultipoleneed to switch tofrom autogalaxy.profiles.light.standard.sersic_multipole import SersicMultipole. The publicimport autogalaxy as ag; ag.lp.SersicMultipolepath keeps working unchanged.Coordination
This PR is part of a 3-PR follow-up to #418:
scripts/jax_likelihood_functions/light_multipole/multipole.pythat exercisesag.lp.SersicMultipoleunderfitness._vmap+jax.jit(analysis.fit_from). Must merge AFTER this PR (depends on the new classes).scripts/jax_likelihood_functions/light_multipole/multipole.pyfor the strong-lens case (lens bulge =al.lp_linear.SersicMultipole). Must merge AFTER this PR (depends on the new linear class).🤖 Generated with Claude Code