# NeuralPDE fails to solve system when parameters change

**URL:** https://discourse.julialang.org/t/neuralpde-fails-to-solve-system-when-parameters-change/114169
**Category:** Machine Learning
**Created:** [May 12, 2024, 4:44pm UTC](https://discourse.julialang.org/t/neuralpde-fails-to-solve-system-when-parameters-change/114169 "2024-05-12T16:44:31Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)
#### Post date: [May 12, 2024, 4:44pm UTC](https://discourse.julialang.org/t/neuralpde-fails-to-solve-system-when-parameters-change/114169/1 "2024-05-12T16:44:31Z")

</div>

I am hitting a weird situation that I can not figure out why – perhaps it’s a bug within `NeuralPDE` or maybe just need to tweak my settings.

Given the [Lorenzs system in this example](https://docs.sciml.ai/NeuralPDE/stable/tutorials/param_estim/) (i.e., `eqs`) I am able to do forward simulation using this code with the parameter values specified

```julia
strategy = NeuralPDE.QuadratureTraining(; abstol = 1e-6, reltol = 1e-6, batch = 200)
discretization = NeuralPDE.PhysicsInformedNN([chain1, chain2, chain3], strategy, param_estim=false)
@named pdesystem = PDESystem(eqs, bcs, domains, [t], [x(t), y(t), z(t)],  
       [σ_, ρ, β], defaults = Dict([σ_ => 10.0, ρ => 9.0, β => 8/3]))
prob = discretize(pdesystem, discretization)
opt = BFGS(linesearch = BackTracking())
res = Optimization.solve(prob, opt; maxiters = 2000)

```

The neural network solution matches the numerical solution (see below) using traditional solvers in `OrdinaryDiffEq`. (Side note: the `retcode` from `solve` is actually a ‘Failure’)  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/f/af7a8861eba5ee7930c7b512d48720d6ebddea0e.png)

Now, if I change the parameter to `ρ => 10.0`, it seems to fail all of a sudden? i.e., running

```julia
@named pdesystem = PDESystem(eqs, bcs, domains, [t], [x(t), y(t), z(t)],  
       [σ_, ρ, β], defaults = Dict([σ_ => 10.0, ρ => 10.0, β => 8/3]))

```

produces the wrong solution (but what’s weird is that now the `retcode` is a 'Success`).  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/4/749b5a42fc0435638723afc2bcf3b77047b450a6.png)

**so the question is** whydoes changing this parameter mess up the results? For values of `ρ` between 1 to 9, it works fine but as soon as you change to `ρ >= 10`, it messes up.

Even more weirdness is that I can use the PINN solver to estimate these parameters (like in the example linked above). So if I start with all parameters `Dict([σ_ => 1.0, ρ => 1.0, β => 1.0]))` and set `param_estim = true`, it can recover the parameters!!!

(Aside: @ChrisRackauckas I know you said not to use the PINN/`PDEsystem` API for ODE systems but I was just testing and learning the API to get a deeper understanding!)

Happy to provide full reproducible code

---

<div class="post-metadata">

### Author: ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)
#### Post date: [May 12, 2024, 6:49pm UTC](https://discourse.julialang.org/t/neuralpde-fails-to-solve-system-when-parameters-change/114169/2 "2024-05-12T18:49:25Z")

</div>

Okay it turns out this was issue with the training and optimization. I switched over to `GridTraining(0.001)` and bumped the max iterations in the optimization to 10,000 which seemed to have worked.

The problem is then if I bump `ρ => 28.0` it fails again. I decreased `dt` again to `0.0001` and increased `maxiters = 50000` but this still does not make the NN converge to the solution.

Is this just the behaviour of the Lorenzs system? Maybe I need a deeper neural network.
