Skip to content

feat: ModelAnalysis forwards modify_before_fit; Analysis.prepare_for_model hook - #1798

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/likelihood-lifecycle-p5-setup-fixes
Nov 25, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/likelihood-lifecycle-p5-setup-fixes

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Part of PyAutoLabs/PyAutoGalaxy#756 (likelihood-lifecycle pre-release setup fixes). Merge order: PyAutoFit → PyAutoGalaxy → PyAutoLens (same branch name in all three).

  • ModelAnalysis now forwards modify_before_fit / modify_after_fit. The base Analysis.modify_before_fit (which returns self) shadowed __getattr__ forwarding, so an analysis wrapped by analysis.with_model(model) never ran its own modify_before_fit, and a setup="auto" analysis wrapped this way (including inside an AnalysisFactor) never resolved its setup. The wrapper now forwards with its own self.model (the model its likelihood is evaluated on), rebinds to whatever the inner call returns, refreshes its backend from it and returns itself, mirroring AnalysisFactor.modify_before_fit / rebind_analysis.
  • New hook Analysis.prepare_for_model(model) (no-op by default), called by print_vram_use and batched_memory_bytes before they read is_jax, so an analysis whose backend depends on the model (PyAutoGalaxy/PyAutoLens setup="auto") resolves it before pre-fit likelihood use. ModelAnalysis forwards it.

API Changes

Added Analysis.prepare_for_model(model); ModelAnalysis gains modify_before_fit, modify_after_fit and prepare_for_model forwarding. No removals; existing behaviour unchanged for analyses that do not override the hook.
See full details below.

Test Plan

  • test_autofit full suite (pytest -x) passes
  • New test_autofit/analysis/test_model_analysis_forwarding.py: forwarding, wrapper returned, inner rebound, is_jax follows, and inside an AnalysisFactor
  • pyauto-heart smoke --affected-by PyAutoFit: 8/8 workspaces passed
  • Heart dev-ship readiness: GREEN. Shown (non-blocking): PyAutoLens canonical checkout 2 commits behind origin; manifest drift (1 mismatch); test run status unknown; no release rehearsal for current source; release push credential check stale.
Full API Changes (for automation & release notes)

Added

  • autofit.Analysis.prepare_for_model(model) — pre-fit hook letting an analysis finish model-dependent setup; called by print_vram_use and batched_memory_bytes. Default: no-op.
  • ModelAnalysis.modify_before_fit(paths, model) / modify_after_fit(paths, model, result) / prepare_for_model(model) — forward to the wrapped analysis with the wrapper's own model.

Changed

  • Analysis.print_vram_use and Analysis.batched_memory_bytes call prepare_for_model(model) first.

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

…for_model

Part of PyAutoLabs/PyAutoGalaxy#756.

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 25, 2026
@Jammy2211
Jammy2211 merged commit 34148e6 into main Nov 25, 2026
6 checks passed
@Jammy2211
Jammy2211 deleted the feature/likelihood-lifecycle-p5-setup-fixes branch November 25, 2026 16:44
@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