Skip to content
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

Error when solving non-DCP problems #523

Merged
merged 14 commits into from Dec 31, 2023
Merged

Error when solving non-DCP problems #523

merged 14 commits into from Dec 31, 2023

Conversation

ericphanson
Copy link
Collaborator

Noticed

WARNING: Method definition emit_dcp_warnings() in module Convex at /Users/eph/Convex.jl/src/Convex.jl:71 overwritten in module Main at /Users/eph/Convex.jl/test/test_utilities.jl:519.
WARNING: Method definition emit_dcp_warnings() in module Main at /Users/eph/Convex.jl/test/test_utilities.jl:519 overwritten at /Users/eph/Convex.jl/test/test_utilities.jl:521.

while running the tests for #522. Using method invalidation for this is silly as there's no reason to recompile code; checking a global ref is very fast compared to everything else Convex is doing. Also, this fix is non-breaking as the previous advice to invalidate the method will continue to work here.

Copy link

codecov bot commented Dec 29, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (819d728) 92.26% compared to head (0679448) 92.30%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #523      +/-   ##
==========================================
+ Coverage   92.26%   92.30%   +0.03%     
==========================================
  Files          86       86              
  Lines        5300     5301       +1     
==========================================
+ Hits         4890     4893       +3     
+ Misses        410      408       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@odow odow left a comment

Choose a reason for hiding this comment

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

I have an alternative suggestion: that instead of a warning, we emit a hard error. This is what CVX(py) does.

I can see so many people ignoring the warnings. Convex is for DCP. There are plenty of other options if people don't want to use DCP.

@ericphanson ericphanson changed the title use a ref to control DCP warnings error by default for non-DCP problems Dec 29, 2023
@ericphanson
Copy link
Collaborator Author

That's a good idea, I've made those changes here. I've still left an opt-out in case there are rare cases in which it can be useful. I chose not to mention the opt-out in the error message since I don't want folks turning to it without understanding all the implications.

src/dcp.jl Outdated Show resolved Hide resolved
docs/src/advanced.md Outdated Show resolved Hide resolved
src/Convex.jl Outdated

Convex.emit_dcp_warnings() = false
to (globally) allow non-DCP problems to be solved. Note that if a problem is not DCP, the solution obtained by Convex.jl can be wildly incorrect (even if the solution status is `OPTIMAL`!).
Copy link
Member

Choose a reason for hiding this comment

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

Is there a practical use-case for allowing this? cc @mlubin

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I remember someone using it for alternating minimization. It could be something where they were going to fix a variable but hadn’t yet and the error occurs too early (when you construct the expression not when you solve the problem). The early errors should give more useful stacktraces though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

actually something weird with the current place the errors are thrown is that it is only when you call vexity. This happens during problem solving so we at least always throw then. But it doesn't happen when you construct the expression, unless you show it, which does check the vexity (to print it). So I think this isn't ideal, since you end up with different-seeming behavior in the REPL (as it shows things).

Copy link
Member

Choose a reason for hiding this comment

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

What about just erroring on optimize!?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok, I've made that change, and removed the opt-out

src/dcp.jl Outdated Show resolved Hide resolved
ericphanson and others added 2 commits December 29, 2023 23:18
Co-authored-by: Oscar Dowson <odow@users.noreply.github.com>
test/test_utilities.jl Outdated Show resolved Hide resolved
@ericphanson ericphanson changed the title error by default for non-DCP problems error when solving non-DCP problems Dec 30, 2023
@odow odow changed the title error when solving non-DCP problems Error when solving non-DCP problems Dec 30, 2023
src/dcp.jl Outdated Show resolved Hide resolved
src/solution.jl Outdated
@@ -52,6 +52,10 @@ function solve!(p::Problem, optimizer_factory; silent_solver = false)
MOI.set(model, MOI.Silent(), true)
end

if vexity(p) == NotDcp()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this isn’t quite right actually, we need to check for eg concave minimization problems

Copy link
Member

@odow odow Dec 30, 2023

Choose a reason for hiding this comment

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

Or at least, this is right, but there are other cases.

@ericphanson ericphanson merged commit 78c0183 into master Dec 31, 2023
10 checks passed
@ericphanson ericphanson deleted the dcp-warnings branch December 31, 2023 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants