Repository navigation
feat: ModelAnalysis forwards modify_before_fit; Analysis.prepare_for_model hook - #1798
Merged
Merged
Conversation
…for_model Part of PyAutoLabs/PyAutoGalaxy#756. 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
Part of PyAutoLabs/PyAutoGalaxy#756 (likelihood-lifecycle pre-release setup fixes). Merge order: PyAutoFit → PyAutoGalaxy → PyAutoLens (same branch name in all three).
ModelAnalysisnow forwardsmodify_before_fit/modify_after_fit. The baseAnalysis.modify_before_fit(which returnsself) shadowed__getattr__forwarding, so an analysis wrapped byanalysis.with_model(model)never ran its ownmodify_before_fit, and asetup="auto"analysis wrapped this way (including inside anAnalysisFactor) never resolved its setup. The wrapper now forwards with its ownself.model(the model its likelihood is evaluated on), rebinds to whatever the inner call returns, refreshes its backend from it and returns itself, mirroringAnalysisFactor.modify_before_fit/rebind_analysis.Analysis.prepare_for_model(model)(no-op by default), called byprint_vram_useandbatched_memory_bytesbefore they readis_jax, so an analysis whose backend depends on the model (PyAutoGalaxy/PyAutoLenssetup="auto") resolves it before pre-fit likelihood use.ModelAnalysisforwards it.API Changes
Added
Analysis.prepare_for_model(model);ModelAnalysisgainsmodify_before_fit,modify_after_fitandprepare_for_modelforwarding. No removals; existing behaviour unchanged for analyses that do not override the hook.See full details below.
Test Plan
test_autofitfull suite (pytest -x) passestest_autofit/analysis/test_model_analysis_forwarding.py: forwarding, wrapper returned, inner rebound,is_jaxfollows, and inside anAnalysisFactorpyauto-heart smoke --affected-by PyAutoFit: 8/8 workspaces passedFull API Changes (for automation & release notes)
Added
autofit.Analysis.prepare_for_model(model)— pre-fit hook letting an analysis finish model-dependent setup; called byprint_vram_useandbatched_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_useandAnalysis.batched_memory_bytescallprepare_for_model(model)first.Generated by the PyAutoLabs agent workflow.
🤖 Generated with Claude Code