Skip to content

Commit 8272465

Browse files
authored
Add a second cache for bridged variables (#584)
1 parent e5b218f commit 8272465

File tree

3 files changed

+39
-22
lines changed

3 files changed

+39
-22
lines changed

src/Context.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@ mutable struct Context{T,M}
2323
conic_form_cache::IdDict{Any,Any}
2424
end
2525

26-
function Context{T}(optimizer_factory) where {T}
27-
model = MOI.instantiate(optimizer_factory, with_bridge_type = T)
26+
function Context{T}(optimizer_factory; add_cache::Bool = false) where {T}
27+
model = if add_cache
28+
MOI.Utilities.CachingOptimizer(
29+
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{T}()),
30+
MOI.instantiate(optimizer_factory; with_bridge_type = T),
31+
)
32+
else
33+
MOI.instantiate(optimizer_factory; with_bridge_type = T)
34+
end
2835
return Context{T,typeof(model)}(
2936
model,
3037
OrderedCollections.OrderedDict{UInt64,Vector{MOI.VariableIndex}}(),

src/MOI_wrapper.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ struct Optimizer{T,M} <: MOI.AbstractOptimizer
1212
)
1313
end
1414
function Optimizer{T}(optimizer_constructor) where {T}
15-
return Optimizer(Context{T}(optimizer_constructor))
15+
# See https://github.com/jump-dev/Convex.jl/issues/564 for details
16+
return Optimizer(Context{T}(optimizer_constructor; add_cache = true))
1617
end
1718
end
1819

test/MOI_wrapper.jl

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,38 @@ function runtests()
1919
end
2020

2121
function test_runtests()
22-
T = Float64
23-
optimizer = MOI.Utilities.CachingOptimizer(
24-
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{T}()),
25-
Convex.Optimizer(ECOS.Optimizer),
22+
inner = Convex.Optimizer(ECOS.Optimizer)
23+
model = MOI.Utilities.CachingOptimizer(
24+
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()),
25+
MOI.Bridges.full_bridge_optimizer(inner, Float64),
2626
)
27-
MOI.set(optimizer, MOI.Silent(), true)
2827
MOI.Bridges.remove_bridge(
29-
optimizer.optimizer.context.model,
30-
MOI.Bridges.Variable.ZerosBridge{T},
28+
inner.context.model.optimizer,
29+
MOI.Bridges.Variable.ZerosBridge{Float64},
3130
)
32-
config = MOI.Test.Config(;
33-
atol = 1e-3,
34-
rtol = 1e-3,
35-
exclude = Any[
36-
MOI.ConstraintBasisStatus,
37-
MOI.VariableBasisStatus,
38-
MOI.ObjectiveBound,
39-
],
31+
MOI.set(model, MOI.Silent(), true)
32+
MOI.Test.runtests(
33+
model,
34+
MOI.Test.Config(;
35+
atol = 1e-3,
36+
rtol = 1e-3,
37+
exclude = Any[
38+
MOI.ConstraintBasisStatus,
39+
MOI.VariableBasisStatus,
40+
MOI.ObjectiveBound,
41+
],
42+
);
43+
exclude = ["hs071"], # HS071 is not convex
4044
)
41-
MOI.Test.runtests(optimizer, config, exclude = [
42-
# HS071 is not convex
43-
"hs071",
44-
])
45+
return
46+
end
47+
48+
function test_issue_564()
49+
model = MOI.instantiate(
50+
() -> Convex.Optimizer(ECOS.Optimizer);
51+
with_bridge_type = Float64,
52+
)
53+
MOI.Test.test_add_parameter(model, MOI.Test.Config())
4554
return
4655
end
4756

0 commit comments

Comments
 (0)