perf(interferometer): cache curvature_matrix / data_vector on sparse and mapping inversions (#581) - #582
Merged
Conversation
…and mapping inversions (#581) On the NumPy path one figure_of_merit of InversionInterferometerSparse / InversionInterferometerSparseNumba built F twice and D four times, because data_vector, curvature_matrix and curvature_matrix_diag were plain properties read by curvature_reg_matrix, reconstruction and fast_chi_squared (43-50 % of an alma RAL CPU call, autolens_profiling #326). They are now autonerves cached_property, as the imaging inversions' already are; the numba curvature_matrix_diag override and the dense InversionInterferometerMapping data_vector / curvature_matrix follow. An inversion is built per fit, so no invalidation is needed; the preloads.curvature_matrix short-circuit is unchanged. Tests: evaluation-count tests (descriptor-preserving counters plus the underlying operator / numba kernel) assert F == 1 and D == 1 per likelihood for Sparse, SparseNumba (serial + parallel kernel) and Mapping; red on the unfixed source (2 / 2 each). 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
On the NumPy path, a single
figure_of_meritofInversionInterferometerSparseorInversionInterferometerSparseNumbabuilt the curvature matrix F twice and the data vector D four times. The reason is thatdata_vector,curvature_matrixandcurvature_matrix_diagwere plain@propertyattributes, read separately bycurvature_reg_matrix,reconstructionandfast_chi_squared. On RAL CPU (autolens_profiling #326 / PR #328) that repeat work is 43–50 % of every alma / alma_high call.They now use
autonerves.cached_property, the same decorator the imaging inversions already use for these attributes, and those run under jit / vmap / grad. Changes:interferometer/sparse.py:data_vector,curvature_matrix,curvature_matrix_diaginterferometer_numba/sparse.py: thecurvature_matrix_diagoverrideinterferometer/mapping.py:data_vector,curvature_matrix(brought in line withimaging/mapping.py)A new inversion is built for every fit, so the cache never needs invalidating. The
preloads.curvature_matrixshort-circuit is unchanged, and its test still asserts that the injected matrix object is returned as-is.Measured (laptop, sma, indicative; phase-1 harness
interferometer_pixelized_numpy.py, 20 iid instances, 1 thread)The JAX sma Delaunay cell gives FoM -3162.627234758772 both before and after. On a small sparse fixture, the traced graph shrinks from 305 to 272 equations, and jit, vmap and grad values are identical before and after. The quotable RAL CPU re-run (sma / alma / alma_high, both meshes) will land as a separate autolens_profiling PR after this merges. That PR also needs a harness counter that understands
cached_property, because the current counter wraps the attribute in a plainpropertyvia.fget.API Changes
None — internal changes only (internal caching; no public API change). The attribute names, signatures and returned values are unchanged. The only behavioural difference is that repeated reads on the same inversion instance return the cached value instead of recomputing it.
See full details below.
Test Plan
InversionInterferometerSparse,InversionInterferometerSparseNumba(serial and parallel kernel) andInversionInterferometerMapping. They count with wrappers that keep the property type, plus the underlying operator callcurvature_matrix_diag_fromand the numba kernel.pytest test_autoarray: 1736 passedmisc/jax_assertions/fit_interferometer_sparse_operator.py,interferometer/jax_likelihood/rectangular_sparse.py(jit + vmap),interferometer/jax_grad/gradient.py(sparse-path grad) all passHeart readiness: YELLOW, acknowledged by the human 2026-09-27: "manifest drift: hub organism blurb (organs present) — 7 mismatch(es) vs PyAutoMind/repos.yaml; manifest drift: organism-map blocks (generated) — 1 mismatch(es) vs PyAutoMind/repos.yaml; manifest drift: workspace checkouts (manifest ↔ disk) — 1 mismatch(es) vs PyAutoMind/repos.yaml; release validation incomplete: no rehearsal for current source".
Full API Changes (for automation & release notes)
Changed Behaviour
InversionInterferometerSparse.data_vector,.curvature_matrix,.curvature_matrix_diag,InversionInterferometerSparseNumba.curvature_matrix_diag,InversionInterferometerMapping.data_vector,.curvature_matrix— cached per instance (autonerves.cached_property), no longer recomputed on each access. Values are unchanged.Closes #581
Generated by the PyAutoLabs agent workflow.
🤖 Generated with Claude Code