perf: batch MGE linear-func PSF convolution on the numpy path (PyAutoArray#496 phase 1) - #588
Merged
Merged
Conversation
Phase 1 of the numba CPU likelihood speed restoration (PyAutoLabs/PyAutoArray#496). LightProfileLinearObjFuncList.operated_mapping_matrix_override convolved each linear light profile separately (60 calls for an MGE, each rebuilding the convolver state). For xp is np and convolve_over_sample_size == 1 it now stacks the profile images and blurring images and calls Convolver.convolved_mapping_matrix_via_real_space_np_from once. The JAX and oversampled branches keep the per-profile loop. Bitwise identical to the loop (same scattered frame, same scipy convolution). MGE-60 operated matrix on the cpu_fast_modeling route: hst 1.11 s -> 0.30 s, euclid 0.68 s -> 0.125 s (memo disabled, fresh FitImaging per call). Tests: batched vs per-profile columns to 1e-13 with a bright Gaussian at the mask edge and a non-symmetric kernel; blurring-mask slim ordering matches the ConvolverState frame. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N6xyNMYmffpHodBrkc2d91
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
Companion PR: PyAutoLabs/PyAutoArray#497
Phase 1 of the numba CPU sparse-operator likelihood speed restoration (PyAutoLabs/PyAutoArray#496, epic
numba-cpu-likelihood).LightProfileLinearObjFuncList.operated_mapping_matrix_overrideconvolved each linear light profile with its ownpsf.convolved_image_fromcall — 60 calls for an MGE, each rebuilding the convolver state. Forxp is npandconvolve_over_sample_size == 1it now stacks the profile and blurring images into(pixels, N)matrices and makes oneConvolver.convolved_mapping_matrix_via_real_space_np_fromcall. The JAX and oversampled branches keep the per-profile loop.The batched call scatters into the same
ConvolverStateframe the loop already used, so the result is bitwise identical (verified:(N_pix, 60)matrices and end-to-endFitImaging.log_likelihoodmax abs diff 0.0). The blurring-mask slim ordering was verified to match the state's derived blurring mask across 8+ configurations (pure translation) and is pinned by a test.Pairs with the PyAutoArray PR (state reuse + caching + pair loop); independently mergeable.
Measured (memo disabled, fresh
FitImagingper call, OMP=1): MGE-60 operated matrix on thecpu_fast_modeling.pyroute — hst 1.11 s → 0.30 s (3.7×), euclid 0.68 s → 0.125 s (5.4×). hst pinned log-likelihood unchanged.API Changes
None — internal changes only.
See full details below.
Test Plan
pytest test_autogalaxy— 1131 passedtest__operated_mapping_matrix_override__batched_numpy_path__matches_per_profile_convolution,test__operated_mapping_matrix_override__blurring_mask_ordering_matches_convolver_state(test_autogalaxy/profiles/light/linear/test_abstract.py)Full API Changes (for automation & release notes)
Changed Behaviour
LightProfileLinearObjFuncList.operated_mapping_matrix_override— numpy, non-oversampled path is computed in one batched convolution; value identical.Generated by the PyAutoLabs agent workflow.
🤖 Generated with Claude Code
https://claude.ai/code/session_01N6xyNMYmffpHodBrkc2d91