Repository navigation
Description
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 orPYAUTO_SETUP=<setup_id>always wins.
- Without
- 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().
- set the analysis backend (
- Write
setup.jsonbesidesettings.jsoninsave_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.
- imaging/interferometer + the model's mesh class (or MGE) →
- 5C-1, PyAutoGalaxy: resolution, apply, banner,
setup.jsonand threads inag.AnalysisDatasetand 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):
- Resolve at
modify_before_fit, not at construction. The variant needs the model, and the banner, not the existinglog_fit_startJAX line, is the authoritative report. - No lens-scale hint arguments: group, multi_galaxy and multi_dataset map to the imaging rule, and cluster to point.
- Multi-dataset (
FactorGraphModel) setup agreement moves to 5D (PyAutoFit):FactorGraphModeldoes not forwardmodify_before_fit. Until then,setup="auto"inside a factor graph raises a clear "not yet supported for factor graphs" error. - 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
- 5C-1
autogalaxy/analysis/analysis/dataset.py(AnalysisDataset.__init__, dataset stored at :71):- Accept
setupand normalise it withautoarray.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 ofmodel.has_model(cls=aa.Pixelization)in lens dataset.py:163.
- Accept
- 5C-1
modify_before_fit(paths, model):- when
setup == "auto":aa.Setup.auto(*key); when it is explicit, use it; - set
self._use_jaxfromsetup.backend == "jax", respectingPYAUTO_DISABLE_JAXand JAX availability asaf.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.
- when
- 5C-1
save_attributes:paths.save_json("setup", {...setup_id, rule_id, regime, hardware_class, decision_id, extrapolated, chosen_by: auto|explicit|PYAUTO_SETUP}). - 5C-1 PyAutoGalaxy
AnalysisImaging/AnalysisInterferometer: threadsetup=through the constructors. The ellipse analysis is untouched, since it has no dataset operator. - 5C-1 tests in
test_autogalaxy/analysis/analysis/test_analysis_dataset.pyandtest_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_jaxFalse; GPU → jax dense); - explicit and
PYAUTO_SETUPprecedence; setup.jsoncontent; the banner; no-setup behaviour unchanged.
- 5C-2 PyAutoLens:
autolens/analysis/analysis/{dataset,lens}.py: keepAnalysisLens._use_jax/_xpin step with the resolved setup.autolens/point/model/analysis.py(fit_positions_cls→ image_plane vs source_plane) andautolens/weak/model/analysis.py(defaultuse_jax=Falsestays unless a setup is given).- A factor-graph guard:
setup="auto"within anaf.AnalysisFactorraises a clear error. - Tests in
test_autolens/analysis/analysis/,test_autolens/imaging/model/andtest_autolens/point/model/, including that a mismatch raises atmodify_before_fitunder the numpy path.
- 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.pyautolens/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) andautoarray/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 throughaa.Setup.autowith 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_setupplus the factory consistency check, so a mismatch raises at construction rather than becoming rejected samples mid-search), writessetup.jsonbeside the search output, and prints the setup banner line at fit start. An explicital.Setup(...), a setup_id string orPYAUTO_SETUP=<setup_id>always wins, anduse_jax=stays as an explicit override that maps onto a Setup. Withoutsetup=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 monkeypatchedEnvironment; full PyAutoGalaxy and PyAutoLens suites are green, andpyauto-heart smoke --affected-by PyAutoLenspasses.
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.jsonis 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>vsimaging/mgefrom the model) toSetup.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 catchInversionException. 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.pyandautolens/analysis/result.py. These hold the SLaM-facing helpers; the SLaM pipelines themselves are workspace scripts and move in 5F.
- PyAutoGalaxy:
- The planning question to settle: do the SLaM helpers live in the library (thread a
setupthroughmodel_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
Jammy2211 commentedon Nov 24, 2026
5C-1 shipped as PyAutoLabs/PyAutoGalaxy#752 (pending-release):
setup=on the PyAutoGalaxy dataset analyses, resolved atmodify_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.Jammy2211 commentedon Nov 24, 2026
5C-2 shipped as #882 (pending-release):
setup=on the lens imaging/interferometer/point/weak analyses, point/weak setup resolution, and aSetupExceptionguard 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).Jammy2211 commentedon Nov 24, 2026
Shipped
Phase 5C is merged in two PRs:
setup=on the PyAutoGalaxy dataset analyses, resolved atmodify_before_fit, plussetup.jsonand the banner line.setup=on the lens imaging, interferometer, point and weak analyses, and the factor-graphSetupExceptionguard.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).