# Indexing variables by vectors not working in JuMPv1.2.x

**URL:** <https://discourse.julialang.org/t/indexing-variables-by-vectors-not-working-in-jumpv1-2-x/86652>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [September 1, 2022, 5:12pm UTC](https://discourse.julialang.org/t/indexing-variables-by-vectors-not-working-in-jumpv1-2-x/86652 "2022-09-01T17:12:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![BatyLeo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/batyleo/32/35017_2.png) [@BatyLeo](https://discourse.julialang.org/u/BatyLeo)\
**Post date:** [September 1, 2022, 5:12pm UTC](https://discourse.julialang.org/t/indexing-variables-by-vectors-not-working-in-jumpv1-2-x/86652/1 "2022-09-01T17:12:31Z")

</div>

Hello, a bug appeared in my package when I updated JuMP to v1.2.1 from v1.1.1.

Here is a minimum (non) working example:

```julia
using GLPK
using JuMP

paths = [
    [1, 2, 15, 3, 20],
    [1, 9, 16, 20],
    [1, 2, 20]
]

model = Model(GLPK.Optimizer)

@variable(model, y[p in paths], Bin)

@objective(
    model,
    Min,
    sum(y[p] for p in paths)
)

```

The variable definition works, but the expression `sum(y[p] for p in paths)` raises a `KeyError: key 1 not found`, which was not the case before.

Did I miss something ?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [September 1, 2022, 6:54pm UTC](https://discourse.julialang.org/t/indexing-variables-by-vectors-not-working-in-jumpv1-2-x/86652/2 "2022-09-01T18:54:11Z")

</div>

Hmm. This may have broken things [Allow `_AxisLookup` to fallback to Dict `getindex` by nickrobinson251 · Pull Request #3028 · jump-dev/JuMP.jl · GitHub](https://github.com/jump-dev/JuMP.jl/pull/3028)

Let me take a look.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [September 1, 2022, 8:24pm UTC](https://discourse.julialang.org/t/indexing-variables-by-vectors-not-working-in-jumpv1-2-x/86652/3 "2022-09-01T20:24:45Z")

</div>

I have a fix: [[Containers] fix DenseAxisArray with Vector key by odow · Pull Request #3064 · jump-dev/JuMP.jl · GitHub](https://github.com/jump-dev/JuMP.jl/pull/3064)

It might take a bit to get a new release, but you can fix your code by adding this function to your script, just after `using JuMP`. Once we update JuMP, you can remove it.

```julia
function Base.getindex(
    x::JuMP.Containers._AxisLookup{Dict{K,Int}},
    key::K,
) where {K<:AbstractVector}
    return x.data[key]
end

```

---

<div class="post-metadata">

**Author:** ![BatyLeo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/batyleo/32/35017_2.png) [@BatyLeo](https://discourse.julialang.org/u/BatyLeo)\
**Post date:** [September 2, 2022, 6:37am UTC](https://discourse.julialang.org/t/indexing-variables-by-vectors-not-working-in-jumpv1-2-x/86652/4 "2022-09-02T06:37:03Z")

</div>

Thanks for the quick answer, your workaround works perfectly !

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [September 4, 2022, 11:47pm UTC](https://discourse.julialang.org/t/indexing-variables-by-vectors-not-working-in-jumpv1-2-x/86652/5 "2022-09-04T23:47:34Z")

</div>

Just to follow up: JuMP v1.3.0 has been released with a fix for this bug.
