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

ERROR: MethodError: no method matching NeuralPDE.Phi #595

Closed
DrEmilGazazyan opened this issue Aug 25, 2022 · 1 comment
Closed

ERROR: MethodError: no method matching NeuralPDE.Phi #595

DrEmilGazazyan opened this issue Aug 25, 2022 · 1 comment

Comments

@DrEmilGazazyan
Copy link

DrEmilGazazyan commented Aug 25, 2022

Dear all,

I cannot understand my problems. Could you please help me?

Julia v 1.7.3

testpde.zip

Warning: FastChain is being deprecated in favor of Lux.jl. Lux.jl uses functions with explicit parameters f(u,p) like FastChain, but is fully featured and documented machine learning library. See the Lux.jl documentation for more details.
└ @ DiffEqFlux C:\Users\XXX.julia\packages\DiffEqFlux\Em1Aj\src\fast_layers.jl:9
ERROR: MethodError: no method matching NeuralPDE.Phi(::FastChain{Tuple{FastDense{typeof(sigmoid_fast), DiffEqFlux.var"#initial_params#107"{Vector{Float32}}, Nothing}, FastDense{typeof(sigmoid_fast), DiffEqFlux.var"#initial_params#107"{Vector{Float32}}, Nothing}, FastDense{typeof(identity), DiffEqFlux.var"#initial_params#107"{Vector{Float32}}, Nothing}}})
Closest candidates are:
NeuralPDE.Phi(::Chain) at C:\Users\XXX.julia\packages\NeuralPDE\Qjcw1\src\pinn_types.jl:352
NeuralPDE.Phi(::Lux.AbstractExplicitLayer) at C:\Users\XXX.julia\packages\NeuralPDE\Qjcw1\src\pinn_types.jl:348
Stacktrace:
[1] PhysicsInformedNN(chain::FastChain{Tuple{FastDense{typeof(sigmoid_fast), DiffEqFlux.var"#initial_params#107"{Vector{Float32}}, Nothing}, FastDense{typeof(sigmoid_fast), DiffEqFlux.var"#initial_params#107"{Vector{Float32}}, Nothing}, FastDense{typeof(identity), DiffEqFlux.var"#initial_params#107"{Vector{Float32}}, Nothing}}}, strategy::QuadratureTraining{IntegralsCubature.CubatureJLh, Float64}; init_params::Nothing, phi::Nothing, derivative::Nothing, param_estim::Bool, additional_loss::Nothing, adaptive_loss::Nothing, logger::Nothing, log_options::LogOptions, iteration::Nothing, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ NeuralPDE C:\Users\XXX.julia\packages\NeuralPDE\Qjcw1\src\pinn_types.jl:115
[2] PhysicsInformedNN(chain::Function, strategy::QuadratureTraining{IntegralsCubature.CubatureJLh, Float64})
@ NeuralPDE C:\Users\XXX.julia\packages\NeuralPDE\Qjcw1\src\pinn_types.jl:109
[3] top-level scope
@ c:\Users\XXX\Repository\testpde.jl:25

CODE

using NeuralPDE, Flux, ModelingToolkit, GalacticOptim, DiffEqFlux
using Quadrature, Cubature

@parameters x y
@variables u(..)
Dxx = Differential(x)^2
Dyy = Differential(y)^2

2D PDE

eq = Dxx(u(x,y)) + Dyy(u(x,y)) ~ -sin(pi*x)sin(piy)

Boundary conditions

bcs = [u(0,y) ~ 0.f0, u(1,y) ~ -sin(pi1)sin(piy),
u(x,0) ~ 0.f0, u(x,1) ~ -sin(pi
x)sin(pi1)]

Space and time domains

domains = [x ∈ IntervalDomain(0.0,1.0),
y ∈ IntervalDomain(0.0,1.0)]

Discretization

dx = 0.1

Neural network

dim = 2 # number of dimensions
chain = FastChain(FastDense(dim,16,Flux.σ),FastDense(16,16,Flux.σ),FastDense(16,1))

discretization = PhysicsInformedNN(chain, QuadratureTraining())

pde_system = PDESystem(eq,bcs,domains,[x,y],[u])
prob = discretize(pde_system,discretization)

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

res = GalacticOptim.solve(prob, ADAM(0.1); cb = cb, maxiters=4000)
prob = remake(prob,u0=res.minimizer)
res = GalacticOptim.solve(prob, ADAM(0.01); cb = cb, maxiters=2000)
phi = discretization.phi

xs,ys = [domain.domain.lower:dx/10:domain.domain.upper for domain in domains]
analytic_sol_func(x,y) = (sin(pi*x)sin(piy))/(2pi^2)

u_predict = reshape([first(phi([x,y],res.minimizer)) for x in xs for y in ys],(length(xs),length(ys)))
u_real = reshape([analytic_sol_func(x,y) for x in xs for y in ys], (length(xs),length(ys)))
diff_u = abs.(u_predict .- u_real)

using Plots
p1 = plot(xs, ys, u_real, linetype=:contourf,title = "analytic");
p2 = plot(xs, ys, u_predict, linetype=:contourf,title = "predict");
p3 = plot(xs, ys, diff_u,linetype=:contourf,title = "error");
plot(p1,p2,p3)

@ChrisRackauckas
Copy link
Member

You're using v4 syntax with v5. Update to using Lux as the docs state if you want to use v5. https://neuralpde.sciml.ai/dev/tutorials/pdesystem/

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

2 participants