Conversation
…pping_matrix_list apply_over_sampling rebuilt Imaging without sparse_operator (and without noise_covariance_matrix), so applying the sparse operator before over-sampling silently fell back to the dense InversionImagingMapping route. Both are now carried through; neither depends on over-sampling. operated_mapping_matrix_list is now a cached_property (imaging and interferometer), so the dense route convolves / NUFFT-transforms the mapping matrix once per likelihood evaluation instead of twice. apply_mask / apply_noise_scaling warn when they discard a (stale) operator; apply_sparse_operator_cpu gains the convolve_over_sample_size > 1 guard; the sparse methods and apply_noise_scaling carry convolve_over_sample_size_*. DR1 tile: operator-first 1011 -> 169.5 ms (sparse), dense 1166.5 -> 592.8 ms, logL bit-identical. test_autoarray: 1743 passed. Fixes #585 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
Fixes #585. Two performance defects found during the Euclid DR1 campaign:
Imaging.apply_over_samplingrebuilt the dataset without thesparse_operator(and without thenoise_covariance_matrix). Callingapply_sparse_operator[_cpu]()beforeapply_over_sampling()thereforesilently fell back to the dense
InversionImagingMappingroute. Every Euclid DR1vis_pixfit ran densebecause of this. Both attributes are now carried through; neither depends on over-sampling.
operated_mapping_matrix_listwas an uncached@property, so the dense route PSF-convolved (imaging) orNUFFT-transformed (interferometer) the mapping matrix twice per likelihood evaluation. It is now a
cached_propertyon the inversion instance. Inversions are built per evaluation / per JAX trace, so thecache never outlives its inputs.
Adjacent hardening from a sweep of every dataset rebuild:
apply_maskandapply_noise_scalingstill discard an attached operator (it is stale there), but now log awarning instead of dropping it silently.
apply_sparse_operator_cpugains theconvolve_over_sample_size > 1guard thatapply_sparse_operatoralready had.
apply_sparse_operator[_cpu]andapply_noise_scalingcarryconvolve_over_sample_size_*through.Measured on a real DR1 tile (median of 16 evals, 1 thread, logL bit-identical in every comparison):
InversionImagingSparseNumba)API Changes
No signatures change. Behaviour changes:
Imaging.apply_over_samplingnow keepssparse_operatorandnoise_covariance_matrix. Scripts that appliedthe operator first now take the sparse route (same likelihood, faster).
Imaging.apply_mask/apply_noise_scalingwarn when they discard a sparse operator.Imaging.apply_sparse_operator_cpuraisesDatasetExceptionfor a PSF withconvolve_over_sample_size > 1.operated_mapping_matrix_list(imaging and interferometer inversions) is cached per inversion.See full details below.
Test Plan
mainfirst and green after the fix:apply_over_sampling;pytest test_autoarray: 1743 passed, 0 failed.Full API Changes (for automation & release notes)
Changed Behaviour
Imaging.apply_over_sampling(...): carriessparse_operatorandnoise_covariance_matrixinto the returneddataset. Previously both were dropped.
Imaging.apply_mask(...),Imaging.apply_noise_scaling(...): log a warning when an attachedsparse_operatoris discarded.Imaging.apply_noise_scaling(...): carriesconvolve_over_sample_size_lp/convolve_over_sample_size_pixelization.Imaging.apply_sparse_operator(...),Imaging.apply_sparse_operator_cpu(): carryconvolve_over_sample_size_lp/convolve_over_sample_size_pixelization.Imaging.apply_sparse_operator_cpu(): raisesDatasetExceptionwhenpsf.convolve_over_sample_size > 1,matching
apply_sparse_operator.AbstractInversionImaging.operated_mapping_matrix_list,AbstractInversionInterferometer.operated_mapping_matrix_list:property→cached_property.AbstractInversion.operated_mapping_matrix: with a single linear object, returns that object's cachedoperated mapping matrix directly rather than an
hstackcopy.Migration
Known follow-ups (not in this PR):
aggregator/imaging/imaging.py,interferometer.py) do not restorea sparse operator, so reloaded fits run dense.
AbstractDataset.trimmed_after_convolution_from(copy.copy) keeps a stale operator. Its only callers arethe Galaxy/Lens simulators, where no operator is attached.
Generated by the PyAutoLabs agent workflow.
🤖 Generated with Claude Code