Skip to content

Using MathProgBase programmatically #201

@gragusa

Description

@gragusa

I am trying to automate the construction of MathProgBase.

I am doing something along these lines:

matable struct MPB <: MathProgBase.AbstractNLPEvaluator end

function foo(f::Function, g!::Function, x0, lvar, uvar, sense, solver, args...)
MathProgBase.features_available(g::MPB) = [:Grad]
    function MathProgBase.initialize(d::MPB, requested_features::Vector{Symbol})
        for feat in requested_features
            if !(feat in [:Grad])
                error("Unsupported feature $feat")
            end
        end
    end

    MathProgBase.jac_structure(g::MPB) = Int[],Int[]
    MathProgBase.eval_jac_g(g::MPB, J, x) = nothing
    MathProgBase.eval_f(g::MPB, x) = f(x)
    MathProgBase.eval_grad_f(g::MPB, gr, x) = g!(gr, x)    
    m = MathProgBase.NonlinearModel(solver)
    MathProgBase.loadproblem!(m, length(x0), 0, lvar, uvar, Float64[], Float64[], sense, MPB())
    MathProgBase.setwarmstart!(m, x0)
    do_computations(m, args...)
end

The function works fails the first time with a ERROR: MethodError: no method matching features_available(::Genoud.Genoud_MPB) The applicable method may be too new: running in world age 21824, while current world is 21830.. After I run it twice everything works as expected. I know about the World count, but I was wondering how can I obviate this problem (I am running out of ideas). The alternative would be to pass the non-linear problem as an argument to foo but I would like to make this automatic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions