# KeyError in PowerModels

**URL:** <https://discourse.julialang.org/t/keyerror-in-powermodels/109656>\
**Category:** Optimization (Mathematical)\
**Tags:** optimization\
**Created:** [February 3, 2024, 2:04am UTC](https://discourse.julialang.org/t/keyerror-in-powermodels/109656 "2024-02-03T02:04:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rasoul](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@Rasoul](https://discourse.julialang.org/u/Rasoul)\
**Post date:** [February 3, 2024, 2:04am UTC](https://discourse.julialang.org/t/keyerror-in-powermodels/109656/1 "2024-02-03T02:04:24Z")

</div>

Hi All,

I developed PowerModels and PowerModelsAnnex, then ran my customized code in PowerModelsAnnex and encountered the following error. Could you please provide guidance on how to resolve this? Thanks in advance!

"ERROR: LoadError: KeyError: key “delta” not found  
Stacktrace:  
[1] getindex(h::Dict{String, Real}, key::String)  
@ Base .\dict.jl:498 "

---

<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:** [February 3, 2024, 2:25am UTC](https://discourse.julialang.org/t/keyerror-in-powermodels/109656/2 "2024-02-03T02:25:43Z")

</div>

Hi @Rasoul,

I think you need to provide a reproducible example for this.

The error is saying you are trying to access a dictionary with the key `"delta"` but it doesn’t exist. But the where and how and why depends on your code.

```julia
julia> d = Dict("alpha" => 1, "beta" => 2)
Dict{String, Int64} with 2 entries:
  "alpha" => 1
  "beta" => 2

julia> d["delta"]
ERROR: KeyError: key "delta" not found
Stacktrace:
 [1] getindex(h::Dict{String, Int64}, key::String)
   @ Base ./dict.jl:498
 [2] top-level scope
   @ REPL[224]:1

```

---

<div class="post-metadata">

**Author:** ![Rasoul](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@Rasoul](https://discourse.julialang.org/u/Rasoul)\
**Post date:** [February 3, 2024, 5:48am UTC](https://discourse.julialang.org/t/keyerror-in-powermodels/109656/3 "2024-02-03T05:48:33Z")

</div>

> [@odow](#):
>
> provide a reproducible example for this.
> 
> The error is saying you are trying to access a dictionary with the key `"delta"` but it doesn’t exist. But the where and how and why depends on your code.

Hi Odow, thanks for the response! The dictionary in PowerModels is defined as follows:

‘buspairs = Dict((i, j) =\> Dict(  
“branch” =\> bp\_branch[(i, j)],  
“angmin” =\> bp\_angmin[(i, j)],  
“angmax” =\> bp\_angmax[(i, j)],  
“tap” =\> branch\_lookup[bp\_branch[(i, j)]][“tap”],  
“vm\_fr\_min” =\> bus\_lookup[i][“vmin”],  
“vm\_fr\_max” =\> bus\_lookup[i][“vmax”],  
“vm\_to\_min” =\> bus\_lookup[j][“vmin”],  
“vm\_to\_max” =\> bus\_lookup[j][“vmax”],  
“delta” =\> angle(1.0 / (branches[bp\_branch[(i, j)]][“br\_r”] + im \* (branches[bp\_branch[(i, j)]][“br\_x”]))),  
“shift” =\> branches[bp\_branch[(i, j)]][“shift”]  
)) for (i, j) in buspair\_indexes’

I ran the same code a year ago, and it worked. Today, when I tried to run the same code, it didn’t work. I removed both PowerModels and PowerModelsAnnex, resolved, and instantiated the packages, but I still get this error.

---

<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:** [February 3, 2024, 6:16am UTC](https://discourse.julialang.org/t/keyerror-in-powermodels/109656/4 "2024-02-03T06:16:20Z")

</div>

Sure. But where is the code that generates the error?

Can you provide a reproducible example?
