-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
add termination callback to SPSA #6839
Conversation
1224260
to
f5c204c
Compare
That's an interesting addition 👍🏻 could you make sure that QN-SPSA (which derives from SPSA) is adjusted accordingly and that the termination callback is included in the settings? |
…erra into feat/spsa_termination
releasenotes/notes/SPSA-termination-callback-a1ec14892f553982.yaml
Outdated
Show resolved
Hide resolved
@Cryoris Addressed the review comments |
releasenotes/notes/SPSA-termination-callback-a1ec14892f553982.yaml
Outdated
Show resolved
Hide resolved
releasenotes/notes/SPSA-termination-callback-a1ec14892f553982.yaml
Outdated
Show resolved
Hide resolved
An ability to allow SPSA to stop ahead of max iters has often asked for more than once but finding suitable criteria was not so easy. This seems like a neat way to address that! |
@nonhermitian I know you had commented in the past about terminating SPSA prior to max iters and there was an issue at one point. I believe you mentioned some thoughts around heuristics for termination. Do you think this mechanism can cater to what you had in mind? |
It looks like it can be quite generic so yeah I would think so. It was hard to find a reliable way to terminate, but this would allow further exploration of that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for this contribution - for the idea, improving the optimizers with it, and for your patience/effort in sorting out all the comments and suggestions to complete this.
Co-authored-by: Julien Gacon <gaconju@gmail.com>
…erra into feat/spsa_termination
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the effort @peendebak!
* add termination callback to SPSA * add release notes * fix linting * update QNSPSA for termination_callback * fix linting * fix linting * fix typo * add termination callback to settings * fix tests * add example to release notes * add example * fix release notes * address review comments * whitespae * address review comments * address review comments * rename to termination_checker; pass Optimizer as argument * complete renames * Update qiskit/algorithms/optimizers/spsa.py Co-authored-by: Julien Gacon <gaconju@gmail.com> * address review comments * fix pylint * trigger build * fix signature of callback * fix pylint * fix pylint * Update qiskit/algorithms/optimizers/spsa.py Co-authored-by: Julien Gacon <gaconju@gmail.com> * update name of callback signature * fix pylint Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com> Co-authored-by: Julien Gacon <gaconju@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* add termination callback to SPSA * add release notes * fix linting * update QNSPSA for termination_callback * fix linting * fix linting * fix typo * add termination callback to settings * fix tests * add example to release notes * add example * fix release notes * address review comments * whitespae * address review comments * address review comments * rename to termination_checker; pass Optimizer as argument * complete renames * Update qiskit/algorithms/optimizers/spsa.py Co-authored-by: Julien Gacon <gaconju@gmail.com> * address review comments * fix pylint * trigger build * fix signature of callback * fix pylint * fix pylint * Update qiskit/algorithms/optimizers/spsa.py Co-authored-by: Julien Gacon <gaconju@gmail.com> * update name of callback signature * fix pylint Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com> Co-authored-by: Julien Gacon <gaconju@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Summary
The
SPSA
optimizer is suitable for noisy optimization if evaluation of the cost function is expensive. The current implementation terminates after the maximum number of iterations, even if the optimizer already converged to a local optimum.This PR adds a callback
termination_callback
that can be implemented by the user to abort the optimization.An example:
Details and comments
For noisy optimization a simple termination criterium such as a
tolerance
on decrease of the objective function is not suitable. For this reason a callback is specified so that the user can choose which termination criterium to use.To keep the number of objective evaluations as low as possible, the internal evaluations of the loss function have been used to provide an estimate of the objective value.