"None Sym BasicSymbolic doesn't have a name" Problem when using NeuralPDE

I try to use NeuralPDE to solve ODE problem, when I define the system with the separate variable u1(…) and u2(…) it run normally. (The code following)

using NeuralPDE, Lux, ModelingToolkit, Optimization, OptimizationOptimJL
import ModelingToolkit: Interval, infimum, supremum

@parameters t
@variables u1(..), u2(..)
D = Differential(t)
eq = [D(u1(t)) ~ u2(t),
    D(u2(t)) ~ 5 - 10*sin(u1(t))-1.7*u2(t)];

import ModelingToolkit: Interval
bcs = [u1(0) ~ -1, u2(0) ~ 7]
domains = [t ∈ Interval(0.0,10.0)]
dt = 0.01

input_ = length(domains) # number of dimensions
n = 16
chain =[Lux.Chain(Dense(input_,n,Lux.σ),Dense(n,n,Lux.σ),Dense(n,1)) for _ in 1:2]

@named pde_system = PDESystem(eq,bcs,domains,[t],[u1(t),u2(t)])

strategy = NeuralPDE.GridTraining(dt)
discretization = PhysicsInformedNN(chain, strategy)
sym_prob = NeuralPDE.symbolic_discretize(pde_system, discretization)

pde_loss_functions = sym_prob.loss_functions.pde_loss_functions
bc_loss_functions = sym_prob.loss_functions.bc_loss_functions

callback = function (p, l)
    println("loss: ", l)
    # println("pde_losses: ", map(l_ -> l_(p), pde_loss_functions))
    # println("bcs_losses: ", map(l_ -> l_(p), bc_loss_functions))
    return false
end

loss_functions =  [pde_loss_functions;bc_loss_functions]

function loss_function(θ,p)
    sum(map(l->l(θ) ,loss_functions))
end

f_ = OptimizationFunction(loss_function, Optimization.AutoZygote())
prob = Optimization.OptimizationProblem(f_, sym_prob.flat_init_params)

res = Optimization.solve(prob,OptimizationOptimJL.BFGS(); callback = callback, maxiters=10000)
phi = discretization.phi

However, when I changed the way to define the variable I got the message that “None Sym BasicSymbolic doesn’t have a name”
The code after changing following:

using NeuralPDE, Lux, ModelingToolkit, Optimization, OptimizationOptimJL
import ModelingToolkit: Interval, infimum, supremum

@parameters t
@variables (u(..))[1:2]
D = Differential(t)
eq = [D(u(t)[1]) ~ u(t)[2],
    D(u(t)[2]) ~ 5 - 10*sin(u(t)[2])-1.7*u(t)[2]];

import ModelingToolkit: Interval
bcs = [u(0)[1] ~ -1, u(0)[2] ~ 7]
domains = [t ∈ Interval(0.0,10.0)]
dt = 0.01

input_ = length(domains) # number of dimensions
n = 16
chain =[Lux.Chain(Dense(input_,n,Lux.σ),Dense(n,n,Lux.σ),Dense(n,1)) for _ in 1:2]

@named pde_system = PDESystem(eq,bcs,domains,[t],[u(t)[1],u(t)[2]])

strategy = NeuralPDE.GridTraining(dt)
discretization = PhysicsInformedNN(chain, strategy)
sym_prob = NeuralPDE.symbolic_discretize(pde_system, discretization)

The message causes by the code sym_prob = NeuralPDE.symbolic_discretize(pde_system, discretization).
Please help me on how to fix it.
Thank you all.

Just as another breadcrumb, this is stemming from a check in SymbolicUtils that is ensuring that a particular variable is a properly-defined symbolic. Not sure why that’s happening, but given that Google doesn’t seem to have indexed SymbolicUtils (but has indexed this thread), I thought it might be useful to give that little bit of context here.

1 Like