feat: imaging shared-state consumer — AnalysisImaging.shared_state_from + mesh preload reuse (phase 2/4)#600
Merged
Conversation
…om + mesh preload reuse Multi-exposure shared-state path (PyAutoArray#379, design PyAutoLens#599 D1-D6 + H amendment): AnalysisImaging(shared_preloads=True) opts in; shared_state_from traces the lead exposure's image-mesh once and returns PreloadsImaging(source_plane_mesh_grid, image_plane_mesh_grid); shared= threads through log_likelihood_function -> fit_from -> FitImaging -> TracerToInversion, whose mesh pg-list properties now consult the preload so every exposure maps its own (offset) grid onto the identical shared mesh. Opt-in default-off; single-dataset path unchanged. Co-Authored-By: Claude Fable 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
The imaging consumer of the multi-exposure shared-state feature (PyAutoArray#379; design locked on PyAutoLens#599 D1–D6 + the regularization amendment). When several exposures of the same lens are fitted as an
af.FactorGraphModel(same wavelength with pixel offsets, different wavelengths, or imaging + interferometer),AnalysisImaging(shared_preloads=True)now computes the source-plane mesh once on the lead factor and every exposure reconstructs on that identical mesh — each mapping its own (offset) data grid onto it.Mirrors the shipped datacube consumer (#566) with the imaging invariance contract: only the mesh geometry is shared; the mapper, mapping matrix, blurred mapping matrix (per-exposure PSFs/offsets) and regularization matrix (may be data-adaptive) are built per-exposure as before.
DatasetModeloffsets compose naturally — the lead's offset applies when the mesh is traced; each factor's offset applies to its own grid (the existingupdated_via_instance_frommesh-grid transform).API Changes
All additive and backward compatible — no removals or renames.
AnalysisImaging(... , shared_preloads=False)— opt-in flag (default off; single-dataset behaviour byte-for-byte unchanged).AnalysisImaging.shared_state_from(instance)— the lead-factor hook (autofit.Analysis.shared_state_fromprotocol): buildsaa.PreloadsImaging(source_plane_mesh_grid, image_plane_mesh_grid)from one fit of the lead exposure; returnsNoneunless opted in and the model performs an inversion.AnalysisImaging.log_likelihood_function(instance, shared=None)/fit_from(instance, preloads=None)/FitImaging(... , preloads=None)— theshared=threading, mirroring feat: datacube shared-state for AnalysisInterferometer via curvature preloads #566.TracerToInversion.image_plane_mesh_grid_pg_list/traced_mesh_grid_pg_listconsultpreloadsand return the shared mesh instead of recomputing (image-mesh + mesh ray-trace skipped);mapper_galaxy_dictthen builds this dataset's mapper onto the shared mesh.FitImagingpytree registration addspreloadstono_flatten(mirrorsFitInterferometer).Depends on the PyAutoArray PR (must merge first).
Test Plan
python -m pytest test_autolens/— full suite passestest_autolens/imaging/model/test_analysis_imaging.py:shared_state_fromreturnsPreloadsImagingcarrying mesh only (noF, no mapper); preloaded mesh reused by identity;figure_of_meritandlog_likelihood_functionshared-vs-unshared parityNonewhen not opted in / when no inversionFactorGraphModelshared-vs-unshared log-likelihood bit-identical (−58.673099306030444);shared_state_fromcomputed once (lead factor only, monkeypatch counter)test_autoarray/(896) +test_autogalaxy/(962) pass against the paired branchAutonomy
--autorun (Autonomy: safe, feature/medium): four-leg ship gate — tests ✅, smoke ✅ (curated subsets, see issue), review ✅ CLEAN, Heart 🟡 YELLOW acknowledged by user (reason set on issue PyAutoArray#379). Ends at PR-open; merge stays human.Phase 2/4 of the
multi_shared_state_examplesepic (design: #599). Phase 3 (workspace example sections +workspace_testshared-vs-unshared assertion script + profiling measurement, mirroring the datacube pattern) follows once this merges.🤖 Generated with Claude Code