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

**URL:** https://discourse.julialang.org/t/undefvarerror-componentarray-not-defined-when-using-gpu-in-neuralpde/102725
**Category:** General Usage
**Tags:** question, gpu, neural-network
**Created:** [August 11, 2023, 4:40pm UTC](https://discourse.julialang.org/t/undefvarerror-componentarray-not-defined-when-using-gpu-in-neuralpde/102725 "2023-08-11T16:40:35Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Ethan\_Tran](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ethan_tran/32/49198_2.png) [@Ethan\_Tran](https://discourse.julialang.org/u/Ethan_Tran)
#### Post date: [August 11, 2023, 4:40pm UTC](https://discourse.julialang.org/t/undefvarerror-componentarray-not-defined-when-using-gpu-in-neuralpde/102725/1 "2023-08-11T16:40:35Z")

</div>

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

```julia
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.σ),
              Dense(inner,inner,Lux.σ),
              Dense(inner,inner,Lux.σ),
              Dense(inner,inner,Lux.σ),
              Dense(inner,1)) 

strategy = GridTraining(0.05)
ps = Lux.setup(Random.default_rng(), chain)[1]
ps = ps |> Lux.ComponentArray |> gpu .|> Float64
discretization = PhysicsInformedNN(chain,
                                   strategy,
                                   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
end

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

```

And got the message:

```julia
UndefVarError: `ComponentArray` not defined

Stacktrace:
 [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.

---

<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: [August 11, 2023, 10:22pm UTC](https://discourse.julialang.org/t/undefvarerror-componentarray-not-defined-when-using-gpu-in-neuralpde/102725/2 "2023-08-11T22:22:53Z")

</div>

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

---

<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: [August 12, 2023, 11:55am UTC](https://discourse.julialang.org/t/undefvarerror-componentarray-not-defined-when-using-gpu-in-neuralpde/102725/3 "2023-08-12T11:55:28Z")

</div>

Is this in the updated docs?

---

<div class="post-metadata">

### Author: ![Ethan\_Tran](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ethan_tran/32/49198_2.png) [@Ethan\_Tran](https://discourse.julialang.org/u/Ethan_Tran)
#### Post date: [August 12, 2023, 11:02pm UTC](https://discourse.julialang.org/t/undefvarerror-componentarray-not-defined-when-using-gpu-in-neuralpde/102725/4 "2023-08-12T23:02:02Z")

</div>

Yes, it has been updated in docs, but I often see the code on the website [NeuralPDE.jl](https://neuralpde.sciml.ai/stable/) and it has not been updated yet. Is the information in the docs on Github and on the website separate?

---

<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: [August 12, 2023, 11:54pm UTC](https://discourse.julialang.org/t/undefvarerror-componentarray-not-defined-when-using-gpu-in-neuralpde/102725/5 "2023-08-12T23:54:50Z")

</div>

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](https://docs.sciml.ai/NeuralPDE/stable/).

---

<div class="post-metadata">

### Author: ![Ethan\_Tran](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ethan_tran/32/49198_2.png) [@Ethan\_Tran](https://discourse.julialang.org/u/Ethan_Tran)
#### Post date: [August 13, 2023, 12:06am UTC](https://discourse.julialang.org/t/undefvarerror-componentarray-not-defined-when-using-gpu-in-neuralpde/102725/6 "2023-08-13T00:06:37Z")

</div>

Got it. Thank you.

---

<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: [August 13, 2023, 12:08am UTC](https://discourse.julialang.org/t/undefvarerror-componentarray-not-defined-when-using-gpu-in-neuralpde/102725/7 "2023-08-13T00:08:24Z")

</div>

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 😅. Sometimes it’s the simplest thing that is causing the biggest issue haha.

---

<div class="post-metadata">

### Author: ![Ethan\_Tran](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ethan_tran/32/49198_2.png) [@Ethan\_Tran](https://discourse.julialang.org/u/Ethan_Tran)
#### Post date: [August 13, 2023, 12:17am UTC](https://discourse.julialang.org/t/undefvarerror-componentarray-not-defined-when-using-gpu-in-neuralpde/102725/8 "2023-08-13T00:17:06Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Ethan\_Tran](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ethan_tran/32/49198_2.png) [@Ethan\_Tran](https://discourse.julialang.org/u/Ethan_Tran)
#### Post date: [August 13, 2023, 12:22am UTC](https://discourse.julialang.org/t/undefvarerror-componentarray-not-defined-when-using-gpu-in-neuralpde/102725/9 "2023-08-13T00:22:55Z")

</div>

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.

---

<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: [August 13, 2023, 12:23am UTC](https://discourse.julialang.org/t/undefvarerror-componentarray-not-defined-when-using-gpu-in-neuralpde/102725/10 "2023-08-13T00:23:14Z")

</div>

[https://book.sciml.ai/notes/03-Introduction\_to\_Scientific\_Machine\_Learning\_through\_Physics-Informed\_Neural\_Networks/](https://book.sciml.ai/notes/03-Introduction_to_Scientific_Machine_Learning_through_Physics-Informed_Neural_Networks/)
