Key error in JuMP on domain tuples

Hi folks,

I’m having a strange problem with JuMP that I hope someone can identify…

The first formulation below results in a key error but the second doesn’t but both should, in theory involve evaluations on the same sets of keys…

It’s frustrating because in the second formulation that works, I can’t name the constraints nicely,

#results in key error on (u,ats)
                (u,ats) in unit__avail_timeseries(),
                (t,s) in T_S
            + v_ps[u,t,s]
            + production_max(unit=u)*time_series_data(time_series=ats,t=t)

# works fine
        for (u,ats) in unit__avail_timeseries(),(t,s) in T_S
                    + v_ps[u,t,s]
                    + production_max(unit=u)*time_series_data(time_series=ats,t=t)

Edit: the error is as follows:

ERROR: LoadError: LoadError: KeyError: key (:NPV_1271_BAL_110, :PV_J) not found
 [1] getindex at .\dict.jl:478 [inlined]
 [2] lookup_index at .julia\packages\JuMP\jnmGG\src\Containers\DenseAxisArray.jl:120 [
 [3] _to_index_tuple(::Tuple{Tuple{Symbol,Symbol},Tuple{Int64,Int64}}, ::Tuple{Dict{Array{Symbol,1},
Int64},Dict{Any,Int64}}) at .julia\packages\JuMP\jnmGG\src\Containers\DenseAxisArray.j
 [4] to_index at .julia\packages\JuMP\jnmGG\src\Containers\DenseAxisArray.jl:147 [inli
 [5] setindex!(::JuMP.Containers.DenseAxisArray{ConstraintRef{Model,C,Shape} where Shape<:AbstractSh
ape where C,2,Tuple{Array{Array{Symbol,1},1},Array{Any,1}},Tuple{Dict{Array{Symbol,1},Int64},Dict{An
y,Int64}}}, ::ConstraintRef{Model,MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunc
tion{Float64},MathOptInterface.LessThan{Float64}},ScalarShape}, ::Tuple{Symbol,Symbol}, ::Tuple{Int6
4,Int64}) at .julia\packages\JuMP\jnmGG\src\Containers\DenseAxisArray.jl:166
 [6] top-level scope at .julia\packages\JuMP\jnmGG\src\macros.jl:621
 [7] include at .\boot.jl:326 [inlined]
 [8] include_relative(::Module, ::String) at .\loading.jl:1038
 [9] include(::Module, ::String) at .\sysimg.jl:29
 [10] include(::String) at .\client.jl:403
 [11] top-level scope at *.jl:81
in expression starting at *constraints.jl:261
in expression starting at *.jl:67

You can try

@constraint(m, q_unit_avail_timeseries[
    uats in unit__avail_timeseries(),
    ts in T_S
], + v_ps[uats[1],ts[1],ts[2]] <= + production_max(unit=uats[1])*time_series_data(time_series=uats[2],t=ts[1]) )

Thanks for that. It’s strange that (t,s) in T_S works but (u,ats) in unit__avail_timeseries()doesn’t… and it doesn’t appear to be because it’s a function returning the set of tuples, I used a variable here in place and that doesn’t work either

It would help, if you could give what unit__avail_timeseries() returns, or an equivalent that give the same error that you obtain by simplifying it until it stops failing.

ok, so

julia> @show unit__avail_timeseries()
unit__avail_timeseries() = ...
154-element Array{Array{Symbol,1},1}:

there is no problem with T_S which is:

julia> @show T_S
T_S = ...
48-element Array{Any,1}:

Ok, so I’ve determined the problem… it works fine if (a,b) is a set of tuples but if (c.d) is an array of arrays, it doesn’t work.

I guess the question is, though, if it works in a for loop, shouldn’t it work in a JuMP constraint?