overload MOI.set & supports for ConstraintAttribute in bridgeoptimizer#699
overload MOI.set & supports for ConstraintAttribute in bridgeoptimizer#699blegat merged 7 commits intojump-dev:masterfrom
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.
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.setandMOI.getto copy/get variable & constraint attributes.These are the definitions of MOI.set & MOI.get in my packages :
During the copy process,
MOI.setofVariableAttributereceives aMOIU.CachingOptimizeras first argument whereasMOI.setofConstraintAttributereceives 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 forVariableAttributebut not forConstraintAttribute.I overloaded
MOI.setforConstraintAttributesin bridge optimizer to pass theMOIU.CachingOptimizeras first argument.I also overloaded
MOI.supportbecause 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?