Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions pints/_optimisers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down
Loading