Repository navigation
Description
Overview
Likelihood-lifecycle epic, phase 5C-3 (PyAutoGalaxy, then PyAutoLens). 5B-3 (PyAutoArray#712) added dataset.sparse_operator_for(xp, needs_operator, settings), a lazy sparse operator that is off by default. This phase makes the Galaxy and Lens fits use it through one choke point, so a plain FitImaging(dataset, tracer) gets the optimal operator when the policy is on. It also makes aggregator reloads reapply the search's setup.json, and merges the duplicated setup-resolution code into one shared helper. It ships as two PRs under this issue: 5C-3a PyAutoGalaxy, then 5C-3b PyAutoLens.
Plan
- One choke point:
AbstractFitInversion.sparse_operator(autogalaxyabstract_fit.py:74-86, inherited by all four fits) returnsself.dataset.sparse_operator_for(xp=self._xp, needs_operator=self.total_mappers > 0, settings=self.settings), falling back todataset.sparse_operatorwhen the dataset has no such method.- Every
aa.DatasetInterface(sparse_operator=...)site uses it. - The interferometer profile-subtraction helpers (
sparse_profile_terms_from,uses_precomputed_data_term_from,sparse_chi_squared_from) take the resolved operator, so the inversion and the dirty-image correction never disagree.
- Every
- Aggregator:
_imaging_from/_interferometer_fromreapplyfit.value(name="setup")after masking and over-sampling. A missing file leaves the dataset unchanged; array-free datasets are skipped; a failed reapply logs one warning and reloads unapplied. - One shared resolution helper: a Galaxy
AnalysisSetupMixin(no__init__) onAnalysisDataset, not onAnalysis. It holds_init_setup,resolve_setupwith an apply hook, the "would choose" line andsave_setup, andsetup_environment()moves intosetup_util. LensAnalysisSetupNoOperatorbecomes a thin subclass. - 5C-3a, PyAutoGalaxy: the property, the Galaxy call sites, the interferometer helpers, the Galaxy aggregator and the mixin.
- 5C-3b, PyAutoLens: the Lens call sites (imaging
:163, interferometer:251), the Lens aggregator fits, point/weak on the mixin, and an MRO test.
Design calls (human-approved 2026-11-24):
- One choke point (the property) for every
DatasetInterfacesite and the interferometer correction helpers. - Fits with only linear light profiles keep an attached operator (
sparse_operator_forreturns it first) but never trigger a lazy build (needs_operator = total_mappers > 0). - The aggregator reapply is best-effort: on failure (e.g. a JAX sparse setup with no JAX), warn once and reload unapplied.
- Tests with the policy on: the figure of merit equals the dense one, the operator is built once, MGE-only builds nothing, JAX
xpreturns None, and a pixelization-plus-light-profile interferometer case exercises the dirty-image correction.
- Tier + merge mode: effective level: supervised; merge mode: human /prm (per PR)
Detailed implementation plan
Affected Repositories
- PyAutoLens (primary, issue home)
- PyAutoGalaxy (5C-3a ships first)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoGalaxy | main | clean |
| ./PyAutoLens | main | clean |
Suggested branches: feature/likelihood-lifecycle-p5c3a-galaxy, then feature/likelihood-lifecycle-p5c3b-lens, in worktree ~/Code/PyAutoLabs-wt/likelihood-lifecycle-p5c3.
Implementation Steps
- 5C-3a
autogalaxy/abstract_fit.py: rewrite theAbstractFitInversion.sparse_operatorproperty as above, usinggetattr(self.dataset, "sparse_operator_for", None)for the fallback. - 5C-3a
autogalaxy/imaging/fit_imaging.py:148andautogalaxy/interferometer/fit_interferometer.py:501: passsparse_operator=self.sparse_operator. - 5C-3a
autogalaxy/interferometer/fit_interferometer.py:sparse_profile_terms_from(:92/:100),uses_precomputed_data_term_from(:198-200) andsparse_chi_squared_from(:285-306) take the resolved operator (anoperator=argument, or readfit.sparse_operator). Update their callers at G :488 and the Lens equivalent; the Lens call site is 5C-3b if its signature changes. - 5C-3a aggregator:
- in
autogalaxy/aggregator/imaging/imaging.py(_imaging_from) andautogalaxy/aggregator/interferometer/interferometer.py(_interferometer_from), afterapply_mask/apply_over_sampling, reapplyfit.value(name="setup"); - the value is a plain dict from
setup_util.setup_dict_from; iffit.valuedoesn't return it as a dict, useSearchOutput.plain; dataset.apply_setup(d["setup_id"]), skipping array-free datasets, with a missing file → no-op and failure → one warning.
- in
- 5C-3a consolidation: add
AnalysisSetupMixin(autogalaxy/analysis/analysis/setup.pyorsetup_util.py) and movesetup_environment()intosetup_util.AnalysisDatasetuses the mixin, overriding the key method and an_apply_resolved_setup(setup)hook (apply + consistency check, run after_use_jaxis set).save_attributescallssave_setup. Behaviour is unchanged (existing 5C tests still pass). - 5C-3b PyAutoLens:
autolens/imaging/fit_imaging.py:163andautolens/interferometer/fit_interferometer.py:251useself.sparse_operator; update the interferometer correction call (~:238);autolens/aggregator/fit_imaging.py/fit_interferometer.pyrely on the Galaxy dataset helpers (verify);AnalysisSetupNoOperator→ a thin subclass of the Galaxy mixin, removing the duplicatedsetup_environment;- an MRO/no-duplicate-base test for
AnalysisPoint/AnalysisWeak.
- Tests:
- Fits: in G
test_autogalaxy/{imaging/test_fit_imaging.py, interferometer/test_fit_interferometer.py}and Ltest_autolens/{imaging,interferometer}/test_fit_*.py, withSettings(lazy_sparse_operator="auto"): figure of merit equals dense, built once, MGE-only builds nothing, JAXxp→ no build, the pixelization + light profile interferometer case, and linear-light-only with an attached operator unchanged. - Aggregator: fake-fit round trip in the
SimpleNamespacepattern oftest_autolens/aggregator/test_tracer.py. - Mixin: the existing 5C setup tests still pass.
- numba, jax and finufft uses go behind
pytest.importorskip.
- Fits: in G
- Full suites plus
pyauto-heart smoke --affected-by <repo>at each ship.
Key Files
autogalaxy/abstract_fit.py,autogalaxy/imaging/fit_imaging.py,autogalaxy/interferometer/fit_interferometer.pyautogalaxy/aggregator/imaging/imaging.py,autogalaxy/aggregator/interferometer/interferometer.pyautogalaxy/analysis/setup_util.py,autogalaxy/analysis/analysis/dataset.pyautolens/imaging/fit_imaging.py,autolens/interferometer/fit_interferometer.py,autolens/analysis/analysis/setup.py,autolens/aggregator/fit_*.py- Upstream: PyAutoArray
autoarray/dataset/lazy_operator.pyandsparse_operator_for(main faa80349)
Original Prompt
Click to expand starting prompt
Likelihood lifecycle phase 5C-3: PyAutoGalaxy + PyAutoLens fit call sites for the lazy operator, aggregator reloads reapply setup.json, one shared setup-resolution path
Type: feature
Target: PyAutoLens
Repos:
- PyAutoGalaxy
- PyAutoLens
Themes: - hpc-gpu
- profiling
Difficulty: large
Autonomy: supervised
Priority: medium
Status: draft
Consequence: judge
Witness: The PyAutoGalaxy and PyAutoLens fits (AbstractFit.sparse_operator,fit_imaging.py/fit_interferometer.py,lens/to_inversion.py) passself.dataset.sparse_operator_for(xp, has_pixelization)(5B-3) intoaa.DatasetInterface, so a plainal.FitImaging(dataset, tracer)gets the lazy operator when the policy is on. Loading a fit from the aggregator (al.agg.FitImagingAgg/FitInterferometerAggand their PyAutoGalaxy counterparts) for a search that wrotefiles/setup.jsonreapplies that setup to the reloaded dataset (dataset.apply_setup). So the reloaded fit takes the same operator route as the search, and its log likelihood matches the stored value to the search's tolerance. A search with nosetup.jsonreloads exactly as before. The analysis'smodify_before_fitresolution and the 5B-3 lazy factory path share one resolution helper rather than two copies. The full PyAutoGalaxy and PyAutoLens suites are green.
Review-minutes: 20
Unattended: no
Lane: any
Gate: 5B-3 MERGED (the lazy factory operator and policy switch in PyAutoArray). Phasing approved by the human 2026-11-24.
Epic: likelihood-lifecycle
Phase: 5
Parent: draft/research/autolens_profiling/likelihood_lifecycle_epic.md
Filed: 2026-11-24
Context
- 5C writes
files/setup.json(setup fields pluschosen_by) beside each search's output, butautolens/aggregator/fit_imaging.py:91/fit_interferometer.py:92rebuild fits fromdataset.fitswith no operator. A reload can therefore take a different route from the search (the routes differ by about 1e-4 relative) and run slowly with heavy memory on CPU. - Setup resolution now lives in PyAutoGalaxy
autogalaxy/analysis/setup_util.py/AnalysisDataset.resolve_setup(5C-1) and in the PyAutoLens point/weak setup mixin (5C-2). 5B-3 adds the factory-side resolution. 5C-3 makes them share one helper.
Out of scope
- The lazy factory operator itself (5B-3).
- The JAX path.
- The default flip (R6).
- Workspace changes (5F).
Activity
Jammy2211 commentedon Nov 24, 2026
5C-3a shipped as PyAutoLabs/PyAutoGalaxy#753 (pending-release): Galaxy fits resolve their sparse operator through one choke point (
AbstractFitInversion.sparse_operator→sparse_operator_for), including the interferometer dirty-image correction; aggregator reloads reapply setup.json;AnalysisSetupMixin. Gate: 1659 Galaxy tests, Lens compat 1086 + 1 xfailed, Heart dev GREEN, smoke 5/5. 5C-3b (PyAutoLens call sites, point/weak on the mixin) follows after it merges.Jammy2211 commentedon Nov 24, 2026
5C-3b shipped as #886 (pending-release): Lens fits resolve their sparse operator through the shared choke point (incl. the interferometer dirty-image correction); point/weak setup resolution now inherits PyAutoGalaxy's
AnalysisSetupMixin. Gate: 1101 passed + 1 xfailed, Heart dev GREEN, smoke 4/4. This issue closes when #886 merges (close-out carries pending-release for PyAutoGalaxy#753 and #886).Jammy2211 commentedon Nov 24, 2026
Shipped
Phase 5C-3 merged in two PRs:
AbstractFitInversion.sparse_operator→sparse_operator_forfor the Galaxy fits and interferometer correction helpers; aggregator reapplies setup.json;AnalysisSetupMixin.Both pending-release. With
lazy_sparse_operatoron, fits outside modeling now get the optimal operator; it flips on with the R6 default flip. Next: 5D (PyAutoFit).