Repository navigation
Description
Overview
mge_model_from(gaussian_per_basis=K>1) builds K bases with identical sigma ladders, iid ell_comps priors and a shared centre, so swapping two bases' ell_comps is an exact label symmetry and an unseeded search lands on either labelling at random (PyAutoLabs/euclid_strong_lens_modeling_pipeline#54). With PyAutoLabs/PyAutoFit#1583 an assertion on the returned Basis model is enforced on both the NumPy and JAX paths, so the ordering can live in the library. Human direction 2026-09-08: implement it as an extension to mge_model_from, default off for now, used by the Euclid pipeline with it on, default on once properly tested.
Plan
order_bases: bool = False: when True (andgaussian_per_basis > 1, not spherical) add one assertion per consecutive pair,ell_comps_1[j] > ell_comps_1[j+1], to the returnedaf.Model(Basis). Key isell_comps_1, not the magnitude (Euclid phase-4 tiles show equal-magnitude cross configurations where a magnitude key slices both modes); docstring records the blind band and the identifier change.ell_comps_limit: float = 1.0: TruncatedGaussian ell_comps bounds become ±limit, so callers can tighten the box without replacing the priors an assertion references.- Tests: default off unchanged; K=2 one assertion, K=3 two, spherical none; ordered vs swapped vector; limit bounds. NumPy only.
- Workspace follow-up: euclid_strong_lens_modeling_pipeline#57 composes the vis_lp lens light with
ell_comps_limit=0.5, order_bases=True.
Detailed implementation plan
Work Classification
Library (PyAutoGalaxy); workspace follow-up tracked as euclid_strong_lens_modeling_pipeline#57.
Affected Repositories
- PyAutoGalaxy (primary)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoGalaxy | main | clean |
Conflict guard: clear. Attached to the existing task worktree ~/Code/PyAutoLabs-wt/order-lens-mge-bases-and-seed/.
Suggested branch: feature/order-lens-mge-bases-and-seed
Implementation Steps
autogalaxy/analysis/model_util.py::mge_model_from: addell_comps_limit(used in_make_ell_comps_priorsfor the TruncatedGaussian bounds) andorder_bases; collect each basis's sharedell_comps_1prior; after buildingaf.Model(Basis, profile_list=...), add the consecutive-pair assertions when enabled. Docstring for both.test_autogalaxy/analysis/test_model_util.py: the cases in the prompt.
Key Files
autogalaxy/analysis/model_util.py—mge_model_from(:7),_make_ell_comps_priors(:146)test_autogalaxy/analysis/test_model_util.pyPyAutoFit/autofit/mapper/prior_model/abstract.py—add_assertion,gathered_assertions(#1583)
Original Prompt
Click to expand starting prompt
mge_model_from: optional ordering of multiple bases and a configurable ell_comps limit
Type: feature
Target: autogalaxy
Repos:
- PyAutoGalaxy
Difficulty: small
Autonomy: supervised
Priority: high
Status: formalised
Issued: 2026-09-08
Consequence: review
Witness:mge_model_from(total_gaussians=20, gaussian_per_basis=2, order_bases=True)returns a Basis model carrying exactly one assertionbasis_0.ell_comps_1 > basis_1.ell_comps_1;order_bases=False(the default) carries none and every existing test is byte-for-byte unchanged;ell_comps_limit=0.5sets the TruncatedGaussian ell_comps bounds to ±0.5; the Euclid pipeline composes its vis_lp lens light withell_comps_limit=0.5, order_bases=Trueand no prior reassignment loop.
Review-minutes: 5
Unattended: ready
Human direction 2026-09-08 (verbatim): "I think that the solution should be implemented in the source as an extension to mge_model_from, I think it should be default off for now but used in the euclid pipeline with it on, and we can swap it to default on once its properly tested".
Context: mge_model_from(gaussian_per_basis=K>1) builds K bases with identical sigma ladders, iid ell_comps priors and a shared centre, so swapping any two bases' ell_comps is an exact label symmetry of the likelihood (euclid_strong_lens_modeling_pipeline#54, docs/mge_label_degeneracy.md). PyAutoFit#1583 (merged 2026-09-08) makes add_assertion enforceable on the JAX path, and gathers child-attached assertions, so an assertion on the returned Basis model is enforced on both backends.
Add to autogalaxy/analysis/model_util.py::mge_model_from:
order_bases: bool = False— when True,gaussian_per_basis > 1and notuse_spherical, add to the returnedaf.Model(Basis)one assertion per consecutive pair,ell_comps_1[j] > ell_comps_1[j+1], namedmge_basis_{j}_ell_comps_1_gt_basis_{j+1}. The key isell_comps_1(cos 2φ component), not the magnitude: on the Euclid phase-4 tiles the two bases often sit at the ±0.5 edge with opposite signs (equal magnitude), where a magnitude key slices both modes. Docstring: what it removes, why e1, the blind band (a small |Δe1| between bases means the ordering did not resolve on that dataset), that it changes the run identifier, thattake_attributesrefuses a target with assertions, and that the default stays off until validated.ell_comps_limit: float = 1.0— the TruncatedGaussian ell_comps bounds become ±ell_comps_limit(uniform priors keepell_comps_uniform_width). Needed so callers set tighter bounds without replacing the prior objects an assertion references.
Tests in test_autogalaxy/analysis/test_model_util.py: default off → no assertions, existing tests unchanged; order_bases with K=2 → one assertion, K=3 → two, spherical → none; an ordered vector satisfies and its swap fails via assertions_satisfied_from_vector; ell_comps_limit=0.5 bounds. No JAX in unit tests.
Follow-up (workspace): euclid_strong_lens_modeling_pipeline#57 composes with ell_comps_limit=0.5, order_bases=True.
Activity
Jammy2211 commentedon Sep 8, 2026
Library PR Created: #611
Next: /start_workspace — euclid_strong_lens_modeling_pipeline#57 composes the vis_lp lens light with mge_model_from(..., ell_comps_limit=0.5, order_bases=True) and the source with ell_comps_limit=0.7, replacing its prior-reassignment loops.
API-change summary: mge_model_from gains order_bases (default False; consecutive-pair ell_comps_1 ordering assertions on the returned Basis model) and ell_comps_limit (default 1.0; TruncatedGaussian ell_comps bounds). No behaviour change by default.
fix: mge_model_from new options at the end of the signature; docstrin…
Merge pull request #611 from PyAutoLabs/feature/order-lens-mge-bases-…
Jammy2211 commentedon Sep 8, 2026
Shipped — 2026-09-08
PRs
Summary
mge_model_fromgainsorder_bases(default off; consecutive-pairell_comps_1ordering assertions on the returned Basis model, enforced on both backends via PyAutoFit#1583) andell_comps_limit(TruncatedGaussian ell_comps bounds). New options sit aftersigma_minso positional callers are unchanged. The Euclid pipeline turns it on (euclid_strong_lens_modeling_pipeline#58). Default flips to on once validated on production runs (human direction).