From 9dc92428377743586066b9203dfc1044119ce200 Mon Sep 17 00:00:00 2001 From: Michael Clerx Date: Thu, 15 Oct 2026 13:12:08 +0100 Subject: [PATCH 1/4] Updated OptimisationController.set_callback() docstring. Fixes #1745. --- pints/_optimisers/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pints/_optimisers/__init__.py b/pints/_optimisers/__init__.py index c0b49de7c..1502d3bdc 100644 --- a/pints/_optimisers/__init__.py +++ b/pints/_optimisers/__init__.py @@ -882,15 +882,18 @@ 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(iter, opt): + plot(f'Iteration {iter} is at {opt.xbest()}') opt.set_callback(cb) + Here, ``iter`` is the current iteration count, and ``opt`` is the + optimiser used by the controller (as returned by :meth:`optimiser()`). """ if cb is not None and not callable(cb): raise ValueError('The argument cb must be None or a callable.') From efc35ab60bfef8488e1a2544b6cff574293b0032 Mon Sep 17 00:00:00 2001 From: Michael Clerx Date: Thu, 15 Oct 2026 13:13:43 +0100 Subject: [PATCH 2/4] Updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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 From 77bb3d4596619766708fe74e00889e751c6014f4 Mon Sep 17 00:00:00 2001 From: Michael Clerx Date: Thu, 15 Oct 2026 13:26:37 +0100 Subject: [PATCH 3/4] Another improvement to docstring for set_callback --- pints/_optimisers/__init__.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pints/_optimisers/__init__.py b/pints/_optimisers/__init__.py index 1502d3bdc..5aff51060 100644 --- a/pints/_optimisers/__init__.py +++ b/pints/_optimisers/__init__.py @@ -887,13 +887,16 @@ def set_callback(self, cb=None): Example:: - def cb(iter, opt): - plot(f'Iteration {iter} is at {opt.xbest()}') + def cb(iteration, optimiser): + plot(f'Iteration {iteration} is at {optimiser.xbest()}') + opt = pints.OptimisationController(...) opt.set_callback(cb) - Here, ``iter`` is the current iteration count, and ``opt`` is the - optimiser used by the controller (as returned by :meth:`optimiser()`). + 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`. """ if cb is not None and not callable(cb): raise ValueError('The argument cb must be None or a callable.') From d4c6584d5237ae2ce73d79d8dac4afdcb1cc6d74 Mon Sep 17 00:00:00 2001 From: Michael Clerx Date: Thu, 15 Oct 2026 13:28:04 +0100 Subject: [PATCH 4/4] Another improvement to docstring for set_callback --- pints/_optimisers/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pints/_optimisers/__init__.py b/pints/_optimisers/__init__.py index 5aff51060..89bbc0fd1 100644 --- a/pints/_optimisers/__init__.py +++ b/pints/_optimisers/__init__.py @@ -897,6 +897,9 @@ def cb(iteration, optimiser): ``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.')