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

Julia 0.7 #100

Merged
merged 17 commits into from
May 6, 2018
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 4 additions & 3 deletions deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ using BinDeps

@BinDeps.setup

using Libdl
using LinearAlgebra.BLAS
using Compat.Libdl
using Compat.LinearAlgebra.BLAS
using Compat.Sys: isapple

blasvendor = BLAS.vendor()

Expand Down Expand Up @@ -38,7 +39,7 @@ prefix = joinpath(BinDeps.depsdir(direct), "usr")
srcdir = joinpath(BinDeps.depsdir(direct), "src", "scs-$version/")

ldflags = ""
if Sys.isapple()
if isapple()
ldflags = "$ldflags -undefined suppress -flat_namespace"
end
cflags = "-DCOPYAMATRIX -DDLONG -DUSE_LAPACK -DCTRLC=1"
Expand Down
17 changes: 15 additions & 2 deletions src/MPBWrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# MathProgBase.jl interface for the SCS.jl solver wrapper
#############################################################################

using LinearAlgebra: dot
using Compat.LinearAlgebra: dot
using MathProgBase.SolverInterface

import MathProgBase.SolverInterface: ConicModel, LinearQuadraticModel,
Expand Down Expand Up @@ -436,10 +436,23 @@ function getvardual(m::SCSMathProgModel)
return dual
end

if VERSION >= v"0.7-"
function addoption!(m::SCSMathProgModel, option::Symbol, value)
nt = NamedTuple{(option,), Tuple{typeof(value)}}((value,))
m.options = pairs(merge(m.options.data, nt))
return m
end
else
function addoption!(m::SCSMathProgModel, option::Symbol, value)
push!(m.options, (option, value))
return m
end
end

# warmstart
# kwargs can be `primal_sol`, `dual_sol`, and `slack`
function setwarmstart!(m::SCSMathProgModel, primal_sol; kwargs...)
m.options = pairs(merge(m.options.data, (warm_start=true,)))
addoption!(m, :warm_start, true)
m.primal_sol = primal_sol
for (k,v) in kwargs
setfield!(m, k, v)
Expand Down
6 changes: 4 additions & 2 deletions src/SCS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ else
error("SCS not properly installed. Please run Pkg.build(\"SCS\") and restart julia")
end

using Libdl
using Compat
using Compat.Libdl
using Compat.Sys: isunix

function __init__()
vnum = VersionNumber(SCS_version())
# default binaries need access to Julia's lapack symbols
if Sys.isunix()
if isunix()
dlopen(Base.liblapack_name, RTLD_LAZY|RTLD_DEEPBIND|RTLD_GLOBAL)
end
depsdir = realpath(joinpath(dirname(@__FILE__),"..","deps"))
Expand Down
8 changes: 7 additions & 1 deletion src/c_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ function SCS_solve(T::Union{Type{Direct}, Type{Indirect}},
cone = Ref(SCSCone(f, l, q, s, ep, ed, p))
info = Ref(SCSInfo())

if (:warm_start=>true) in options && length(primal_sol) == n && length(dual_sol) == m && length(slack) == m
if VERSION >= v"0.7-"
ws = (:warm_start=>true) in options
else
ws = (:warm_start, true) in options
end

if ws && length(primal_sol) == n && length(dual_sol) == m && length(slack) == m
x = primal_sol
y = dual_sol
s = slack
Expand Down
4 changes: 2 additions & 2 deletions src/types.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using SparseArrays
using Compat.SparseArrays

export SCSMatrix, SCSData, SCSSettings, SCSSolution, SCSInfo, SCSCone, SCSVecOrMatOrSparse

Expand Down Expand Up @@ -68,7 +68,7 @@ struct SCSData
stgs::Ptr{SCSSettings}
end

struct SCSSolution
@compat struct SCSSolution
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This @compat shouldn't be needed.

x::Ptr{Nothing}
y::Ptr{Nothing}
s::Ptr{Nothing}
Expand Down
2 changes: 1 addition & 1 deletion test/MPBWrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
include("mpb_linear.jl")
end

using Pkg.dir
using Compat.Pkg: dir
@testset "MathProgBase" begin
include(joinpath(dir("MathProgBase"),"test","conicinterface.jl"))
coniclineartest(SCS.SCSSolver(), duals=true, tol=1e-2)
Expand Down
4 changes: 2 additions & 2 deletions test/mpb_linear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#############################################################################

using MathProgBase
using LinearAlgebra
using SparseArrays
using Compat.LinearAlgebra
using Compat.SparseArrays

solver = SCSSolver()
objtol = 1e-4
Expand Down
3 changes: 2 additions & 1 deletion test/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ MathProgBase.optimize!(m)
@test isapprox(MathProgBase.getobjval(m), -99.0, atol=1e-5)

# With a warmstart from the eps = 1e-8 solution, solution should be extremely accurate even after 1 iteration
m.options = pairs(merge(m.options.data, (warm_start=true, max_iters=1)))
SCS.addoption!(m, :warm_start, true)
SCS.addoption!(m, :max_iters, 1)
MathProgBase.optimize!(m)
@test isapprox(MathProgBase.getobjval(m), -99.0, atol=1e-5)

Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Test
using Compat.Test
using SCS

tests = ["direct.jl",
Expand Down
2 changes: 1 addition & 1 deletion test/test_problems.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using SparseArrays
using Compat.SparseArrays

# Random, feasible conic problem (no exponential or SDP cones)
# Problem data taken from https://github.com/cvxgrp/scs/blob/master/examples/raw/demo_data
Expand Down