# A problem with JuMP Tutorial-linear problem-cannery problem

**URL:** <https://discourse.julialang.org/t/a-problem-with-jump-tutorial-linear-problem-cannery-problem/78795>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [March 31, 2022, 9:58am UTC](https://discourse.julialang.org/t/a-problem-with-jump-tutorial-linear-problem-cannery-problem/78795 "2022-03-31T09:58:13Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahon](https://avatars.discourse-cdn.com/v4/letter/m/9e8a1a/32.png) [@mahon](https://discourse.julialang.org/u/mahon)\
**Post date:** [March 31, 2022, 9:58am UTC](https://discourse.julialang.org/t/a-problem-with-jump-tutorial-linear-problem-cannery-problem/78795/1 "2022-03-31T09:58:13Z")

</div>

![image](https://global.discourse-cdn.com/julialang/original/3X/4/2/42cd467ce69563db2c6b3dcfdb46ded1d57d8223.png)

when I code like this , it leads a error

 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/7/777d57b4f83c17bb54f19b47d929c63742816921.png)

---

<div class="post-metadata">

**Author:** ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)\
**Post date:** [March 31, 2022, 2:59pm UTC](https://discourse.julialang.org/t/a-problem-with-jump-tutorial-linear-problem-cannery-problem/78795/2 "2022-03-31T14:59:26Z")

</div>

Positing screenshots of snippets makes it difficult to help

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [March 31, 2022, 4:48pm UTC](https://discourse.julialang.org/t/a-problem-with-jump-tutorial-linear-problem-cannery-problem/78795/3 "2022-03-31T16:48:35Z")

</div>

At a minimum, you need to show us what `data` and `x` are. It looks like `data` might be some kind of nested `Dict` but I can’t really tell.

---

<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:** [March 31, 2022, 7:12pm UTC](https://discourse.julialang.org/t/a-problem-with-jump-tutorial-linear-problem-cannery-problem/78795/4 "2022-03-31T19:12:14Z")

</div>

The Julia source code is here:  
[https://github.com/jump-dev/JuMP.jl/blob/master/docs/src/tutorials/linear/cannery.jl](https://github.com/jump-dev/JuMP.jl/blob/master/docs/src/tutorials/linear/cannery.jl)

If you’re trying to copy the tutorial, you probably made a typo somewhere. Just copy-paste from the Julia file.

If you’ve changed the data, then please provide a reproducible example.

---

<div class="post-metadata">

**Author:** ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)\
**Post date:** [March 31, 2022, 9:26pm UTC](https://discourse.julialang.org/t/a-problem-with-jump-tutorial-linear-problem-cannery-problem/78795/5 "2022-03-31T21:26:22Z")

</div>

I can confirm that code produces an error

```julia
julia> includet("/tmp/cannery.jl")
ERROR: MethodError: no method matching getindex(::Base.KeySet{String, Dict{String, Any}}, ::Colon)
Stacktrace:
  [1] _getindex_recurse(data::Tuple{Base.KeySet{String, Dict{String, Any}}}, keys::Tuple{Colon}, condition::typeof(JuMP.Containers._is_range))
    @ JuMP.Containers ~/.julia/packages/JuMP/klrjG/src/Containers/DenseAxisArray.jl:250
  [2] _getindex_recurse(data::Tuple{Base.KeySet{String, Dict{String, Any}}, Base.KeySet{String, Dict{String, Any}}}, keys::Tuple{Int64, Colon}, condition::typeof(JuMP.Containers._is_range))
    @ JuMP.Containers ~/.julia/packages/JuMP/klrjG/src/Containers/DenseAxisArray.jl:249
  [3] getindex(::JuMP.Containers.DenseAxisArray{VariableRef, 2, Tuple{Base.KeySet{String, Dict{String, Any}}, Base.KeySet{String, Dict{String, Any}}}, Tuple{JuMP.Containers._AxisLookup{Dict{String, Int64}}, JuMP.Containers._AxisLookup{Dict{String, Int64}}}}, ::String, ::Function)
    @ JuMP.Containers ~/.julia/packages/JuMP/klrjG/src/Containers/DenseAxisArray.jl:270
  [4] macro expansion
    @ ~/.julia/packages/MutableArithmetics/6pKCK/src/rewrite.jl:279 [inlined]
  [5] macro expansion
    @ ~/.julia/packages/JuMP/klrjG/src/macros.jl:676 [inlined]
  [6] (::var"#3#4")(p::String)
    @ Main ~/.julia/packages/JuMP/klrjG/src/Containers/macro.jl:194
  [7] #38
    @ ~/.julia/packages/JuMP/klrjG/src/Containers/container.jl:105 [inlined]
  [8] iterate
    @ ./generator.jl:47 [inlined]
  [9] collect(itr::Base.Generator{JuMP.Containers.VectorizedProductIterator{Tuple{Base.KeySet{String, Dict{String, Any}}}}, JuMP.Containers.var"#38#39"{var"#3#4"}})
    @ Base ./array.jl:678
 [10] map(f::Function, A::JuMP.Containers.VectorizedProductIterator{Tuple{Base.KeySet{String, Dict{String, Any}}}})
    @ Base ./abstractarray.jl:2323
 [11] container(f::Function, indices::JuMP.Containers.VectorizedProductIterator{Tuple{Base.KeySet{String, Dict{String, Any}}}}, #unused#::Type{JuMP.Containers.DenseAxisArray})
    @ JuMP.Containers ~/.julia/packages/JuMP/klrjG/src/Containers/container.jl:105
 [12] container(f::Function, indices::JuMP.Containers.VectorizedProductIterator{Tuple{Base.KeySet{String, Dict{String, Any}}}})
    @ JuMP.Containers ~/.julia/packages/JuMP/klrjG/src/Containers/container.jl:66
 [13] top-level scope
    @ /tmp/cannery.jl:100
in expression starting at /tmp/cannery.jl:100

```

for anyone who can help

```julia

julia> x
2-dimensional DenseAxisArray{VariableRef,2,...} with index sets:
    Dimension 1, ["Seattle", "San-Diego"]
    Dimension 2, ["Chicago", "Topeka", "New-York"]
And data, a 2×3 Matrix{VariableRef}:
 x[Seattle,Chicago] x[Seattle,Topeka] x[Seattle,New-York]
 x[San-Diego,Chicago] x[San-Diego,Topeka] x[San-Diego,New-York]

```

The code is attempting

```julia
julia> sum([x["Seattle", "Chicago"], x["Seattle", "Topeka"], x["Seattle", "New-York"]])

```

using what would work for integer indexing

```julia
julia> sum(x[1, :])

```

but this fails

```julia
julia> sum(x["Seattle", :])
ERROR: MethodError: no method matching getindex(::Base.KeySet{String, Dict{String, Any}}, ::Colon)
Stacktrace:
 [1] _getindex_recurse(data::Tuple{Base.KeySet{String, Dict{String, Any}}}, keys::Tuple{Colon}, condition::typeof(JuMP.Containers._is_range))
   @ JuMP.Containers ~/.julia/packages/JuMP/klrjG/src/Containers/DenseAxisArray.jl:250
 [2] _getindex_recurse(data::Tuple{Base.KeySet{String, Dict{String, Any}}, Base.KeySet{String, Dict{String, Any}}}, keys::Tuple{Int64, Colon}, condition::typeof(JuMP.Containers._is_range))
   @ JuMP.Containers ~/.julia/packages/JuMP/klrjG/src/Containers/DenseAxisArray.jl:249
 [3] getindex(::JuMP.Containers.DenseAxisArray{VariableRef, 2, Tuple{Base.KeySet{String, Dict{String, Any}}, Base.KeySet{String, Dict{String, Any}}}, Tuple{JuMP.Containers._AxisLookup{Dict{String, Int64}}, JuMP.Containers._AxisLookup{Dict{String, Int64}}}}, ::String, ::Function)
   @ JuMP.Containers ~/.julia/packages/JuMP/klrjG/src/Containers/DenseAxisArray.jl:270
 [4] top-level scope
   @ REPL[49]:1

```

---

<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:** [March 31, 2022, 9:30pm UTC](https://discourse.julialang.org/t/a-problem-with-jump-tutorial-linear-problem-cannery-problem/78795/6 "2022-03-31T21:30:30Z")

</div>

What is `import Pkg; Pkg.status()`? Are you using an old version of JuMP?

---

<div class="post-metadata">

**Author:** ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)\
**Post date:** [March 31, 2022, 9:42pm UTC](https://discourse.julialang.org/t/a-problem-with-jump-tutorial-linear-problem-cannery-problem/78795/7 "2022-03-31T21:42:43Z")

</div>

perhaps that’s the problem, because I tried on Julia 1.6 and my JuMP is v0.21.10

---

<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:** [March 31, 2022, 9:46pm UTC](https://discourse.julialang.org/t/a-problem-with-jump-tutorial-linear-problem-cannery-problem/78795/8 "2022-03-31T21:46:13Z")

</div>

> my JuMP is v0.21.10

Yes, please update your packages. (JuMP is now 1.0! [JuMP 1.0.0 is released | JuMP](https://jump.dev/blog/1.0.0-release/) If you update, you won’t have problems like this breakage in future.)

Here’s the tutorial from JuMP v0.21:  
[https://jump.dev/JuMP.jl/v0.21/tutorials/Mixed-integer%20linear%20programs/cannery/](https://jump.dev/JuMP.jl/v0.21/tutorials/Mixed-integer%20linear%20programs/cannery/)

---

<div class="post-metadata">

**Author:** ![mahon](https://avatars.discourse-cdn.com/v4/letter/m/9e8a1a/32.png) [@mahon](https://discourse.julialang.org/u/mahon)\
**Post date:** [April 1, 2022, 8:15am UTC](https://discourse.julialang.org/t/a-problem-with-jump-tutorial-linear-problem-cannery-problem/78795/9 "2022-04-01T08:15:56Z")

</div>

Hi，very thanks for replying，i think the problem is that the P and M are a keysets，so x[p,:] makes a error, i find a method ,change the code P = keys(data[“plants”]) to P = collect(keys(data[“plants”])), so the problem addressed.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/5/a/5aa3670e27eaf7275daa46184e34b5f94eb7f4ff.png)

---

<div class="post-metadata">

**Author:** ![mahon](https://avatars.discourse-cdn.com/v4/letter/m/9e8a1a/32.png) [@mahon](https://discourse.julialang.org/u/mahon)\
**Post date:** [April 1, 2022, 8:31am UTC](https://discourse.julialang.org/t/a-problem-with-jump-tutorial-linear-problem-cannery-problem/78795/10 "2022-04-01T08:31:05Z")

</div>

Hi, i tried to code Pkg.update(“JuMP”), but my JuMP version is still v0.21.10, so how can i update my JuMP to v1.0.0? very thanks!

---

<div class="post-metadata">

**Author:** ![Elmo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elmo/32/17979_2.png) [@Elmo](https://discourse.julialang.org/u/Elmo)\
**Post date:** [April 1, 2022, 11:00am UTC](https://discourse.julialang.org/t/a-problem-with-jump-tutorial-linear-problem-cannery-problem/78795/11 "2022-04-01T11:00:14Z")

</div>

You probably have some dependency that prevents you from updating JuMP, check this [thread out.](https://discourse.julialang.org/t/how-to-find-package-preventing-others-from-updating/8235)

---

<div class="post-metadata">

**Author:** ![mahon](https://avatars.discourse-cdn.com/v4/letter/m/9e8a1a/32.png) [@mahon](https://discourse.julialang.org/u/mahon)\
**Post date:** [April 2, 2022, 3:06am UTC](https://discourse.julialang.org/t/a-problem-with-jump-tutorial-linear-problem-cannery-problem/78795/12 "2022-04-02T03:06:06Z")

</div>

![image](https://global.discourse-cdn.com/julialang/original/3X/e/5/e56b3724fa6d22e27afd121cd0908298225c1ef6.png)  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/7/676b3e64a858739edd976c828da57ef2e88c4d2f.png)  
i’m really confused

---

<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:** [April 2, 2022, 3:24am UTC](https://discourse.julialang.org/t/a-problem-with-jump-tutorial-linear-problem-cannery-problem/78795/13 "2022-04-02T03:24:36Z")

</div>

The error is saying that AnyMOD requires JuMP v0.21. So you cannot have both AnyMOD and JuMP 1.0.

Try removing AnyMOD first, then update.

---

<div class="post-metadata">

**Author:** ![mahon](https://avatars.discourse-cdn.com/v4/letter/m/9e8a1a/32.png) [@mahon](https://discourse.julialang.org/u/mahon)\
**Post date:** [April 2, 2022, 4:09am UTC](https://discourse.julialang.org/t/a-problem-with-jump-tutorial-linear-problem-cannery-problem/78795/14 "2022-04-02T04:09:26Z")

</div>

i removed both AnyMOD and JuMP,and reinstall JuMP, but still produced a error

 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/e/9edea3b35d804f805e004622a5de62f9569347ce.png)

maybe i didn’t remove old JuMP clearly?

---

<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:** [April 2, 2022, 4:22am UTC](https://discourse.julialang.org/t/a-problem-with-jump-tutorial-linear-problem-cannery-problem/78795/15 "2022-04-02T04:22:46Z")

</div>

This is now saying the same thing about powermodelsdistribution.

Given we only released JuMP 1.0 recently, it may take some time for packages which build on top of JuMP to update as well.

---

<div class="post-metadata">

**Author:** ![mahon](https://avatars.discourse-cdn.com/v4/letter/m/9e8a1a/32.png) [@mahon](https://discourse.julialang.org/u/mahon)\
**Post date:** [April 2, 2022, 4:26am UTC](https://discourse.julialang.org/t/a-problem-with-jump-tutorial-linear-problem-cannery-problem/78795/16 "2022-04-02T04:26:13Z")

</div>

very thanks for solving my problem , i remove PowerModelsDistribution and it works
