Skip to content

feat: lazy, size-gated sparse operator on the dataset (5B-3) - #712

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/likelihood-lifecycle-p5b3-array
Nov 24, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/likelihood-lifecycle-p5b3-array

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Likelihood-lifecycle phase 5B-3 (#711). 5C applies the compute setup only in modify_before_fit, so calculations outside modeling, such as a plain FitImaging(dataset, tracer), aggregator reloads and fit_from before a search, stay on the slow, memory-heavy dense mapping route on CPU. This PR adds dataset.sparse_operator_for(xp, needs_operator) on Imaging and Interferometer. With the policy on, it builds the designated sparse operator once, lazily, and caches it on the real dataset. The policy is off by default (R6), so behaviour is unchanged until it is switched on. The Galaxy/Lens fits call the method in 5C-3.

API Changes

  • Imaging.sparse_operator_for(xp=np, needs_operator=True, settings=None) / Interferometer.sparse_operator_for(...) return the attached operator, else the cached or lazily built one when the policy allows, else None.
  • Policy: general.yaml inversion: lazy_sparse_operator: "off" | "auto" (Settings.lazy_sparse_operator, with constructor override), or PYAUTO_SETUP=auto. An explicit Settings value always wins.
  • Nothing is ever built under JAX (xp not numpy, or a tracer), inside a multiprocessing worker (workers return the parent's inherited cache), with an explicit dense setup, or when needs_operator=False.
  • Interferometer: the NUFFT builder, switching to apply_sparse_operator_from_chunks above a visibility budget (1e6; config inversion: lazy_sparse_operator_visibility_budget). If the real and imaginary noise differ, it skips with a one-time warning and never pools.
  • New module autoarray.dataset.lazy_operator (policy, gates, budget).
    See full details below.

Test Plan

  • pytest test_autoarray: 2614 passed (20 new in test_lazy_operator.py; the lazy operators equal apply_sparse_operator_cpu() exactly and apply_sparse_operator() to 1e-14, and the chunked build matches to 1e-12)
  • 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.sparse_operator_for(xp=np, needs_operator=True, settings=None).
  • Interferometer.sparse_operator_for(xp=np, needs_operator=True, settings=None).
  • Settings(lazy_sparse_operator="off" | "auto") and the Settings.lazy_sparse_operator property.
  • Config keys inversion: lazy_sparse_operator (default "off") and inversion: lazy_sparse_operator_visibility_budget (default null = 1e6).
  • autoarray.dataset.lazy_operator: lazy_sparse_operator_enabled, lazy_build_blocked_reason, in_worker_process, is_jax_tracer, visibility_budget, VISIBILITY_BUDGET, CHUNK_VISIBILITIES.

Changed

  • Imaging.apply_over_sampling carries the lazy cache. apply_setup's no-rebuild shortcut and AbstractDataset.trimmed_after_convolution_from clear it. Every apply_* that rebuilds the dataset starts with no cache.

Migration

  • None. The new behaviour is off by default.

Notes:

  • The hook is on the real dataset, not the inversion factory (approved design call 1). Every fit wraps its data in a fresh aa.DatasetInterface with no back-reference, so a factory-side cache would be lost after each fit. The factory is unchanged.
  • Builds reuse apply_sparse_operator_cpu() / apply_sparse_operator(), so the lazy operator is the explicit one, and one log line gives the build time.
  • Next: 5C-3 adds the Galaxy/Lens call sites (self.dataset.sparse_operator_for(xp, has_pixelization) into DatasetInterface) and aggregator reapplication of setup.json.

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

Imaging.sparse_operator_for / Interferometer.sparse_operator_for return
the attached operator, else (policy on) build the designated sparse
operator once and cache it on the real dataset: numba for imaging, NUFFT
w-tilde for interferometer (chunked above a 1e6-visibility budget). Never
built under JAX, inside multiprocessing workers, with an explicit dense
setup or without a pixelization; real != imaginary noise skips with a
one-time warning and never pools. Policy general.yaml
inversion: lazy_sparse_operator (default "off") or PYAUTO_SETUP=auto.

Closes #711 (likelihood-lifecycle phase 5B-3).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Nov 24, 2026
@Jammy2211
Jammy2211 merged commit faa8034 into main Nov 24, 2026
4 checks passed
@Jammy2211
Jammy2211 deleted the feature/likelihood-lifecycle-p5b3-array branch November 24, 2026 13:41
@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