-1

I have a program written in julia, and I cannot figure out why I am getting a key error. The relevant portion of the code is shown below:

try
    println("THIS IS s[ [j, k] ]: ", s [ [j, k] ])
catch e 
    println("THIS IS s: ", s)
    println("THIS IS j: ", j)
    println("THIS IS k: ", k)
    println("THIS IS [j, k]: ", [j, k])

And I get the following output, which given that I am using try-catch means that it found an error:

enter image description here

Without doing a try-catch structure, it gives me the following error:

enter image description here

I do not understand why it would try to use "macross_base" as a key even to search for within s when the key we give is [j, k] which is [["macross_base", 50400], "Oversized_Equipment"]. Any clarification would be much appreciated.

graphtheory123
  • 311
  • 1
  • 6
  • 3
    It could be because you have posted images of the error messages. This is not recommended, and makes them hard to read. Please copy and paste the output as text instead, like you did with your code. – DNF Mar 10 '23 at 05:57
  • 2
    Also, your question omits crucial details, like the definitions of `s`, `j` and `k`. Always make sure that your problem is reproducible, including all code necessary to reproduce the issue. – DNF Mar 10 '23 at 05:59

1 Answers1

1

This is a bug in JuMP: https://github.com/jump-dev/JuMP.jl/issues/3279.

As a work-around, don't create Vector{Any}.

Create tuples as the keys instead:

key = (("macros", 1), "Outsized_Equipment")
Oscar Dowson
  • 2,395
  • 1
  • 5
  • 13
  • That seemed to solve it. Thanks! Can you please explain why what I had didn't work though. I still don't understand that. Especially because when I ran the same exact code on my local machine it worked. On my local machine I use julia v 1.5.2, whereas on the system I was running it on in my question was julia 1.8.5. Does this explain the problem? Thanks again – graphtheory123 Mar 11 '23 at 04:04
  • It should work; not doing so is a bug. Your two machines probably have different versions of JuMP, and I've introduced the bug in a recent version. – Oscar Dowson Mar 12 '23 at 00:11