Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed May 30, 2019
1 parent 44a581f commit bfc39d8
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 40 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name = "SemidefiniteOptInterface"
uuid = "f0680fed-b2cd-5302-98f9-f4da282d86b5"
repo = "https://github.com/JuliaOpt/SemidefiniteOptInterface.jl.git"
version = "0.7.0"
version = "0.6.0"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"

[compat]
Expand Down
20 changes: 14 additions & 6 deletions src/SemidefiniteOptInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,16 @@ SDOIOptimizer(sdoptimizer::AbstractSDOptimizer, T=Float64) = SOItoMOIBridge{T}(s

include("load.jl")

function MOI.get(optimizer::SOItoMOIBridge, attr::MOI.SolverName)
function MOI.supports(optimizer::SOItoMOIBridge, attr::MOI.AbstractOptimizerAttribute)
return MOI.supports(optimizer.sdoptimizer, attr)
end
function MOI.get(optimizer::SOItoMOIBridge, attr::MOI.AbstractOptimizerAttribute)
return MOI.get(optimizer.sdoptimizer, attr)
end
function MOI.set(optimizer::SOItoMOIBridge,
attr::MOI.AbstractOptimizerAttribute, value)
return MOI.set(optimizer.sdoptimizer, attr, value)
end

function MOI.is_empty(optimizer::SOItoMOIBridge)
isempty(optimizer.double) &&
Expand Down Expand Up @@ -104,7 +111,7 @@ end

function setconstant!(optimizer::SOItoMOIBridge, ci::CI, s) end
function setconstant!(optimizer::SOItoMOIBridge, ci::CI, s::MOI.AbstractScalarSet)
optimizer.setconstant[ci.value] = MOIU.getconstant(s)
optimizer.setconstant[ci.value] = MOI.constant(s)
end
function set_constant(optimizer::SOItoMOIBridge,
ci::CI{<:MOI.AbstractScalarFunction,
Expand Down Expand Up @@ -168,10 +175,11 @@ function MOI.get(m::SOItoMOIBridge, attr::Union{MOI.ObjectiveValue, MOI.DualObje
end

# Attributes

const SolverStatus = Union{MOI.TerminationStatus, MOI.PrimalStatus, MOI.DualStatus}
MOI.get(m::SOItoMOIBridge, s::SolverStatus) = MOI.get(m.sdoptimizer, s)

function MOI.get(m::SOItoMOIBridge,
attr::Union{MOI.RawStatusString, MOI.TerminationStatus,
MOI.PrimalStatus, MOI.DualStatus, MOI.SolveTime})
return MOI.get(m.sdoptimizer, attr)
end

MOI.get(m::SOItoMOIBridge, ::MOI.ResultCount) = 1

Expand Down
2 changes: 1 addition & 1 deletion src/constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function loadcoefficients!(m::SOItoMOIBridge, cs::UnitRange,
f = MOIU.canonical(f) # sum terms with same variables and same outputindex
@assert length(cs) == 1
c = first(cs)
rhs = MOIU.getconstant(s) - MOI._constant(f)
rhs = MOI.constant(s) - MOI.constant(f)
for t in f.terms
if !iszero(t.coefficient)
for (blk, i, j, coef, shift) in varmap(m, t.variable_index)
Expand Down
10 changes: 5 additions & 5 deletions src/variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ end
function _constraintvariable!(m::SOItoMOIBridge{T}, vs::VIS, s::ZS) where T
blk = newblock(m, -_length(vs))
for (i, v) in _enumerate(vs)
setvarmap!(m, v, (blk, i, i, one(T), _getconstant(m, s)))
setvarmap!(m, v, (blk, i, i, one(T), _constant(m, s)))
unfree(m, v)
end
blk
Expand All @@ -27,7 +27,7 @@ _enumerate(vi::VI) = enumerate((vi,))
_enumerate(vi::Vector{VI}) = enumerate(vi)
function _constraintvariable!(m::SOItoMOIBridge, vs::VIS, s::S) where S<:Union{NS, PS}
blk = newblock(m, -_length(vs))
cst = _getconstant(m, s)
cst = _constant(m, s)
m.blkconstant[blk] = cst
for (i, v) in _enumerate(vs)
setvarmap!(m, v, (blk, i, i, vscaling(S), cst))
Expand Down Expand Up @@ -84,8 +84,8 @@ function MOIU.allocate_constraint(m::SOItoMOIBridge{T}, f::VF, s::SupportedSets)
end
end

_getconstant(m::SOItoMOIBridge, s::MOI.AbstractScalarSet) = MOIU.getconstant(s)
_getconstant(m::SOItoMOIBridge{T}, s::MOI.AbstractSet) where T = zero(T)
_constant(m::SOItoMOIBridge, s::MOI.AbstractScalarSet) = MOI.constant(s)
_constant(m::SOItoMOIBridge{T}, s::MOI.AbstractSet) where T = zero(T)

_var(f::SVF, j) = f.variable
_var(f::VVF, j) = f.variables[j]
Expand All @@ -101,7 +101,7 @@ function MOIU.load_constraint(m::SOItoMOIBridge, ci::CI, f::VF, s::SupportedSets
(blk, i, j, coef, shift) = first(vm)
c = cs[k]
setconstraintcoefficient!(m.sdoptimizer, coef, c, blk, i, j)
setconstraintconstant!(m.sdoptimizer, _getconstant(m, s) - coef * shift, c)
setconstraintconstant!(m.sdoptimizer, _constant(m, s) - coef * shift, c)
end
end
end
Expand Down
27 changes: 16 additions & 11 deletions test/contconic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ end
[-1.4142, 1.0, -0.1768, 1.0, -0.3536, -0.1768]))
MOIT.rotatedsoc1ftest(bridged, config)
MOIU.set_mock_optimize!(mock, (mock) -> MOIU.mock_optimize!(mock,
[[0.0], [0.0], [0.5 0.7071 0.7071; 0.7071 2.0 0.0; 0.7071 0.0 2.0], [2.6164 0.0; 0.0 1.9093], [2.6164 0.0; 0.0 1.9093]],
[5183.15, 5182.44, -1.4142, 1.0, -0.1768, 1.0, -0.3536, -0.1768]))
[[0.5 1/√2 1/√2; 1/√2 2.0 0.0; 1/√2 0.0 2.0], [0.0], [0.0], [3.65568 0; 0 2.94857], [3.65568 0; 0 2.94857]],
[-√2, 1.0, -0.176777, 1.0, -0.353555, -0.176777, 2189.72, 2189.01]))
MOIT.rotatedsoc1vtest(bridged, config)
MOIU.set_mock_optimize!(mock, (mock) -> MOIU.mock_optimize!(mock,
MOI.INFEASIBLE,
tuple(),
[141.088, -47.8864, 47.5533, -46.2201]))
[-47.8864, 47.5533, -46.2201, 141.088]))
MOIT.rotatedsoc2test(bridged, config)
# FIXME u >= 0.0 followed by u <= ub. We need to drop support for
# SingleVariable-in-LessThan but we need variable bridge otherwise,
Expand All @@ -73,12 +73,14 @@ end
end
@testset "GeoMean" begin
MOIU.set_mock_optimize!(mock, (mock) -> MOIU.mock_optimize!(mock,
[[0.0], [0.0], [1.4142 2.0; 2.0 2.8284], [1.0 1.4142; 1.4142 2.0], [1.0 1.4142; 1.4142 2.0], [1.8324 0.0; 0.0 0.8324], [1.7758 0.0; 0.0 0.7758], [1.7772 0.0; 0.0 0.7772], [1.7728 0.0; 0.0 0.7728], [2.5017 0.0; 0.0 0.5017], [2.0744 0.0; 0.0 0.6602], [2.0671 0.0; 0.0 0.6529]],
[1.0, 0.3333, -0.4714, 0.6667, -0.2357, -0.3333, 0.4714, -0.1667, -0.3333, 0.4714, -0.1667]))
[[2 2.0; 2.0 2*√2], [1.0 2; 2 2.0], [1.0 2; 2 2.0], [0.0], [0.0],
[1.83238 0; 0 0.832376], [1.77579 0; 0 0.775793],
[1.77719 0; 0 0.777194], [1.77283 0; 0 0.772829],
[2.50173 0; 0 0.501735], [2.07437 0; 0 0.660159],
[2.06708 0; 0 0.652869]],
[1.0, -0.471405, 2/3, -0.235702, -1/3, 0.471405, -1/6, -1/3, 0.471405,
-1/6, 1/3]))
MOIT.geomean1ftest(bridged, config)
MOIU.set_mock_optimize!(mock, (mock) -> MOIU.mock_optimize!(mock,
[[0.0], [0.0], [1.4142 2.0; 2.0 2.8284], [1.0 1.4142; 1.4142 2.0], [1.0 1.4142; 1.4142 2.0], [1.8324 0.0; 0.0 0.8324], [1.7758 0.0; 0.0 0.7758], [1.7772 0.0; 0.0 0.7772], [1.7728 0.0; 0.0 0.7728], [2.5017 0.0; 0.0 0.5017], [2.0744 0.0; 0.0 0.6602], [2.0671 0.0; 0.0 0.6529]],
[1.0, 0.3333, -0.4714, 0.6667, -0.2357, -0.3333, 0.4714, -0.1667, -0.3333, 0.4714, -0.1667]))
MOIT.geomean1vtest(bridged, config)
end
@testset "PSD" begin
Expand Down Expand Up @@ -125,8 +127,11 @@ end
[0.4475 0; 0 0.4475-xv[2]]],
[-y2/√2, y2, -y2/√2/2, y2, -y2/√2, -y2/√2/2, y2*√2-1, -y2]))
MOIT.psdt1vtest(bridged, config)
MOIU.set_mock_optimize!(mock, (mock) -> MOIU.mock_optimize!(mock,
[[0.0], [20/3 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 10/3 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0], [4.0981 -2.1213; -2.1213 1.0981], [7.3275 0.0; 0.0 0.6608], [1.7945 0.0; 0.0 1.7945], [4.1881 0.0; 0.0 0.8547], [1.7945 0.0; 0.0 1.7945], [1.7945 0.0; 0.0 1.7945], [1.7945 0.0; 0.0 1.7945], [2.8504 0.0; 0.0 0.9485]],
[-0.190192, 0, 0.125977, 0, 0.142644, 0.142644, 0.0127405, -0.211325, -0.816497, -0.788675, 0]))
MOIU.set_mock_optimize!(mock, (mock) -> MOIU.mock_optimize!(mock,
[[20/3 0 0 0 0 0; 0 0 0 0 0 0; 0 0 10/3 0 0 0; 0 0 0 0 0 0; 0 0 0 0 0 0; 0 0 0 0 0 0],
[4.09808 -2.12132; -2.12132 1.09808], [0.0], [7.32746 0; 0 0.660794],
[1.79451 0; 0 1.79451], [4.18806 0; 0 0.854733], [1.79451 0; 0 1.79451],
[1.79451 0; 0 1.79451], [1.79451 0; 0 1.79451], [2.85043 0; 0 0.94851]],
[-0.190192, 0.0, 0.125977, 0.0, 0.142644, 0.142644, 0.0127405, -0.211325, -0.816497, -0.788675, 0.0]))
MOIT.psdt2test(bridged, config)
end
14 changes: 9 additions & 5 deletions test/mock_tests_generator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"const MOIU = MOI.Utilities\n",
"MOIU.@model(SDModelData,\n",
" (), (MOI.EqualTo, MOI.GreaterThan, MOI.LessThan),\n",
" (MOI.Zeros, MOI.Nonnegatives, MOI.Nonpositives, MOI.PositiveSemidefiniteConeTriangle), (),\n",
" (MOI.SingleVariable,), (MOI.ScalarAffineFunction,),\n",
" (), (MOI.ScalarAffineFunction,),\n",
" (MOI.VectorOfVariables,), ())"
]
},
Expand Down Expand Up @@ -117,13 +119,15 @@
"metadata": {},
"outputs": [],
"source": [
"generate_mock_test(MOIT.psdt0ftest)"
"generate_mock_test(MOIT.geomean1vtest)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"for testfun in map(p -> p.second, sort(collect(MOIT.lintests), by=p->p.first))\n",
Expand Down Expand Up @@ -166,7 +170,7 @@
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.1.0"
"version": "1.1.1"
}
},
"nbformat": 4,
Expand Down
11 changes: 3 additions & 8 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@ include("sdpa.jl")

const MOIU = MOI.Utilities
MOIU.@model(SDModelData,
(),
(MOI.EqualTo, MOI.GreaterThan, MOI.LessThan),
(), (MOI.EqualTo, MOI.GreaterThan, MOI.LessThan),
(MOI.Zeros, MOI.Nonnegatives, MOI.Nonpositives,
MOI.PositiveSemidefiniteConeTriangle),
(),
(MOI.SingleVariable,),
(MOI.ScalarAffineFunction,),
(MOI.VectorOfVariables,),
())
MOI.PositiveSemidefiniteConeTriangle), (),
(), (MOI.ScalarAffineFunction,), (MOI.VectorOfVariables,), ())

mock = SDOI.MockSDOptimizer{Float64}()
mock_optimizer = SDOI.SDOIOptimizer(mock, Float64)
Expand Down
6 changes: 3 additions & 3 deletions test/unit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ MOIU.set_mock_optimize!(mock, (mock) -> MOIU.mock_optimize!(mock,
[[0.0], [0.0 0; 0 0.0]],
[1.0]),
(mock) -> MOIU.mock_optimize!(mock,
[[1.0], [0.0], [0.624034 0; 0 0.624034]],
[0.0, 1.0]),
[[0.0], [1.0], [0.624034 0; 0 0.624034]],
[1.0, 0.0]),
(mock) -> MOIU.mock_optimize!(mock,
[[0.0], [2.73683 0; 0 1.73683]],
[1.0]),
(mock) -> MOIU.mock_optimize!(mock,
[[1.88804e-9], [1.0], [3.25375 0; 0 2.25375]],
[[1.0], [0.0], [3.25375 0; 0 2.25375]],
[1.0, 0.0]),
(mock) -> MOIU.mock_optimize!(mock,
[[0.0], [4.47626 0; 0 2.47626]],
Expand Down

0 comments on commit bfc39d8

Please sign in to comment.