jump-dev / DiffOpt.jl

Differentiating convex optimization programs w.r.t. program parameters
https://jump.dev/DiffOpt.jl/stable
MIT License
123 stars 14 forks source link

SingleVariable objective should be compatible with QPs #82

Closed matbesancon closed 3 years ago

matbesancon commented 3 years ago
const QP_OBJECTIVE_TYPES = Union{
    MathOptInterface.ScalarAffineFunction{Float64},
    MathOptInterface.ScalarQuadraticFunction{Float64},
}

This makes LPs with MOI.SingleVariable conic programs, which is a bit overkill

matbesancon commented 3 years ago

this errors, because calls the conic interface:

    model = direct_model(diff_optimizer(Clp.Optimizer))
    MOI.set(model, MOI.Silent(), true)

    @variable(model, x[1:1])

    @objective(model, Min, x[1])
    @constraint(model, x[1] ≥ 0)
    @constraint(model, x[1] ≥ 3)

    optimize!(model)

    # obtain gradients
    grads = backward(JuMP.backend(model), ["G", "h"], [1.0])

This fixes the problem:

    @objective(model, Min, 1.1 * x[1])
joaquimg commented 3 years ago

This should be fixed in the #81 rewrite

matbesancon commented 3 years ago

OK great. I had a quick fix in an upcoming PR but a more systematic one will be better

joaquimg commented 3 years ago

fixed by #83