Skip to content

feat: mge_model_from order_bases option and ell_comps_limit #610

Closed

Description

@Jammy2211

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 (and gaussian_per_basis > 1, not spherical) add one assertion per consecutive pair, ell_comps_1[j] > ell_comps_1[j+1], to the returned af.Model(Basis). Key is ell_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

  1. autogalaxy/analysis/model_util.py::mge_model_from: add ell_comps_limit (used in _make_ell_comps_priors for the TruncatedGaussian bounds) and order_bases; collect each basis's shared ell_comps_1 prior; after building af.Model(Basis, profile_list=...), add the consecutive-pair assertions when enabled. Docstring for both.
  2. 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.py
  • PyAutoFit/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 assertion basis_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.5 sets the TruncatedGaussian ell_comps bounds to ±0.5; the Euclid pipeline composes its vis_lp lens light with ell_comps_limit=0.5, order_bases=True and 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:

  1. order_bases: bool = False — when True, gaussian_per_basis > 1 and not use_spherical, add to the returned af.Model(Basis) one assertion per consecutive pair, ell_comps_1[j] > ell_comps_1[j+1], named mge_basis_{j}_ell_comps_1_gt_basis_{j+1}. The key is ell_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, that take_attributes refuses a target with assertions, and that the default stays off until validated.
  2. ell_comps_limit: float = 1.0 — the TruncatedGaussian ell_comps bounds become ±ell_comps_limit (uniform priors keep ell_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

  1. Jammy2211 commented on Sep 8, 2026

    @Jammy2211
    CollaboratorAuthor

    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.

  2. added 2 commits that reference this issue on Sep 8, 2026
  3. Jammy2211 commented on Sep 8, 2026

    @Jammy2211
    CollaboratorAuthor

    Shipped — 2026-09-08

    PRs

    Summary

    mge_model_from gains order_bases (default off; consecutive-pair ell_comps_1 ordering assertions on the returned Basis model, enforced on both backends via PyAutoFit#1583) and ell_comps_limit (TruncatedGaussian ell_comps bounds). New options sit after sigma_min so 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).

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