diff --git a/CHANGELOG.md b/CHANGELOG.md index b123d289c..142e81ded 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. ### Deprecated ### Removed ### Fixed +- [#1746](https://github.com/pints-team/pints/pull/1746) Corrected the function signature in the docstring for `OptimisationController.set_callback`. ## [0.6.1] - 2026-03-06 diff --git a/pints/_optimisers/__init__.py b/pints/_optimisers/__init__.py index c0b49de7c..89bbc0fd1 100644 --- a/pints/_optimisers/__init__.py +++ b/pints/_optimisers/__init__.py @@ -882,15 +882,24 @@ def set_callback(self, cb=None): Allows a "callback" function to be passed in that will be called at the end of every iteration. - This can be used for e.g. visualising optimiser progress. + This can be used to provide feedback on progress, but also, for + example, to make detailed study of an optimiser's behaviour. Example:: - def cb(opt): - plot(opt.xbest()) + def cb(iteration, optimiser): + plot(f'Iteration {iteration} is at {optimiser.xbest()}') + opt = pints.OptimisationController(...) opt.set_callback(cb) + The function signature is ``(iteration, optimiser)``, where + ``iteration`` is an integer with the current iteration count, while + ``optimiser`` is a :class:`Optimiser`. Note that in the example above, + ``opt`` is a :class:`OptimisationController`. + + Only one callback function can be set. To unset the callback use + ``set_callback(None)``. """ if cb is not None and not callable(cb): raise ValueError('The argument cb must be None or a callable.')