Add BatchLM fitter to perform many fits simultaneously#298
Add BatchLM fitter to perform many fits simultaneously#298ConnorStoneAstro merged 8 commits intodevfrom
Conversation
There was a problem hiding this comment.
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
BatchLMoptimizer to run LM fits across aTargetImageBatchsimultaneously. - Extended LM functional utilities to support batch-wise NLL/gradient/Hessian and added
batch_lm_step. - Updated tutorial notebook to demonstrate creating
TargetImageBatchand fitting it withBatchLM.
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.
Codecov Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.