Skip to content

feat: cache per-galaxy result images for SLaM resume fast-path (#502) - #504

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/slam-resume-fastpath
Jul 17, 2026
Merged

feat: cache per-galaxy result images for SLaM resume fast-path (#502)#504
Jammy2211 merged 1 commit into
mainfrom
feature/slam-resume-fastpath

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Implements the PyAutoGalaxy leg of the SLaM resume fast-path (#502, judgment from autolens_profiling#70): galaxy_name_image_dict_via_result_from now caches the raw per-galaxy image dictionary into the upstream result's own files/ folder on first computation and loads it on every later call, instead of rebuilding the result's maximum log likelihood fit (fresh JIT compile + inversion) each time.

Key mechanics:

  • Cache artifacts galaxy_images_model.fits / galaxy_images_snr.fits, FITS layout mirroring the aggregator's adapt_images artifact (mask HDU + per-galaxy EXTNAME HDUs).
  • The cache file is also appended into the search's .zip (_append_to_search_zip) — a resumed search's paths.restore() deletes the output dir and re-extracts the zip, so a files/-only cache would be destroyed by the next resume (found empirically during validation).
  • First arrival computes exactly as before and writes; staleness structurally guarded (model/search changes ⇒ new identifier ⇒ fresh dir); NullPaths results always compute; the minimum-percent clip applies after load/compute identically.

Validated with the PyAutoLens leg via the autolens_profiling pipeline_resume instant recipe: per-stage inter-stage resume cost 151s / 130s / 128s → 0.3s / 0.0s / 0.1s.

API Changes

None — no public API changes. Behaviour of galaxy_name_image_dict_via_result_from is identical on first computation; later calls return equal values from disk. New side effect: two FITS cache files written into a result's files/ folder (and its zip) when the result has on-disk output.

Details

Added

  • autogalaxy/analysis/adapt_images/adapt_images.py: private helpers _galaxy_images_cache_path, _galaxy_image_dict_from_cache, _galaxy_image_dict_to_cache, _append_to_search_zip (the last is imported by the PyAutoLens leg).

Changed Behaviour

  • galaxy_name_image_dict_via_result_from: cache-aside on the result's paths; compute-and-write on first arrival, load thereafter.

Migration

  • None required.

Test Plan

  • test_autogalaxy/analysis/test_adapt_images.py — 3 new tests: FITS round-trip equality, poisoned-result cache hit (recompute raises), pathless result always computes.
  • Full test_autogalaxy/ suite green in the task worktree.
  • End-to-end validation via autolens_profiling pipeline_resume (numbers above).

Companion PR: PyAutoLens positions leg (same branch name, link added after creation).

🤖 Generated with Claude Code

galaxy_name_image_dict_via_result_from rebuilds the result's maximum log
likelihood fit (fresh JIT compile + inversion for pixelized fits) on every
call — on a resumed SLaM pipeline this dominates resume overhead
(autolens_profiling#70: ~55s of a 148s resume, more in production).

The raw per-galaxy image dict is now cached into the upstream result's own
files/ folder on first computation (galaxy_images_model.fits /
galaxy_images_snr.fits, FITS layout mirroring the aggregator's adapt_images
artifact) and loaded on every later call. The cache file is also appended
into the search's .zip — a resumed search's paths.restore() wipes the output
dir and re-extracts the zip, so a files/-only cache would be destroyed by
the next resume. Staleness is structurally guarded: model/search changes
produce a new identifier and a fresh output dir. Results with no on-disk
output (NullPaths) always compute. The minimum-percent clip is applied
after load/compute identically, so returned values are unchanged.

Validated via autolens_profiling pipeline_resume (with the PyAutoLens
positions leg): per-stage inter-stage resume cost 151s/130s/128s -> 0.3s/
0.0s/0.1s. Issue: PyAutoGalaxy#502.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Jul 17, 2026
@Jammy2211

Copy link
Copy Markdown
Collaborator Author

Companion PyAutoLens PR: PyAutoLabs/PyAutoLens#619 (merge this PyAutoGalaxy PR first — the PyAutoLens leg imports _append_to_search_zip from it).

@Jammy2211
Jammy2211 merged commit 4761de6 into main Jul 17, 2026
5 checks passed
@Jammy2211
Jammy2211 deleted the feature/slam-resume-fastpath branch July 17, 2026 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pending-release PR queued for the next release build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant