Skip to content

feat: aa.Setup, Setup.auto and apply_setup from the Pulse designations #708

Done

Description

@Jammy2211

Overview

Likelihood-lifecycle epic, phase 5B (PyAutoArray only). This adds aa.Setup and aa.Setup.auto, which pick the Pulse-designated optimal compute setup (backend, device, operator, precision, transformer) for a likelihood on the current hardware. It also adds dataset.apply_setup, which attaches the matching operator or transformer, and an inversion-factory check that refuses an operator/backend mismatch. It builds on 5A (PyAutoNerves#223: autonerves.environment). It ships as two PRs under this issue.

Plan

5B-1: choosing a setup. No dataset behaviour changes.

  • aa.Setup: the setup tuple plus its provenance (rule, regime, hardware class, Pulse decision id, extrapolated).
  • autoarray/config/setup_rules.yaml, generated from the 39 Pulse designations with a provenance header.
  • aa.Setup.auto(dataset_type, variant) reads the hardware via Environment.detect(). PYAUTO_SETUP=<setup_id> or an explicit aa.Setup(...) always wins.

5B-2: applying a setup.

  • Imaging.apply_setup / Interferometer.apply_setup: idempotent, and carried through apply_mask / apply_over_sampling / apply_noise_scaling.
  • The inversion factory raises on an operator/backend mismatch.
  • Run-time thread helper.

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

  1. Hardware with no designation (a laptop, a non-A100 GPU) uses the nearest class, with extrapolated=True.
  2. The parity test regenerates the table from a local Pulse checkout, and is skipped without one.
  3. Lens-scale keys (group, multi_galaxy, cluster, point source) are resolved by the caller in 5C.
  4. The mismatch check raises rather than warns; a smoke hit stops and is reported.
  • Tier + merge mode: effective level: supervised; merge mode: human /prm (per PR)
Detailed implementation plan

Affected Repositories

  • PyAutoArray (primary)

Branch Survey

Repository Current Branch Dirty?
./PyAutoArray main clean

Suggested branch: feature/likelihood-lifecycle-p5b-array (5B-1). 5B-2 goes on a follow-up branch after 5B-1 merges.

Implementation Steps

  1. autoarray/setup/setup.py:
    • A frozen Setup dataclass (backend, device, operator, precision, transformer, rule_id, regime, hardware_class, decision_id, extrapolated), with from_setup_id() and .setup_id, using autonerves.environment.parse_setup_intent's grammar.
    • Setup.auto(dataset_type, variant, regime="standard", environment=None): an explicit PYAUTO_SETUP setup_id wins; otherwise the hardware class comes from Environment.detect() (gpu → gpu_a100, else cpu_many_core, with extrapolated=True unless the GPU name contains A100 or the CPU is many-core) and the rule table is looked up. An unknown key raises an error listing the known keys.
  2. Rule table:
    • autoarray/setup/generate_rules.py --pulse <path> reads PyAutoPulse decisions.yaml (kind: designation) and writes autoarray/config/setup_rules.yaml, with a header holding the Pulse commit and date, and rows of likelihood, regime, hardware_class, optimal, secondary, decision_id and rule.
    • Tests: the schema; every setup_id round-trips; Setup.auto for every row with a faked Environment; the override precedence; the parity regeneration when PYAUTO_PULSE, or a sibling Pulse checkout, exists, skipped otherwise.
  3. (5B-2) apply_setup:
    • Imaging: a sparse setup uses apply_sparse_operator (jax) or apply_sparse_operator_cpu (numba); a dense setup attaches nothing.
    • Interferometer: a _nufft setup uses the NUFFT transformer (under auto this replaces the >10,000-visibility DFT guard); a _wtilde setup uses apply_sparse_operator.
    • The dataset stores .setup, and the apply_* methods carry it.
  4. (5B-2) Inversion factory consistency check for imaging and interferometer, with a test per mismatch.
  5. (5B-2) Setup.apply_threads(): numba.set_num_threads, plus threadpoolctl when installed. It is safe inside multiprocessing workers (no prange in workers; it pins and never raises).
  6. Full test suite, plus pyauto-heart smoke --affected-by PyAutoArray at each ship.

Key Files

  • autoarray/setup/ (new), autoarray/config/setup_rules.yaml (new)
  • autoarray/dataset/imaging/dataset.py, autoarray/dataset/interferometer/dataset.py
  • autoarray/inversion/inversion/factory.py
  • autoarray/__init__.py (export Setup)
  • Rule source: PyAutoPulse decisions.yaml

Original Prompt

Click to expand starting prompt

Likelihood lifecycle phase 5B: PyAutoArray aa.Setup, Setup.auto, rule table from the Pulse designations, dataset.apply_setup, operator/backend consistency check

Type: feature
Target: PyAutoArray
Repos:

  • PyAutoArray
    Themes:
  • hpc-gpu
  • profiling
    Difficulty: large
    Autonomy: supervised
    Priority: high
    Status: draft
    Consequence: judge
    Witness: PyAutoArray main carries aa.Setup (the report §3.1 setup tuple plus rule_id, regime, hardware_class, decision_id, extrapolated) with Setup.from_setup_id() round-tripping every setup_id in the rule table; autoarray/config/setup_rules.yaml generated from PyAutoPulse decisions.yaml (39 designations) with a provenance header, and a parity test that regenerates it from a Pulse checkout when one is available (skipped otherwise); aa.Setup.auto(dataset_type, variant, environment=None) returns the designated optimal setup for every (likelihood, hardware class) row, unit-tested with a monkeypatched Environment; PYAUTO_SETUP=<setup_id> and an explicit aa.Setup(...) always win; Imaging.apply_setup / Interferometer.apply_setup attach the matching operator/transformer, are idempotent and survive apply_mask / apply_over_sampling / apply_noise_scaling; the inversion factory raises a clear error on an operator/backend mismatch instead of silently taking another path; full test suite green
    Review-minutes: 30
    Unattended: no
    Lane: any
    Gate: 5A MERGED 2026-11-23 (PyAutoNerves#223; autonerves.environment.Environment.detect() and parse_setup_intent() on Nerves main; Heart lib-tests install Nerves from source main, so no release is needed for Array CI). Boundary table (report §3.4) and 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-23

Context

  • Phase 5 order: 5A Nerves (done) → 5B Array (this prompt) → 5C Galaxy+Lens (setup="auto" on analyses, setup.json, banner, SLaM threading) → 5D Fit (number_of_cores="auto") → 5E estimator → 5F–5H workspace/assistant/science. One issue in PyAutoArray.
  • Design: report §3.5, PyAutoArray row (draft/research/autolens_profiling/likelihood_lifecycle_epic_report.md): aa.Setup dataclass; Setup.auto(...) with rule table config/setup_rules.yaml generated from the Pulse designation decisions; regimes computed from the dataset; dataset.apply_setup(setup) idempotent and carried by apply_over_sampling / apply_mask / apply_noise_scaling; inversion factory raises when operator and backend disagree; threads at runtime via numba.set_num_threads (+ threadpoolctl if available).
  • Boundary (report §3.4): auto decides backend, device, operator, precision, transformer/route, threads; never the model (mesh, over-sampling, regularisation), the sampler or the HPC request; an explicit override always wins.
  • Rule source: @PyAutoPulse/decisions.yaml, 39 kind: designation rows, keyed (likelihood = <dataset_type>/<variant>, regime = standard, hardware_class ∈ {cpu_many_core, gpu_a100}) → optimal: <setup_id>, secondary: [...], rule (one sentence in dataset terms). Examples: imaging/{rectangular,delaunay,delaunay_nn} cpu → numba_cpu_sparse_fp64, gpu → jax_gpu_dense_fp64; imaging/mge cpu → jax_cpu_dense_fp64; interferometer pixelized cpu → numba_cpu_sparse_fp64_wtilde, gpu → jax_gpu_sparse_fp64_wtilde; interferometer/mge → jax_{cpu,gpu}_dense_fp64_nufft; point-source/cluster → jax_{cpu,gpu}_na_fp64.
  • Array knows dataset classes, not lens-scale concepts: group / multi_galaxy / cluster / point-source likelihood keys are resolved by the caller (5C passes dataset_type/variant); 5B ships the full table and the lookup, and the Array-level helpers for imaging and interferometer.
  • Existing code: @PyAutoArray/autoarray/dataset/imaging/dataset.py (apply_sparse_operator, apply_sparse_operator_cpu, apply_mask, apply_over_sampling, apply_noise_scaling), @PyAutoArray/autoarray/dataset/interferometer/dataset.py (the >10,000-visibility DFT guard, apply_sparse_operator), @PyAutoArray/autoarray/inversion/inversion/factory.py (operator dispatch), @PyAutoArray/autoarray/settings.py (interferometer_route).

Out of scope

setup="auto" on analyses, setup.json, banner, SLaM threading (5C); number_of_cores="auto" (5D); the estimator (5E); workspace prose (5F). Mixed precision is never chosen by auto (R4). No compute.

Activity

  1. Jammy2211 commented on Nov 23, 2026

    @Jammy2211
    CollaboratorAuthor

    5B-1 PR created — awaiting human /prm

    PR: #709 (pending-release), commit 4d54c54.

    • Tests: test_autoarray/setup 85 passed. That includes the parity regeneration against a local Pulse checkout at 94a101f4, which ran rather than being skipped. Full suite: 2562 passed.
    • Smoke: pyauto-heart smoke --affected-by PyAutoArray, run against the task worktree: 7/7 PASS. autolens and autolens_test failed on the first parallel run because two environments were building wheels from the same library source trees at once. Rerun one at a time, both PASS.
    • Heart dev readiness (PyAutoArray): GREEN. Shown but not blocking: manifest drift; no release rehearsal for current source. CI: GREEN.
    • Deviation, within design call 1: datacube/delaunay has only a CPU designation, so on a GPU node auto returns that CPU setup with extrapolated=True.

    Next: 5B-2 (apply_setup, the inversion-factory mismatch check, run-time threads) on a follow-up branch once #709 merges.

  2. Jammy2211 commented on Nov 24, 2026

    @Jammy2211
    CollaboratorAuthor

    5B-2 shipped as #710 (pending-release): Imaging/Interferometer.apply_setup, inversion-factory operator/backend mismatch check (raises), Setup.apply_threads(). Gate: 2594 tests pass, Heart dev GREEN, smoke 7/7 against the branch. This issue stays open until #710 merges; the close-out carries pending-release lines for #709 and #710.

  3. Jammy2211 commented on Nov 24, 2026

    @Jammy2211
    CollaboratorAuthor

    Shipped

    Phase 5B is merged in two PRs:

    Both are pending release. Next: phase 5C (PyAutoGalaxy + PyAutoLens: setup="auto" opt-in, setup.json, banner, multi-dataset and SLaM setup threading, lens-scale keys).

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