Skip to content

Commit a8e64d4

Browse files
rofinnararslan
authored andcommitted
Completely drop the DEFAULT_SOLVER logic (#250)
- Dropped get_default_solver and set_default_solver - Reorganized tests to not depend on get_default_solver (the giant at-testset for loop can be changed). - Only API change is that if you didn't define a problem with a solver/model then `solve!(p)` throws an argument (e.g., `solve!(p, solver)` is preferred now. NOTE: The existing `solve!(p, solver)` just assigns the problem model anyways with `problem.model = MathProgBase.ConicModel(s)`
1 parent 9490233 commit a8e64d4

17 files changed

+797
-955
lines changed

src/problems.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ mutable struct Problem
2525
constraints::Array{Constraint}
2626
status::Symbol
2727
optval::Float64OrNothing
28-
model::MathProgBase.AbstractConicModel
28+
model::Union{MathProgBase.AbstractConicModel, Nothing}
2929
solution::Solution
3030

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

4142
# constructor if model is not specified
4243
function Problem(head::Symbol, objective::AbstractExpr, constraints::Array=Constraint[],
43-
solver::MathProgBase.AbstractMathProgSolver=DEFAULT_SOLVER)
44-
Problem(head, objective, MathProgBase.ConicModel(solver), constraints)
44+
solver::Union{MathProgBase.AbstractMathProgSolver, Nothing}=nothing)
45+
model = solver !== nothing ? MathProgBase.ConicModel(solver) : solver
46+
Problem(head, objective, model, constraints)
4547
end
4648

4749
# If the problem constructed is of the form Ax=b where A is m x n

src/solution.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ function solve!(problem::Problem;
1818
check_vexity=true,
1919
verbose=true)
2020

21+
if problem.model === nothing
22+
throw(ArgumentError(
23+
"The provided problem hasn't been initialized with a conic model.
24+
You can resolve this by passing in `AbstractMathProgSolver` such as:
25+
solve!(problem, ECOSSolver())"
26+
))
27+
end
28+
2129
if check_vexity
2230
vex = vexity(problem)
2331
end

src/solver_info.jl

Lines changed: 4 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,7 @@
11
using Pkg
22
import MathProgBase
33
export can_solve_mip, can_solve_socp, can_solve_sdp, can_solve_exp
4-
export set_default_solver, get_default_solver, isinstalled
5-
6-
function set_default_solver(solver::MathProgBase.AbstractMathProgSolver)
7-
Base.depwarn(
8-
"Default solvers are deprecated and will not be provided in a future release.
9-
You can still manually load and use solvers such as ECOS by running:
10-
using ECOS
11-
p = minimize(...);
12-
solve!(p, ECOSSolver())",
13-
:set_default_solver
14-
)
15-
16-
global DEFAULT_SOLVER
17-
DEFAULT_SOLVER = solver
18-
end
19-
20-
function get_default_solver()
21-
Base.depwarn(
22-
"Default solvers are deprecated and will not be provided in a future release.
23-
You can still manually load and use installed solvers such as ECOS by running:
24-
using ECOS
25-
p = minimize(...);
26-
solve!(p, ECOSSolver())",
27-
:get_default_solver
28-
)
29-
30-
if DEFAULT_SOLVER == nothing
31-
error("The default solver is set to `nothing`
32-
You must have at least one solver installed to use Convex.
33-
You can install a solver such as SCS by running:
34-
Pkg.add(\"SCS\").
35-
You will have to restart Julia after that.")
36-
end
37-
38-
return DEFAULT_SOLVER
39-
end
40-
41-
# TODO: I have not listed solvers such as CPLEX etc because I have not tested Convex with them
42-
solvers = [("ECOS", "ECOSSolver"), ("SCS", "SCSSolver"), ("Gurobi", "GurobiSolver"), ("Mosek", "MosekSolver"),
43-
("GLPKMathProgInterface", "GLPKSolverMIP")]
4+
export isinstalled
445

456
function isinstalled(pkg)
467
for path in Base.DEPOT_PATH
@@ -52,24 +13,10 @@ function isinstalled(pkg)
5213
return false
5314
end
5415

55-
for (dir, solver) in solvers
56-
if isinstalled(dir) && DEFAULT_SOLVER == nothing
57-
eval(Meta.parse("using $dir"))
58-
eval(Meta.parse("set_default_solver($solver())"))
59-
end
60-
end
61-
16+
# TODO: I have not listed solvers such as CPLEX etc because I have not tested Convex with them
17+
solvers = [("ECOS", "ECOSSolver"), ("SCS", "SCSSolver"), ("Gurobi", "GurobiSolver"), ("Mosek", "MosekSolver"),
18+
("GLPKMathProgInterface", "GLPKSolverMIP")]
6219

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

7421
function can_solve_mip(solver)
7522
name = typeof(solver).name.name

test/runtests.jl

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
using Convex
2+
using Convex: DotMultiplyAtom
23
using Test
34
using ECOS
45
using SCS
56
using GLPKMathProgInterface
67
using Random
78

9+
import LinearAlgebra.eigen
10+
import LinearAlgebra.I
11+
import LinearAlgebra.opnorm
12+
import Random.shuffle
13+
import Statistics.mean
14+
15+
TOL = 1e-3
16+
eye(n) = Matrix(1.0I, n, n)
17+
818
# Seed random number stream to improve test reliability
919
Random.seed!(2)
1020

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

27-
for solver in solvers
28-
println("Running tests with $(solver):")
29-
set_default_solver(solver)
30-
println(get_default_solver())
31-
include("runtests_single_solver.jl")
37+
@testset "Convex" begin
38+
include("test_utilities.jl")
39+
include("test_affine.jl")
40+
include("test_lp.jl")
41+
include("test_socp.jl")
42+
include("test_sdp.jl")
43+
include("test_exp.jl")
44+
include("test_sdp_and_exp.jl")
45+
include("test_mip.jl")
3246
end

test/runtests_single_solver.jl

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)