Skip to content

feat: fits use the lazy sparse operator; aggregator reapplies setup.json (5C-3a) - #753

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

Jammy2211 merged 1 commit into
mainfrom
feature/likelihood-lifecycle-p5c3a-galaxy

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Likelihood-lifecycle phase 5C-3a, the first of two PRs under PyAutoLabs/PyAutoLens#885. The PyAutoGalaxy fits now get their sparse operator from one choke point, AbstractFitInversion.sparse_operator, which calls dataset.sparse_operator_for(xp, needs_operator=total_mappers > 0, settings) (PyAutoArray#712). So a plain FitImaging(dataset, galaxies) uses the lazy operator when the policy is on (aa.Settings(lazy_sparse_operator="auto") or PYAUTO_SETUP=auto; off by default). The interferometer profile-subtraction helpers use the same resolved operator, so the inversion and the dirty-image correction never disagree. Aggregator reloads reapply the search's files/setup.json, and setup resolution moves into one shared AnalysisSetupMixin.

API Changes

  • AbstractFitInversion.sparse_operator is now a cached property: the resolved operator (attached → returned whatever the fit; otherwise the lazy one for pixelized numpy fits when the policy is on; else None). It was unused before; the Galaxy DatasetInterface sites now read it.
  • sparse_profile_terms_from, sparse_dirty_image_from, uses_precomputed_data_term_from and sparse_chi_squared_from take an optional sparse_operator= (None → the old dataset.sparse_operator behaviour, so PyAutoLens callers are unchanged until 5C-3b).
  • New agg_util.dataset_with_setup_from(fit, dataset), called by _imaging_from / _interferometer_from: reapplies setup.json (no file → unchanged; array-free → skipped; failure → one warning, reload unapplied).
  • New AnalysisSetupMixin (autogalaxy/analysis/analysis/setup.py, no __init__, not on Analysis); AnalysisDataset(AnalysisSetupMixin, Analysis). setup_util.setup_environment() is public.
    See full details below.

Test Plan

  • pytest test_autogalaxy: 1659 passed
  • PyAutoLens compatibility (pytest test_autolens on Lens main against this branch): 1086 passed, 1 xfailed
  • Heart dev gate (pyauto-heart readiness --dev --repos PyAutoGalaxy): GREEN. Non-blocking shown reasons: the canonical PyAutoFit checkout was 5 commits behind origin (an unrelated Nautilus wall-clock budget, PyAutoFit#1793), so smoke used the older Fit; manifest drift; test run status unknown; no release rehearsal for current source; release push credential check 49 h old.
  • pyauto-heart smoke --affected-by PyAutoGalaxy --jobs 3: 5/5 workspaces PASS against this branch via PYAUTO_ROOT (autogalaxy, autolens_test, euclid, howtolens in the parallel run; autolens failed there with ModuleNotFoundError numpy/yaml during its environment rebuild, the known parallel build race, and passed rerun alone: 42/42 scripts, 2/2 notebooks)
Full API Changes (for automation & release notes)

Added

  • autogalaxy.aggregator.agg_util.dataset_with_setup_from(fit, dataset).
  • autogalaxy.analysis.analysis.setup.AnalysisSetupMixin (_init_setup, setup_key_and_note_from, _apply_resolved_setup, resolve_setup, _log_setup_auto_would_choose, save_setup).
  • autogalaxy.analysis.setup_util.setup_environment().
  • Optional sparse_operator= on sparse_profile_terms_from, sparse_dirty_image_from, uses_precomputed_data_term_from and sparse_chi_squared_from.

Changed

  • AbstractFitInversion.sparse_operator: now a functools.cached_property resolving through sparse_operator_for. It returns an attached operator for fits with only linear light profiles, where it used to return None (the property was unused).
  • FitImaging / FitInterferometer pass self.sparse_operator into aa.DatasetInterface.
  • Aggregator _imaging_from / _interferometer_from reapply setup.json.
  • Setup log lines come from the logger autogalaxy.analysis.analysis.setup (previously ...analysis.dataset).

Migration

  • None. With the lazy policy off (the default), fits behave exactly as before.

Notes:

  • Pytree safety: the property is cached on the fit. register_instance_pytree adds every cached_property to a fit's no_flatten set, so JAX treats the cached operator as static, never a pytree child.
  • Design calls (human-approved): one choke point; linear-light-only fits keep an attached operator but never trigger a lazy build; best-effort aggregator reapply; tests with the policy on (figure of merit equals dense, built once, MGE-only builds nothing, JAX builds nothing, and pixelization plus light profile on interferometer exercises the dirty-image correction).
  • Next: 5C-3b (PyAutoLens). The Lens DatasetInterface and interferometer-helper call sites pass self.sparse_operator; point/weak adopt the mixin. Until then a Lens fit's inversion stays dense even with the policy on.

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

…son, shared setup mixin (5C-3a)

AbstractFitInversion.sparse_operator (cached) resolves through
dataset.sparse_operator_for(xp, total_mappers > 0, settings); the Galaxy
DatasetInterface sites and the interferometer profile-subtraction helpers
use it, so the inversion and the dirty-image correction share one operator.
Aggregator _imaging_from/_interferometer_from reapply files/setup.json
(best-effort). Setup resolution moves into AnalysisSetupMixin.

Part of PyAutoLabs/PyAutoLens#885 (likelihood-lifecycle phase 5C-3a).

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 e357d1e into main Nov 24, 2026
5 checks passed
@Jammy2211
Jammy2211 deleted the feature/likelihood-lifecycle-p5c3a-galaxy branch November 24, 2026 16:29
@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