Dear All,
I am attempting to run the following Physics-Informed Neural Network (PINN) problem on a GPU. However, I encounter an error related to scalar indexing. Despite my efforts to debug this issue and explore potential solutions, I have been unable to find any relevant threads or guidance.
Could you please provide some advice or suggestions on how to address and resolve this scalar indexing error?
Thank you for your assistance.
code ===>
begin
using ModelingToolkit, DomainSets
using Lux
using NeuralPDE
using LuxCUDA, ComponentArrays, Random
end
# Parameters, variables, and derivatives
@parameters Xꜛ Yꜛₛₒₗ Yꜛₐ
@variables Θꜛₐ(..) ωꜛₐ(..)
@variables Θꜛₛₒₗ(..) ξꜛₛₒₗ(..)
DXꜛ = Differential(Xꜛ)
DYꜛₐ = Differential(Yꜛₐ)
DYꜛₛₒₗ = Differential(Yꜛₛₒₗ)
DYꜛₐ² = Differential(Yꜛₐ)^2
DYꜛₛₒₗ² = Differential(Yꜛₛₒₗ)^2
function Uꜛₛₒₗ(Yꜛₛₒₗ)
y = Yꜛₛₒₗ * 1.2
uₛₒₗ = 2 * y * (1.0 - 0.5 * y) / 4.0
return uₛₒₗ / 1.5
end
function Uꜛₐ(Yꜛₐ)
y = Yꜛₐ * 1.2
uₐ = -1.2 - 5.0 *(3.0 ^ 2 - y ^ 2)
return -uₐ / 2.0
end
i_fg(t_) = 4t_^3 - 3t_^4 + 10.0
function c2(Θ)
t_ = Θ * 5.0 + 10.0
return 10.0 * i_fg(t_) * 0.5 / (10.0 * 5000.0)
end
@register_symbolic c2(Θ)
# Equations
eqs = [
Uꜛₐ(Yꜛₐ) * DXꜛ(Θꜛₐ(Xꜛ,Yꜛₐ)) ~ 5.0 * DYꜛₐ²(Θꜛₐ(Xꜛ,Yꜛₐ)),
Uꜛₐ(Yꜛₐ) * DXꜛ(ωꜛₐ(Xꜛ,Yꜛₐ)) ~ 6.0 * DYꜛₐ²(ωꜛₐ(Xꜛ,Yꜛₐ)),
Uꜛₛₒₗ(Yꜛₛₒₗ) * DXꜛ(Θꜛₛₒₗ(Xꜛ,Yꜛₛₒₗ)) ~ 8.0 * DYꜛₛₒₗ²(Θꜛₛₒₗ(Xꜛ,Yꜛₛₒₗ)),
Uꜛₛₒₗ(Yꜛₛₒₗ) * DXꜛ(ξꜛₛₒₗ(Xꜛ,Yꜛₛₒₗ)) ~ 11.0 * DYꜛₛₒₗ²(ξꜛₛₒₗ(Xꜛ,Yꜛₛₒₗ))
]
bcs = [
Θꜛₐ(1.0, Yꜛₐ) ~ 1.0,
ωꜛₐ(1.0, Yꜛₐ) ~ 1.0,
Θꜛₛₒₗ(0.0, Yꜛₛₒₗ) ~ 1.0,
ξꜛₛₒₗ(0.0, Yꜛₛₒₗ) ~ 1.0,
DYꜛₐ(Θꜛₐ(Xꜛ, 0.0)) ~ 0.0,
DYꜛₐ(ωꜛₐ(Xꜛ, 0.0)) ~ 0.0,
Θꜛₛₒₗ(Xꜛ, 0.0) ~ 0.0,
DYꜛₛₒₗ(ξꜛₛₒₗ(Xꜛ, 0.0)) ~ 0.0,
DYꜛₐ(Θꜛₐ(Xꜛ, 1.0)) + 5.0 * DYꜛₛₒₗ(Θꜛₛₒₗ(Xꜛ, 1.0)) - 5.0 * c2(Θꜛₛₒₗ(Xꜛ, 1.0)) * DYꜛₛₒₗ(ξꜛₛₒₗ(Xꜛ, 1.0)) ~ 0.0,
DYꜛₐ(ωꜛₐ(Xꜛ, 1.0)) + 1.05 * DYꜛₛₒₗ(ξꜛₛₒₗ(Xꜛ, 1.0)) ~ 0.0
]
domains = [
Xꜛ ∈ Interval(0.0, 1.0),
Yꜛₐ ∈ Interval(0.0, 1.0),
Yꜛₛₒₗ ∈ Interval(0.0, 1.0),
]
@named pdesystem = PDESystem(eqs, bcs, domains,[Xꜛ, Yꜛₐ, Yꜛₛₒₗ], [Θꜛₐ(Xꜛ,Yꜛₐ), ωꜛₐ(Xꜛ,Yꜛₐ), Θꜛₛₒₗ(Xꜛ,Yꜛₛₒₗ), ξꜛₛₒₗ(Xꜛ,Yꜛₛₒₗ)])
# Neural network
dim = 2 # number of dimensions
N_nr = 8 # number of neurons
chain = [Lux.Chain(Dense(dim, N_nr, Lux.σ), Dense(N_nr, N_nr, Lux.σ), Dense(N_nr, 1)) for _ in 1:4]
strategy = QuasiRandomTraining(100)
gpu_dev = gpu_device()
# Seeding
rng = Random.default_rng()
Random.seed!(rng, 0)
ps = Lux.setup(Random.default_rng(), chain)[1]
ps = ps |> gpu_dev
ps = f64(ps)
discretization = PhysicsInformedNN(chain, strategy,init_params = ps)
prob = discretize(pdesystem, discretization)
error ===>
ERROR: Scalar indexing is disallowed.
Invocation of getindex resulted in scalar indexing of a GPU array.
This is typically caused by calling an iterating implementation of a method.
Such implementations *do not* execute on the GPU, but very slowly on the CPU,
and therefore should be avoided.
If you want to allow scalar iteration, use `allowscalar` or `@allowscalar`
to enable scalar iteration globally or for the operations in question.