Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo not running #690

Closed
flmuk opened this issue Jun 2, 2023 · 10 comments
Closed

Demo not running #690

flmuk opened this issue Jun 2, 2023 · 10 comments

Comments

@flmuk
Copy link

flmuk commented Jun 2, 2023

Hello,
I am trying to run the example https://docs.sciml.ai/NeuralPDE/stable/tutorials/pdesystem/, on a newly created Julia project.

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

@parameters x y
@variables u(..)
Dxx = Differential(x)^2
Dyy = Differential(y)^2

# 2D PDE
eq = Dxx(u(x, y)) + Dyy(u(x, y)) ~ -sin(pi * x) * sin(pi * y)

# Boundary conditions
bcs = [u(0, y) ~ 0.0, u(1, y) ~ 0.0,
    u(x, 0) ~ 0.0, u(x, 1) ~ 0.0]
# Space and time domains
domains = [x ∈ Interval(0.0, 1.0),
    y ∈ Interval(0.0, 1.0)]

# Neural network
dim = 2 # number of dimensions
chain = Lux.Chain(Dense(dim, 16, Lux.σ), Dense(16, 16, Lux.σ), Dense(16, 1))

# Discretization
dx = 0.05
discretization = PhysicsInformedNN(chain, GridTraining(dx))

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

#Optimizer
opt = OptimizationOptimJL.BFGS()

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

res = Optimization.solve(prob, opt, callback = callback, maxiters = 1000)
phi = discretization.phi

using Plots

xs, ys = [infimum(d.domain):(dx / 10):supremum(d.domain) for d in domains]
analytic_sol_func(x, y) = (sin(pi * x) * sin(pi * y)) / (2pi^2)

u_predict = reshape([first(phi([x, y], res.u)) for x in xs for y in ys],
                    (length(xs), length(ys)))
u_real = reshape([analytic_sol_func(x, y) for x in xs for y in ys],
                 (length(xs), length(ys)))
diff_u = abs.(u_predict .- u_real)

p1 = plot(xs, ys, u_real, linetype = :contourf, title = "analytic");
p2 = plot(xs, ys, u_predict, linetype = :contourf, title = "predict");
p3 = plot(xs, ys, diff_u, linetype = :contourf, title = "error");
plot(p1, p2, p3)

I created the project by running ] activate .; add NeuralPDE.

I use Julia Version 1.8.5
Commit 17cfb8e65ea (2023-01-08 06:45 UTC)

Here is the output I get when running ] st -m: pstatus.txt

When running the above mentioned example, I get the following error when executing
res = Optimization.solve(prob, opt, callback = callback, maxiters = 1000):
ERROR: ArgumentError: The passed automatic differentiation backend choice is not available. Please load the corresponding AD package Zygote. (see here for the full stack trace:
errmsg.txt)

What can I do? Although the tutorial says that the code is copy-pastable, for me it just won't run. I also tried running ] add Zygote, but that didn't work either.

EDIT:

When running using NeuralPDE, Lux, Optimization, OptimizationOptimJL I get

┌ Warning: Error requiring `Zygote` from `Optimization`
│   exception =
│    LoadError: ArgumentError: Package Optimization does not have Zygote in its dependencies:
│    - You may have a partially installed environment. Try `Pkg.instantiate()`
│      to ensure all packages in the environment are installed.
│    - Or, if you have Optimization checked out for development and have
│      added Zygote as a dependency but haven't updated your primary
│      environment's manifest file, try `Pkg.resolve()`.
│    - Otherwise you may need to report an issue with Optimization
│    Stacktrace:
│      [1] macro expansion
│        @ ./loading.jl:1167 [inlined]
│      [2] macro expansion
│        @ ./lock.jl:223 [inlined]
│      [3] require(into::Module, mod::Symbol)
│        @ Base ./loading.jl:1144
│      [4] include(mod::Module, _path::String)
│        @ Base ./Base.jl:419
│      [5] include(x::String)
│        @ Optimization ~/.julia/packages/Optimization/q952d/src/Optimization.jl:4
│      [6] macro expansion
│        @ ~/.julia/packages/Requires/Z8rfN/src/Requires.jl:40 [inlined]
│      [7] top-level scope
│        @ ~/.julia/packages/Optimization/q952d/src/Optimization.jl:46
│      [8] eval
│        @ ./boot.jl:368 [inlined]
│      [9] eval
│        @ ~/.julia/packages/Optimization/q952d/src/Optimization.jl:4 [inlined]
│     [10] (::Optimization.var"#48#69")()
│        @ Optimization ~/.julia/packages/Requires/Z8rfN/src/require.jl:101
│     [11] macro expansion
│        @ timing.jl:382 [inlined]
│     [12] err(f::Any, listener::Module, modname::String, file::String, line::Any)
│        @ Requires ~/.julia/packages/Requires/Z8rfN/src/require.jl:47
│     [13] (::Optimization.var"#47#68")()
│        @ Optimization ~/.julia/packages/Requires/Z8rfN/src/require.jl:100
│     [14] withpath(f::Any, path::String)
│        @ Requires ~/.julia/packages/Requires/Z8rfN/src/require.jl:37
│     [15] (::Optimization.var"#46#67")()
│        @ Optimization ~/.julia/packages/Requires/Z8rfN/src/require.jl:99
│     [16] listenpkg(f::Any, pkg::Base.PkgId)
│        @ Requires ~/.julia/packages/Requires/Z8rfN/src/require.jl:20
│     [17] macro expansion
│        @ ~/.julia/packages/Requires/Z8rfN/src/require.jl:98 [inlined]
│     [18] __init__()
│        @ Optimization ~/.julia/packages/Optimization/q952d/src/Optimization.jl:45
│     [19] _include_from_serialized(pkg::Base.PkgId, path::String, depmods::Vector{Any})
│        @ Base ./loading.jl:831
│     [20] _tryrequire_from_serialized(modkey::Base.PkgId, path::String, sourcepath::String, depmods::Vector{Any})
│        @ Base ./loading.jl:938
│     [21] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt64)
│        @ Base ./loading.jl:1028
│     [22] _require(pkg::Base.PkgId)
│        @ Base ./loading.jl:1315
│     [23] _require_prelocked(uuidkey::Base.PkgId)
│        @ Base ./loading.jl:1200
│     [24] macro expansion
│        @ ./loading.jl:1180 [inlined]
│     [25] macro expansion
│        @ ./lock.jl:223 [inlined]
│     [26] require(into::Module, mod::Symbol)
│        @ Base ./loading.jl:1144
│     [27] eval
│        @ ./boot.jl:368 [inlined]
│     [28] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
│        @ Base ./loading.jl:1428
│     [29] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
│        @ Base ./essentials.jl:729
│     [30] invokelatest(::Any, ::Any, ::Vararg{Any})
│        @ Base ./essentials.jl:726
│     [31] inlineeval(m::Module, code::String, code_line::Int64, code_column::Int64, file::String; softscope::Bool)
│        @ VSCodeServer ~/.vscode-server/extensions/julialang.language-julia-1.47.2/scripts/packages/VSCodeServer/src/eval.jl:233
│     [32] (::VSCodeServer.var"#66#70"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
│        @ VSCodeServer ~/.vscode-server/extensions/julialang.language-julia-1.47.2/scripts/packages/VSCodeServer/src/eval.jl:157
│     [33] withpath(f::VSCodeServer.var"#66#70"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams}, path::String)
│        @ VSCodeServer ~/.vscode-server/extensions/julialang.language-julia-1.47.2/scripts/packages/VSCodeServer/src/repl.jl:249
│     [34] (::VSCodeServer.var"#65#69"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
│        @ VSCodeServer ~/.vscode-server/extensions/julialang.language-julia-1.47.2/scripts/packages/VSCodeServer/src/eval.jl:155
│     [35] hideprompt(f::VSCodeServer.var"#65#69"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})
│        @ VSCodeServer ~/.vscode-server/extensions/julialang.language-julia-1.47.2/scripts/packages/VSCodeServer/src/repl.jl:38
│     [36] (::VSCodeServer.var"#64#68"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
│        @ VSCodeServer ~/.vscode-server/extensions/julialang.language-julia-1.47.2/scripts/packages/VSCodeServer/src/eval.jl:126
│     [37] with_logstate(f::Function, logstate::Any)
│        @ Base.CoreLogging ./logging.jl:511
│     [38] with_logger
│        @ ./logging.jl:623 [inlined]
│     [39] (::VSCodeServer.var"#63#67"{VSCodeServer.ReplRunCodeRequestParams})()
│        @ VSCodeServer ~/.vscode-server/extensions/julialang.language-julia-1.47.2/scripts/packages/VSCodeServer/src/eval.jl:225
│     [40] #invokelatest#2
│        @ ./essentials.jl:729 [inlined]
│     [41] invokelatest(::Any)
│        @ Base ./essentials.jl:726
│     [42] macro expansion
│        @ ~/.vscode-server/extensions/julialang.language-julia-1.47.2/scripts/packages/VSCodeServer/src/eval.jl:34 [inlined]
│     [43] (::VSCodeServer.var"#61#62")()
│        @ VSCodeServer ./task.jl:484
│    in expression starting at /home/ga48kuh/.julia/packages/Optimization/q952d/ext/OptimizationZygoteExt.jl:1
└ @ Requires ~/.julia/packages/Requires/Z8rfN/src/require.jl:51

I suppose this is related, but don't know how to fix it. Any ideas?

@flmuk flmuk changed the title Problems with precompiling and running NeuralPDE Demo not running Jun 2, 2023
@E-B-Manohar
Copy link

E-B-Manohar commented Jun 19, 2023

I faced same issue, using julia 1.9.1 resolved it.

@ChrisRackauckas
Copy link
Member

@Vaibhavdixit02

@Vaibhavdixit02
Copy link
Member

Vaibhavdixit02 commented Jun 19, 2023

@E-B-Manohar Can you post the package versions ]st you are using?

@Vaibhavdixit02
Copy link
Member

@flmuk from your Manifest I can see you are on Optimization 3.14, please update to 3.15 that should fix it for you

@E-B-Manohar
Copy link

@E-B-Manohar Can you post the package versions ]st you are using?

[7073ff75] IJulia v1.24.2
[b2108857] Lux v0.4.54
[961ee093] ModelingToolkit v8.59.1
[315f7962] NeuralPDE v5.7.0
[7f7a1694] Optimization v3.15.2
[36348300] OptimizationOptimJL v0.1.9
[42dfb2eb] OptimizationOptimisers v0.1.4
[91a5bcdd] Plots v1.38.16
[e88e6eb3] Zygote v0.6.62

@Vaibhavdixit02
Copy link
Member

This is on the 1.9 julia that worked for you or the 1.8 environment that didn't work?

@E-B-Manohar
Copy link

This is on the 1.9 julia that worked for you or the 1.8 environment that didn't work?

Earlier I was using Julia 1.6.9. Then I faced this error.
After reinstalling Julia with version 1.9.1, this error vanished

@Vaibhavdixit02
Copy link
Member

I think on 1.6 you might have had older package versions and hence got the error. It should work if you update packages

@E-B-Manohar
Copy link

I think on 1.6 you might have had older package versions and hence got the error. It should work if you update packages

Yeah, Probably you are right.

@flmuk
Copy link
Author

flmuk commented Jun 20, 2023

Thank you @Vaibhavdixit02 , this helped!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants