Skip to content

Commit c589802

Browse files
authored
Relax AbstractOptimizer requirement in instantiate (#1781)
1 parent 26ea446 commit c589802

4 files changed

Lines changed: 22 additions & 8 deletions

File tree

src/Utilities/cachingoptimizer.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,7 @@ mutable struct CachingOptimizer{O,M<:MOI.ModelLike} <: MOI.AbstractOptimizer
9090
)
9191
end
9292

93-
function CachingOptimizer(
94-
cache::MOI.ModelLike,
95-
optimizer::MOI.AbstractOptimizer,
96-
)
93+
function CachingOptimizer(cache::MOI.ModelLike, optimizer::MOI.ModelLike)
9794
@assert MOI.is_empty(optimizer)
9895
model = new{typeof(optimizer),typeof(cache)}(
9996
optimizer,

src/instantiate.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,18 @@ const _INSTANTIATE_NOT_CALLABLE_MESSAGE =
5555
_instantiate_and_check(optimizer_constructor)
5656
5757
Create an instance of optimizer by calling `optimizer_constructor`.
58-
Then check that the type returned is an empty [`AbstractOptimizer`](@ref).
58+
Then check that the type returned is an empty [`ModelLike`](@ref).
5959
"""
6060
function _instantiate_and_check(optimizer_constructor)
6161
if !applicable(optimizer_constructor)
6262
error(_INSTANTIATE_NOT_CALLABLE_MESSAGE)
6363
end
6464
optimizer = optimizer_constructor()
65-
if !isa(optimizer, AbstractOptimizer)
65+
if !isa(optimizer, ModelLike)
6666
error(
6767
"The provided `optimizer_constructor` returned an object of type " *
6868
"$(typeof(optimizer)). Expected a " *
69-
"MathOptInterface.AbstractOptimizer.",
69+
"MathOptInterface.ModelLike.",
7070
)
7171
end
7272
if !is_empty(optimizer)

test/FileFormats/FileFormats.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,23 @@ function test_copying()
4949
end
5050
end
5151

52+
function test_instantiate()
53+
models = [
54+
MOI.FileFormats.CBF.Model,
55+
MOI.FileFormats.LP.Model,
56+
MOI.FileFormats.MOF.Model,
57+
MOI.FileFormats.MPS.Model,
58+
MOI.FileFormats.SDPA.Model,
59+
]
60+
for src in models
61+
model = MOI.instantiate(src)
62+
@test model isa src
63+
bridged = MOI.instantiate(src; with_bridge_type = Float64)
64+
@test bridged isa MOI.Bridges.LazyBridgeOptimizer
65+
end
66+
return
67+
end
68+
5269
function test_compressed_open()
5370
for cs in [MOI.FileFormats.Bzip2(), MOI.FileFormats.Gzip()]
5471
for open_type in ["a", "r+", "w+", "a+"]

test/instantiate.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function _test_instantiate(T)
6767

6868
err = ErrorException(
6969
"The provided `optimizer_constructor` returned an object of type " *
70-
"$Int. Expected a MathOptInterface.AbstractOptimizer.",
70+
"$Int. Expected a MathOptInterface.ModelLike.",
7171
)
7272
h() = 1
7373
@test_throws err MOI.instantiate(h)

0 commit comments

Comments
 (0)