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

**URL:** <https://discourse.julialang.org/t/a-way-to-add-the-iteration-number-on-the-callback-function-of-julias-neuralpde/101507>\
**Category:** Modelling & Simulations\
**Created:** [July 12, 2023, 3:04am UTC](https://discourse.julialang.org/t/a-way-to-add-the-iteration-number-on-the-callback-function-of-julias-neuralpde/101507 "2023-07-12T03:04:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pex/32/49986_2.png) [@PeX](https://discourse.julialang.org/u/PeX)\
**Post date:** [July 12, 2023, 3:04am UTC](https://discourse.julialang.org/t/a-way-to-add-the-iteration-number-on-the-callback-function-of-julias-neuralpde/101507/1 "2023-07-12T03:04:41Z")

</div>

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:

```julia
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!

---

<div class="post-metadata">

**Author:** ![Larbino1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/larbino1/32/37831_2.png) [@Larbino1](https://discourse.julialang.org/u/Larbino1)\
**Post date:** [July 12, 2023, 8:56am UTC](https://discourse.julialang.org/t/a-way-to-add-the-iteration-number-on-the-callback-function-of-julias-neuralpde/101507/2 "2023-07-12T08:56:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![PeX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pex/32/49986_2.png) [@PeX](https://discourse.julialang.org/u/PeX)\
**Post date:** [July 12, 2023, 6:31pm UTC](https://discourse.julialang.org/t/a-way-to-add-the-iteration-number-on-the-callback-function-of-julias-neuralpde/101507/3 "2023-07-12T18:31:44Z")

</div>

Thank you so much! Simple and works perfectly!
