Weird bug: Printing a variable vs. not printing a variable give different results

Hi folks,

I’m using Julia/JuMP and I recently encountered a weird bug. The whole package I’m writing is too big so I only include the code that this bug occurs. I have the following lines of code


The code does not give me the results I expect.
However, if I uncomment the “println” on line 483 and 488, the code runs all right.

I really have no idea why this occurs. It seems that if I do not print “m.ext[:varmap]”, Julia just treats “m.ext[:varmap]” as an empty dictionary and ignores all the elements in m.ext[:varmap].

This seems to be a Julia issue rather than JuMP issue. I wonder if anyone has encountered the same problem before.
Thanks in advance.

Best regards,
Can

Unfortunately it is really hard to say anything without code that demonstrates the problem.

Try commenting out code until you have the smallest reproducible error.

I’m guessing that :varmap is an extension you are writing? What is the type of the value in :varmap? A dictionary?

What happens if you print keys(m.ext[:varmap]) instead?

Hi Oscar,

Thanks for your answer. I will try to reproduce it with a small example.

Yes, :varmap is an extension for a JuMP model and it’s a Dict(). The keys of :varmap is JuMP variables. The values in :varmap are IntArray.

If I print keys(m.ext[:varmap]), it still works.

What do you mean?

In addition to posting a “minimal working example”, remember to post the actual code instead of an image of the code, since one cannot cut and paste from an image. Rember to put the code inside backticks (see here: PSA: how to quote code with backticks)

2 Likes