# Lux.jl demo with Lotka-Voltera with UODE

**URL:** https://discourse.julialang.org/t/lux-jl-demo-with-lotka-voltera-with-uode/91538
**Category:** General Usage
**Created:** [December 11, 2022, 10:40pm UTC](https://discourse.julialang.org/t/lux-jl-demo-with-lotka-voltera-with-uode/91538 "2022-12-11T22:40:27Z")
**Posts on this page:** 6
**Page:** 2

<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: [December 16, 2022, 8:44pm UTC](https://discourse.julialang.org/t/lux-jl-demo-with-lotka-voltera-with-uode/91538/21 "2022-12-16T20:44:43Z")

</div>

Okay, the deployment just finished: [https://docs.sciml.ai/Overview/dev/showcase/missing\_physics/](https://docs.sciml.ai/Overview/dev/showcase/missing_physics/)

It looks like the full example got good results in the end. And since it runs the tutorial and generates the plots at build time, that means it should be working now. Walk through it and see if you run into anything. I took the disclaimer off the page now because it now seems to work.

I’ll be keeping it on dev until [https://docs.sciml.ai/Overview/dev/getting\_started/fit\_simulation/](https://docs.sciml.ai/Overview/dev/getting_started/fit_simulation/) and [https://docs.sciml.ai/Overview/dev/getting\_started/integral\_approx/](https://docs.sciml.ai/Overview/dev/getting_started/integral_approx/) are complete, but those should be done over the weekend and the new SciML overview page should launch with that.

---

<div class="post-metadata">

### Author: ![erlebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/erlebach/32/12973_2.png) [@erlebach](https://discourse.julialang.org/u/erlebach)
#### Post date: [December 16, 2022, 10:47pm UTC](https://discourse.julialang.org/t/lux-jl-demo-with-lotka-voltera-with-uode/91538/22 "2022-12-16T22:47:39Z")

</div>

Hi @ChrisRackauckas ,

Congratulations, the code runs with no changes. I ran the code as a single program, outside of Jupyter. I like the StableRNG. Nice touch!  
Recall I am on an M1 Mac, Ventura OS, just for reference.

On most of the run, I got the same results sometimes to 6-7 digits, but not everything.

One discrepancy was the ideal\_problem case. After running ideal\_res.residuals, I got residuals of 1.e-30, whereas your demo get residuals of 6.1. The other two cases produced the same results to at least one significant digit. This difference is really surprising. It suggests that a slight shift of parameters makes the fit not work well.

When fitting experimental or numerical data, I doubt things will out most of the time. Presumably there is lots of trial and error.

Thanks for all the help!

```
Gordon

```

---

<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: [December 17, 2022, 1:27am UTC](https://discourse.julialang.org/t/lux-jl-demo-with-lotka-voltera-with-uode/91538/23 "2022-12-17T01:27:13Z")

</div>

> [@erlebach](#):
>
> On most of the run, I got the same results sometimes to 6-7 digits, but not everything.

That’s expected. Different SIMD vector sizes and BLAS implementations cause floating point differences. M1 uses a different BLAS for matmuls IIRC

---

<div class="post-metadata">

### Author: ![erlebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/erlebach/32/12973_2.png) [@erlebach](https://discourse.julialang.org/u/erlebach)
#### Post date: [December 19, 2022, 10:31pm UTC](https://discourse.julialang.org/t/lux-jl-demo-with-lotka-voltera-with-uode/91538/24 "2022-12-19T22:31:10Z")

</div>

Hi @ChrisRackauckas ,

I have a question related to the demo code. I am trying to modularize the code for more extensive experimentation, so I have create a module, under the control of Revise.jl. All Good.  
In the code, one sees the three lines:

```julia
    optf = Optimization.OptimizationFunction((x,p)->loss(x, dct), adjoint_type)
    optprob = Optimization.OptimizationProblem(optf, ComponentVector{Float64}(p))
    res1 = Optimization.solve(optprob, ADAM(), callback=callback, maxiters = 500)

```

together with the callback function:

```julia
    callback = function (p, l) # GE added kwargs
        push!(losses, l)
        if length(losses)%50==0
            println("Current loss after $(length(losses)) iterations: $(losses[end])")
        end
        return false
    end

```

This function has two arguments. How would I have known this if I had written a code on my own? I added an additional argument and the code crashed. I searched `Optimziation.jl` and did not find a reference to `callback`. I searched `DiffEqCallbacks`, which also did not help me. Any help is appreciated.

---

<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: [December 20, 2022, 1:49am UTC](https://discourse.julialang.org/t/lux-jl-demo-with-lotka-voltera-with-uode/91538/25 "2022-12-20T01:49:14Z")

</div>

> [@erlebach](#):
>
> This function has two arguments. How would I have known this if I had written a code on my own? I added an additional argument and the code crashed. I searched `Optimziation.jl` and did not find a reference to `callback`. I searched `DiffEqCallbacks`, which also did not help me. Any help is appreciated.

[https://docs.sciml.ai/Optimization/stable/search/?q=callback](https://docs.sciml.ai/Optimization/stable/search/?q=callback)

> **[Common Solver Options (Solve Keyword Arguments) · Optimization.jl](https://docs.sciml.ai/Optimization/stable/API/solve/#CommonSolve.solve-Tuple%7BOptimizationProblem,%20Any%7D)**
>
> Documentation for Optimization.jl.

> **Callback Functions**

> The callback function `callback` is a function which is called after every optimizer step. Its signature is:

> ```julia
> callback = (x,other_args) -> false
> 
> ```

> where `other_args` is are the extra return arguments of the optimization `f`. This allows for saving values from the optimization and using them for plotting and display without recalculating. The callback should return a Boolean value, and the default should be `false`, such that the optimization gets stopped if it returns `true`.

I’m surprised the search didn’t catch it better but it is there.

---

<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: [January 29, 2023, 12:24pm UTC](https://discourse.julialang.org/t/lux-jl-demo-with-lotka-voltera-with-uode/91538/26 "2023-01-29T12:24:15Z")

</div>

The new docs have launched.

The example is here: [Automatically Discover Missing Physics by Embedding Machine Learning into Differential Equations · Overview of Julia's SciML](https://docs.sciml.ai/Overview/stable/showcase/missing_physics/)

Other ones will be added to the examples section of SciMLSensitivity

[Previous page](https://discourse.julialang.org/t/lux-jl-demo-with-lotka-voltera-with-uode/91538.md?page=1)
