Repository navigation
Description
Overview
Four rough edges in the automatic compute setup (setup="auto") that must be fixed before the release carrying likelihood-lifecycle 5A–5E and the setup banner: pre-fit likelihood use (print_vram_use) before the setup resolves, estimate_runtime not accepting "auto", the Setup: banner reporting JAX when JAX is disabled, and ModelAnalysis (analysis.with_model) never forwarding modify_before_fit to its inner analysis. One task, three PRs on one shared branch, merged Fit → Galaxy → Lens.
Plan
- Fix 4 (PyAutoFit):
ModelAnalysisforwardsmodify_before_fitto its wrapped analysis, rebinds to whatever it returns, refreshes its backend, and returns the wrapper. (Today the baseAnalysis.modify_before_fitshadows__getattr__, so the inner setup never resolves.) - Fix 1 (Fit + Galaxy + Lens):
print_vram_use(model=...)before the fit resolves the setup from that model first (once, no double banner later); the PyAutoLens unresolved-setup error covers "used before the fit started", not only factor graphs. - Fix 3 (PyAutoGalaxy): with JAX disabled or missing, the
Setup:line reports the numpy backend that actually runs, noting the JAX designation;Parallel:agrees. - Fix 2 (PyAutoLens):
estimate_runtime(..., setup="auto", number_of_cores="auto")resolves both the way a fit does; a setup with no profiling cell gives an estimate saying so instead ofNone. - Tests per fix; Fit/Galaxy/Lens suites green;
pyauto-heart smoke --affected-by PyAutoFit; HowToLens tutorial 2 withsetup="auto"runs locally in test mode.
Tier + merge mode: effective level: supervised; merge mode: human /prm
Detailed implementation plan
Affected Repositories
- PyAutoGalaxy (primary)
- PyAutoFit
- PyAutoLens
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoFit | main | clean |
| ./PyAutoGalaxy | main | clean |
| ./PyAutoLens | main | clean |
Suggested branch: feature/likelihood-lifecycle-p5-setup-fixes (same name in all three, so library CI clones matching branches)
Note: PyAutoLens is claimed by cluster-family-fit-figures (awaiting-merge, feature/family-plot-api); different branch and files, proceeding with human approval.
Implementation Steps
- PyAutoFit
autofit/non_linear/analysis/model_analysis.py: addModelAnalysis.modify_before_fit(paths, model)→inner = self.analysis.modify_before_fit(paths=paths, model=model);self.analysis = inner;self._use_jax = inner.is_jax;return self(mirrorsAnalysisFactor.modify_before_fit/rebind_analysisinautofit/graphical/declarative/factor/analysis.py). - PyAutoFit
autofit/non_linear/analysis/analysis.py: add a no-opAnalysis.prepare_for_model(model)hook;print_vram_usecalls it before itsis_jaxcheck;ModelAnalysisforwards it. - PyAutoGalaxy
autogalaxy/analysis/analysis/setup.py:AnalysisSetupMixin.prepare_for_model(model)callsresolve_setup(model)when unresolved;resolve_setupremembers its resolved setup so a latermodify_before_fitlanding on the samesetup_idre-applies silently (no second banner), a different one re-applies and logs. - PyAutoGalaxy
autogalaxy/analysis/setup_util.py:setup_text_from/setup_banner_lines_fromtake the effective backend (use_jax_from), rendering e.g.numpy · CPU · dense · fp64 (rule imaging/mge · designated JAX; JAX disabled). - PyAutoLens
autolens/analysis/analysis/setup.py: rewordSETUP_UNRESOLVED_MESSAGEfor pre-fit use as well as factor graphs (drop the "planned 5D" text). - PyAutoLens
autolens/analysis/runtime_estimate.py:estimate_runtimeacceptssetup="auto"(rule key viasetup_util.setup_key_and_note_from(dataset, model)+aa.Setup.auto) andnumber_of_cores="auto"(via PyAutoFitresolve_number_of_cores; 1 for JAX); no profiling cell → estimate whoseline()saysno estimate for <setup_id> (no profiling cell). - Tests for each fix; run the three suites,
pyauto-heart smoke --affected-by PyAutoFit, and HowToLenschapter_2_lens_modeling/tutorial_2_practicalities.pyin test mode withsetup="auto"(local only,MPLBACKEND=Agg). - Ship with ship_library,
pending-releaselabel; at merge retire the three superseded drafts in one record.
Key Files
PyAutoFit/autofit/non_linear/analysis/model_analysis.py— ModelAnalysis forwardingPyAutoFit/autofit/non_linear/analysis/analysis.py—print_vram_use, new hookPyAutoGalaxy/autogalaxy/analysis/analysis/setup.py—AnalysisSetupMixin.resolve_setupPyAutoGalaxy/autogalaxy/analysis/setup_util.py— banner textPyAutoLens/autolens/analysis/analysis/setup.py— unresolved-setup guardPyAutoLens/autolens/analysis/runtime_estimate.py—estimate_runtime
Original Prompt
Click to expand starting prompt
Likelihood lifecycle pre-release fixes: four rough edges in the automatic compute setup, before the release that ships it
Type: feature
Target: PyAutoGalaxy
Repos:
- PyAutoFit
- PyAutoGalaxy
- PyAutoLens
Themes: - hpc-gpu
Difficulty: medium
Autonomy: supervised
Priority: high
Status: draft
Consequence: judge
Witness: All four fixes are merged on library main before the next release.
- With
analysis = al.AnalysisImaging(dataset, setup="auto"), callinganalysis.print_vram_use(model=model, batch_size=...)(or any pre-fit likelihood use) beforesearch.fitresolves the setup on demand from that model: the banner prints once and the call proceeds. Where it can't (no model available), it raises a clear error saying the setup resolves when the fit starts, instead of the PyAutoLensSetupExceptionthat blames factor graphs. HowToLenschapter_2_lens_modeling/tutorial_2_practicalities.pyruns in test mode withsetup="auto"added (local check only, no HowToLens PR needed). al.estimate_runtime(dataset, model, search, setup="auto", number_of_cores="auto")works. The setup resolves viaaa.Setup.autowith the same dataset/model rule key the analyses use; the cores resolve via PyAutoFit's resolution (detected cores; 1 for JAX). A setup with no profiling row (e.g.numba_cpu_dense_fp64) returns an estimate whoseline()says "no estimate for <setup_id> (no profiling cell)" instead ofNone.- With
PYAUTO_DISABLE_JAX=1(or JAX not installed) and a setup resolving to a JAX designation, theSetup:line reports what actually runs, e.g.Setup: numpy · CPU · dense · fp64 (rule imaging/mge · designated JAX; JAX disabled), and theParallel:line agrees. ModelAnalysis(PyAutoFitautofit/non_linear/analysis/model_analysis.py, created byanalysis.with_model(...)) forwardsmodify_before_fit(and returns the wrapper with its inner analysis rebound if the inner call returns a new object), sosetup="auto"resolves for analyses wrapped this way, including inside factor graphs.
Tests cover each fix. The PyAutoFit, PyAutoGalaxy and PyAutoLens suites are green, and pyauto-heart smoke --affected-by PyAutoFit passes.
Review-minutes: 25
Unattended: no
Lane: any
Gate: likelihood-lifecycle 5A–5E and the setup banner MERGED (PyAutoNerves#223/#224, PyAutoArray#709/#710/#712/#713, PyAutoFit#1795/#1796/#1797, PyAutoGalaxy#752/#753/#755, PyAutoLens#882/#886/#888/#889). Must land before the release that carries them. The workspace PRs autolens_workspace#689/#690, HowToLens#139, autolens_assistant#192 and euclid_strong_lens_modeling_pipeline#142 wait for that release.
Epic: likelihood-lifecycle
Phase: 5
Parent: draft/research/autolens_profiling/likelihood_lifecycle_epic.md
Filed: 2026-11-25
Supersedes:
- draft/bug/autogalaxy/setup_auto_unresolved_before_fit_print_vram_use.md
- draft/feature/autolens/estimate_runtime_accept_auto.md
- draft/bug/autogalaxy/setup_banner_shows_jax_under_disable_jax.md
Context
This is one task with up to three PRs (PyAutoFit, PyAutoGalaxy, PyAutoLens). Give them the same branch name, because library CI clones dependency repos at a matching branch name, otherwise main. Merge order: Fit → Galaxy → Lens.
- Fix 1 (PyAutoGalaxy + PyAutoLens):
- The setup resolves in
modify_before_fitviaAnalysisSetupMixin.resolve_setup(model)(PyAutoGalaxyautogalaxy/analysis/analysis/setup.py). - PyAutoLens
raise_if_setup_unresolved(autolens/analysis/analysis/setup.py) guards eachlog_likelihood_functionwith a factor-graph message. print_vram_useevaluates the likelihood before the fit.- Options: make
resolve_setup(model)safe to call early and idempotent (no double banner whenmodify_before_fitlater runs), call it fromprint_vram_use(model=...)when unresolved, and reword the guard to cover "used before the fit started" as well as factor graphs.
- The setup resolves in
- Fix 2 (PyAutoLens):
autolens/analysis/runtime_estimate.pyestimate_runtime(...)currently raises "'auto' is a device intent, not a setup_id" and needs an intnumber_of_cores.- Reuse the setup key logic (
setup_util.setup_key_and_note_fromin PyAutoGalaxy) and PyAutoFitautofit/non_linear/parallel/pool.pyresolve_number_of_cores. - Note for prose (not a bug): the wall model's FLOOR_S = 0.014 s/eval dominates very fast GPU likelihoods.
- Reuse the setup key logic (
- Fix 3 (PyAutoGalaxy):
autogalaxy/analysis/setup_util.pysetup_banner_fromprints the designated backend, althoughuse_jax_fromfalls back to numpy. Found under the workspace smoke profile (PYAUTO_DISABLE_JAX=1). - Fix 4 (PyAutoFit):
ModelAnalysishas nomodify_before_fittoday (only__init__,gradient_mode,__getattr__).__getattr__may forward it implicitly, but the return value would then be the inner analysis, not the wrapper. Verify and fix.- See how 5D's
AnalysisFactor.modify_before_fit/rebind_analysishandles the same wrapper problem (autofit/graphical/declarative/factor/analysis.py).
- Running scripts: prefix every script run with
MPLBACKEND=Agg(the default qtagg backend pops windows on the human's desktop). Generate notebooks only from inside a workspace repo directory, never from a task-root folder. - Shipping: ship_library with the
pending-releaselabel. When it merges, retire the three superseded drafts listed in the header (one record).
Out of scope
- The R6 default flip and
use_jaxsweep. - Workspace and assistant docs (already written in the open 5F/5G PRs; a later docs pass can switch them to the simpler calls).
- The double-source-plane visualizer and sensitivity-script bugs.
Activity
Jammy2211 commentedon Nov 25, 2026
Library PRs created
ModelAnalysisforwardsmodify_before_fit/modify_after_fit; newAnalysis.prepare_for_modelhook used byprint_vram_useSetup:line reports the JAX fallbackestimate_runtimeacceptssetup="auto"/number_of_cores="auto", no-cell and JAX-fallback estimates, reworded setup guardAll labelled
pending-release; merge order Fit → Galaxy → Lens (shared branchfeature/likelihood-lifecycle-p5-setup-fixes). Suites green (Fit 4391, Galaxy 1671, Lens 1169), Heart smoke --affected-by PyAutoFit 8/8 against the worktree, HowToLens tutorial 2 withsetup="auto"runs in test mode. Heart dev-ship readiness GREEN.No workspace impact. Consequence: judge → human
/prm.test: price JAX setups as if JAX were installed in runtime-estimate t…
Jammy2211 commentedon Nov 25, 2026
Shipped
Merged in order: PyAutoLabs/PyAutoFit#1798 → #757 → PyAutoLabs/PyAutoLens#892 (all
pending-release).ModelAnalysisforwardsmodify_before_fit/modify_after_fit; newAnalysis.prepare_for_modelhook (print_vram_use,batched_memory_bytes).setup="auto"resolves before pre-fit use; banner logged once;Setup:line reports the numpy fallback when JAX is disabled or not installed.al.estimate_runtimeacceptssetup="auto"/number_of_cores="auto"; no-cell and JAX-fallback estimates; unresolved-setup error reworded.Note: the first Lens CI run failed on the no-JAX leg (runtime-estimate tests assumed JAX installed); fixed test-only in 712be5c2c before merge.