# How to show progress when using DifferentialEquations.jl?

**URL:** https://discourse.julialang.org/t/how-to-show-progress-when-using-differentialequations-jl/104168
**Category:** Numerics
**Tags:** differentialequation
**Created:** [September 22, 2023, 11:11pm UTC](https://discourse.julialang.org/t/how-to-show-progress-when-using-differentialequations-jl/104168 "2023-09-22T23:11:35Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![yhchang96](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yhchang96/32/36499_2.png) [@yhchang96](https://discourse.julialang.org/u/yhchang96)
#### Post date: [September 22, 2023, 11:11pm UTC](https://discourse.julialang.org/t/how-to-show-progress-when-using-differentialequations-jl/104168/1 "2023-09-22T23:11:35Z")

</div>

The ODEs I’m solving typically takes an hour and I would like it to print the current time step for every, e.g. 10 time steps. I have tried the method shown on this [page](https://docs.sciml.ai/DiffEqDocs/stable/features/progress_bar/) about progress bar, but it doesn’t work (i.e. nothing is displayed) on both VS Code and jupyter notebook. Then I tried using a discrete callback with the following codes:

```julia
function lorenz!(du, u, p, t)
    du[1] = 10.0 * (u[2] - u[1])
    du[2] = u[1] * (28.0 - u[3]) - u[2]
    du[3] = u[1] * u[2] - (8 / 3) * u[3]
end

u0 = [1.0; 0.0; 0.0]
tspan = (0.0, 100.0)
prob = ODEProblem(lorenz!, u0, tspan);

function do_nth!(integrator)
    println(@sprintf("no. of time steps : %4d, t = %.3e", length(integrator.sol.t), integrator.t))
    return nothing
end

condition1(u, t, integrator) = (mod(length(integrator.sol.t), 50) == 0) # triggered every 50 time steps
cb1 = DiscreteCallback(condition1, do_nth!; save_positions=(false,false));

sol1 = solve(prob, FBDF(autodiff=true))
sol2 = solve(prob, FBDF(autodiff=true), callback=cb1)

```

I use `FBDF(autodiff=true)` in the above code because that’s the specific solver I will be using for my actual ODE. Now the problem is that `sol1` and `sol2` give different solution, and by comparing the second component of the solution to the example in the [documentation](https://docs.sciml.ai/DiffEqDocs/stable/getting_started/#Example-2:-Solving-Systems-of-Equations), it looks like `sol2` (the one with the callback) is wrong. So what else did I do wrong? What’s the best way to show the progress every X time steps?

---

<div class="post-metadata">

### Author: ![jlchan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlchan/32/10958_2.png) [@jlchan](https://discourse.julialang.org/u/jlchan)
#### Post date: [September 22, 2023, 11:20pm UTC](https://discourse.julialang.org/t/how-to-show-progress-when-using-differentialequations-jl/104168/2 "2023-09-22T23:20:40Z")

</div>

Trixi.jl uses a simple AliveCallback to print the status of the solve at regular timestep intervals.

> **[Trixi.jl · Trixi.jl](https://trixi-framework.github.io/Trixi.jl/stable/reference-trixi/#Trixi.AliveCallback)**
>
> Documentation for Trixi.jl.

It’s pretty short so you can either just copy and paste it, or just load it from Trixi.jl if precompilation time isn’t an issue.

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [September 23, 2023, 1:26am UTC](https://discourse.julialang.org/t/how-to-show-progress-when-using-differentialequations-jl/104168/3 "2023-09-23T01:26:18Z")

</div>

> [@yhchang96](#):
>
> (the one with the callback) is wrong

No, it’s just chaotic, so changing `dt` just a little bit gives an O(1) difference in the solution.

Set `u_modified!(integrator,false)` to tell it that no changes occurred in the equation and thus it’s fine to not reset dt and such after the callback. I.e.:

```julia
function do_nth!(integrator)
    println(@sprintf("no. of time steps : %4d, t = %.3e", length(integrator.sol.t), integrator.t))
    u_modified(integrator,false)
    return nothing
end

```

But as for using the progress bar, did you try enabling TerminalLoggers?

@pfitzseb did the logging information change for VS Code?

---

<div class="post-metadata">

### Author: ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)
#### Post date: [September 23, 2023, 10:26am UTC](https://discourse.julialang.org/t/how-to-show-progress-when-using-differentialequations-jl/104168/4 "2023-09-23T10:26:55Z")

</div>

> [@ChrisRackauckas](#):
>
> @pfitzseb did the logging information change for VS Code?

Nothing changed as far as I’m aware, no. Note that ProgressLogging.jl needs to be loaded for progress bars to work in VS Code though.

---

<div class="post-metadata">

### Author: ![Gautameshwar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gautameshwar/32/220531_2.png) [@Gautameshwar](https://discourse.julialang.org/u/Gautameshwar)
#### Post date: [May 14, 2024, 6:22am UTC](https://discourse.julialang.org/t/how-to-show-progress-when-using-differentialequations-jl/104168/5 "2024-05-14T06:22:41Z")

</div>

I too have the same problem while implementing the examples given in the documentation such as

```julia
using OrdinaryDiffEq, ProgressLogging
function lorenz!(du, u, p, t)
    du[1] = 10.0(u[2] - u[1])
    du[2] = u[1] * (28.0 - u[3]) - u[2]
    du[3] = u[1] * u[2] - (8 / 3) * u[3]
end
u0 = [1.0; 0.0; 0.0]
tspan = (0.0, 1000000.0)
prob = ODEProblem(lorenz!, u0, tspan)
sol = solve(prob, Tsit5(), progress = true)

```

There is no progress bar shown in VSCode and I do not know a workaround to it.

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [May 14, 2024, 1:30pm UTC](https://discourse.julialang.org/t/how-to-show-progress-when-using-differentialequations-jl/104168/6 "2024-05-14T13:30:27Z")

</div>

On Julia v1.10? Share `]st`.

---

<div class="post-metadata">

### Author: ![homocomputeris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/homocomputeris/32/8933_2.png) [@homocomputeris](https://discourse.julialang.org/u/homocomputeris)
#### Post date: [May 21, 2024, 6:37pm UTC](https://discourse.julialang.org/t/how-to-show-progress-when-using-differentialequations-jl/104168/7 "2024-05-21T18:37:24Z")

</div>

> [@Gautameshwar](#):
>
> There is no progress bar shown in VSCode and I do not know a workaround to it.

I have the same issue.

```julia-auto
Status `~/Code/SciMLExpectations/Project.toml`
  [31c24e10] Distributions v0.25.108
  [19dc6840] HCubature v1.6.0
  [de52edbc] Integrals v4.4.1
  [b964fa9f] LaTeXStrings v1.3.1
  [1dea7af3] OrdinaryDiffEq v6.78.0
  [8314cec4] PGFPlotsX v1.6.1
  [91a5bcdd] Plots v1.40.4
  [33c8b6b6] ProgressLogging v0.1.4
  [afe9f18d] SciMLExpectations v2.2.0
  [f3b207a7] StatsPlots v0.15.7
  [5d786b92] TerminalLoggers v0.1.7

```

---

<div class="post-metadata">

### Author: ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)
#### Post date: [May 21, 2024, 7:06pm UTC](https://discourse.julialang.org/t/how-to-show-progress-when-using-differentialequations-jl/104168/8 "2024-05-21T19:06:57Z")

</div>

add this:

```julia

using Logging: global_logger
using TerminalLoggers: TerminalLogger
global_logger(TerminalLogger())

```

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [May 22, 2024, 9:33am UTC](https://discourse.julialang.org/t/how-to-show-progress-when-using-differentialequations-jl/104168/9 "2024-05-22T09:33:07Z")

</div>

That’s for logging into the terminal though.

@pfitzseb has something changed in the VS Code API?

---

<div class="post-metadata">

### Author: ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)
#### Post date: [May 22, 2024, 9:42am UTC](https://discourse.julialang.org/t/how-to-show-progress-when-using-differentialequations-jl/104168/10 "2024-05-22T09:42:11Z")

</div>

No. The above example works fine for me:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/e/b/ebd1afdbe7e6ae6c4c0f84d028d2d8266fb11156.png)

---

<div class="post-metadata">

### Author: ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)
#### Post date: [May 22, 2024, 10:16am UTC](https://discourse.julialang.org/t/how-to-show-progress-when-using-differentialequations-jl/104168/11 "2024-05-22T10:16:48Z")

</div>

it works in VS code, on the bottom bar
