-
Notifications
You must be signed in to change notification settings - Fork 92
Support of bridges with external sets/funcs #510
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
Support of bridges with external sets/funcs #510
Conversation
Yes, you can create unique field names with |
src/Bridges/singlebridgeoptimizer.jl
Outdated
@@ -45,7 +45,7 @@ macro bridge(modelname, bridge, ss, sst, vs, vst, sf, sft, vf, vft) | |||
esc(quote | |||
$MOIU.@model $bridged_model_name $ss $sst $vs $vst $sf $sft $vf $vft | |||
const $modelname{T, OT<:MOI.ModelLike} = $MOIB.SingleBridgeOptimizer{$bridge{T}, $bridged_model_name{T}, OT} | |||
is_bridged(::$modelname, ::Type{<:$bridged_funs}, ::Type{<:$bridged_sets}) = true | |||
MathOptInterface.Bridges.is_bridged(::$modelname, ::Type{<:$bridged_funs}, ::Type{<:$bridged_sets}) = true |
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 use $MOIB.is_bridged
I guess I should have tested first. I was surprised that this is not needed and the reason is: julia> struct abc
my.name::String
end
ERROR: syntax: field name "my.name" is not a symbol As Expected. But using metaprogramming you can put a dot inside the name of a field, although it s not clean at all. julia> s = Symbol("my.name")
Symbol("my.name")
julia> code = quote
struct abc
$(s)::String
end
end
quote
#= REPL[24]:2 =#
struct abc
#= REPL[24]:3 =#
my.name::String
end
end
julia> eval(code)
julia> abc("Bob")
abc("Bob") Maybe I will transform it to underscore to keep readable names? |
Codecov Report
@@ Coverage Diff @@
## master #510 +/- ##
==========================================
+ Coverage 95.59% 95.62% +0.02%
==========================================
Files 46 46
Lines 4700 4704 +4
==========================================
+ Hits 4493 4498 +5
+ Misses 207 206 -1
Continue to review full report at Codecov.
|
@IssamT The fields are not shown in printing so I have never seen the fields in fact. If you can make it work with underscores, it is fine too. |
src/Utilities/model.jl
Outdated
# (:Zeros) -> :(MOI.Zeros) | ||
_moi(s::Symbol) = _mod(MOI, s) | ||
_moi(s::Union{Symbol,Expr}) = _mod(MOI, s) | ||
_set(s::SymbolSet) = _moi(s.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.
Let's remove _moi
and _mod
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.
Looks good, thanks ! :)
src/Utilities/model.jl
Outdated
@@ -393,12 +393,12 @@ abstract type Constraints{F} end | |||
|
|||
abstract type SymbolFS end | |||
struct SymbolFun <: SymbolFS | |||
s::Symbol | |||
s::Union{Symbol,Expr} |
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.
Nit: missing a space Union{Symbol, Expr}
src/Utilities/model.jl
Outdated
@@ -579,14 +577,14 @@ macro model(modelname, ss, sst, vs, vst, sf, sft, vf, vft) | |||
end | |||
|
|||
for (func, T) in ((:_add_constraint, CI), (:_modify, CI), (:_delete, CI), (:_getindex, CI), (:_getfunction, CI), (:_getset, CI), (:_getnoc, MOI.NumberOfConstraints)) | |||
funct = _mod(MOIU, func) | |||
funct = func |
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.
Why have this extra variable?
src/Utilities/model.jl
Outdated
|
||
end) | ||
end | ||
esc(code) |
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.
Style: missing a return
test/runtests.jl
Outdated
(VectorAffineFunction, VectorQuadraticFunction)) | ||
(MOI.ZeroOne, MOI.Integer), | ||
(MOI.EqualTo, MOI.GreaterThan, MOI.LessThan, MOI.Interval, MOI.Semicontinuous, MOI.Semiinteger), | ||
(MOI.Reals, MOI.Zeros, MOI.Nonnegatives, MOI.Nonpositives, MOI.SecondOrderCone, MOI.RotatedSecondOrderCone, MOI.GeometricMeanCone, MOI.ExponentialCone, MOI.DualExponentialCone, MOI.PositiveSemidefiniteConeTriangle, MOI.PositiveSemidefiniteConeSquare, MOI.RootDetConeTriangle, MOI.RootDetConeSquare, MOI.LogDetConeTriangle, MOI.LogDetConeSquare), |
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.
Style: wrap really long lines? (Lots of places with this in the model definitions.)
src/Bridges/singlebridgeoptimizer.jl
Outdated
@@ -17,7 +17,7 @@ is_bridged(b::SingleBridgeOptimizer, ::Type{<:MOI.AbstractFunction}, ::Type{<:MO | |||
bridge_type(b::SingleBridgeOptimizer{BT}, F::Type{<:MOI.AbstractFunction}, S::Type{<:MOI.AbstractSet}) where BT = BT | |||
|
|||
# :((Zeros, SecondOrderCone)) -> (:(MOI.Zeros), :(MOI.SecondOrderCone)) | |||
_tuple_prefix_moi(t) = MOIU._moi.(t.args) | |||
_tuple_prefix_moi(t) = t.args |
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.
It seems the function is not used anymore, let's remove it
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.
I have some ideas to improve the syntax of these macros, but that can happen later.
Simpler solution as suggested by @blegat. Of course we can now delete _mod function and get rid of its calls.
However even with this solution, we still need to import sets/functions to be used by @bridge
If we want the modules passed to @bridge like
MOI.xxxfunction/MOI.xxxset
, we need more modifications in @model since it uses the names passed to create field names of the new structure. Do we go for that?