"ERROR: LoadError: LoadError: UndefVarError: AbstractADType not defined" during GalacticOpim precompilation

I tried using this example found here: https://github.com/SciML/NeuralPDE.jl but I get the error “ERROR: LoadError: LoadError: UndefVarError: AbstractADType not defined” during the precompilation of the GalacticOptim package.

Here is the code:

using NeuralPDE, Flux, ModelingToolkit, Optim, DiffEqFlux
using GalacticOptim
using Base
#GalacticOptim
# 3D PDE
@parameters x y t θ
@variables u(..)
@derivatives Dxx''~x
@derivatives Dyy''~y
@derivatives Dt'~t

# 3D PDE
eq  = Dt(u(x,y,t,θ)) ~ Dxx(u(x,y,t,θ)) + Dyy(u(x,y,t,θ))
# Initial and boundary conditions
bcs = [u(x,y,0,θ) ~ exp(x+y)*cos(x+y) ,
       u(0,y,t,θ) ~ exp(y)*cos(y+4t),
       u(2,y,t,θ) ~ exp(2+y)*cos(2+y+4t) ,
       u(x,0,t,θ) ~ exp(x)*cos(x+4t),
       u(x,2,t,θ) ~ exp(x+2)*cos(x+2+4t)]
# Space and time domains
domains = [x ∈ IntervalDomain(0.0,2.0),
           y ∈ IntervalDomain(0.0,2.0),
           t ∈ IntervalDomain(0.0,2.0)]

# Discretization
dx = 0.25; dy= 0.25; dt = 0.25
# Neural network
chain = FastChain(FastDense(3,16,Flux.σ),FastDense(16,16,Flux.σ),FastDense(16,1))

discretization = NeuralPDE.PhysicsInformedNN([dx,dy,dt],
                                             chain,
                                             strategy = NeuralPDE.StochasticTraining(include_frac=0.9))
pde_system = PDESystem(eq,bcs,domains,[x,y,t],[u])
prob = NeuralPDE.discretize(pde_system,discretization)

res = GalacticOptim.solve(prob, ADAM(0.1), progress = false; cb = cb, maxiters=3000)
phi = discretization.phi


ts,xs = [domain.domain.lower:dx:domain.domain.upper for domain in domains]

analytic_sol_func(t,x) = [exp(-t)*sin(pi*x), exp(-t)*cos(pi*x), (1+pi^2)*exp(-t)]
u_real  = [[analytic_sol_func(t,x)[i] for t in ts for x in xs] for i in 1:3]
u_predict  = [[phi([t,x],res.minimizer)[i] for t in ts for x in xs] for i in 1:3]
diff_u = [abs.(u_real[i] .- u_predict[i] ) for i in 1:3]

for i in 1:3
    p1 = plot(xs, ts, u_real[i], st=:surface,title = "u$i, analytic");
    p2 = plot(xs, ts, u_predict[i], st=:surface,title = "predict");
    p3 = plot(xs, ts, diff_u[i],linetype=:contourf,title = "error");
    plot(p1,p2,p3)
    savefig("sol_u$i")
end
1 Like

Try updating. I just fixed a lower bound that should fix this error. Sorry it showed up!

2 Likes

Ok, we succeeded in precompiling but we still have another issue, namely, when we run the following line:

discretization = NeuralPDE.PhysicsInformedNN([dx,dy,dt], chain, strategy = NeuralPDE.StochasticTraining(include_frac=0.9))

we read:

UndefVarError: StochasticTraining not defined

and no methods under NeuralPDE seem working…

@sazio did you try from a fresh REPL session again?

1 Like

We tried to do everything on a blank TOML (] activate .), if we try to install GalacticOptim on the default environment we receive a version error during installation.
The status of the default environment is the following:

 [c52e3926] Atom v0.12.23
  [fbb218c0] BSON v0.2.6
  [6e4b80f9] BenchmarkTools v0.5.0
  [8f4d0f93] Conda v1.4.1
  [aae7a2af] DiffEqFlux v1.17.0
  [41bf760c] DiffEqSensitivity v6.32.0
  [0c46a032] DifferentialEquations v6.15.0
  [587475ba] Flux v0.10.4
  [e5e0dc1b] Juno v0.8.4
  [961ee093] ModelingToolkit v3.21.0
  [315f7962] NeuralPDE v2.0.0
  [429524aa] Optim v0.20.1
  [1dea7af3] OrdinaryDiffEq v5.42.3
  [91a5bcdd] Plots v1.6.7
  [438e738f] PyCall v1.92.0
  [d330b81b] PyPlot v2.9.0
  [d2ef9438] Seaborn v0.4.1
  [1d978283] TensorFlow v0.11.0
  [e88e6eb3] Zygote v0.4.22
  [8bb1440f] DelimitedFiles

The example we are trying to run is the following:

using NeuralPDE, Flux, ModelingToolkit, GalacticOptim, Optim, DiffEqFlux

#GalacticOptim
# 3D PDE
@parameters x y t θ
@variables u(..)
@derivatives Dxx''~x
@derivatives Dyy''~y
@derivatives Dt'~t

# 3D PDE
eq  = Dt(u(x,y,t,θ)) ~ Dxx(u(x,y,t,θ)) + Dyy(u(x,y,t,θ))
# Initial and boundary conditions
bcs = [u(x,y,0,θ) ~ exp(x+y)*cos(x+y),
       u(0,y,t,θ) ~ exp(y)*cos(y+4t),
       u(2,y,t,θ) ~ exp(2+y)*cos(2+y+4t) ,
       u(x,0,t,θ) ~ exp(x)*cos(x+4t),
       u(x,2,t,θ) ~ exp(x+2)*cos(x+2+4t)]
# Space and time domains
domains = [x ∈ IntervalDomain(0.0,2.0),
           y ∈ IntervalDomain(0.0,2.0),
           t ∈ IntervalDomain(0.0,2.0)]

# Discretization
dx = 0.25; dy= 0.25; dt = 0.25
# Neural network
chain = FastChain(FastDense(3,16,Flux.σ),FastDense(16,16,Flux.σ),FastDense(16,1))


discretization = NeuralPDE.PhysicsInformedNN([dx,dy,dt],
                                             chain,
                                             strategy = NeuralPDE.StochasticTraining(include_frac=0.9))


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

res = GalacticOptim.solve(prob, ADAM(0.1), progress = false; cb = cb, maxiters=3000)
phi = discretization.phi


ts,xs = [domain.domain.lower:dx:domain.domain.upper for domain in domains]

analytic_sol_func(t,x) = [exp(-t)*sin(pi*x), exp(-t)*cos(pi*x), (1+pi^2)*exp(-t)]
u_real  = [[analytic_sol_func(t,x)[i] for t in ts for x in xs] for i in 1:3]
u_predict  = [[phi([t,x],res.minimizer)[i] for t in ts for x in xs] for i in 1:3]
diff_u = [abs.(u_real[i] .- u_predict[i] ) for i in 1:3]

for i in 1:3
    p1 = plot(xs, ts, u_real[i], st=:surface,title = "u$i, analytic");
    p2 = plot(xs, ts, u_predict[i], st=:surface,title = "predict");
    p3 = plot(xs, ts, diff_u[i],linetype=:contourf,title = "error");
    plot(p1,p2,p3)
    savefig("sol_u$i")
end
1 Like

You’ll need the latest version, NeuralPDE.jl v2.5 for that. You have an old version of NeuralPDE, an old version of Flux, an old version of Zygote, etc. Are you on Julia v1.5? When is the last time you did a package update?

1 Like

We created a new TOML and we reinstalled everything, these are the versions:

  [2b5f629d] DiffEqBase v6.48.0
  [aae7a2af] DiffEqFlux v1.24.0
  [587475ba] Flux v0.11.1
  [a75be94c] GalacticOptim v0.3.0
  [961ee093] ModelingToolkit v3.21.0
  [315f7962] NeuralPDE v2.5.0
  [429524aa] Optim v1.2.0
  [e88e6eb3] Zygote v0.5.8

but Julia throws this error while precompiling GalacticOptim:

julia>

[ Info: Precompiling GalacticOptim [a75be94c-b780-496d-a8a9-0878b188d577]

WARNING: could not import DiffEqBase.OptimizationFunction into GalacticOptim

WARNING: could not import DiffEqBase.AbstractADType into GalacticOptim

ERROR: LoadError: LoadError: UndefVarError: AbstractADType not defined

Stacktrace:

[1] top-level scope at /home/unitoprojectxgcp/.julia/packages/GalacticOptim/TzUrT/src/function.jl:1

[2] include(::Function, ::Module, ::String) at ./Base.jl:380

[3] include at ./Base.jl:368 [inlined]

[4] include(::String) at /home/unitoprojectxgcp/.julia/packages/GalacticOptim/TzUrT/src/GalacticOptim.jl:1

[5] top-level scope at /home/unitoprojectxgcp/.julia/packages/GalacticOptim/TzUrT/src/GalacticOptim.jl:15

[6] include(::Function, ::Module, ::String) at ./Base.jl:380

[7] include(::Module, ::String) at ./Base.jl:368

[8] top-level scope at none:2

[9] eval at ./boot.jl:331 [inlined]

[10] eval(::Expr) at ./client.jl:467

[11] top-level scope at ./none:3

in expression starting at /home/unitoprojectxgcp/.julia/packages/GalacticOptim/TzUrT/src/function.jl:1

in expression starting at /home/unitoprojectxgcp/.julia/packages/GalacticOptim/TzUrT/src/GalacticOptim.jl:15

Did you run this in a new Julia session?

@vpagliarino please do the following from a fresh Julia session and let us know

(@v1.5) pkg> activate myenv
 Activating new environment at `~/myenv/Project.toml`

(myenv) pkg> add NeuralPDE GalacticOptim
  Resolving package versions...
Updating `~/Bioequivalence.jl/myenv/Project.toml`
  [a75be94c] + GalacticOptim v0.3.0
  [315f7962] + NeuralPDE v2.5.0

and then try to use the packages. I am not sure what’s happening here on your end but I double checked and there doesn’t seem to be a problem with the release versions of either NeuralPDE or GalacticOptim