-
Notifications
You must be signed in to change notification settings - Fork 94
Description
So basically, I want to wrap and general MathOpt model structure so I can parse it into different equivalent and derivative problems. So I was planning on just adding a MOIU.Model field for this storage. That said, I ran into some interesting behavior for the full_bridge_optimizer which I can't explain.
Basically, the underlying optimizer opt
in MOIB.full_bridge_optimizer(opt, Float64)
supports the the MOI.SingleVariable
in MOI.Interval{Float64}
but when the full_bridge_optimizer
is used to wrap it then it results in an unsupported constraint error. Am I misinterpreting the expected behavior or is this some sort of bug?
MWE:
using MathOptInterface
const MOI = MathOptInterface
const MOIU = MOI.Utilities
const MOIB = MOI.Bridges
Base.@kwdef mutable struct MiniOpt <: MOI.AbstractOptimizer
model::MOIU.Model{Float64} = MOIU.Model{Float64}()
end
MOI.is_empty(m::MiniOpt) = MOI.is_empty(m.model)
MOI.empty!(m::MiniOpt) = MOI.empty!(m.model)
MOI.add_variable(d::MiniOpt) = MOI.add_variable(d.model)
function MOI.supports_constraint(m::MiniOpt, ::MOI.SingleVariable, ::MOI.Interval{Float64})
MOI.supports_constraint(m.model)
end
function MOI.add_constraint(d::MiniOpt, f::MOI.SingleVariable, s::MOI.Interval{Float64})
MOI.add_constraint(d.model, f, s)
end
function MOI.copy_to(dest::MiniOpt, src::MOI.ModelLike; kws...)
return MOIU.automatic_copy_to(dest.model, src; kws...)
end
MOIU.supports_default_copy_to(model::MiniOpt, copy_names::Bool) = MOIU.supports_default_copy_to(dest.model)
function add_test!(q)
x = MOI.add_variable(q)
MOI.add_constraint(q, MOI.SingleVariable(x),
MOI.Interval{Float64}(-3.1, 2.1))
return
end
opt_1 = MiniOpt()
add_test!(opt_1) # Passes
opt_2 = MOIU.Model{Float64}()
add_test!(opt_2) # Passes
opt_3 = MOIU.CachingOptimizer(MOIU.UniversalFallback(MOIU.Model{Float64}()), MiniOpt())
add_test!(opt_3) # Passes
opt_4 = MOIB.full_bridge_optimizer(MOIU.Model{Float64}(), Float64)
add_test!(opt_4) # Passes
opt_5 = MOIB.full_bridge_optimizer(MiniOpt(), Float64)
add_test!(opt_5) # Fails
Stacktrace:
ERROR: LoadError: MathOptInterface.UnsupportedConstraint{MathOptInterface.SingleVariable,MathOptInterface.Interval{Float64}}: MathOptInterface.SingleVariable
-in-MathOptInterface.Interval{Float64}
constraint is not supported by the model.
Stacktrace:
[1] bridge_type(::MathOptInterface.Bridges.LazyBridgeOptimizer{MiniOpt}, ::Type{MathOptInterface.SingleVariable}, ::Type{MathOptInterface.Interval{Float64}}) at C:\Users\wilhe\Desktop\Package Development\MathOptInterface.jl\src\Bridges\lazy_bridge_optimizer.jl:419
[2] concrete_bridge_type(::MathOptInterface.Bridges.LazyBridgeOptimizer{MiniOpt}, ::Type{MathOptInterface.SingleVariable}, ::Type{MathOptInterface.Interval{Float64}}) at C:\Users\wilhe\Desktop\Package Development\MathOptInterface.jl\src\Bridges\Constraint\bridge.jl:138
[3] add_constraint(::MathOptInterface.Bridges.LazyBridgeOptimizer{MiniOpt}, ::MathOptInterface.SingleVariable, ::MathOptInterface.Interval{Float64}) at C:\Users\wilhe\Desktop\Package Development\MathOptInterface.jl\src\Bridges\bridge_optimizer.jl:1350
[4] add_test!(::MathOptInterface.Bridges.LazyBridgeOptimizer{MiniOpt}) at C:\Users\wilhe\Dropbox\My PC (DESKTOP-P6322LG)\Desktop\test_interval.jl:25
[5] top-level scope at C:\Users\wilhe\Dropbox\My PC (DESKTOP-P6322LG)\Desktop\test_interval.jl:44
[6] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1088
in expression starting at C:\Users\wilhe\Dropbox\My PC (DESKTOP-P6322LG)\Desktop\test_interval.jl:44
Version info:
MathOptInterface v0.9.20
Julia Version 1.5.1
Commit 697e782ab8 (2020-08-25 20:08 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Core(TM) i9-10900 CPU @ 2.80GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
Environment:
JULIA_NUM_THREADS = 10