UndefVarError: `ComponentArray` not defined when using GPU in NeuralPDE

I tried to run NeuralPDE with GPU by the tutorial code in NeuralPDE.jl as follows:

using NeuralPDE, Lux, CUDA, Random
using Optimization
using OptimizationOptimisers
import ModelingToolkit: Interval

@parameters t x y
@variables u(..)
Dxx = Differential(x)^2
Dyy = Differential(y)^2
Dt = Differential(t)
t_min= 0.
t_max = 2.0
x_min = 0.
x_max = 2.
y_min = 0.
y_max = 2.

# 2D PDE
eq  = Dt(u(t,x,y)) ~ Dxx(u(t,x,y)) + Dyy(u(t,x,y))

analytic_sol_func(t,x,y) = exp(x+y)*cos(x+y+4t)
# Initial and boundary conditions
bcs = [u(t_min,x,y) ~ analytic_sol_func(t_min,x,y),
       u(t,x_min,y) ~ analytic_sol_func(t,x_min,y),
       u(t,x_max,y) ~ analytic_sol_func(t,x_max,y),
       u(t,x,y_min) ~ analytic_sol_func(t,x,y_min),
       u(t,x,y_max) ~ analytic_sol_func(t,x,y_max)]

# Space and time domains
domains = [t ∈ Interval(t_min,t_max),
           x ∈ Interval(x_min,x_max),
           y ∈ Interval(y_min,y_max)]

# Neural network
inner = 25
chain = Chain(Dense(3,inner,Lux.σ),

strategy = GridTraining(0.05)
ps = Lux.setup(Random.default_rng(), chain)[1]
ps = ps |> Lux.ComponentArray |> gpu .|> Float64
discretization = PhysicsInformedNN(chain,
                                   init_params = ps)

@named pde_system = PDESystem(eq,bcs,domains,[t,x,y],[u(t, x, y)])
prob = discretize(pde_system,discretization)
symprob = symbolic_discretize(pde_system,discretization)

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

res = Optimization.solve(prob,Adam(0.01);callback = callback,maxiters=2500)

And got the message:

UndefVarError: `ComponentArray` not defined

 [1] getproperty(x::Module, f::Symbol)
   @ Base .\Base.jl:31
 [2] top-level scope
   @ In[11]:44

I also installed ComponentArrays.jl, but it still had this error. Please help me on how to fix it.
Thank you all.

Lux.ComponentArray that should just be ComponentArray after you’ve done using ComponentArrays


Is this in the updated docs?

Yes, it has been updated in docs, but I often see the code on the website NeuralPDE.jl and it has not been updated yet. Is the information in the docs on Github and on the website separate?

That link wasn’t redirecting correctly for some reason. It’s now redirecting to the correct website NeuralPDE.jl: Automatic Physics-Informed Neural Networks (PINNs) · NeuralPDE.jl.


Got it. Thank you.

At least now I know where your issues were coming from haha. With this website redirect updated, I wonder if the NeuralPDE questions start instantly going down. I was curious because the same questions of things already updated in the docs kept getting brought up, now I know why :sweat_smile:. Sometimes it’s the simplest thing that is causing the biggest issue haha.

1 Like

I am a newbie and not familiar with Github, so I prefer the tutorial on the website, I will pay more attention to docs. Thank you a lot for your time and help.

I want to understand more about the discretization and symbolic discretization (PINNs) with Lux and Flux packages, however, there have not been any references related to this on GitHub. Would you please provide me where I can find it? Thank you.


1 Like