feat: skip N_vis allocations for sparse fits without non-linear light (Discussion #13) - #637
Merged
Merged
Conversation
…#588) Phase 1 of Discussion PyAutoLabs/13. uses_precomputed_data_term_from decides when the inversion interface may carry data=None (sparse operator with data_term, dataset's own data/noise map, no non-linear light profile); galaxies_to_inversion then never evaluates profile_visibilities or profile_subtracted_visibilities on the likelihood path. Add FitInterferometer.inversion_with_data for output paths and use it in the visualizer. Likelihood bit-equal to before; per-evaluation memory flat in N_vis. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This was referenced Sep 30, 2026
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
PyAutoGalaxy half of Phase 1 of GitHub Discussion https://github.com/orgs/PyAutoLabs/discussions/13 (see PyAutoLabs/PyAutoArray#588 and its PR). On the sparse path a fit with no non-linear light profile still allocated two N_vis arrays per likelihood evaluation:
profile_visibilities(Visibilities.zeros) andprofile_subtracted_visibilities(data - zeros). This PR:uses_precomputed_data_term_from(dataset, galaxies, data, noise_map)(exposed asFitInterferometer._uses_precomputed_data_term): true when the sparse operator carriesdata_term, the data and noise map fitted are the dataset's own, and no galaxy has a non-linear light profile. All checks are identity/type checks, so the branch is fixed at trace time and jit-safe;galaxies_to_inversionthen passesdata=Nonetoaa.DatasetInterface, sofast_chi_squaredreads the cached scalar and neither visibility property is ever evaluated on the likelihood path. Dense-path and light-profile fits are byte-identical to before;FitInterferometer.inversion_with_data: the inversion, or a shallow copy carryingfit.datawhen the inversion ran withdata=None, for output paths (data_subtracted_dict→subplot_of_mapper). The visualizer uses it.Witness (1e5 vis NUFFT, 616-pixel mask, 15x15 rectangular mesh,
InversionInterferometerSparseNumba): log_evidence one-shot vs chunked operator 1.8e-16 rel; predicate on vs off bit-equal; tracemalloc peak perfigure_of_merit3.19 MB on vs 7.59 MB off at 1e5 and 3.21 MB vs 21.99 MB at 4e5 (flat in N_vis with the predicate on); 9.8 ms vs 11.2 ms per evaluation.PyAutoLens has its own
FitInterferometer/tracer_to_inversionand still passes the subtracted data, so it is unchanged here (follow-up filed in Mind).API Changes
Additive. New public names
autogalaxy.interferometer.fit_interferometer.uses_precomputed_data_term_fromandFitInterferometer.inversion_with_data. Behaviour change: on the sparse path with no non-linear light profile,fit.inversion.dataset.datais nowNone(usefit.inversion_with_dataorfit.datafor outputs). Requires the PyAutoArray PR (DatasetInterface(data=None),sparse_operator.data_term).See full details below.
Test Plan
pytest test_autogalaxy— 1262 passedpytest test_autogalaxy/interferometer— 43 passed (new: interface getsdata=None, novisibilities_from/Visibilities.zeroscall duringfigure_of_merit, both visibility properties unevaluated; sparse pixelization-only and light+pixelization fits match dense at rel 1e-8; scalarnoise_normalization== array;inversion_with_datashares the reconstruction;jax.jitsparse fit matches numpy)pytest PyAutoLens/test_autolens/interferometeragainst these branches — 25 passedFull API Changes (for automation & release notes)
Added
autogalaxy.interferometer.fit_interferometer.uses_precomputed_data_term_from(dataset, galaxies, data, noise_map) -> boolFitInterferometer._uses_precomputed_data_term(private property)FitInterferometer.inversion_with_data -> Optional[aa.AbstractInversion]— inversion carrying the fitted data for output/plot pathsChanged Behaviour
FitInterferometer.galaxies_to_inversionpassesdata=Nonetoaa.DatasetInterfacewhenuses_precomputed_data_term_from(...)holds (sparse operator withdata_term, dataset's own data/noise map, no non-linear light profile);profile_visibilities/profile_subtracted_visibilitiesare then never evaluated on the likelihood pathinterferometer/model/visualizer.pypassesfit.inversion_with_datato the inversion plotterMigration
fit.inversion.data/fit.inversion.data_subtracted_dicton a sparse pixelization-only fit should usefit.inversion_with_data(orfit.data).Generated by the PyAutoLabs agent workflow.
🤖 Generated with Claude Code