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

Gurobi Error 10005: Unable to retrieve attribute 'Pi' #390

Closed
rezabayani opened this issue Jan 20, 2021 · 3 comments
Closed

Gurobi Error 10005: Unable to retrieve attribute 'Pi' #390

rezabayani opened this issue Jan 20, 2021 · 3 comments

Comments

@rezabayani
Copy link

rezabayani commented Jan 20, 2021

I am trying to retrieve some Gurobi attributes for through MOI.get() function with direct_model() enabled. Everything seems to be working but when I try to get "Pi" (dual value for a constraint), I encounter the error:

Gurobi Error 10005: Unable to retrieve attribute 'Pi'
in top-level scope at initial_test.jl:53
in get at JuMP\e0Uc2\src\JuMP.jl:889
in get at Gurobi\Lci9Q\src\MOI_wrapper.jl:3657
in _get_attribute at Gurobi\Lci9Q\src\MOI_wrapper.jl:3619
in _check_ret at Gurobi\Lci9Q\src\MOI_wrapper.jl:277

versioninfo():
Commit 2d5741174c (2019-12-30 21:36 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:
JULIA_EDITOR = "C:\Users\Reza\AppData\Local\atom\app-1.54.0\atom.exe" -a
JULIA_NUM_THREADS = 4

Pkg.status():
C:\Users\Reza\.julia\environments\v1.3\Project.toml
[c52e3926] Atom v0.12.30
[fa961155] CEnum v0.3.0
[be33ccc6] CUDAnative v3.1.0
[8f4d0f93] Conda v1.5.0
[7806a523] DecisionTree v0.10.10
[31c24e10] Distributions v0.23.8
[587475ba] Flux v0.10.4
[60bf3e95] GLPK v0.14.5
[61eb1bfa] GPUCompiler v0.2.0
[2e9cd046] Gurobi v0.9.7
[7073ff75] IJulia v1.23.1
[b6b21f68] Ipopt v0.6.5
[4076af6c] JuMP v0.21.4
[e5e0dc1b] Juno v0.8.4
[1902f260] Knet v1.3.6
[91a5bcdd] Plots v1.6.12
[438e738f] PyCall v1.92.2
[3646fa90] ScikitLearn v0.6.3
[2913bbd2] StatsBase v0.33.2
[9a3f8284] Random

steps to reproduce:
using Gurobi
using JuMP

define a simple UC problem

n_u = 8
n_t = 4
U = collect(1:n_u) # num units
T = collect(1:n_t) # num time steps
p_g_min = round.(0.3rand(n_u), digits=2)
p_g_max = 1 .+ round.(rand(n_u), digits=2)
cost_g = 10 .+ round.(10.0
rand(n_u), digits=1)
cost_g0 = round.(3.0rand(n_u), digits=1)
d0 = rand((sum(p_g_min):.01:.5
sum(p_g_max)),n_t)

basic_uc_model = Model(Gurobi.Optimizer)

basic_uc_model = direct_model(Gurobi.Optimizer())
@variable(basic_uc_model, p_g[i in U, t in T])
@variable(basic_uc_model, I_g[i in U, t in T], Bin)
@constraint(basic_uc_model, lower_band[i in U, t in T], p_g[i,t] >= p_g_min[i]*I_g[i,t])
@constraint(basic_uc_model, upper_band[i in U, t in T], p_g[i,t] <= p_g_max[i]*I_g[i,t])
@constraint(basic_uc_model, demand[t in T], sum(p_g[i,t] for i in U) == d0[t])
@objective(basic_uc_model, Min, sum(p_g[i,t]*cost_g[i] + I_g[i,t]*cost_g0[i] for i in U, t in T))

optimize!(basic_uc_model)
JuMP.objective_value(basic_uc_model)
JuMP.value.(p_g)
JuMP.value.(I_g)

MOI.get(basic_uc_model, Gurobi.ModelAttribute("ObjVal")) # Objective value for current solution
MOI.get(basic_uc_model, Gurobi.VariableAttribute("Obj"), p_g[2,2]) # Linear objective coefficient
MOI.get(basic_uc_model, Gurobi.ConstraintAttribute("Slack"), lower_band[2,2]) #
MOI.get(basic_uc_model, Gurobi.ConstraintAttribute("Pi"), upper_band[2,2]) # Dual value (also known as the shadow price)

I can obtain other attributes as can be seen, this only happens when I try "Pi". Also, I tried different versions of Gurobi (version 8.1 solver and julia package, instead of 9.1) but it did not help. I even tried it on both JuliaPro and Atom+Juno but that did not help neither. I would appreciate your feedback.

@odow
Copy link
Member

odow commented Jan 20, 2021

Dual variables are not available for models with binary variables. You can check this with

JuMP.dual_status(basic_uc_model)  # MOI.NO_SOLUTION

Here is the documentation: https://jump.dev/JuMP.jl/stable/solutions/#Solution-statuses-1

Closing because this is not a bug in Gurobi.jl.

p.s. These questions are better suited to the community forum: https://discourse.julialang.org/c/domain/opt/13

@odow odow closed this as completed Jan 20, 2021
@frederikgeth
Copy link

I ran into this yesterday, and this thread pointed us to the solution. I agree it's not a bug, but the error message is sort of unhelpful when using packages that offer functionality to automatically extract duals from a model (such as InfrastructureModels, PowerModels).

@odow
Copy link
Member

odow commented Jun 17, 2021

This has come up multiple times, and we settled on Gurobi's default behavior:
#309
#312

Did Gurobi not print a warning like:

Warning: to get QCP duals, please set parameter QCPDual to 1

Edit: ah. This is for integers. Tell Gurobi support you want a better error message :)

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

No branches or pull requests

3 participants