Skip to content

Commit

Permalink
chore: format the whole repo
Browse files Browse the repository at this point in the history
  • Loading branch information
sathvikbhagavan committed Mar 29, 2024
1 parent 86ab97c commit b0daed7
Show file tree
Hide file tree
Showing 60 changed files with 1,150 additions and 1,001 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ 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.minimizer)) for x in xs for y in ys],
(length(xs), length(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)))
(length(xs), length(ys)))
diff_u = abs.(u_predict .- u_real)

using Plots
Expand Down
16 changes: 8 additions & 8 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ using Plots
include("pages.jl")

makedocs(sitename = "NeuralPDE.jl",
authors = "#",
modules = [NeuralPDE],
clean = true, doctest = false, linkcheck = true,
warnonly = [:missing_docs],
format = Documenter.HTML(assets = ["assets/favicon.ico"],
canonical = "https://docs.sciml.ai/NeuralPDE/stable/"),
pages = pages)
authors = "#",
modules = [NeuralPDE],
clean = true, doctest = false, linkcheck = true,
warnonly = [:missing_docs],
format = Documenter.HTML(assets = ["assets/favicon.ico"],
canonical = "https://docs.sciml.ai/NeuralPDE/stable/"),
pages = pages)

deploydocs(repo = "github.com/SciML/NeuralPDE.jl.git";
push_preview = true)
push_preview = true)
62 changes: 31 additions & 31 deletions docs/pages.jl
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
pages = ["index.md",
"ODE PINN Tutorials" => Any["Introduction to NeuralPDE for ODEs" => "tutorials/ode.md",
"Bayesian PINNs for Coupled ODEs" => "tutorials/Lotka_Volterra_BPINNs.md",
"PINNs DAEs" => "tutorials/dae.md",
"Parameter Estimation with PINNs for ODEs" => "tutorials/ode_parameter_estimation.md",
"Deep Galerkin Method" => "tutorials/dgm.md"
#"examples/nnrode_example.md", # currently incorrect
],
"PDE PINN Tutorials" => Any["Introduction to NeuralPDE for PDEs" => "tutorials/pdesystem.md",
"Bayesian PINNs for PDEs" => "tutorials/low_level_2.md",
"Using GPUs" => "tutorials/gpu.md",
"Defining Systems of PDEs" => "tutorials/systems.md",
"Imposing Constraints" => "tutorials/constraints.md",
"The symbolic_discretize Interface" => "tutorials/low_level.md",
"Optimising Parameters (Solving Inverse Problems)" => "tutorials/param_estim.md",
"Solving Integro Differential Equations" => "tutorials/integro_diff.md",
"Transfer Learning with Neural Adapter" => "tutorials/neural_adapter.md",
"The Derivative Neural Network Approximation" => "tutorials/derivative_neural_network.md"],
"Bayesian PINNs for Coupled ODEs" => "tutorials/Lotka_Volterra_BPINNs.md",
"PINNs DAEs" => "tutorials/dae.md",
"Parameter Estimation with PINNs for ODEs" => "tutorials/ode_parameter_estimation.md",
"Deep Galerkin Method" => "tutorials/dgm.md" #"examples/nnrode_example.md", # currently incorrect
],
"PDE PINN Tutorials" => Any[
"Introduction to NeuralPDE for PDEs" => "tutorials/pdesystem.md",
"Bayesian PINNs for PDEs" => "tutorials/low_level_2.md",
"Using GPUs" => "tutorials/gpu.md",
"Defining Systems of PDEs" => "tutorials/systems.md",
"Imposing Constraints" => "tutorials/constraints.md",
"The symbolic_discretize Interface" => "tutorials/low_level.md",
"Optimising Parameters (Solving Inverse Problems)" => "tutorials/param_estim.md",
"Solving Integro Differential Equations" => "tutorials/integro_diff.md",
"Transfer Learning with Neural Adapter" => "tutorials/neural_adapter.md",
"The Derivative Neural Network Approximation" => "tutorials/derivative_neural_network.md"],
"Extended Examples" => Any["examples/wave.md",
"examples/3rd.md",
"examples/ks.md",
"examples/heterogeneous.md",
"examples/linear_parabolic.md",
"examples/nonlinear_elliptic.md",
"examples/nonlinear_hyperbolic.md",
"examples/complex.md"],
"examples/3rd.md",
"examples/ks.md",
"examples/heterogeneous.md",
"examples/linear_parabolic.md",
"examples/nonlinear_elliptic.md",
"examples/nonlinear_hyperbolic.md",
"examples/complex.md"],
"Manual" => Any["manual/ode.md",
"manual/dae.md",
"manual/pinns.md",
"manual/bpinns.md",
"manual/training_strategies.md",
"manual/adaptive_losses.md",
"manual/logging.md",
"manual/neural_adapters.md"],
"Developer Documentation" => Any["developer/debugging.md"],
"manual/dae.md",
"manual/pinns.md",
"manual/bpinns.md",
"manual/training_strategies.md",
"manual/adaptive_losses.md",
"manual/logging.md",
"manual/neural_adapters.md"],
"Developer Documentation" => Any["developer/debugging.md"]
]
17 changes: 9 additions & 8 deletions docs/src/developer/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ strategy = NeuralPDE.GridTraining(dx)
integral = NeuralPDE.get_numeric_integral(strategy, indvars, multioutput, chain, derivative)

_pde_loss_function = NeuralPDE.build_loss_function(eq, indvars, depvars, phi, derivative,
integral, multioutput, init_params,
strategy)
integral, multioutput, init_params,
strategy)
```

```
Expand All @@ -83,9 +83,9 @@ julia> bc_indvars = NeuralPDE.get_variables(bcs,indvars,depvars)

```julia
_bc_loss_functions = [NeuralPDE.build_loss_function(bc, indvars, depvars,
phi, derivative, integral, multioutput,
init_params, strategy,
bc_indvars = bc_indvar)
phi, derivative, integral, multioutput,
init_params, strategy,
bc_indvars = bc_indvar)
for (bc, bc_indvar) in zip(bcs, bc_indvars)]
```

Expand Down Expand Up @@ -126,7 +126,7 @@ julia> expr_bc_loss_functions = [NeuralPDE.build_symbolic_loss_function(bc,indva

```julia
train_sets = NeuralPDE.generate_training_sets(domains, dx, [eq], bcs, eltypeθ, indvars,
depvars)
depvars)
pde_train_set, bcs_train_set = train_sets
```

Expand All @@ -145,8 +145,9 @@ julia> bcs_train_set
```

```julia
pde_bounds, bcs_bounds = NeuralPDE.get_bounds(domains, [eq], bcs, eltypeθ, indvars, depvars,
NeuralPDE.StochasticTraining(100))
pde_bounds, bcs_bounds = NeuralPDE.get_bounds(
domains, [eq], bcs, eltypeθ, indvars, depvars,
NeuralPDE.StochasticTraining(100))
```

```
Expand Down
18 changes: 10 additions & 8 deletions docs/src/examples/complex.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,29 @@ function bloch_equations(u, p, t)
γ = Γ / 2
ρ₁₁, ρ₂₂, ρ₁₂, ρ₂₁ = u
d̢ρ = [im * Ω * (ρ₁₂ - ρ₂₁) + Γ * ρ₂₂;
-im * Ω * (ρ₁₂ - ρ₂₁) - Γ * ρ₂₂;
-(γ + im * Δ) * ρ₁₂ - im * Ω * (ρ₂₂ - ρ₁₁);
conj(-(γ + im * Δ) * ρ₁₂ - im * Ω * (ρ₂₂ - ρ₁₁))]
-im * Ω * (ρ₁₂ - ρ₂₁) - Γ * ρ₂₂;
-(γ + im * Δ) * ρ₁₂ - im * Ω * (ρ₂₂ - ρ₁₁);
conj(-(γ + im * Δ) * ρ₁₂ - im * Ω * (ρ₂₂ - ρ₁₁))]
return d̢ρ
end
u0 = zeros(ComplexF64, 4)
u0[1] = 1.0
time_span = (0.0, 2.0)
time_span = (0.0, 2.0)
parameters = [2.0, 0.0, 1.0]
problem = ODEProblem(bloch_equations, u0, time_span, parameters)
chain = Lux.Chain(
Lux.Dense(1, 16, tanh; init_weight = (rng, a...) -> Lux.kaiming_normal(rng, ComplexF64, a...)) ,
Lux.Dense(16, 4; init_weight = (rng, a...) -> Lux.kaiming_normal(rng, ComplexF64, a...))
)
Lux.Dense(1, 16, tanh;
init_weight = (rng, a...) -> Lux.kaiming_normal(rng, ComplexF64, a...)),
Lux.Dense(
16, 4; init_weight = (rng, a...) -> Lux.kaiming_normal(rng, ComplexF64, a...))
)
ps, st = Lux.setup(rng, chain)
opt = OptimizationOptimisers.Adam(0.01)
ground_truth = solve(problem, Tsit5(), saveat = 0.01)
ground_truth = solve(problem, Tsit5(), saveat = 0.01)
alg = NNODE(chain, opt, ps; strategy = StochasticTraining(500))
sol = solve(problem, alg, verbose = false, maxiters = 5000, saveat = 0.01)
```
Expand Down
4 changes: 2 additions & 2 deletions docs/src/examples/heterogeneous.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ domains = [x ∈ Interval(0.0, 1.0),
numhid = 3
chains = [[Lux.Chain(Dense(1, numhid, Lux.σ), Dense(numhid, numhid, Lux.σ),
Dense(numhid, 1)) for i in 1:2]
Dense(numhid, 1)) for i in 1:2]
[Lux.Chain(Dense(2, numhid, Lux.σ), Dense(numhid, numhid, Lux.σ),
Dense(numhid, 1)) for i in 1:2]]
Dense(numhid, 1)) for i in 1:2]]
discretization = NeuralPDE.PhysicsInformedNN(chains, QuadratureTraining())
@named pde_system = PDESystem(eq, bcs, domains, [x, y], [p(x), q(y), r(x, y), s(y, x)])
Expand Down
3 changes: 2 additions & 1 deletion docs/src/examples/linear_parabolic.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ w(t, 1) = \frac{e^{\lambda_1} cos(\frac{x}{a})-e^{\lambda_2}cos(\frac{x}{a})}{\l
with a physics-informed neural network.

```@example linear_parabolic
using NeuralPDE, Lux, ModelingToolkit, Optimization, OptimizationOptimisers, OptimizationOptimJL, LineSearches
using NeuralPDE, Lux, ModelingToolkit, Optimization, OptimizationOptimisers,
OptimizationOptimJL, LineSearches
using Plots
using ModelingToolkit: Interval, infimum, supremum
Expand Down
4 changes: 2 additions & 2 deletions docs/src/examples/nonlinear_hyperbolic.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ where k is a root of the algebraic (transcendental) equation f(k) = g(k), j0 and
We solve this with Neural:

```@example nonlinear_hyperbolic
using NeuralPDE, Lux, ModelingToolkit, Optimization, OptimizationOptimJL, Roots, LineSearches
using NeuralPDE, Lux, ModelingToolkit, Optimization, OptimizationOptimJL, Roots,
LineSearches
using SpecialFunctions
using Plots
using ModelingToolkit: Interval, infimum, supremum
Expand Down Expand Up @@ -121,7 +122,6 @@ for i in 1:2
end
```


```@example nonlinear_hyperbolic
ps[1]
```
Expand Down
21 changes: 11 additions & 10 deletions docs/src/examples/wave.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ function analytic_sol_func(t, x)
end
u_predict = reshape([first(phi([t, x], res.u)) for t in ts for x in xs],
(length(ts), length(xs)))
(length(ts), length(xs)))
u_real = reshape([analytic_sol_func(t, x) for t in ts for x in xs],
(length(ts), length(xs)))
(length(ts), length(xs)))
diff_u = abs.(u_predict .- u_real)
p1 = plot(ts, xs, u_real, linetype = :contourf, title = "analytic");
Expand Down Expand Up @@ -121,7 +121,7 @@ eq = Dx(Dxu(t, x)) ~ 1 / v^2 * Dt(Dtu(t, x)) + b * Dtu(t, x)
bcs_ = [u(t, 0) ~ 0.0,# for all t > 0
u(t, L) ~ 0.0,# for all t > 0
u(0, x) ~ x * (1.0 - x), # for all 0 < x < 1
Dtu(0, x) ~ 1 - 2x, # for all 0 < x < 1
Dtu(0, x) ~ 1 - 2x # for all 0 < x < 1
]
ep = (cbrt(eps(eltype(Float64))))^2 / 6
Expand All @@ -139,16 +139,16 @@ domains = [t ∈ Interval(0.0, L),
inn = 25
innd = 4
chain = [[Lux.Chain(Dense(2, inn, Lux.tanh),
Dense(inn, inn, Lux.tanh),
Dense(inn, inn, Lux.tanh),
Dense(inn, 1)) for _ in 1:3]
Dense(inn, inn, Lux.tanh),
Dense(inn, inn, Lux.tanh),
Dense(inn, 1)) for _ in 1:3]
[Lux.Chain(Dense(2, innd, Lux.tanh), Dense(innd, 1)) for _ in 1:2]]
strategy = GridTraining(0.02)
discretization = PhysicsInformedNN(chain, strategy;)
@named pde_system = PDESystem(eq, bcs, domains, [t, x],
[u(t, x), Dxu(t, x), Dtu(t, x), O1(t, x), O2(t, x)])
[u(t, x), Dxu(t, x), Dtu(t, x), O1(t, x), O2(t, x)])
prob = discretize(pde_system, discretization)
sym_prob = NeuralPDE.symbolic_discretize(pde_system, discretization)
Expand Down Expand Up @@ -201,10 +201,11 @@ gif(anim, "1Dwave_damped_adaptive.gif", fps = 200)
# Surface plot
ts, xs = [infimum(d.domain):0.01:supremum(d.domain) for d in domains]
u_predict = reshape([first(phi([t, x], res.u.depvar.u)) for
t in ts for x in xs], (length(ts), length(xs)))
u_predict = reshape(
[first(phi([t, x], res.u.depvar.u)) for
t in ts for x in xs], (length(ts), length(xs)))
u_real = reshape([analytic_sol_func(t, x) for t in ts for x in xs],
(length(ts), length(xs)))
(length(ts), length(xs)))
diff_u = abs.(u_predict .- u_real)
p1 = plot(ts, xs, u_real, linetype = :contourf, title = "analytic");
Expand Down
4 changes: 2 additions & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# NeuralPDE.jl: Automatic Physics-Informed Neural Networks (PINNs)

[NeuralPDE.jl](https://github.com/SciML/NeuralPDE.jl) is a solver package which
consists of neural network solvers for partial differential equations using
[NeuralPDE.jl](https://github.com/SciML/NeuralPDE.jl) is a solver package which
consists of neural network solvers for partial differential equations using
physics-informed neural networks (PINNs) and the ability to generate neural
networks which both approximate physical laws and real data simultaneously.

Expand Down
1 change: 0 additions & 1 deletion docs/src/manual/bpinns.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ SciMLBase.symbolic_discretize(::PDESystem, ::NeuralPDE.AbstractPINN)
NeuralPDE.BPINNstats
NeuralPDE.BPINNsolution
```

2 changes: 1 addition & 1 deletion docs/src/manual/ode.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ NNODE

```@docs
BNNODE
```
```
13 changes: 7 additions & 6 deletions docs/src/tutorials/constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ domains = [x ∈ Interval(x_0, x_end)]
# Neural network
inn = 18
chain = Lux.Chain(Dense(1, inn, Lux.σ),
Dense(inn, inn, Lux.σ),
Dense(inn, inn, Lux.σ),
Dense(inn, 1))
Dense(inn, inn, Lux.σ),
Dense(inn, inn, Lux.σ),
Dense(inn, 1))
lb = [x_0]
ub = [x_end]
Expand All @@ -63,8 +63,8 @@ function norm_loss_function(phi, θ, p)
end
discretization = PhysicsInformedNN(chain,
QuadratureTraining(),
additional_loss = norm_loss_function)
QuadratureTraining(),
additional_loss = norm_loss_function)
@named pdesystem = PDESystem(eq, bcs, domains, [x], [p(x)])
prob = discretize(pdesystem, discretization)
Expand All @@ -84,7 +84,8 @@ cb_ = function (p, l)
return false
end
res = Optimization.solve(prob, BFGS(linesearch = BackTracking()), callback = cb_, maxiters = 600)
res = Optimization.solve(
prob, BFGS(linesearch = BackTracking()), callback = cb_, maxiters = 600)
```

And some analysis:
Expand Down
8 changes: 3 additions & 5 deletions docs/src/tutorials/dae.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
It is highly recommended you first read the [solving ordinary differential
equations with DifferentialEquations.jl tutorial](https://docs.sciml.ai/DiffEqDocs/stable/tutorials/dae_example/) before reading this tutorial.


This tutorial is an introduction to using physics-informed neural networks (PINNs) for solving differential algebraic equations (DAEs).

This tutorial is an introduction to using physics-informed neural networks (PINNs) for solving differential algebraic equations (DAEs).

## Solving an DAE with PINNs

Let's solve a simple DAE system:

```@example dae
using NeuralPDE
using NeuralPDE
using Random
using OrdinaryDiffEq, Statistics
using Lux, OptimizationOptimisers
Expand Down Expand Up @@ -57,4 +55,4 @@ ground_sol = solve(prob_mm, Rodas5(), reltol = 1e-8, abstol = 1e-8)
using Plots
plot(ground_sol, tspan = tspan, layout = (2, 1), label = "ground truth")
plot!(sol, tspan = tspan, layout = (2, 1), label = "dae with pinns")
```
```
3 changes: 2 additions & 1 deletion docs/src/tutorials/derivative_neural_network.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ input_ = length(domains)
n = 15
chain = [Lux.Chain(Dense(input_, n, Lux.σ), Dense(n, n, Lux.σ), Dense(n, 1)) for _ in 1:7]
training_strategy = NeuralPDE.QuadratureTraining(; batch = 200, reltol = 1e-6, abstol = 1e-6)
training_strategy = NeuralPDE.QuadratureTraining(;
batch = 200, reltol = 1e-6, abstol = 1e-6)
discretization = NeuralPDE.PhysicsInformedNN(chain, training_strategy)
vars = [u1(t, x), u2(t, x), u3(t, x), Dxu1(t, x), Dtu1(t, x), Dxu2(t, x), Dtu2(t, x)]
Expand Down
Loading

0 comments on commit b0daed7

Please sign in to comment.