-
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
overload MOI.set & supports for ConstraintAttribute in bridgeoptimizer #699
Conversation
Codecov Report
@@ Coverage Diff @@
## master #699 +/- ##
=========================================
- Coverage 95.26% 95.1% -0.17%
=========================================
Files 54 54
Lines 5597 5618 +21
=========================================
+ Hits 5332 5343 +11
- Misses 265 275 +10
Continue to review full report at Codecov.
|
These two methods are indeed missing, thanks for the PR! However, the implementation you suggest will only work if the constraint is not bridged, the implementation should branch on whether it is bridged or not, see, e.g.: |
So now I have to implement starting values for constraint bridges and the test should be something like MOI.set(mock_optimizer, ConstraintPrimalStart(), index_of_a_bridged_constraint, value) and when I'll do MOI.get(mock_optimizer, ConstraintPrimalStart(), index_of_a_bridged_constraint) I should be able to retrieve Did I understand ? Where should I do the tests ? |
You can for instance implement it to |
src/Bridges/bridgeoptimizer.jl
Outdated
function MOI.supports(b::AbstractBridgeOptimizer, attr::MOI.ConstraintName, | ||
Index::Type{<:CI}) | ||
Index::Type{CI{F, S}}) where {F,S} |
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.
You can leave <:CI
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.
Julia throws an "ambiguous name" method error if I leave <:CI
.
Hi, I try writing a basic test : struct FlipSign <: MOI.AbstractConstraintAttribute end
MOI.set(bridged_mock, FlipSign(), ci, true)
@test MOI.get(bridged_mock, FlipSign(), ci) The constraint is bridged so it calls But I'm stuck because I'm not sure what is going on here. What should I do with this constraint bridge? Should I overload MOI.set for all types of constraint bridge? |
Yes an set method should be added for every bridge. |
Let's add the tests in a separate PR (#719), thanks for the contribution ! |
Hi, this PR follows my message in gitter.
I'm working on a package that creates variable/constraint attributes in the JuMP model. Then, another package retrieves these attributes through the MOI interface. In the second package, I overloaded
MOI.set
andMOI.get
to copy/get variable & constraint attributes.These are the definitions of MOI.set & MOI.get in my packages :
During the copy process,
MOI.set
ofVariableAttribute
receives aMOIU.CachingOptimizer
as first argument whereasMOI.set
ofConstraintAttribute
receives aMOIU.Bridges.LazyBridgeOptimizer
. Since LazyBridge is not a subtype of UniversalFallback, MOI throws an error. Looking in file bridgeoptimizer.jl, the following functions are defined forVariableAttribute
but not forConstraintAttribute
.I overloaded
MOI.set
forConstraintAttributes
in bridge optimizer to pass theMOIU.CachingOptimizer
as first argument.I also overloaded
MOI.support
because there is no definition of it forConstraintAttribute
. However, I'm not sure of it is needed and I don't know how to test it. (I can get the attributes without overloading supports in my packages).I can retrieve constraints attributes with these changes but is this the reason of my bug?