Skip to content

feat: likelihood-lifecycle pre-release setup fixes (auto setup before fit, estimate_runtime auto, JAX-disabled banner, ModelAnalysis forwarding) #756

Done

Description

@Jammy2211

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): ModelAnalysis forwards modify_before_fit to its wrapped analysis, rebinds to whatever it returns, refreshes its backend, and returns the wrapper. (Today the base Analysis.modify_before_fit shadows __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 of None.
  • Tests per fix; Fit/Galaxy/Lens suites green; pyauto-heart smoke --affected-by PyAutoFit; HowToLens tutorial 2 with setup="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

  1. PyAutoFit autofit/non_linear/analysis/model_analysis.py: add ModelAnalysis.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 (mirrors AnalysisFactor.modify_before_fit / rebind_analysis in autofit/graphical/declarative/factor/analysis.py).
  2. PyAutoFit autofit/non_linear/analysis/analysis.py: add a no-op Analysis.prepare_for_model(model) hook; print_vram_use calls it before its is_jax check; ModelAnalysis forwards it.
  3. PyAutoGalaxy autogalaxy/analysis/analysis/setup.py: AnalysisSetupMixin.prepare_for_model(model) calls resolve_setup(model) when unresolved; resolve_setup remembers its resolved setup so a later modify_before_fit landing on the same setup_id re-applies silently (no second banner), a different one re-applies and logs.
  4. PyAutoGalaxy autogalaxy/analysis/setup_util.py: setup_text_from / setup_banner_lines_from take the effective backend (use_jax_from), rendering e.g. numpy · CPU · dense · fp64 (rule imaging/mge · designated JAX; JAX disabled).
  5. PyAutoLens autolens/analysis/analysis/setup.py: reword SETUP_UNRESOLVED_MESSAGE for pre-fit use as well as factor graphs (drop the "planned 5D" text).
  6. PyAutoLens autolens/analysis/runtime_estimate.py: estimate_runtime accepts setup="auto" (rule key via setup_util.setup_key_and_note_from(dataset, model) + aa.Setup.auto) and number_of_cores="auto" (via PyAutoFit resolve_number_of_cores; 1 for JAX); no profiling cell → estimate whose line() says no estimate for <setup_id> (no profiling cell).
  7. Tests for each fix; run the three suites, pyauto-heart smoke --affected-by PyAutoFit, and HowToLens chapter_2_lens_modeling/tutorial_2_practicalities.py in test mode with setup="auto" (local only, MPLBACKEND=Agg).
  8. Ship with ship_library, pending-release label; at merge retire the three superseded drafts in one record.

Key Files

  • PyAutoFit/autofit/non_linear/analysis/model_analysis.py — ModelAnalysis forwarding
  • PyAutoFit/autofit/non_linear/analysis/analysis.py — print_vram_use, new hook
  • PyAutoGalaxy/autogalaxy/analysis/analysis/setup.py — AnalysisSetupMixin.resolve_setup
  • PyAutoGalaxy/autogalaxy/analysis/setup_util.py — banner text
  • PyAutoLens/autolens/analysis/analysis/setup.py — unresolved-setup guard
  • PyAutoLens/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.
  1. With analysis = al.AnalysisImaging(dataset, setup="auto"), calling analysis.print_vram_use(model=model, batch_size=...) (or any pre-fit likelihood use) before search.fit resolves 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 PyAutoLens SetupException that blames factor graphs. HowToLens chapter_2_lens_modeling/tutorial_2_practicalities.py runs in test mode with setup="auto" added (local check only, no HowToLens PR needed).
  2. al.estimate_runtime(dataset, model, search, setup="auto", number_of_cores="auto") works. The setup resolves via aa.Setup.auto with 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 whose line() says "no estimate for <setup_id> (no profiling cell)" instead of None.
  3. With PYAUTO_DISABLE_JAX=1 (or JAX not installed) and a setup resolving to a JAX designation, the Setup: line reports what actually runs, e.g. Setup: numpy · CPU · dense · fp64 (rule imaging/mge · designated JAX; JAX disabled), and the Parallel: line agrees.
  4. ModelAnalysis (PyAutoFit autofit/non_linear/analysis/model_analysis.py, created by analysis.with_model(...)) forwards modify_before_fit (and returns the wrapper with its inner analysis rebound if the inner call returns a new object), so setup="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_fit via AnalysisSetupMixin.resolve_setup(model) (PyAutoGalaxy autogalaxy/analysis/analysis/setup.py).
    • PyAutoLens raise_if_setup_unresolved (autolens/analysis/analysis/setup.py) guards each log_likelihood_function with a factor-graph message.
    • print_vram_use evaluates the likelihood before the fit.
    • Options: make resolve_setup(model) safe to call early and idempotent (no double banner when modify_before_fit later runs), call it from print_vram_use(model=...) when unresolved, and reword the guard to cover "used before the fit started" as well as factor graphs.
  • Fix 2 (PyAutoLens): autolens/analysis/runtime_estimate.py estimate_runtime(...) currently raises "'auto' is a device intent, not a setup_id" and needs an int number_of_cores.
    • Reuse the setup key logic (setup_util.setup_key_and_note_from in PyAutoGalaxy) and PyAutoFit autofit/non_linear/parallel/pool.py resolve_number_of_cores.
    • Note for prose (not a bug): the wall model's FLOOR_S = 0.014 s/eval dominates very fast GPU likelihoods.
  • Fix 3 (PyAutoGalaxy): autogalaxy/analysis/setup_util.py setup_banner_from prints the designated backend, although use_jax_from falls back to numpy. Found under the workspace smoke profile (PYAUTO_DISABLE_JAX=1).
  • Fix 4 (PyAutoFit):
    • ModelAnalysis has no modify_before_fit today (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_analysis handles 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-release label. When it merges, retire the three superseded drafts listed in the header (one record).

Out of scope

  • The R6 default flip and use_jax sweep.
  • 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

  1. Jammy2211 commented on Nov 25, 2026

    @Jammy2211
    CollaboratorAuthor

    Library PRs created

    All labelled pending-release; merge order Fit → Galaxy → Lens (shared branch feature/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 with setup="auto" runs in test mode. Heart dev-ship readiness GREEN.

    No workspace impact. Consequence: judge → human /prm.

  2. Jammy2211 commented on Nov 25, 2026

    @Jammy2211
    CollaboratorAuthor

    Shipped

    Merged in order: PyAutoLabs/PyAutoFit#1798 → #757 → PyAutoLabs/PyAutoLens#892 (all pending-release).

    • ModelAnalysis forwards modify_before_fit/modify_after_fit; new Analysis.prepare_for_model hook (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_runtime accepts setup="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.

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