Skip to content

feat: setup="auto" (opt-in), setup.json and setup banner in the analyses (5C) #881

Done

Description

@Jammy2211

Overview

Likelihood-lifecycle epic, phase 5C (PyAutoGalaxy + PyAutoLens). This wires the 5B aa.Setup machinery into the analyses. setup="auto" (opt-in, per ruling R6) resolves the Pulse-designated optimal setup for the likelihood and hardware at fit start, applies it to the dataset, and pins threads. It prints a banner line, writes setup.json beside the search output, and turns an operator/backend mismatch into a clear error instead of silently rejected samples. It ships as two PRs under this issue: 5C-1 PyAutoGalaxy, then 5C-2 PyAutoLens.

Plan

  • Add setup=None | "auto" | aa.Setup | "<setup_id>" to the dataset analyses: imaging and interferometer in both libraries, plus PyAutoLens point and weak.
    • Without setup=, behaviour is unchanged apart from one "auto would choose …" banner line (R6: opt-in first).
    • use_jax= stays an explicit override; an explicit Setup or PYAUTO_SETUP=<setup_id> always wins.
  • Resolve the setup in modify_before_fit(paths, model), because the rule key needs the model (pixelized mesh vs MGE). There:
    • set the analysis backend (_use_jax) from the setup;
    • apply the setup to the dataset, with the factory consistency check, outside the likelihood, so a mismatch raises instead of being resampled as a FitException;
    • print the banner (Setup: … · rule … · optimal|extrapolated (decision …));
    • call Setup.apply_threads().
  • Write setup.json beside settings.json in save_attributes (files/).
  • Rule key mapping:
    • imaging/interferometer + the model's mesh class (or MGE) → imaging/<mesh> / interferometer/<mesh>;
    • point → point_source_*; weak → weak/isothermal;
    • group, multi_galaxy and cluster need no hint, because their rule rows equal imaging/point. The banner names the rule used.
  • 5C-1, PyAutoGalaxy: resolution, apply, banner, setup.json and threads in ag.AnalysisDataset and its subclasses, plus tests.
  • 5C-2, PyAutoLens: the lens analyses inherit it; add point and weak; test that a mismatch surfaces despite raise_fit_exception; smoke --affected-by PyAutoLens.

Design calls (human-approved 2026-11-24):

  1. Resolve at modify_before_fit, not at construction. The variant needs the model, and the banner, not the existing log_fit_start JAX line, is the authoritative report.
  2. No lens-scale hint arguments: group, multi_galaxy and multi_dataset map to the imaging rule, and cluster to point.
  3. Multi-dataset (FactorGraphModel) setup agreement moves to 5D (PyAutoFit): FactorGraphModel does not forward modify_before_fit. Until then, setup="auto" inside a factor graph raises a clear "not yet supported for factor graphs" error.
  4. SLaM "one setup" is 5F (workspace). The library has no SLaM analysis builders; the setup is idempotent and stored on the dataset, so pipelines pass one setup to every stage.
  • Tier + merge mode: effective level: supervised; merge mode: human /prm (per PR)
Detailed implementation plan

Affected Repositories

  • PyAutoLens (primary, issue home)
  • PyAutoGalaxy (5C-1 ships first)

Branch Survey

Repository Current Branch Dirty?
./PyAutoGalaxy main clean
./PyAutoLens main clean

Unregistered worktrees exist (not hard conflicts): PyAutoGalaxy docs/dermot-readme and feature/three-autos-public-framing; PyAutoLens docs/kyle-readme, feature/mge-feature-review and feature/three-autos-public-framing.

Suggested branches: feature/likelihood-lifecycle-p5c1-galaxy (5C-1), then feature/likelihood-lifecycle-p5c2-lens (5C-2), in worktree ~/Code/PyAutoLabs-wt/likelihood-lifecycle-p5c-galaxy-lens.

Implementation Steps

  1. 5C-1 autogalaxy/analysis/analysis/dataset.py (AnalysisDataset.__init__, dataset stored at :71):
    • Accept setup and normalise it with autoarray.setup.setup.setup_from ("auto" stays a sentinel).
    • Add a helper setup_key_from(dataset, model) that maps the dataset type and the model's pixelization mesh class (Rectangular* → rectangular, Delaunay → delaunay, a nearest-neighbour Delaunay interpolator → delaunay_nn, otherwise an MGE/parametric fallback → mge) to (dataset_type, variant). It follows the precedent of model.has_model(cls=aa.Pixelization) in lens dataset.py:163.
  2. 5C-1 modify_before_fit(paths, model):
    • when setup == "auto": aa.Setup.auto(*key); when it is explicit, use it;
    • set self._use_jax from setup.backend == "jax", respecting PYAUTO_DISABLE_JAX and JAX availability as af.Analysis.__init__ does;
    • self.dataset = self.dataset.apply_setup(setup) (imaging and interferometer), then the consistency check outside the likelihood;
    • setup.apply_threads(), then log the banner;
    • with no setup, log the one-line "auto would choose …" without applying anything.
  3. 5C-1 save_attributes: paths.save_json("setup", {...setup_id, rule_id, regime, hardware_class, decision_id, extrapolated, chosen_by: auto|explicit|PYAUTO_SETUP}).
  4. 5C-1 PyAutoGalaxy AnalysisImaging / AnalysisInterferometer: thread setup= through the constructors. The ellipse analysis is untouched, since it has no dataset operator.
  5. 5C-1 tests in test_autogalaxy/analysis/analysis/test_analysis_dataset.py and test_autogalaxy/imaging/model/test_analysis_imaging.py:
    • key mapping for each mesh and for MGE;
    • auto with a monkeypatched Environment (CPU many-core → numba sparse operator attached and _use_jax False; GPU → jax dense);
    • explicit and PYAUTO_SETUP precedence;
    • setup.json content; the banner; no-setup behaviour unchanged.
  6. 5C-2 PyAutoLens:
    • autolens/analysis/analysis/{dataset,lens}.py: keep AnalysisLens._use_jax / _xp in step with the resolved setup.
    • autolens/point/model/analysis.py (fit_positions_cls → image_plane vs source_plane) and autolens/weak/model/analysis.py (default use_jax=False stays unless a setup is given).
    • A factor-graph guard: setup="auto" within an af.AnalysisFactor raises a clear error.
    • Tests in test_autolens/analysis/analysis/, test_autolens/imaging/model/ and test_autolens/point/model/, including that a mismatch raises at modify_before_fit under the numpy path.
  7. At each ship: the full suites of both repos and pyauto-heart smoke --affected-by <repo>.

Key Files

  • autogalaxy/analysis/analysis/{analysis,dataset}.py, autogalaxy/imaging/model/analysis.py, autogalaxy/interferometer/model/analysis.py
  • autolens/analysis/analysis/{dataset,lens}.py, autolens/{imaging,interferometer,point,weak}/model/analysis.py, autolens/analysis/exceptions.py
  • Upstream: autoarray/setup/setup.py (Setup.auto, setup_from, apply_threads) and autoarray/config/setup_rules.yaml (PyAutoArray main 7db095a4)

Original Prompt

Click to expand starting prompt

Likelihood lifecycle phase 5C: PyAutoGalaxy + PyAutoLens setup="auto" (opt-in), setup.json, the setup banner, one setup through multi-dataset sums and SLaM, lens-scale keys resolved

Type: feature
Target: PyAutoLens
Repos:

  • PyAutoGalaxy
  • PyAutoLens
    Themes:
  • hpc-gpu
  • profiling
    Difficulty: large
    Autonomy: supervised
    Priority: high
    Status: draft
    Consequence: judge
    Witness: with PyAutoGalaxy and PyAutoLens main, al.AnalysisImaging(dataset, setup="auto") (and the interferometer, point, weak and multi-dataset analyses, plus their PyAutoGalaxy counterparts) resolves the setup through aa.Setup.auto with the lens-scale keys mapped by the caller (imaging/interferometer variant from the model's pixelization / linear light profiles; group, multi_galaxy, cluster and point-source keys from the analysis type), applies it once at construction (dataset.apply_setup plus the factory consistency check, so a mismatch raises at construction rather than becoming rejected samples mid-search), writes setup.json beside the search output, and prints the setup banner line at fit start. An explicit al.Setup(...), a setup_id string or PYAUTO_SETUP=<setup_id> always wins, and use_jax= stays as an explicit override that maps onto a Setup. Without setup= the behaviour is unchanged apart from a one-line "auto would choose …" banner (R6: opt-in release first, default flipped in a later release). Unit tests cover every analysis type, with a monkeypatched Environment; full PyAutoGalaxy and PyAutoLens suites are green, and pyauto-heart smoke --affected-by PyAutoLens passes.
    Review-minutes: 30
    Unattended: no
    Lane: any
    Gate: 5B MERGED (PyAutoArray#709 e70af85d, PyAutoArray#710: aa.Setup, Setup.auto, setup_rules.yaml, Imaging/Interferometer.apply_setup, the inversion-factory mismatch check, Setup.apply_threads). Heart lib-tests install Array from source main, so no release is needed for CI. R6 = opt-in first (approved 2026-11-16).
    Epic: likelihood-lifecycle
    Phase: 5
    Parent: draft/research/autolens_profiling/likelihood_lifecycle_epic.md
    Filed: 2026-11-24

Context

  • Phase 5 order: 5A Nerves (done) → 5B Array (done) → 5C Galaxy+Lens (this prompt) → 5D Fit (number_of_cores="auto", banner hook, search metadata) → 5E estimator (the banner's second, "Estimate:" line) → 5F–5H workspace/assistant/science.
  • Design: report §3.5, PyAutoGalaxy/PyAutoLens row (draft/research/autolens_profiling/likelihood_lifecycle_epic_report.md):
    • Analysis*(dataset, setup="auto"); use_jax= is kept as an explicit override that maps onto a Setup.
    • Weak and point analyses are aligned with the rest.
    • A multi-dataset sum resolves one setup.
    • SLaM helpers accept a setup once.
    • setup.json is written beside the search output.
    • The banner reads Setup: jax/gpu/dense/fp64 (A100-SXM4-80GB) · rule imaging-pixelized-gpu · optimal (Pulse day zero …). The "Estimate:" line is 5E's.
  • Boundary (report §3.4): auto decides the backend, device, operator, precision, transformer/route and threads. It never decides the model (mesh, over-sampling, regularisation), the sampler or the HPC request. An explicit override always wins.
  • 5B design call 3: Array knows dataset classes only. 5C maps the lens-scale likelihood keys (group, multi_galaxy, cluster, point source, and imaging/<mesh> vs imaging/mge from the model) to Setup.auto(dataset_type, variant).
  • 5B-2 lesson: the PyAutoLens numpy-path analyses wrap every exception as af.exc.FitException, which the search treats as a rejected sample, and the PyAutoGalaxy visualizers catch InversionException. So the setup must be applied and checked when the analysis is constructed, or a mismatch shows up as silently rejected samples.
  • Threads: Setup.apply_threads() at fit start (5B-2) is safe inside multiprocessing workers. number_of_cores="auto" belongs to 5D.
  • Existing code:
    • PyAutoGalaxy: autogalaxy/analysis/analysis/{analysis,dataset}.py (use_jax).
    • PyAutoLens: autolens/analysis/analysis/{dataset,lens}.py, autolens/{imaging,interferometer,point,weak}/model/analysis.py, autolens/analysis/model_util.py and autolens/analysis/result.py. These hold the SLaM-facing helpers; the SLaM pipelines themselves are workspace scripts and move in 5F.
  • The planning question to settle: do the SLaM helpers live in the library (thread a setup through model_util / result chaining), or is "accept a setup once" only a workspace change for 5F?

Out of scope

  • number_of_cores="auto" and search metadata (5D).
  • The runtime estimate and the banner's second line (5E).
  • Workspace and HowTo prose, and the SLaM workspace scripts (5F).
  • Assistant skills (5G).
  • Science projects (5H).
  • Flipping the default to setup="auto", which happens in the release after this one (R6).
  • Mixed precision is never chosen by auto (R4).
  • No compute.

Activity

  1. Jammy2211 commented on Nov 24, 2026

    @Jammy2211
    CollaboratorAuthor

    5C-1 shipped as PyAutoLabs/PyAutoGalaxy#752 (pending-release): setup= on the PyAutoGalaxy dataset analyses, resolved at modify_before_fit, setup.json, banner line, opt-in per R6. Gate: 1641 tests, Heart dev GREEN, smoke 5/5 against the branch. 5C-2 (PyAutoLens: lens analyses, point, weak, factor-graph guard) follows after it merges.

  2. Jammy2211 commented on Nov 24, 2026

    @Jammy2211
    CollaboratorAuthor

    5C-2 shipped as #882 (pending-release): setup= on the lens imaging/interferometer/point/weak analyses, point/weak setup resolution, and a SetupException guard for factor graphs. Gate: 1086 passed + 1 xfailed, Heart dev GREEN, smoke 4/4 against the branch. This issue closes when #882 merges (close-out carries pending-release for PyAutoGalaxy#752 and #882). Follow-ups filed: 5B-3 (lazy factory operator for calculations outside modeling) and 5C-3 (aggregator reapplies setup.json).

  3. Jammy2211 commented on Nov 24, 2026

    @Jammy2211
    CollaboratorAuthor

    Shipped

    Phase 5C is merged in two PRs:

    Both are pending release. Next: 5B-3 (a lazy, size-gated operator in the PyAutoArray inversion factory for calculations outside modeling), then 5C-3 (aggregator reloads reapply setup.json), then 5D (PyAutoFit).

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