Skip to content

[Bug]: MIP run fails when writing capacity outputs due to unconditional dual access for cMaxCap #897

@JesseJenkins

Description

@JesseJenkins

Bug description

In GenX MIP runs (e.g. discrete capacity or operational decisions), output writing can fail with:

Gurobi Error 10005: Unable to retrieve attribute 'Pi'

This happens in write_capacity.jl when it always calls dual(EP[:cMaxCap][y]), even when duals are unavailable for MIP solutions. This is triggered even if WriteShadowPrices=0 in genx_settings.yml.

Steps to reproduce:

Run a MIP GenX case with Gurobi (UCommit>0).
Ensure outputs include capacity (WriteCapacity=1).
Observe crash during output writing with Pi error.

Expected:
Outputs should be written without requiring duals when shadow prices are disabled.

Actual:
write_capacity.jl attempts to read duals from cMaxCap, causing a solver error and output failure.

Suggested fix:
Guard dual access in write_capacity.jl:

If !has_duals(EP), leave capacity constraint duals at zero (or skip entirely).
Example patch:
capacity_constraint_dual = zeros(size(inputs["RESOURCE_NAMES"]))
if has_duals(EP)
    for y in ids_with_positive(gen, max_cap_mw)
        capacity_constraint_dual[y] = -dual.(EP[:cMaxCap][y])
    end
end

Notes:

This matches how other outputs handle duals (gated by has_duals or WriteShadowPrices).
This error occurs even when WriteShadowPrices=0.

This Bug Report written by GTP-5.2-Codex with direction from @JesseJenkins

Environment and Version

This is run on a local branch of GenX with Benders implemented, so it may not match the current Main. Please check that this usage occurs in the main branch as well. If it does not, then close this Bug report out.

Relevant error messages

Gurobi Error 10005: Unable to retrieve attribute 'Pi'

Additional context

No response

Metadata

Metadata

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions