-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
BUG: trust-constr evaluates function out of bounds #11712
Conversation
Ohh, Sorry for taking soo long to respond. I not entirely sure this solution is better than #11650. At least not in principle. #11650 -> Create a patch that in I think we should try, as much as possible, to abstract away details about the differentiation from the implementation of the optimization algorithms. This make it easier to understand the code and make both the abstraction DifferentiableFunction and the optimization algorithm easier to reuse and combine in different ways. Simply returning np.inf when outside the bounds would not fix the problem? I suggested that in #11650 |
@antonior92 Perhaps I'm overlooking something, it's been some time since I looked at this, but I don't see how to do that without modifying the I think, in principle, you could simply return inf when an out of bounds evaluation is attempted in the |
Updating bug fix branch
@antonior92 I have some time to work on this bug and I'd like to get it resolved. I'm looking back over at what has been attempted thus far. As far as I can tell, what is implemented in this PR is the most straightforward way to ensure that a bound constraint violating function evaluation is not attempted. In this PR, we check for feasibility within the interior point algorithm and return inf if the bound constraints are violated. We could instead make this the responsibility of the
This PR implements the check in tr_interior_point.py, line 82. Once we go into |
One needs to be careful when |
Approx_derivative will obey any bounds for numerical differentiation, but requesting gradients for an |
Agreed, I think this is why it makes sense to keep this fix local to the interior point algorithm, at least for now. I've not observed the bug with other optimizers. |
Hi all, it has been some time since I last checked this thread. So correct me if I miss something. But I think I have never suggested changing In this sense, this is very much a problem of Anyway, I still think trying to fix it here in
Have you tried, just changing:
to:
I totally agree with @andyfaff that we need to be very careful when changing the ``_differentiable_functions.py`. But I think a punctual change is probably the best option here... |
@antonior92 Thanks for your comments. I briefly tried your suggested change, and it is not working as-is. First, as noted above, the variable that would allow us to check the bounds is not an instance variable of the
Then I implement your suggested change:
We still error out in the next line in
In the call to the constraint evaluation, it looks like we are using the
and
This allows us to get past both initial failing calls to self.fun() and self.constr(). However, we error out at a different point in the next sequence of calls:
Do we want to just add checks for constraint violations at every possible point in |
Thank you for trying it out so quickly @dpoerio.
I agree that adding checks everywhere is definitely not a good solution. I still think the problem is general from I agree that your solution is a clean and easy one. Since it solves the problem where it is most apparent I think we can merge it. @andyfaff what do you think? |
I went ahead and resolved the merge conflicts, but I noticed that PEP8 issues will need to be resolved. I can do that. Otherwise, @andyfaff did this look good to you? It seemed to have Antonio's approval. If you're happy with the approach - at least if it's better than not having it at all - it might be worth merging. |
Hi, I agree with merging it |
Thanks @antonior92. Normally I'd hesitate to make the objective/constraints non-smooth like this, but it sounds like it is compatible with the algorithm and fixes the bug - plus it has the support of the The CI failure looked unrelated, so I went ahead and merged. |
@mdhaber It looks like this is causing a failure at the CI for ARM Macs. I guess this is not tested for PRs? I don't have the hardware handy to debug this (without provisioning a cloud machine at least). On first pass, it looks like just a warning, maybe caused by numerous function evaluations returning inf at multiple points beyond the bounds, making the function appear constant/linear.
Perhaps we should revert until this can be debugged/investigated? |
…ut of bounds (scipy#11712)" This reverts commit 48c3dc8.
MAINT: optimize.minimize: revert gh-11712 to fix macos_arm64_test
Reference issue
Attempts to close #11649, different approach than #11650
What does this implement/fix?
Finite difference bounds are now passed to tr_interior_point, and responsibility for checking feasibility of the current solution is in the BarrierSubproblem class. If the current solution is out of bounds, the objective and constraint functions are not evaluated and are set to inf and 0, respectively. This causes the trust region to shrink until the current solution is feasible again.