Skip to content

feat: setup= on the lens analyses, point/weak setups and a factor-graph guard (5C-2) - #882

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

Jammy2211 merged 1 commit into
mainfrom
feature/likelihood-lifecycle-p5c2-lens

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Likelihood-lifecycle phase 5C-2, the second of two PRs under #881. 5C-1 was PyAutoGalaxy#752. The PyAutoLens analyses take setup=None | "auto" | aa.Setup | "<setup_id>":

  • AnalysisImaging / AnalysisInterferometer pass it to the PyAutoGalaxy base, which resolves it at modify_before_fit.
  • AnalysisPoint and AnalysisWeak resolve it themselves through a new mixin. They have no dataset operator; the setup sets the backend and threads, logs the banner and writes setup.json.

Factor graphs, which never call modify_before_fit, now raise a clear SetupException from the likelihood instead of silently ignoring the setup. It stays opt-in (R6): without setup=, nothing changes beyond the "auto would choose …" log line.

API Changes

  • setup= on al.AnalysisImaging, al.AnalysisInterferometer, al.AnalysisPoint and al.AnalysisWeak (and lens AnalysisDataset).
  • Point rule key: point_source_source/source_plane when fit_positions_cls is a FitPositionsSource subclass, otherwise point_source_image/image_plane. Weak: weak/isothermal.
  • New al.exc.SetupException. It is raised at the top of log_likelihood_function, outside the raise_fit_exception wrapper, when an analysis was given setup= but it was never resolved (factor graphs; calling the likelihood directly without modify_before_fit). fit_from is not guarded.
  • New module autolens.analysis.analysis.setup (AnalysisSetupNoOperator mixin, raise_if_setup_unresolved).
    See full details below.

Test Plan

  • pytest test_autolens: 1086 passed, 1 xfailed
  • Heart dev gate (pyauto-heart readiness --dev --repos PyAutoLens): 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 PyAutoLens --jobs 3: 4/4 workspaces PASS (autolens, autolens_test, euclid, howtolens), run against this branch via PYAUTO_ROOT
Full API Changes (for automation & release notes)

Added

  • setup keyword on AnalysisDataset (lens), AnalysisImaging, AnalysisInterferometer, AnalysisPoint and AnalysisWeak. On imaging and interferometer it comes after shared_preloads, so existing positional calls still work.
  • AnalysisPoint.setup_key_from(model) and AnalysisWeak.setup_key_from(model).
  • AnalysisPoint.modify_before_fit and AnalysisWeak.modify_before_fit resolve the setup, then call super. Their save_attributes writes files/setup.json.
  • autolens.analysis.analysis.setup: AnalysisSetupNoOperator (_init_setup, resolve_setup, save_setup), raise_if_setup_unresolved and setup_environment.
  • autolens.exc.SetupException(AnalysisException). It is deliberately not a FitException, so it is never resampled.

Changed

  • log_likelihood_function of imaging, interferometer, point and weak first checks that a given setup was resolved, and raises SetupException otherwise.

Migration

  • None. The new behaviour is opt-in. A factor graph whose analyses pass setup= now raises. Apply the setup to each dataset (dataset.apply_setup(...)) and pass use_jax= instead, until PyAutoFit phase 5D adds factor-graph setups.

Notes:

  • _xp is a property derived from _use_jax in both af.Analysis and AnalysisLens, so a resolved setup switches it with no extra code. Tests check numpy vs jax.numpy for all four analyses.
  • The PyAutoFit order was checked: preflight runs in start_resume_fit, after modify_before_fit, so the guard never fires on a normal search.
  • No cluster analysis class exists, so the cluster/* rules are unused for now.
  • Follow-ups already filed:
    • 5B-3: a lazy, size-gated operator in the PyAutoArray inversion factory, for calculations outside modeling.
    • 5C-3: aggregator reloads reapply setup.json, and one shared resolution helper replaces the small overlap between this mixin and PyAutoGalaxy's AnalysisDataset (including the duplicated setup_environment).

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

…factor-graph guard (5C-2)

AnalysisImaging / AnalysisInterferometer pass setup= to the PyAutoGalaxy
base (resolved at modify_before_fit). AnalysisPoint and AnalysisWeak
resolve it through a new AnalysisSetupNoOperator mixin (point_source_* /
weak/isothermal rule keys): backend, threads, banner and setup.json. A setup
that was never resolved (factor graphs) raises SetupException from the
likelihood, outside the FitException wrapper.

Part of #881 (likelihood-lifecycle phase 5C-2).

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 c10d627 into main Nov 24, 2026
5 checks passed
@Jammy2211
Jammy2211 deleted the feature/likelihood-lifecycle-p5c2-lens branch November 24, 2026 12: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