Skip to content

BUG: optimize.minimize: set trust-constr success=False when constraints are not satisfied #21407

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

Merged
merged 2 commits into from
Oct 25, 2024

Conversation

CarrascoCesar
Copy link
Contributor

Reference issue

Fixes #18882.

What does this implement/fix?

Previously trust-constr returned success=True (i.e. status equal to 1 or 2) even when the constraints were not satisfied.  Now trust-constr returns success=False and status=4 with message="Constraints are not satisfied."
 A test is implemented in test_minimized_constrained.py to check success=False when constr_violation>gtol.

Additional information

This fix is based in part on the PR created by @ellieLitwack at #18890 (comment), but approaches the solution to the bug in a way that does not require a modification to the stop criteria.  The feedback from @andyfaff to this previous PR was also considered in the creation of this new fix.

…aints are not satisfied

 
Reference issue
Fixes scipy#18882.
 
What does this implement/fix?
Previously trust-constr returned success=True (i.e. status equal to 1 or 2) even when the constraints were not satisfied.  Now trust-constr returns success=False and status=4 with message="Constraints are not satisfied."
A test is implemented in test_minimized_constrained.py to check success=False when constr_violation>gtol.
 
Additional information
This fix is based in part on the PR created by @ellieLitwack at scipy#18890 (comment), but approaches the solution to the bug in a way that does not require a modification to the stop criteria.  The feedback from @andyfaff to this previous PR was also considered in the creation of this new fix.
@github-actions github-actions bot added scipy.optimize defect A clear bug or issue that prevents SciPy from being installed or used as expected maintenance Items related to regular maintenance tasks labels Aug 18, 2024
Copy link
Member

@lucascolley lucascolley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good to me, apologies for the long wait for a review. @andyfaff perhaps you would be able to follow up on your previous comments from the linked PR?

@lucascolley lucascolley changed the title BUG/TST: optimize.minimize: fix trust-constr success=True when constraints are not satisfied BUG/TST: optimize.minimize: set trust-constr success=False when constraints are not satisfied Oct 17, 2024
@lucascolley lucascolley changed the title BUG/TST: optimize.minimize: set trust-constr success=False when constraints are not satisfied BUG: optimize.minimize: set trust-constr success=False when constraints are not satisfied Oct 17, 2024
@lucascolley lucascolley removed the maintenance Items related to regular maintenance tasks label Oct 17, 2024
@lucascolley lucascolley added this to the 1.15.0 milestone Oct 17, 2024
@@ -18,7 +18,8 @@
0: "The maximum number of function evaluations is exceeded.",
1: "`gtol` termination condition is satisfied.",
2: "`xtol` termination condition is satisfied.",
3: "`callback` function requested termination."
3: "`callback` function requested termination.",
4: "Constraints are not satisfied."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the status message can be improved here, currently it doesn't give enough information as to why the status was set to 4.

How about Constraint violation exceeds 'gtol'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are right. Your status message is more clear. I'll go ahead and update it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick question. Should I rebase before attempting another commit? This is my first PR and am not familiar with the process to update an existing commit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to just commit the change on top of your current branch - a reviewer can always 'squash' commits down before merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I just added a new commit with the updated status message.

@andyfaff andyfaff merged commit 6f3a8bc into scipy:main Oct 25, 2024
5 of 6 checks passed
@andyfaff
Copy link
Contributor

Thank you for your contribution @CarrascoCesar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.optimize
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: minimize does not satisfy nonlinear constraint even if keep_feasible=True
3 participants