Skip to content
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

Implement MOI.default_cache #137

Merged
merged 8 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/MOI_wrapper/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const OptimizerCache = MOI.Utilities.GenericModel{
},
}

Base.show(io::IO, ::Type{OptimizerCache}) = print(io, "ECOS.OptimizerCache")

mutable struct _Solution
ret_val::Union{Nothing,idxint}
primal::Vector{pfloat}
Expand Down Expand Up @@ -95,6 +97,10 @@ mutable struct Optimizer <: MOI.AbstractOptimizer
Optimizer() = new(nothing, nothing, _Solution(), false, Dict{Symbol,Any}())
end

function MOI.default_cache(::Optimizer, ::Type{pfloat})
odow marked this conversation as resolved.
Show resolved Hide resolved
return MOI.Utilities.UniversalFallback(OptimizerCache())
end

function MOI.is_empty(optimizer::Optimizer)
return optimizer.zeros === nothing && optimizer.cones === nothing
end
Expand Down Expand Up @@ -311,6 +317,13 @@ function MOI.optimize!(dest::Optimizer, src::OptimizerCache)
return MOI.Utilities.identity_index_map(src), false
end

function MOI.copy_to(
dest::Optimizer,
src::MOI.Utilities.UniversalFallback{OptimizerCache},
)
return MOI.copy_to(dest, src.model)
end

function MOI.optimize!(dest::Optimizer, src::MOI.ModelLike)
cache = OptimizerCache()
index_map = MOI.copy_to(cache, src)
Expand Down
7 changes: 6 additions & 1 deletion test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ function runtests()
end

function test_runtests()
model = MOI.instantiate(ECOS.Optimizer, with_bridge_type = Float64)
# This is what JuMP would construct
model = MOI.Utilities.CachingOptimizer(
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()),
MOI.instantiate(ECOS.Optimizer; with_bridge_type = Float64),
)
@test model.optimizer.model.model_cache isa MOI.Utilities.UniversalFallback{ECOS.OptimizerCache}
MOI.set(model, MOI.Silent(), true)
exclude = String[
# Expected test failures:
Expand Down