Skip to content

ENH: add callback to optimize.least_squares #22231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 2, 2025
Merged

Conversation

andyfaff
Copy link
Contributor

@andyfaff andyfaff commented Jan 2, 2025

Supercedes #21722. It was going to be difficult to append to that PR, fork wasn't called scipy, diff was on main not a feature branch.

This PR retains authorship.

vpecanins and others added 11 commits October 16, 2024 02:59
Add a new optional parameter `callback` to least_squares.
A user-defined function that is called on each iteration, can stop
optimization by returning True or raising StopIteration.
Same signature and API as in eg. scipy.optimize.differential_evolution.
Only implemented for trf and dogleg methods so far.
Callback for least_squares
@github-actions github-actions bot added scipy.optimize enhancement A new feature or improvement labels Jan 2, 2025
@andyfaff
Copy link
Contributor Author

andyfaff commented Jan 2, 2025

The PR doesn't halt if the callback returns True. Most of the other minimize methods don't do that, and it seems more Pythonic to raise a StopIteration.

@andyfaff andyfaff merged commit 34a4bbf into scipy:main Jan 2, 2025
38 checks passed
@andyfaff andyfaff deleted the call branch January 2, 2025 20:35
@j-bowhay j-bowhay added this to the 1.16.0 milestone Jan 2, 2025
@lucascolley lucascolley added the needs-release-note a maintainer should add a release note written by a reviewer/author to the wiki label Jan 31, 2025
@lucascolley lucascolley removed the needs-release-note a maintainer should add a release note written by a reviewer/author to the wiki label Jun 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature or improvement scipy.optimize
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants