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

Completely dropped the DEFAULT_SOLVER logic #250

Merged
merged 3 commits into from Dec 12, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/problems.jl
Expand Up @@ -25,11 +25,12 @@ mutable struct Problem
constraints::Array{Constraint}
status::Symbol
optval::Float64OrNothing
model::MathProgBase.AbstractConicModel
model::Union{MathProgBase.AbstractConicModel, Nothing}
solution::Solution

function Problem(head::Symbol, objective::AbstractExpr,
model::MathProgBase.AbstractConicModel, constraints::Array=Constraint[])
model::Union{MathProgBase.AbstractConicModel, Nothing}=nothing,
constraints::Array=Constraint[])
if sign(objective)== Convex.ComplexSign()
error("Objective can not be a complex expression")
else
Expand All @@ -40,8 +41,9 @@ end

# constructor if model is not specified
function Problem(head::Symbol, objective::AbstractExpr, constraints::Array=Constraint[],
solver::MathProgBase.AbstractMathProgSolver=DEFAULT_SOLVER)
Problem(head, objective, MathProgBase.ConicModel(solver), constraints)
solver::Union{MathProgBase.AbstractMathProgSolver, Nothing}=nothing)
model = solver !== nothing ? MathProgBase.ConicModel(solver) : solver
Problem(head, objective, model, constraints)
end
rofinn marked this conversation as resolved.
Show resolved Hide resolved

# If the problem constructed is of the form Ax=b where A is m x n
Expand Down
8 changes: 8 additions & 0 deletions src/solution.jl
Expand Up @@ -18,6 +18,14 @@ function solve!(problem::Problem;
check_vexity=true,
verbose=true)

if problem.model === nothing
throw(ArgumentError(
"The provided problem hasn't been initialized with a conic model.
You can resolve this by passing in `AbstractMathProgSolver` such as:
solve!(problem, ECOSSolver())"
))
end

if check_vexity
vex = vexity(problem)
end
Expand Down
61 changes: 4 additions & 57 deletions src/solver_info.jl
@@ -1,46 +1,7 @@
using Pkg
import MathProgBase
export can_solve_mip, can_solve_socp, can_solve_sdp, can_solve_exp
export set_default_solver, get_default_solver, isinstalled

function set_default_solver(solver::MathProgBase.AbstractMathProgSolver)
Base.depwarn(
"Default solvers are deprecated and will not be provided in a future release.
You can still manually load and use solvers such as ECOS by running:
using ECOS
p = minimize(...);
solve!(p, ECOSSolver())",
:set_default_solver
)

global DEFAULT_SOLVER
DEFAULT_SOLVER = solver
end

function get_default_solver()
Base.depwarn(
"Default solvers are deprecated and will not be provided in a future release.
You can still manually load and use installed solvers such as ECOS by running:
using ECOS
p = minimize(...);
solve!(p, ECOSSolver())",
:get_default_solver
)

if DEFAULT_SOLVER == nothing
error("The default solver is set to `nothing`
You must have at least one solver installed to use Convex.
You can install a solver such as SCS by running:
Pkg.add(\"SCS\").
You will have to restart Julia after that.")
end

return DEFAULT_SOLVER
end

# TODO: I have not listed solvers such as CPLEX etc because I have not tested Convex with them
solvers = [("ECOS", "ECOSSolver"), ("SCS", "SCSSolver"), ("Gurobi", "GurobiSolver"), ("Mosek", "MosekSolver"),
("GLPKMathProgInterface", "GLPKSolverMIP")]
export isinstalled

function isinstalled(pkg)
for path in Base.DEPOT_PATH
Expand All @@ -52,24 +13,10 @@ function isinstalled(pkg)
return false
end

for (dir, solver) in solvers
if isinstalled(dir) && DEFAULT_SOLVER == nothing
eval(Meta.parse("using $dir"))
eval(Meta.parse("set_default_solver($solver())"))
end
end

# TODO: I have not listed solvers such as CPLEX etc because I have not tested Convex with them
solvers = [("ECOS", "ECOSSolver"), ("SCS", "SCSSolver"), ("Gurobi", "GurobiSolver"), ("Mosek", "MosekSolver"),
("GLPKMathProgInterface", "GLPKSolverMIP")]

if get_default_solver() == nothing
packages = join([dir for (dir, solver) in solvers], " | ")
@warn "***********************************************************************************************
You don't have any of
"*packages*" installed.
You must have at least one of these solvers. You can install a solver such as SCS by running:
Pkg.add(\"SCS\")
You will have to restart Julia after that.
***********************************************************************************************"
end

function can_solve_mip(solver)
name = typeof(solver).name.name
Expand Down
24 changes: 19 additions & 5 deletions test/runtests.jl
@@ -1,10 +1,20 @@
using Convex
using Convex: DotMultiplyAtom
using Test
using ECOS
using SCS
using GLPKMathProgInterface
using Random

import LinearAlgebra.eigen
import LinearAlgebra.I
import LinearAlgebra.opnorm
import Random.shuffle
import Statistics.mean

TOL = 1e-3
eye(n) = Matrix(1.0I, n, n)

# Seed random number stream to improve test reliability
Random.seed!(2)

Expand All @@ -24,9 +34,13 @@ if isinstalled("Mosek")
push!(solvers, MosekSolver(LOG=0))
end

for solver in solvers
println("Running tests with $(solver):")
set_default_solver(solver)
println(get_default_solver())
include("runtests_single_solver.jl")
@testset "Convex" begin
include("test_utilities.jl")
include("test_affine.jl")
include("test_lp.jl")
include("test_socp.jl")
include("test_sdp.jl")
include("test_exp.jl")
include("test_sdp_and_exp.jl")
include("test_mip.jl")
end
61 changes: 0 additions & 61 deletions test/runtests_single_solver.jl

This file was deleted.