-
Notifications
You must be signed in to change notification settings - Fork 87
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
ListOfConstraints -> ListOfConstraintTypes #357
Conversation
Codecov Report
@@ Coverage Diff @@
## master #357 +/- ##
=======================================
Coverage 96.27% 96.27%
=======================================
Files 36 36
Lines 4723 4723
=======================================
Hits 4547 4547
Misses 176 176
Continue to review full report at Codecov.
|
The change looks good to me. |
Illustrated by the fact I've just spent the last few days writing tests for the MOI API and I mis-remembered the name of the method... |
Maybe Then there is a clear separation between "can I add right now" and "do you even support this constraint type." |
Agreed that would be an improvement from what we do now. |
|
Surely
The type stable way is to check |
There is a point there that having an explicit list of all possible constraint types supported could be problematic and even infinite for |
How about renaming Long and verbose (and has an ugly Other options
|
No it supports everything, if what is not supported by
Why would it be less confusing ? The distinction that should be made is:
It seems to me that the |
I'm going to re-suggest (#295 (comment)) that we remove this concept completely. If a model claims to support a constraint independently of its state, but for some reason the constraint cannot be added right now, I would like to see an error message on |
Copy-only solvers will return |
|
That's fine, they can return errors in that case, and users can work around them. The extra complexity in the API is not worth it, IMO. |
We may keep the current MOI.canaddconstraint!(m::ModelLike, F::Type{<:AbstractFunction}, S::Type{<:AbstractSet}) = MOI.canaddconstraint!(m) && MOI.supports Most solvers will only define |
Could you walk through a realisitc example of why this is important and what would go wrong if |
Suppose that once MOI.supportsconstraint(m::MySolver, ::Type{<:ScalarAffineFunction}, S::Type{<:LessThan}) = true
MOI.supportsconstraint(m::MySolver, ::Type{<:SingleVariable}, S::Type{<:Integer}) = true
MOI.canaddconstraint(m::MySolver) = !m.optimized
MOI.canaddconstraint(m::MySolver, ::Type{<:ScalarAffineFunction}, S::Type{<:LessThan}) = true
MOI.canaddconstraint(m::MySolver, ::Type{<:SingleVariable}, S::Type{<:Integer}) = !m.optimized |
I think it's perfectly fine for the CachingOptimizer to attempt to change the integrality of the variables and then return an error in that case. Users will just need to manually reset the solver. |
The user could be an algorithm and the algorithm could be solver independent where some solvers support the action and some do not. If reset is not called, the algorithm will fail for some solver and if reset is called, the algorithm will unnecessarily reset some solver. |
There's a reason why there's not a single other API that tries to solve this problem. It's hard; we have to make trade-offs at some point.
Overall not worth it to me.
If you want to be on the safe side, always reset the solver. It's ok really. You'll still be able to publish your paper. If that's not good enough, use direct mode and throw errors if the user provides a solver that doesn't support the functionality you need. If that's not good enough, write your own version of caching optimizer that's suited for your application. |
FWIW if you want to rename |
I agree that they are tradeoffs to be made. In the use case I was mentionning can still be solved by the solver caching the integrality changes internally. It is more work but there is also the cost of having If everyone agrees on replacing |
I don't have a problem with
I would change the second definition to "The model supports the constraint type independently of it state" Therefore, what about renaming Maybe also have a fallback so |
I'm also proposing to dump the whole |
The
The first solution would kill the |
It's a problematic definition however. The issue is that The difference between |
what's the status of this particular PR? |
@blegat is probably the best person to comment on this. I'm in favor of |
The renaming is agreed upon but the change of definition would not work because of UniversalFallback for instance. What are the advantages of changing the definition ? |
I don't see a pressing need to change the definition. I support a renaming, maybe to |
Closing this as stale. I'll leave the issue open for now. |
Closes #214
I also propose changing
to
Updated: changed
cansupport
tosupportsconstraint
.