Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 18 additions & 4 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mutable struct Optimizer <: MOI.AbstractOptimizer
blockmatrix(), nothing, blockmatrix(), nothing, blockmatrix(),
-1, NaN, NaN, NaN, false, Dict{Symbol, Any}())
for (key, value) in kwargs
MOI.set(optimizer, MOI.RawParameter(key), value)
MOI.set(optimizer, MOI.RawParameter(String(key)), value)
end
# May need to call `free_loaded_prob` and `free_loading_prob`.
finalizer(MOI.empty!, optimizer)
Expand All @@ -39,17 +39,31 @@ end
varmap(optimizer::Optimizer, vi::MOI.VariableIndex) = optimizer.varmap[vi.value]

function MOI.supports(optimizer::Optimizer, param::MOI.RawParameter)
return param.name in ALLOWED_OPTIONS
return Symbol(param.name) in ALLOWED_OPTIONS
end
function MOI.set(optimizer::Optimizer, param::MOI.RawParameter, value)
if !(param.name isa String)
Base.depwarn(
"passing `$(param.name)` to `MOI.RawParameter` as type " *
"`$(typeof(param.name))` is deprecated. Use a string instead.",
Symbol("MOI.set")
)
end
if !MOI.supports(optimizer, param)
throw(MOI.UnsupportedAttribute(param))
end
optimizer.options[param.name] = value
optimizer.options[Symbol(param.name)] = value
end
function MOI.get(optimizer::Optimizer, param::MOI.RawParameter)
# TODO: This gives a poor error message if the name of the parameter is invalid.
return optimizer.options[param.name]
if !(param.name isa String)
Base.depwarn(
"passing `$(param.name)` to `MOI.RawParameter` as type " *
"`$(typeof(param.name))` is deprecated. Use a string instead.",
Symbol("MOI.set")
)
end
return optimizer.options[Symbol(param.name)]
end

MOI.supports(::Optimizer, ::MOI.Silent) = true
Expand Down
13 changes: 5 additions & 8 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const MOIU = MOI.Utilities
const MOIB = MOI.Bridges

import CSDP
const optimizer = CSDP.Optimizer()
MOI.set(optimizer, MOI.Silent(), true)
const optimizer_constructor = MOI.OptimizerWithAttributes(CSDP.Optimizer, MOI.Silent() => true)
const optimizer = MOI.instantiate(optimizer_constructor)

@testset "SolverName" begin
@test MOI.get(optimizer, MOI.SolverName()) == "CSDP"
Expand All @@ -19,16 +19,13 @@ end
@test !MOIU.supports_allocate_load(optimizer, true)
end

# UniversalFallback is needed for starting values, even if they are ignored by CSDP
const cache = MOIU.UniversalFallback(MOIU.Model{Float64}())
const cached = MOIU.CachingOptimizer(cache, optimizer)
const bridged = MOIB.full_bridge_optimizer(cached, Float64)
const bridged = MOI.instantiate(optimizer_constructor, with_bridge_type=Float64)
const config = MOIT.TestConfig(atol=1e-4, rtol=1e-4)

@testset "Options" begin
param = MOI.RawParameter(:bad_option)
param = MOI.RawParameter("bad_option")
err = MOI.UnsupportedAttribute(param)
@test_throws err CSDP.Optimizer(bad_option = 1)
@test_throws err MOI.set(optimizer, MOI.RawParameter("bad_option"), 0)
end

@testset "Unit" begin
Expand Down