Skip to content

feat: apply_setup, operator/backend mismatch check and Setup.apply_threads (5B-2) - #710

Merged
Jammy2211 merged 2 commits into
mainfrom
feature/likelihood-lifecycle-p5b2-array
Nov 24, 2026
Merged

Jammy2211 merged 2 commits into
mainfrom
feature/likelihood-lifecycle-p5b2-array

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Likelihood-lifecycle phase 5B-2 (second PR under #708; 5B-1 was #709). This applies a compute setup to a dataset. Imaging.apply_setup / Interferometer.apply_setup attach the operator or transformer an aa.Setup names. The inversion factory raises on an operator/backend mismatch instead of silently taking another path. Setup.apply_threads() pins the run-time thread pools.

Part of #708 (stays open until this merges).

API Changes

  • Imaging.apply_setup(setup): a sparse setup attaches apply_sparse_operator (jax) or apply_sparse_operator_cpu (numba); a dense setup attaches none. It is idempotent.
  • Interferometer.apply_setup(setup): _nufft uses TransformerNUFFT, and _wtilde (sparse) attaches apply_sparse_operator. A dataset constructed with a setup skips the >10,000-visibility DFT check, because the setup decides the transformer.
  • Both datasets take setup= and store .setup. Imaging carries it through apply_mask / apply_noise_scaling (the operator is rebuilt for the new mask or noise-map) and apply_over_sampling. Interferometer carries it through apply_sparse_operator* and from_fits.
  • The inversion factory raises InversionException on an operator/backend mismatch.
  • Setup.apply_threads(n=None) calls numba.set_num_threads, plus threadpoolctl if it is installed. It never raises, and inside multiprocessing workers it leaves numba alone.
  • Without a setup, dataset behaviour is unchanged. There is one exception: a numba imaging operator used by an inversion running on JAX now raises, where it previously took a path with no JAX support.
    See full details below.

Test Plan

  • pytest test_autoarray: 2594 passed
  • Heart dev gate (pyauto-heart readiness --dev --repos PyAutoArray): GREEN. Non-blocking shown reasons: manifest drift (1 workspace checkout mismatch vs repos.yaml); release validation has no rehearsal for current source.
  • pyauto-heart smoke --affected-by PyAutoArray --jobs 3: 7/7 workspaces PASS (autogalaxy, autolens, autolens_test, euclid, howtolens, autocti, autocti_test), run against this branch via PYAUTO_ROOT
Full API Changes (for automation & release notes)

Added

  • Imaging.apply_setup(setup: Setup | str, batch_size=128) -> Imaging: attaches the operator the setup names. It is idempotent (returns self when the operator already matches).
  • Interferometer.apply_setup(setup: Setup | str, **sparse_operator_kwargs) -> Interferometer: attaches the NUFFT transformer and/or the sparse operator the setup names. It is idempotent.
  • Imaging(..., setup=None), Interferometer(..., setup=None), Interferometer.from_fits(..., setup=None): the dataset stores the setup as .setup. Passing it here only records it.
  • Setup.apply_threads(n=None) -> int | None: pins numba and BLAS/OpenMP threads and returns the count applied.
  • autoarray.setup.setup.setup_from(setup): converts a Setup, a setup_id string or None to a Setup (or None).

Changed

  • Imaging.apply_mask / apply_noise_scaling: with a .setup, the result has the setup re-applied, and the "sparse operator discarded" warning is not emitted. Without a setup, behaviour is unchanged.

  • Interferometer.__init__: a setup disables the >10,000-visibility DFT check. A _nufft setup replaces a non-NUFFT transformer_class with TransformerNUFFT.

  • inversion_imaging_from / inversion_interferometer_from raise InversionException when:

    • imaging: a numba operator is used under JAX xp; a numba setup carries the JAX operator, or a jax setup the numba operator; a sparse setup has no operator; a dense/na setup has an operator;
    • interferometer: a numba setup runs under JAX xp; a sparse setup has no operator; a dense/na setup has an operator.

    Still allowed: a JAX operator under numpy (visualization), and func-list-only imaging inversions, which stay on the mapping formalism.

Migration

  • None needed. The new raise only fires on a numba imaging operator used by a JAX inversion. Use apply_sparse_operator() (or apply_setup("jax_...")) for JAX fits.

Notes:

  • The interferometer has one sparse operator class for both backends. Jax and numba setups both build it with the default finufft builder, and the inversion's xp picks the route.
  • For 5C: a factory mismatch raised during a search is caught as a rejected sample (FitException), so 5C should run the check, or apply_setup, once when the analysis is constructed.

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

…hreads (5B-2)

Imaging.apply_setup / Interferometer.apply_setup attach the operator or
transformer an aa.Setup names; datasets store .setup and carry it through
apply_mask / apply_noise_scaling / apply_over_sampling. The inversion
factory raises InversionException on an operator/backend mismatch.
Setup.apply_threads pins numba and threadpoolctl thread pools, safely
inside multiprocessing workers.

Part of #708 (likelihood-lifecycle phase 5B-2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The unittest-nojax leg failed on five new tests that build the JAX
ImagingSparseOperator. Guard their JAX parts with pytest.importorskip, as
other test modules do; the numba halves still run without jax.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jammy2211
Jammy2211 merged commit 7db095a into main Nov 24, 2026
4 checks passed
@Jammy2211
Jammy2211 deleted the feature/likelihood-lifecycle-p5b2-array branch November 24, 2026 10:52
@pyautolabs-bot pyautolabs-bot Bot removed the pending-release PR queued for the next release build label Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant