Skip to content

Normal execution path of CLP involves exception throwing/catching #1249

@mabokhamis

Description

@mabokhamis

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)

Clp_profile

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions