Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The value function retsults in Getting attribute MathOptInterface.VariablePrimal cannot be performed #114

Closed
votroto opened this issue Mar 12, 2024 · 4 comments · Fixed by #115

Comments

@votroto
Copy link
Contributor

votroto commented Mar 12, 2024

After optimizing a model

using JuMP, PolyJuMP, Gurobi

m = Model(() -> PolyJuMP.QCQP.Optimizer(Gurobi.Optimizer()))

@variable m -1 <= c <= 1
@constraint m c ^ 2 == 0.5
@objective m Min c
optimize!(m)

I can get the result with this

MOI.get(unsafe_backend(m).model, MOI.VariablePrimal(), c.index)

but this

@show value(c)

throws an Error

LoadError: MathOptInterface.GetAttributeNotAllowed{MathOptInterface.VariablePrimal}: Getting attribute MathOptInterface.VariablePrimal(1) cannot be performed: PolyJuMP.QCQP.Optimizer{Float64, Gurobi.Optimizer} does not support getting the attribute MathOptInterface.VariablePrimal(1). You may want to use a `CachingOptimizer` in `AUTOMATIC` mode or you may need to call `reset_optimizer` before doing this operation if the `CachingOptimizer` is in `MANUAL` mode.
@odow
Copy link
Member

odow commented Mar 12, 2024

Yeah I noticed this the other day, but I wasn't sure if this was a deliberate choice by @blegat?

@votroto
Copy link
Contributor Author

votroto commented Mar 14, 2024

Adding just a "fall through" get

function MOI.get(model::Optimizer, attr::MOI.AbstractVariableAttribute, vi::MOI.VariableIndex)
    return MOI.get(model.model, attr, vi)
end

would fix it. There are a few places in the QCQP code which do gets and sets on model.model, such a method would help there too.

@blegat
Copy link
Member

blegat commented Mar 14, 2024

I started a draft yesterday doing that with tests that I forgot to push

@odow
Copy link
Member

odow commented Mar 14, 2024

Okay, want to make a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants