# Key 1.0 not found

**URL:** https://discourse.julialang.org/t/key-1-0-not-found/67400
**Category:** Optimization (Mathematical)
**Created:** [August 31, 2021, 4:41am UTC](https://discourse.julialang.org/t/key-1-0-not-found/67400 "2021-08-31T04:41:42Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![fksayaci](https://avatars.discourse-cdn.com/v4/letter/f/b77776/32.png) [@fksayaci](https://discourse.julialang.org/u/fksayaci)
#### Post date: [August 31, 2021, 4:41am UTC](https://discourse.julialang.org/t/key-1-0-not-found/67400/1 "2021-08-31T04:41:43Z")

</div>

Hi,

I have an optimization model, which I have run for a long time on my personal machine. When I run the same model on a cluster, it gives some errors. The error is as follows:

```julia
ERROR: LoadError: KeyError: key 1.0 not found
Stacktrace:
  [1] getindex(#unused#::JuMP.Containers._AxisLookup{Dict{Int64, Int64}}, key::Float64)
    @ JuMP.Containers ~/.julia/packages/JuMP/b3hGi/src/Containers/DenseAxisArray.jl:18
  [2] _getindex_recurse(data::Tuple{JuMP.Containers._AxisLookup{Dict{Int64, Int64}}}, keys::Tuple{Float64}, condition::JuMP.Containers.var"#8#10")
    @ JuMP.Containers ~/.julia/packages/JuMP/b3hGi/src/Containers/DenseAxisArray.jl:250
  [3] _getindex_recurse(data::Tuple{JuMP.Containers._AxisLookup{Dict{Int64, Int64}}, JuMP.Containers._AxisLookup{Dict{Int64, Int64}}}, keys::Tuple{Int64, Float64}, condition::JuMP.Containers.var"#8#10")
    @ JuMP.Containers ~/.julia/packages/JuMP/b3hGi/src/Containers/DenseAxisArray.jl:249
  [4] to_index(A::JuMP.Containers.DenseAxisArray{VariableRef, 2, Tuple{Vector{Int64}, Vector{Int64}}, Tuple{JuMP.Containers._AxisLookup{Dict{Int64, Int64}}, JuMP.Containers._AxisLookup{Dict{Int64, Int64}}}}, idx::Tuple{Int64, Float64})
    @ JuMP.Containers ~/.julia/packages/JuMP/b3hGi/src/Containers/DenseAxisArray.jl:259
  [5] getindex(::JuMP.Containers.DenseAxisArray{VariableRef, 2, Tuple{Vector{Int64}, Vector{Int64}}, Tuple{JuMP.Containers._AxisLookup{Dict{Int64, Int64}}, JuMP.Containers._AxisLookup{Dict{Int64, Int64}}}}, ::Int64, ::Float64)
    @ JuMP.Containers ~/.julia/packages/JuMP/b3hGi/src/Containers/DenseAxisArray.jl:266
  [6] macro expansion
    @ ~/.julia/packages/MutableArithmetics/8xkW3/src/rewrite.jl:279 [inlined]
  [7] macro expansion
    @ ~/.julia/packages/JuMP/b3hGi/src/macros.jl:676 [inlined]
  [8] (::var"#119#281"{JuMP.Containers.DenseAxisArray{VariableRef, 2, Tuple{Vector{Int64}, Vector{Int64}}, Tuple{JuMP.Containers._AxisLookup{Dict{Int64, Int64}}, JuMP.Containers._AxisLookup{Dict{Int64, Int64}}}}, JuMP.Containers.DenseAxisArray{VariableRef, 2, Tuple{Vector{Int64}, Vector{Int64}}, Tuple{JuMP.Containers._AxisLookup{Dict{Int64, Int64}}, JuMP.Containers._AxisLookup{Dict{Int64, Int64}}}}, Model})(g::Int64, t::Int64)
    @ Main ~/.julia/packages/JuMP/b3hGi/src/Containers/macro.jl:194
  [9] #38
    @ ~/.julia/packages/JuMP/b3hGi/src/Containers/container.jl:105 [inlined]
 [10] iterate
    @ ./generator.jl:47 [inlined]
 [11] collect(itr::Base.Generator{JuMP.Containers.VectorizedProductIterator{Tuple{Vector{Int64}, Vector{Int64}}}, JuMP.Containers.var"#38#39"{var"#119#281"{JuMP.Containers.DenseAxisArray{VariableRef, 2, Tuple{Vector{Int64}, Vector{Int64}}, Tuple{JuMP.Containers._AxisLookup{Dict{Int64, Int64}}, JuMP.Containers._AxisLookup{Dict{Int64, Int64}}}}, JuMP.Containers.DenseAxisArray{VariableRef, 2, Tuple{Vector{Int64}, Vector{Int64}}, Tuple{JuMP.Containers._AxisLookup{Dict{Int64, Int64}}, JuMP.Containers._AxisLookup{Dict{Int64, Int64}}}}, Model}}})
    @ Base ./array.jl:678
 [12] map(f::Function, A::JuMP.Containers.VectorizedProductIterator{Tuple{Vector{Int64}, Vector{Int64}}})
    @ Base ./abstractarray.jl:2323
 [13] container(f::Function, indices::JuMP.Containers.VectorizedProductIterator{Tuple{Vector{Int64}, Vector{Int64}}}, #unused#::Type{JuMP.Containers.DenseAxisArray})
    @ JuMP.Containers ~/.julia/packages/JuMP/b3hGi/src/Containers/container.jl:105
 [14] container(f::Function, indices::JuMP.Containers.VectorizedProductIterator{Tuple{Vector{Int64}, Vector{Int64}}})
    @ JuMP.Containers ~/.julia/packages/JuMP/b3hGi/src/Containers/container.jl:66
 [15] macro expansion
    @ ~/.julia/packages/JuMP/b3hGi/src/macros.jl:142 [inlined]
 [16] ExpansionModel()
    @ Main ~/RenewableOpt/WECC-model/ExpansionModel.jl:232
 [17] top-level scope
    @ ~/RenewableOpt/WECC-model/Run.jl:20
in expression starting at /home/fkucuksayacigil/RenewableOpt/WECC-model/Run.jl:20

```

I feel that packages installed on my machine and the cluster are different versions, that is why errors show up. When I go to line 232 of ExpansionModel.jl, I realized that I am using Array() function. I feel that this is something changed from the version of Julia on my machine to the version of Julia on the cluster.

Could you please help me with this?

Kind regards

---

<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: [August 31, 2021, 5:38am UTC](https://discourse.julialang.org/t/key-1-0-not-found/67400/2 "2021-08-31T05:38:25Z")

</div>

Please provide a reproducible example. This looks like a mistake in your code, where you are using `1.0` to index an array instead of `1`.

What is your local machine? What versions of Julia? What versions of the packages?

---

<div class="post-metadata">

### Author: ![fksayaci](https://avatars.discourse-cdn.com/v4/letter/f/b77776/32.png) [@fksayaci](https://discourse.julialang.org/u/fksayaci)
#### Post date: [September 1, 2021, 3:15pm UTC](https://discourse.julialang.org/t/key-1-0-not-found/67400/3 "2021-09-01T15:15:41Z")

</div>

Thank you so much for your reply. I am sorry for the delay, but I delayed the response to figure out the error by myself. It was an easy one.

I was using Julia 1.3 and I now updated to Julia 1.6.2.

Below is a reproducible error:

```julia
numbers = rand(10)

for n in Array(3 - 2.0 : 8)
     println(numbers(n))
end

```

Above loop did not give any error and printed numbers in `numbers` indexed at {1,2,3,…,8}. When I updated Julia to 1.6.2., it gives error because `Array(3 - 2.0 : 8)` produces float numbers and they can not be used for indexing. To correct that, I changed it to

`round.(Int, Array(3 - 2.0 : 8))`

I know that this is a simple one, but I was also surprised about how it was previously indexing with float numbers.

Kind regards,

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [September 1, 2021, 4:07pm UTC](https://discourse.julialang.org/t/key-1-0-not-found/67400/4 "2021-09-01T16:07:08Z")

</div>

I don’t think that’s right. First of all you can’t index with round brackets:

```julia
julia> numbers = rand(10);

julia> for n in Array(3 - 2.0 : 8)
            println(numbers(n))
       end
ERROR: MethodError: objects of type Array{Float64,1} are not callable
Use square brackets [] for indexing an Array.
Stacktrace:
 [1] top-level scope at .\REPL[2]:2

```

but fixing that:

```julia
julia> for n in Array(3 - 2.0 : 8)
            println(numbers[n])
       end
ERROR: ArgumentError: invalid index: 1.0 of type Float64
Stacktrace:
 [1] to_index(::Float64) at .\indices.jl:273
 [2] to_index(::Array{Float64,1}, ::Float64) at .\indices.jl:250
 [3] to_indices at .\indices.jl:301 [inlined]
 [4] to_indices at .\indices.jl:298 [inlined]
 [5] getindex(::Array{Float64,1}, ::Float64) at .\abstractarray.jl:981
 [6] top-level scope at .\REPL[3]:2

julia> versioninfo()
Julia Version 1.3.1

```

So `Array(3 - 2.0 : 8)` produces floats in 1.3 and 1.6, and indexing with floats isn’t allowed in either Julia version.

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [September 1, 2021, 4:13pm UTC](https://discourse.julialang.org/t/key-1-0-not-found/67400/5 "2021-09-01T16:13:53Z")

</div>

Can’t you just write

```julia
for n in (3 - 2):8
     println(numbers[n])
end

```

?  
Where does the number `2.0` come from?

Notice also that you shouldn’t use `Array` on the range.

---

<div class="post-metadata">

### Author: ![fksayaci](https://avatars.discourse-cdn.com/v4/letter/f/b77776/32.png) [@fksayaci](https://discourse.julialang.org/u/fksayaci)
#### Post date: [September 1, 2021, 4:30pm UTC](https://discourse.julialang.org/t/key-1-0-not-found/67400/6 "2021-09-01T16:30:10Z")

</div>

Thank you. Yes, I typed it wrong. It should be square bracket. However, it is interesting that Julia 1.3 does not allow indexing with float (I know that this is supposed to be, but it was working in my case). Anyway, maybe I messed up something.

---

<div class="post-metadata">

### Author: ![fksayaci](https://avatars.discourse-cdn.com/v4/letter/f/b77776/32.png) [@fksayaci](https://discourse.julialang.org/u/fksayaci)
#### Post date: [September 1, 2021, 4:31pm UTC](https://discourse.julialang.org/t/key-1-0-not-found/67400/7 "2021-09-01T16:31:50Z")

</div>

2.0 comes from an external file. I do not know in advance if it is integer or float. You are right, I realized that Array() is not a good idea to create range. I do not know either whether I had a specific reason to Array() in this context.

---

<div class="post-metadata">

### Author: ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)
#### Post date: [September 1, 2021, 4:32pm UTC](https://discourse.julialang.org/t/key-1-0-not-found/67400/8 "2021-09-01T16:32:46Z")

</div>

> [@fksayaci](#):
>
> However, it is interesting that Julia 1.3 does not allow indexing with float

I do not know any language besides Lua that allows indexing the primitive “vector” with floating point numbers. And such design decision is kinda strange to me until today.

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [September 1, 2021, 4:34pm UTC](https://discourse.julialang.org/t/key-1-0-not-found/67400/9 "2021-09-01T16:34:00Z")

</div>

Then I think you should convert or round that single number to an `Int` before using it.

---

<div class="post-metadata">

### Author: ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)
#### Post date: [September 1, 2021, 6:31pm UTC](https://discourse.julialang.org/t/key-1-0-not-found/67400/10 "2021-09-01T18:31:44Z")

</div>

> [@Henrique\_Becker](#):
>
> I do not know any language besides Lua that allows indexing the primitive “vector” with floating point numbers. And such design decision is kinda strange to me until today.

Julia did allow indexing with integer valued floats once, but that’s ancient history, maybe around version 0.1 or so. Matlab and Octave still allow it.

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [September 1, 2021, 6:56pm UTC](https://discourse.julialang.org/t/key-1-0-not-found/67400/11 "2021-09-01T18:56:10Z")

</div>

In Matlab the literal ‘`2`’ is actually a float, so they basically have to.

Haha, actually, it’s even worse: it’s a 1x1 _matrix_ of floats…

---

<div class="post-metadata">

### Author: ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)
#### Post date: [September 1, 2021, 11:59pm UTC](https://discourse.julialang.org/t/key-1-0-not-found/67400/12 "2021-09-01T23:59:14Z")

</div>

Oh, does it allows only _integer_ floating values, or any floating point values, in the indexing?

---

<div class="post-metadata">

### Author: ![fksayaci](https://avatars.discourse-cdn.com/v4/letter/f/b77776/32.png) [@fksayaci](https://discourse.julialang.org/u/fksayaci)
#### Post date: [September 2, 2021, 3:48am UTC](https://discourse.julialang.org/t/key-1-0-not-found/67400/13 "2021-09-02T03:48:36Z")

</div>

As far as I understand and observe, it allows neither of them. Index should be integer, not integer valued float.

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [September 2, 2021, 5:03am UTC](https://discourse.julialang.org/t/key-1-0-not-found/67400/14 "2021-09-02T05:03:38Z")

</div>

The float indices must be integer-valued in Matlab.
