Callback function for Fminbox


I am trying to perform a constrained optimization using fminbox in the optim.jl package and would like to execute a callback function within the inner loop AND the outer loop to terminate the optimization if too much time has passed. The callback appears to work properly in the inner loop, but not the outer loop (and thus the optimization will never terminate the way I’d like). Any suggestions about what’s going wrong, or a workaround?

# optimize
od = OnceDifferentiable(x->func(x, data), x; autodiff = :forward)
@time results = optimize(od, x, lower, upper, Fminbox{BFGS}(); iterations = 10, callback = my_callback, optimizer_o = Optim.Options(iterations = 10, callback = my_callback))