A way to add the iteration number on the callback function of Julia's NeuralPDE?

I’m using NeuralPDE.jl to solve a system of nonlinear PDEs, following the example in the docs.
I wonder if there is a way to add the iteration number in the callback function, so I will know the progress.
The callback function I’m using from the docs is:

callback = function (p, l)
    println("loss: ", l)
    println("pde_losses: ", map(l_ -> l_(p), pde_inner_loss_functions))
    println("bcs_losses: ", map(l_ -> l_(p), bcs_inner_loss_functions))
    return false
end

Which shows the different loss functions, but not the iteration number.

Thank you!

Create a reference to an int: i = Base.RefValue{Int}(1) immediately prior to defining the callback. Increment i inside the callback using i[] += 1. you can print i using println(i[]), the square brackets ‘dereference’ i to access its value

1 Like

Thank you so much! Simple and works perfectly!