GalacticOptim.solve ignores callback

Hi All,

It seems the callback doesn’t work when it is called from “GalacticOptim.solve”.

using DifferentialEquations, DiffEqFlux, GalacticOptim

function lotka_volterra!(du, u, p, t)
  x, y = u
  α, β, δ, γ = p
  du[1] = α*x - β*x*y
  du[2] = -δ*y + γ*x*y
end

u0 = [1.0, 1.0]
tspan = (0.0, 10.0)
tsteps = 0.0:0.1:10.0
p = [1.5, 1.0, 3.0, 1.0]

prob = ODEProblem(lotka_volterra!, u0, tspan, p)

function loss1(p)
  sol = solve(prob, Tsit5(), p=p, saveat = tsteps)
  loss1 = sum(abs2, sol.-1)
  return loss1
end

callback = function(p, l)
  println("++++++++++++++++++")
  println(p, l)
  return false
end

result = DiffEqFlux.sciml_train(loss1, p, ADAM(0.01), cb = callback, maxiters = 5)

The result is:

++++++++++++++++++
[1.5, 1.0, 3.0, 1.0]1015.3325849591358
++++++++++++++++++
[1.4900000000019646, 1.0099999999998726, 2.9900000000001135, 1.009999999999966]969.2675720319974
++++++++++++++++++
[1.480156578018994, 1.0199763495310485, 2.980009538186138, 1.0199855317203501]926.6593153982388
++++++++++++++++++
[1.4706570510782024, 1.0299134633039642, 2.9700346384057585, 1.0299474292653887]885.466159373063
++++++++++++++++++
[1.461876797763696, 1.0397956562328647, 2.9600816210469576, 1.0398767066170915]846.5357155282032
++++++++++++++++++
[1.461876797763696, 1.0397956562328647, 2.9600816210469576, 1.0398767066170915]846.5357155282032
u: 4-element Vector{Float64}:
 1.461876797763696
 1.0397956562328647
 2.9600816210469576
 1.0398767066170915

But when I run:

optf1 = GalacticOptim.OptimizationFunction((x, p) -> loss1(x),  GalacticOptim.AutoZygote())
optprob1 = GalacticOptim.OptimizationProblem(optf1, prob.p)
result1 = GalacticOptim.solve(optprob1, ADAM(0.01), cb=callback, maxiters=5)

The result is:

u: 4-element Vector{Float64}:
 1.4611152669058112
 1.03979575254029
 2.960081183292951
 1.039876503867809

The question is - why I can not see the callback output in the last case.

Thanks!

The problem is solved by updating “GalacticOptim” to the latest version (3.4.0) and changing the keyarg: “cb” → callback.

The next code works as expected.

result1 = GalacticOptim.solve(optprob1, ADAM(0.01), callback=callback, maxiters=10)