Hi, after updating some packages I got this error:
`ClpSolver` is no longer supported. If you are using JuMP, upgrade to the latest version and use `Clp.Optimizer` instead. If you are using MathProgBase (e.g., via `lingprog`), you will need to upgrade to MathOptInterface (https://github.com/JuliaOpt/MathOptInterface.jl).
No problem, I was certainly using MathProgBase
via lingprog
so I just needed to migrate my code and use JuMP
. But, after doing it, I am having performance problems. Solving the same model now can take up to an order of magnitude longer.
I’m working with metabolic networks doing some FBA, so the optimization problem is quite simple:
\text{Maximize:} \: obj \in x
\text{subject to:}\\ Sx = b \\ lb \leq x \leq ub
Here was my code when using MathProgBase
:
import MathProgBase.HighLevelInterface: linprog
import Clp
function fba_MathProgBase(S, b, lb, ub, obj_idx::Integer;
sense = -1.0;
solver = Clp.ClpSolver())
M, N, = size(S)
sv = zeros(N);
sv[obj_idx] = sense
sol = linprog(
sv, # Opt sense vector
S, # Stoichiometric matrix
b, # row lb (mets)
b, # row ub (mets)
lb, # column lb (rxns)
ub, # column ub (rxns)
solver);
return sol.sol
end
Now using JuMP
:
import Clp
import JuMP
function fba_Jump(S, b, lb, ub, obj_idx::Integer;
sense = JuMP.MOI.MAX_SENSE,
solver = Clp.Optimizer)
M, N, = size(S)
model = JuMP.Model(solver)
JuMP.set_optimizer_attribute(model, "LogLevel", 0)
JuMP.@variable(model, x[1:N])
JuMP.@constraint(model, balance, S * x .== b)
JuMP.@constraint(model, bounds, lb .<= x .<= ub)
JuMP.@objective(model, sense, x[obj_idx])
JuMP.optimize!(model)
return JuMP.value.(x)
end
benchmarks results (using @btime
):
Julia Version 1.1.0
Commit 80516ca202 (2019-01-21 21:24 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin14.5.0)
CPU: Intel(R) Core(TM) i5-8210Y CPU @ 1.60GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:
JULIA_NUM_THREADS = 4
JULIA_EDITOR = code
Model: toy_model.json size: (5, 8) -------------------
fba_JuMP-GLPK.Optimizer
322.222 μs (1831 allocations: 112.19 KiB)
obj_val: 3.181818181818181
fba_JuMP-Clp.Optimizer
916.346 μs (3214 allocations: 193.47 KiB)
obj_val: 3.1818181818181817
fba_MathProgBase-ClpSolver
150.475 μs (32 allocations: 2.47 KiB)
obj_val: 3.1818181818181817
Model: e_coli_core.json size: (72, 95) -------------------
fba_JuMP-GLPK.Optimizer
1.812 ms (10908 allocations: 533.33 KiB)
obj_val: 0.8739215069685011
fba_JuMP-Clp.Optimizer
3.128 ms (19681 allocations: 973.48 KiB)
obj_val: 0.8739215069684311
fba_MathProgBase-ClpSolver
688.877 μs (32 allocations: 11.58 KiB)
obj_val: 0.8739215069684311
Model: iJR904.json size: (762, 976) -------------------
fba_JuMP-GLPK.Optimizer
41.945 ms (101450 allocations: 4.41 MiB)
obj_val: 0.5782403962872187
fba_JuMP-Clp.Optimizer
42.815 ms (190924 allocations: 14.62 MiB)
obj_val: 0.5782403962871316
fba_MathProgBase-ClpSolver
17.824 ms (35 allocations: 118.00 KiB)
obj_val: 0.5782403962871316
Model: HumanGEM.json size: (8461, 13417) -------------------
fba_JuMP-GLPK.Optimizer
15.458 s (1300964 allocations: 61.45 MiB)
obj_val: 2.334553007169305
fba_JuMP-Clp.Optimizer
5.295 s (2456570 allocations: 1.43 GiB)
obj_val: 2.334553007230854
fba_MathProgBase-ClpSolver
568.137 ms (45 allocations: 1.35 MiB)
obj_val: 2.3345530071688514
You can find the tests here, I pushed a Manifest.toml
Thansk!!
[EDITED] Fix bug in benchmarks because @btime global design