Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameters estimation using NeuralPDE.jl is not working for PDEs #681

Closed
OSHamouda opened this issue Apr 30, 2023 · 5 comments
Closed

Parameters estimation using NeuralPDE.jl is not working for PDEs #681

OSHamouda opened this issue Apr 30, 2023 · 5 comments

Comments

@OSHamouda
Copy link

Hello,
The inverse PINN problems handling partial differential equations does not work well as the code stops at the optimization (training ) step and the following error appears:
ERROR: type NamedTuple has no field layer_1
image
While it works well with ordinary differential equations such as Lorenz eqs example illustrated in the package's docs.
The used Julia version: 1.8.5

@ChrisRackauckas
Copy link
Member

MWE?

@allen-adastra
Copy link

I've already ID'd the problem and the workaround:
#679

@OSHamouda
Copy link
Author

OSHamouda commented May 1, 2023

I've already ID'd the problem and the workaround:
#679

I believe it's a different point here as the training process does not even start

@OSHamouda
Copy link
Author

solved

@acaltran
Copy link

Hello,

I am relatively new to Julia and NeuralPDE. For learning purposes, I am trying to solve an inverse problem related to a simple Poiseuille flow. I seem to be encountering the same issue that was mentioned earlier. Unfortunately, I'm struggling to understand why this is happening.

I get the following error at the beginning of the solve process.

ERROR: type NamedTuple has no field layer_1

Could anyone explain how the issue was resolved previously, or possibly assist me in debugging my code?

The PDE that I'm working with is:

$$ \frac{d^2\tilde{w}}{dy^2}+\frac{1}{y}\frac{d\tilde{w}}{dy}+\tilde{w}_{source} = 0 \quad y \in [0, 1] $$

where

$$ \tilde{w}_{source} = \frac{\Delta P}{\mu l}R^2 $$

Here, $\tilde{w}(t)$ represents the flow velocity, and $\tilde{w}_{source}$ is the source parameter that I wish to optimize to match with the given noisy data.

using SciMLBase
using NeuralPDE, ModelingToolkit, Lux, Optimization, OptimizationOptimJL

using Plots
using Pipe

R = 10.0
l = 2.0
ΔP = 15
μ = 3.2

analytical = function (y::Real, R::Real, l::Real, ΔP::Real, μ::Real)
    ΔP / (4 * μ * l) * R^2 * (1 - y^2)
end

ndata = 10
noise_fact = 0.1
y_data = reshape(range(0, 1, ndata), 1, ndata)
w_data = analytical.(y_data, R, l, ΔP, μ) .+ noise_fact * analytical(0, R, l, ΔP, μ) * randn(size(y_data))

@parameters y, w̃ₛ
@variables (..)

Dy = Differential(y)
Dyy = Differential(y)^2

eq = Dyy((y)) + 1 / y * Dy((y)) + w̃ₛ ~ 0

bcs = [(1) ~ 0]

ε = 1e-9 #Avoir cost function evaluation at y=0
domains = [y  (ε, 1)]

@named pde_system = PDESystem(eq, bcs, domains, [y], [(y)], [w̃ₛ], defaults=Dict(w̃ₛ => 1.0))

chain = Chain(Dense(1, 4, Lux.σ), Dense(4, 1, Lux.σ))

additional_loss = function (phi, θ, p)
    sum(abs2, phi(y_data, θ) - w_data)
end

callback = function (p, l)
    println("Current loss is: $l")
    return false
end

pinn_inv = NeuralPDE.PhysicsInformedNN(chain, QuasiRandomTraining(100), additional_loss=additional_loss, param_estim=true)
prob_inv = NeuralPDE.discretize(pde_system, pinn_inv)

res_inv = Optimization.solve(prob_inv, BFGS(); maxiters=5000)


y_plot = range(0, 1, 100)
plot(y_plot, analytical.(y_plot, R, l, ΔP, μ), label="analytical")
plot!(y_plot, @pipe(y_plot |> reshape(_, 1, length(_)) |> pinn.phi(_, res_inv.u)'), label="PINN")
plot!(y_data', w_data', seriestype=:scatter, label="data")

The st command provide the following output.

Status `~/infrastructure_ae/Project.toml`
  [b2108857] Lux v0.4.54
  [961ee093] ModelingToolkit v8.59.1
  [315f7962] NeuralPDE v5.7.0
  [7f7a1694] Optimization v3.15.2
  [36348300] OptimizationOptimJL v0.1.9
  [b98c9c47] Pipe v1.3.0
  [91a5bcdd] Plots v1.38.16
  [0bca4576] SciMLBase v1.93.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants