-
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
Raise error for missing bounds in optimizer SNOBFIT #8638
Conversation
Raise error for invalid `None`s in bounds of optimizer SNOBFIT
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the the following people are requested to review this:
|
Thanks for the contribution @cpossel! Could you add a test that checks this error is correctly raised? You could add it to and check e.g. the following for an example of how to check that a code raises an error: |
Pull Request Test Coverage Report for Build 3054844486
💛 - Coveralls |
@Cryoris Test for failing SNOBFIT is added. |
I need to add the scikit-quant package to the requirements file in order to fix the error |
There is a unit test for the scikit-quant optimizers BOBYQA, SNOBFIT, IMFIL https://github.com/Qiskit/qiskit-terra/blob/main/test/python/algorithms/optimizers/test_optimizers_scikitquant.py but I don't think we have ever run it in CI. Any additional test should be in this file. The documentation notes this on scikit-quant: |
The test cases in test_optimizers.py follow the logic to test the proper functioning of the optimizer itself while test_optimizers_scikitquant.py uses a holistic approach i.e. testing for the correct output of a VQE calculation with the chosen optimizer. test_optimizers_scikitquant.py uses the Making the test case run without installing the third party package would still be possible catching the |
I am not sure I am fully following. The unit test method is just checking the bounds. All you need is to call minimize on it and pass some dummy objective function since it should fail immediately right. The run_optimizer is way more than is needed since that was done to check the optimizer could find the minimum of a function to check its correct working. Your test just checks that it fails as expected given an invalid bounds on the minimize right. To me it would be better to include that in the test suite for those 3. Yes it does use VQE - maybe finding some more straightforward function did not test the optimizers adequately. Ideally we would use as little other code as was needed to check their correctness - but I know sometimes things just don't work out. |
Maybe my thoughts were a little too over-complicated... With your suggestions I added a minimal test function to |
As far as I understand the output of the CI tests the test's failure is due to some CI configuration and not due to the code changes. |
The tests are all passing now - I see that the last commit had a test failure that's since been re-run, and it was just caused by a dodgy network connection / overallocated hardware on Azure's side. Nothing to worry about - it's just transient and we don't have control over it. |
Looks good, but can you add a release note for this bug fix. |
@woodsp-ibm Okay, I added the release note. Is anything else missing? |
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 contribution. All looks good to me now.
* Update snobfit.py Raise error for invalid `None`s in bounds of optimizer SNOBFIT * Add SNOBFIT test for missing bounds * Move refactored SNOBFIT test for missing bounds to test_optimizers_scikitquant.py * Remove obsolete SNOBFIT import * Add release note Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* Update snobfit.py Raise error for invalid `None`s in bounds of optimizer SNOBFIT * Add SNOBFIT test for missing bounds * Move refactored SNOBFIT test for missing bounds to test_optimizers_scikitquant.py * Remove obsolete SNOBFIT import * Add release note Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Summary
Raise error for invalid
None
s in bounds (i.e. missing bounds) of optimizer SNOBFIT.Closes #8580
Details and comments
Function signature is misleading, allowing None for bounds. The resulting error is non-intuitive. So, this PR adds raising a more concise error message. This includes also
None
values within the bounds list (can happen e.g. with ansatz UCCSD).