From 2077cc7f521b38f5a8aaa978e5aa3b2b5fab624a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Tue, 21 Nov 2017 21:01:48 +0100 Subject: [PATCH 1/3] Transition to MOIT and remove solver --- src/DSDPSolverInterface.jl | 41 ++++++++++++++++---------------------- test/maxcut.jl | 2 +- test/moi.jl | 17 +++++++--------- test/options.jl | 5 ++--- 4 files changed, 27 insertions(+), 38 deletions(-) diff --git a/src/DSDPSolverInterface.jl b/src/DSDPSolverInterface.jl index 5f8ebc1..94ecff5 100644 --- a/src/DSDPSolverInterface.jl +++ b/src/DSDPSolverInterface.jl @@ -1,17 +1,12 @@ using SemidefiniteOptInterface -SOI = SemidefiniteOptInterface +SDOI = SemidefiniteOptInterface using MathOptInterface MOI = MathOptInterface -export DSDPSolver +export DSDPInstance -struct DSDPSolver <: SOI.AbstractSDSolver - options::Dict{Symbol,Any} -end -DSDPSolver(;kwargs...) = DSDPSolver(Dict{Symbol,Any}(kwargs)) - -mutable struct DSDPSolverInstance <: SOI.AbstractSDSolverInstance +mutable struct DSDPSolverInstance <: SDOI.AbstractSDSolverInstance dsdp::DSDPT lpcone::LPCone.LPConeT nconstrs::Int @@ -36,7 +31,7 @@ mutable struct DSDPSolverInstance <: SOI.AbstractSDSolverInstance m end end -SOI.SDSolverInstance(s::DSDPSolver) = DSDPSolverInstance(; s.options...) +DSDPInstance(; kws...) = SDOI.SDOIInstance(DSDPSolverInstance(; kws...)) function _free(m::DSDPSolverInstance) if m.dsdp != C_NULL @@ -78,12 +73,10 @@ const options = Dict( const options_setters = Dict{Symbol, Function}() -abstract type Option <: MOI.AbstractSolverAttribute end +abstract type Option <: MOI.AbstractInstanceAttribute end abstract type GettableOption <: Option end -MOI.canget(solver::Union{DSDPSolver, DSDPSolverInstance}, ::Option) = true -MOI.set!(solver::DSDPSolver, o::Option, val) = _dict_set!(solver.options, o, val) -MOI.get(solver::DSDPSolver, o::Option) = _dict_get(solver.options, o) +MOI.canget(solver::DSDPSolverInstance, ::Option) = true function MOI.set!(m::DSDPSolverInstance, o::Option, val) # Need to set it in the dictionary so that it is also used when initinstance! is called again _dict_set!(m.options, o, val) @@ -135,7 +128,7 @@ for (param, default) in Iterators.flatten((options, gettable_options)) end end -function SOI.initinstance!(m::DSDPSolverInstance, blkdims::Vector{Int}, nconstrs::Int) +function SDOI.initinstance!(m::DSDPSolverInstance, blkdims::Vector{Int}, nconstrs::Int) _free(m) @assert nconstrs >= 0 m.nconstrs = nconstrs @@ -176,7 +169,7 @@ function SOI.initinstance!(m::DSDPSolverInstance, blkdims::Vector{Int}, nconstrs m.z_computed = false end -function SOI.setconstraintconstant!(m::DSDPSolverInstance, val, constr::Integer) +function SDOI.setconstraintconstant!(m::DSDPSolverInstance, val, constr::Integer) SetDualObjective(m.dsdp, constr, val) end function _setcoefficient!(m::DSDPSolverInstance, coef, constr::Integer, blk::Integer, i::Integer, j::Integer) @@ -189,11 +182,11 @@ function _setcoefficient!(m::DSDPSolverInstance, coef, constr::Integer, blk::Int error("TODO") end end -function SOI.setconstraintcoefficient!(m::DSDPSolverInstance, coef, constr::Integer, blk::Integer, i::Integer, j::Integer) +function SDOI.setconstraintcoefficient!(m::DSDPSolverInstance, coef, constr::Integer, blk::Integer, i::Integer, j::Integer) _setcoefficient!(m, coef, constr, blk, i, j) end -function SOI.setobjectivecoefficient!(m::DSDPSolverInstance, coef, blk::Integer, i::Integer, j::Integer) - # in SOI, convention is MAX but in DSDP, convention is MIN so we reverse the sign of coef +function SDOI.setobjectivecoefficient!(m::DSDPSolverInstance, coef, blk::Integer, i::Integer, j::Integer) + # in SDOI, convention is MAX but in DSDP, convention is MIN so we reverse the sign of coef _setcoefficient!(m, -coef, 0, blk, i, j) end @@ -271,10 +264,10 @@ function MOI.get(m::DSDPSolverInstance, ::MOI.DualStatus) end end -function SOI.getprimalobjectivevalue(m::DSDPSolverInstance) +function SDOI.getprimalobjectivevalue(m::DSDPSolverInstance) -GetPPObjective(m.dsdp) end -function SOI.getdualobjectivevalue(m::DSDPSolverInstance) +function SDOI.getdualobjectivevalue(m::DSDPSolverInstance) -GetDDObjective(m.dsdp) end @@ -304,15 +297,15 @@ function Base.getindex(x::XBlockMat, i) @assert x.instance.blkdims[i] < 0 LPXBlock(x.instance.lpcone, x.instance.blk[i]) end -function SOI.getX(m::DSDPSolverInstance) +function SDOI.getX(m::DSDPSolverInstance) XBlockMat(m) end -function SOI.gety(m::DSDPSolverInstance) +function SDOI.gety(m::DSDPSolverInstance) if !m.y_valid m.y = Vector{Cdouble}(m.nconstrs) GetY(m.dsdp, m.y) - map!(-, m.y, m.y) # The primal objective is Max in SOI but Min in DSDP + map!(-, m.y, m.y) # The primal objective is Max in SDOI but Min in DSDP end m.y end @@ -342,6 +335,6 @@ function Base.getindex(z::ZBlockMat, i) @assert z.instance.blkdims[i] < 0 LPZBlock(z.instance.lpcone, z.instance.blk[i]) end -function SOI.getZ(m::DSDPSolverInstance) +function SDOI.getZ(m::DSDPSolverInstance) ZBlockMat(m) end diff --git a/test/maxcut.jl b/test/maxcut.jl index 8842d56..0e431b5 100644 --- a/test/maxcut.jl +++ b/test/maxcut.jl @@ -85,7 +85,7 @@ function maxcut(nnodes, edges) DSDP.SetPNormTolerance(dsdp, 1.0) #info = TCheckArgs(dsdp,argc,argv) - DSDP.SetStandardMonitor(dsdp,1) + DSDP.SetStandardMonitor(dsdp,0) DSDP.Setup(dsdp) diff --git a/test/moi.jl b/test/moi.jl index ef4d9fc..f92cab6 100644 --- a/test/moi.jl +++ b/test/moi.jl @@ -1,14 +1,11 @@ +using MathOptInterfaceTests +const MOIT = MathOptInterfaceTests + +const solver = () -> DSDP.DSDPInstance() +const config = MOIT.TestConfig(1e-6, 1e-6, true, true, true) + @testset "Linear tests" begin - include(joinpath(Pkg.dir("MathOptInterface"), "test", "contlinear.jl")) - linear2test(DSDP.DSDPSolver(), atol=1e-7, rtol=1e-7) - linear3test(DSDP.DSDPSolver(), atol=1e-7, rtol=1e-7) - linear4test(DSDP.DSDPSolver(), atol=1e-7, rtol=1e-7) - linear5test(DSDP.DSDPSolver(), atol=1e-7, rtol=1e-7) - linear6test(DSDP.DSDPSolver(), atol=1e-6, rtol=1e-6) - linear7test(DSDP.DSDPSolver(), atol=1e-6, rtol=1e-6) - linear8test(DSDP.DSDPSolver(), atol=1e-7, rtol=1e-7) - linear9test(DSDP.DSDPSolver(), atol=1e-7, rtol=1e-7) - linear10test(DSDP.DSDPSolver(), atol=1e-7, rtol=1e-7) + MOIT.contlineartest(solver, config, ["linear1", "linear11", "linear12"]) end #@testset "Conic tests" begin # include(joinpath(Pkg.dir("MathOptInterface"), "test", "contconic.jl")) diff --git a/test/options.jl b/test/options.jl index 29e991f..e4498b5 100644 --- a/test/options.jl +++ b/test/options.jl @@ -5,12 +5,11 @@ using SemidefiniteOptInterface const SOI = SemidefiniteOptInterface @testset "Options" begin - solver = DSDPSolver() - instance = SOI.SDSolverInstance(solver) + instance = DSDP.DSDPSolverInstance() SOI.initinstance!(instance, [1], 42) for (option, default) in Iterators.flatten((DSDP.options, DSDP.gettable_options)) @eval begin - @test MOI.get($solver, DSDP.$option()) == MOI.get($instance, DSDP.$option()) == $default + @test MOI.get($instance, DSDP.$option()) == $default end end end From 7a42d5f17f0f45d541fc448f94ee94bfabb42ccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Wed, 22 Nov 2017 00:17:42 +0100 Subject: [PATCH 2/3] Fix travis --- .travis.yml | 1 + REQUIRE | 1 + 2 files changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 370f049..6d55bad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ notifications: before_script: - julia -e 'Pkg.clone("https://github.com/JuliaOpt/MathOptInterface.jl.git")' - julia -e 'Pkg.clone("https://github.com/JuliaOpt/MathOptInterfaceUtilities.jl.git")' + - julia -e 'Pkg.clone("https://github.com/JuliaOpt/MathOptInterfaceTests.jl.git")' - julia -e 'Pkg.clone("https://github.com/JuliaOpt/SemidefiniteOptInterface.jl.git")' # uncomment the following lines to override the default test script #script: diff --git a/REQUIRE b/REQUIRE index d59df15..b6a9c8f 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,4 +1,5 @@ julia 0.6 BinDeps MathOptInterface +MathOptInterfaceTests SemidefiniteOptInterface From e1031fe3f420171e18faf82d55ca3928889e4c15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Fri, 29 Dec 2017 01:36:49 +0100 Subject: [PATCH 3/3] Update --- test/moi.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/moi.jl b/test/moi.jl index f92cab6..bd08a0b 100644 --- a/test/moi.jl +++ b/test/moi.jl @@ -2,7 +2,7 @@ using MathOptInterfaceTests const MOIT = MathOptInterfaceTests const solver = () -> DSDP.DSDPInstance() -const config = MOIT.TestConfig(1e-6, 1e-6, true, true, true) +const config = MOIT.TestConfig(1e-6, 1e-6, true, true, true, true) @testset "Linear tests" begin MOIT.contlineartest(solver, config, ["linear1", "linear11", "linear12"])