Repository navigation
feat: lazy, size-gated sparse operator on the dataset (5B-3) - #712
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Likelihood-lifecycle phase 5B-3 (#711). 5C applies the compute setup only in
modify_before_fit, so calculations outside modeling, such as a plainFitImaging(dataset, tracer), aggregator reloads andfit_frombefore a search, stay on the slow, memory-heavy dense mapping route on CPU. This PR addsdataset.sparse_operator_for(xp, needs_operator)onImagingandInterferometer. 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.general.yamlinversion: lazy_sparse_operator: "off" | "auto"(Settings.lazy_sparse_operator, with constructor override), orPYAUTO_SETUP=auto. An explicitSettingsvalue always wins.xpnot numpy, or a tracer), inside a multiprocessing worker (workers return the parent's inherited cache), with an explicit dense setup, or whenneeds_operator=False.apply_sparse_operator_from_chunksabove a visibility budget (1e6; configinversion: lazy_sparse_operator_visibility_budget). If the real and imaginary noise differ, it skips with a one-time warning and never pools.autoarray.dataset.lazy_operator(policy, gates, budget).See full details below.
Test Plan
pytest test_autoarray: 2614 passed (20 new intest_lazy_operator.py; the lazy operators equalapply_sparse_operator_cpu()exactly andapply_sparse_operator()to 1e-14, and the chunked build matches to 1e-12)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_ROOTFull 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 theSettings.lazy_sparse_operatorproperty.inversion: lazy_sparse_operator(default"off") andinversion: 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_samplingcarries the lazy cache.apply_setup's no-rebuild shortcut andAbstractDataset.trimmed_after_convolution_fromclear it. Everyapply_*that rebuilds the dataset starts with no cache.Migration
Notes:
aa.DatasetInterfacewith no back-reference, so a factory-side cache would be lost after each fit. The factory is unchanged.apply_sparse_operator_cpu()/apply_sparse_operator(), so the lazy operator is the explicit one, and one log line gives the build time.self.dataset.sparse_operator_for(xp, has_pixelization)intoDatasetInterface) and aggregator reapplication ofsetup.json.Generated by the PyAutoLabs agent workflow.
🤖 Generated with Claude Code