Skip to content

Commit

Permalink
Merge pull request #729 from sdesai1287/docs_update
Browse files Browse the repository at this point in the history
Docs modifications to use QuadratureTraining instead of GridTraining
  • Loading branch information
ChrisRackauckas authored Oct 7, 2023
2 parents f63468d + 0528d75 commit 4c79038
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "CUDA", "SafeTestsets", "OptimizationOptimisers", "OptimizationOptimJL", "Pkg", "OrdinaryDiffEq", "IntegralsCuba"]
test = ["Test", "CUDA", "SafeTestsets", "OptimizationOptimisers", "OptimizationOptimJL", "Pkg", "OrdinaryDiffEq", "IntegralsCuba"]
8 changes: 3 additions & 5 deletions docs/src/tutorials/constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ Dxx = Differential(x)^2
_σ = 0.5
x_0 = -2.2
x_end = 2.2
# Discretization
dx = 0.01
eq = Dx((α * x - β * x^3) * p(x)) ~ (_σ^2 / 2) * Dxx(p(x))
Expand All @@ -57,15 +55,15 @@ lb = [x_0]
ub = [x_end]
function norm_loss_function(phi, θ, p)
function inner_f(x, θ)
dx * phi(x, θ) .- 1
0.01 * phi(x, θ) .- 1
end
prob = IntegralProblem(inner_f, lb, ub, θ)
norm2 = solve(prob, HCubatureJL(), reltol = 1e-8, abstol = 1e-8, maxiters = 10)
abs(norm2[1])
end
discretization = PhysicsInformedNN(chain,
GridTraining(dx),
QuadratureTraining(),
additional_loss = norm_loss_function)
@named pdesystem = PDESystem(eq, bcs, domains, [x], [p(x)])
Expand Down Expand Up @@ -98,7 +96,7 @@ using Plots
C = 142.88418699042 #fitting param
analytic_sol_func(x) = C * exp((1 / (2 * _σ^2)) * (2 * α * x^2 - β * x^4))
xs = [infimum(d.domain):dx:supremum(d.domain) for d in domains][1]
xs = [infimum(d.domain):0.01:supremum(d.domain) for d in domains][1]
u_real = [analytic_sol_func(x) for x in xs]
u_predict = [first(phi(x, res.u)) for x in xs]
Expand Down
4 changes: 2 additions & 2 deletions docs/src/tutorials/derivative_neural_network.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ input_ = length(domains)
n = 15
chain = [Lux.Chain(Dense(input_, n, Lux.σ), Dense(n, n, Lux.σ), Dense(n, 1)) for _ in 1:7]
grid_strategy = NeuralPDE.GridTraining(0.07)
training_strategy = NeuralPDE.QuadratureTraining()
discretization = NeuralPDE.PhysicsInformedNN(chain,
grid_strategy)
training_strategy)
vars = [u1(t, x), u2(t, x), u3(t, x), Dxu1(t, x), Dtu1(t, x), Dxu2(t, x), Dtu2(t, x)]
@named pdesystem = PDESystem(eqs_, bcs__, domains, [t, x], vars)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/gpu.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ chain = Chain(Dense(3, inner, Lux.σ),
Dense(inner, inner, Lux.σ),
Dense(inner, 1))

strategy = GridTraining(0.05)
strategy = QuadratureTraining()
ps = Lux.setup(Random.default_rng(), chain)[1]
ps = ps |> ComponentArray |> gpu .|> Float64
discretization = PhysicsInformedNN(chain,
Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/integro_diff.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bcs = [i(0.0) ~ 0.0]
domains = [t ∈ Interval(0.0, 2.0)]
chain = Chain(Dense(1, 15, Flux.σ), Dense(15, 1)) |> f64
strategy_ = GridTraining(0.05)
strategy_ = QuadratureTraining()
discretization = PhysicsInformedNN(chain,
strategy_)
@named pde_system = PDESystem(eq, bcs, domains, [t], [i(t)])
Expand Down
7 changes: 2 additions & 5 deletions docs/src/tutorials/low_level.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,9 @@ bcs = [u(0, x) ~ -sin(pi * x),
domains = [t ∈ Interval(0.0, 1.0),
x ∈ Interval(-1.0, 1.0)]
# Discretization
dx = 0.05
# Neural network
chain = Lux.Chain(Dense(2, 16, Lux.σ), Dense(16, 16, Lux.σ), Dense(16, 1))
strategy = NeuralPDE.GridTraining(dx)
strategy = NeuralPDE.QuadratureTraining()
indvars = [t, x]
depvars = [u(t, x)]
Expand Down Expand Up @@ -79,7 +76,7 @@ And some analysis:
```@example low_level
using Plots
ts, xs = [infimum(d.domain):dx:supremum(d.domain) for d in domains]
ts, xs = [infimum(d.domain):0.01:supremum(d.domain) for d in domains]
u_predict_contourf = reshape([first(phi([t, x], res.u)) for t in ts for x in xs],
length(xs), length(ts))
plot(ts, xs, u_predict_contourf, linetype = :contourf, title = "predict")
Expand Down
8 changes: 4 additions & 4 deletions docs/src/tutorials/neural_adapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function loss(cord, θ)
chain2(cord, θ) .- phi(cord, res.u)
end

strategy = NeuralPDE.GridTraining(0.02)
strategy = NeuralPDE.QuadratureTraining()

prob_ = NeuralPDE.neural_adapter(loss, init_params2, pde_system, strategy)
callback = function (p, l)
Expand Down Expand Up @@ -179,7 +179,7 @@ for i in 1:count_decomp
bcs_ = create_bcs(domains_[1].domain, phi_bound)
@named pde_system_ = PDESystem(eq, bcs_, domains_, [x, y], [u(x, y)])
push!(pde_system_map, pde_system_)
strategy = NeuralPDE.GridTraining([0.1 / count_decomp, 0.1])
strategy = NeuralPDE.QuadratureTraining()

discretization = NeuralPDE.PhysicsInformedNN(chains[i], strategy;
init_params = init_params[i])
Expand Down Expand Up @@ -243,10 +243,10 @@ callback = function (p, l)
end

prob_ = NeuralPDE.neural_adapter(losses, init_params2, pde_system_map,
NeuralPDE.GridTraining([0.1 / count_decomp, 0.1]))
NeuralPDE.QuadratureTraining())
res_ = Optimization.solve(prob_, BFGS(); callback = callback, maxiters = 2000)
prob_ = NeuralPDE.neural_adapter(losses, res_.minimizer, pde_system_map,
NeuralPDE.GridTraining([0.05 / count_decomp, 0.05]))
NeuralPDE.QuadratureTraining())
res_ = Optimization.solve(prob_, BFGS(); callback = callback, maxiters = 1000)

phi_ = NeuralPDE.get_phi(chain2)
Expand Down
6 changes: 3 additions & 3 deletions docs/src/tutorials/param_estim.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ u0 = [1.0; 0.0; 0.0]
tspan = (0.0, 1.0)
prob = ODEProblem(lorenz!, u0, tspan)
sol = solve(prob, Tsit5(), dt = 0.1)
ts = [infimum(d.domain):dt:supremum(d.domain) for d in domains][1]
ts = [infimum(d.domain):0.01:supremum(d.domain) for d in domains][1]
function getData(sol)
data = []
us = hcat(sol(ts).u...)
Expand Down Expand Up @@ -113,7 +113,7 @@ Then finally defining and optimizing using the `PhysicsInformedNN` interface.

```@example param_estim
discretization = NeuralPDE.PhysicsInformedNN([chain1, chain2, chain3],
NeuralPDE.GridTraining(dt), param_estim = true,
NeuralPDE.QuadratureTraining(), param_estim = true,
additional_loss = additional_loss)
@named pde_system = PDESystem(eqs, bcs, domains, [t], [x(t), y(t), z(t)], [σ_, ρ, β],
defaults = Dict([p .=> 1.0 for p in [σ_, ρ, β]]))
Expand All @@ -130,7 +130,7 @@ And then finally some analysis by plotting.

```@example param_estim
minimizers = [res.u.depvar[depvars[i]] for i in 1:3]
ts = [infimum(d.domain):(dt / 10):supremum(d.domain) for d in domains][1]
ts = [infimum(d.domain):(0.001):supremum(d.domain) for d in domains][1]
u_predict = [[discretization.phi[i]([t], minimizers[i])[1] for t in ts] for i in 1:3]
plot(sol)
plot!(ts, u_predict, label = ["x(t)" "y(t)" "z(t)"])
Expand Down
7 changes: 3 additions & 4 deletions docs/src/tutorials/pdesystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ on the space domain:
x \in [0, 1] \, , \ y \in [0, 1] \, ,
```

with grid discretization `dx = 0.05` using physics-informed neural networks.
Using physics-informed neural networks.

## Copy-Pasteable Code

Expand Down Expand Up @@ -52,7 +52,7 @@ chain = Lux.Chain(Dense(dim, 16, Lux.σ), Dense(16, 16, Lux.σ), Dense(16, 1))
# Discretization
dx = 0.05
discretization = PhysicsInformedNN(chain, GridTraining(dx))
discretization = PhysicsInformedNN(chain, QuadratureTraining())
@named pde_system = PDESystem(eq, bcs, domains, [x, y], [u(x, y)])
prob = discretize(pde_system, discretization)
Expand Down Expand Up @@ -122,9 +122,8 @@ Here, we build PhysicsInformedNN algorithm where `dx` is the step of discretizat
`strategy` stores information for choosing a training strategy.

```@example poisson
# Discretization
dx = 0.05
discretization = PhysicsInformedNN(chain, GridTraining(dx))
discretization = PhysicsInformedNN(chain, QuadratureTraining())
```

As described in the API docs, we now need to define the `PDESystem` and create PINNs
Expand Down

0 comments on commit 4c79038

Please sign in to comment.