Skip to content

Add BatchLM fitter to perform many fits simultaneously#298

Merged
ConnorStoneAstro merged 8 commits intodevfrom
batchlm
Apr 2, 2026
Merged

Add BatchLM fitter to perform many fits simultaneously#298
ConnorStoneAstro merged 8 commits intodevfrom
batchlm

Conversation

@ConnorStoneAstro
Copy link
Copy Markdown
Member

Batching fits gives huge compute gains. The LM fitter for the batched version is slightly simplified to account for the fact that it is running many fits in parallel, and so should generally be used for simpler models. But that is exactly the use case for batching, many small simple models to be fit at once.

Copilot AI review requested due to automatic review settings April 2, 2026 19:44
@ConnorStoneAstro ConnorStoneAstro added feat Introduces a new feature to the codebase perf A code change that improves performance labels Apr 2, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a batched Levenberg–Marquardt (LM) optimizer to efficiently fit many small, similar models/images in parallel, and documents how to use batched images and fitting in the tutorials.

Changes:

  • Added BatchLM optimizer to run LM fits across a TargetImageBatch simultaneously.
  • Extended LM functional utilities to support batch-wise NLL/gradient/Hessian and added batch_lm_step.
  • Updated tutorial notebook to demonstrate creating TargetImageBatch and fitting it with BatchLM.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
docs/source/tutorials/ImageTypes.ipynb Adds a new “Batch Images” tutorial section and a runnable BatchLM example.
astrophot/models/batch_model_object.py Uses WCS fields from the windowed working_image for batched scene evaluation.
astrophot/fit/lm.py Improves invalid-likelihood error messaging and relies on BaseOptimizer for max_iter.
astrophot/fit/func/lm.py Updates NLL/linear algebra helpers for batch support; adds rho() and batch_lm_step().
astrophot/fit/func/init.py Exposes batch_lm_step from the fit function namespace.
astrophot/fit/batch_lm.py New BatchLM fitter implementation (forward/jacobian vmaps, batched LM stepping, uncertainty updates).
astrophot/fit/init.py Exports BatchLM in the public astrophot.fit API.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ConnorStoneAstro ConnorStoneAstro merged commit e85be4c into dev Apr 2, 2026
11 of 12 checks passed
@ConnorStoneAstro ConnorStoneAstro deleted the batchlm branch April 2, 2026 20:09
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 2, 2026

Codecov Report

❌ Patch coverage is 79.64072% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.17%. Comparing base (ac7b90a) to head (c83aff3).
⚠️ Report is 25 commits behind head on dev.

Files with missing lines Patch % Lines
astrophot/fit/batch_lm.py 76.52% 27 Missing ⚠️
astrophot/fit/func/lm.py 84.78% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #298      +/-   ##
==========================================
- Coverage   92.37%   91.17%   -1.21%     
==========================================
  Files         117      113       -4     
  Lines        5785     6199     +414     
==========================================
+ Hits         5344     5652     +308     
- Misses        441      547     +106     
Flag Coverage Δ
unittests 91.17% <79.64%> (-1.21%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat Introduces a new feature to the codebase perf A code change that improves performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants