I spent the last few hours hunting a bug and boiled it down to a behaviour which I do not understand at all. Here is an MWE which basically reflects the core of the issue I had with my package:
using JuMP using Ipopt function wtf() f(x) = (x+2)^2 model = Model(with_optimizer(Ipopt.Optimizer, print_level=0)) register(model, :f, 1, f, autodiff=true) @variable(model, x) @NLobjective(model, Min, f(x)) optimize!(model) retval = value(x) if false f(x) = (x-10)^2 end return retval end
10 instead of
So what kind of magic is going on there? Is
f(x) which is redefined by the compiler even if the body of the
if-block is not reachable? Whaaat?
Edit: to avoid any confusion, I originally wanted to rerun
optimize! with an updated quality function (
f(x) in the example) only when some conditions are met, but it obviously always gets overwritten. So any advise how to rerun an optimisation procedure without all the boiler plate (
@NLobjective etc.) and only with a new function is really welcome!