The normal execution path of using Clp to solve a linear program through JuMP involves throwing and catching an exception. In particular, an exception is always thrown here
|
add_variable(model::ModelLike) = throw(AddVariableNotAllowed()) |
and is caught here (or in a similar place in the same file)
The exception handling can take up a significant portion of the overall optimization time, as shown by the benchmark below. Is there a way to avoid it?
using JuMP, Clp, MathOptInterface
using Profile, PProf
function test_clp(n::Int = 1000)
for i = 1:n
model = Model(Clp.Optimizer)
set_optimizer_attribute(model, "LogLevel", 0)
@variable(model, λ[1:3] ≥ 0.0)
obj = @expression(model, sum(λ[jj] for jj in 1:3))
@objective(model, Min, obj)
@constraint(model, con[ii in 1:3],
sum(λ[jj] for jj in 1:3 if jj != ii) ≥ 1.0)
optimize!(model)
@assert termination_status(model) == MathOptInterface.OPTIMAL
sol = value.(λ)
obj_value = objective_value(model)
end
end
test_clp(1000) # warmpup
Profile.init(n=Int(1e8), delay=0.002)
@pprof test_clp(1000)

The normal execution path of using
Clpto solve a linear program throughJuMPinvolves throwing and catching an exception. In particular, an exception is always thrown hereMathOptInterface.jl/src/variables.jl
Line 37 in ac22378
and is caught here (or in a similar place in the same file)
MathOptInterface.jl/src/Utilities/cachingoptimizer.jl
Line 308 in ac22378
The exception handling can take up a significant portion of the overall optimization time, as shown by the benchmark below. Is there a way to avoid it?