Skip to content

Commit 4a43b22

Browse files
lots of misc clean up
1 parent 1ed5eac commit 4a43b22

13 files changed

+548
-461
lines changed

.github/workflows/CI.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ jobs:
1414
matrix:
1515
group:
1616
- NNODE
17-
- NNPDEHan
18-
- NNPDENS
19-
- NNPDE
17+
- NNPDE1
18+
- NNPDE2
2019
- AdaptiveLoss
2120
- NeuralAdapter
2221
- IntegroDiff

CITATION.bib

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
@article{DifferentialEquations.jl-2017,
2-
author = {Rackauckas, Christopher and Nie, Qing},
3-
doi = {10.5334/jors.151},
4-
journal = {The Journal of Open Research Software},
5-
keywords = {Applied Mathematics},
6-
note = {Exported from https://app.dimensions.ai on 2019/05/05},
7-
number = {1},
8-
pages = {},
9-
title = {DifferentialEquations.jl – A Performant and Feature-Rich Ecosystem for Solving Differential Equations in Julia},
10-
url = {https://app.dimensions.ai/details/publication/pub.1085583166 and http://openresearchsoftware.metajnl.com/articles/10.5334/jors.151/galley/245/download/},
11-
volume = {5},
12-
year = {2017}
13-
}
1+
@misc{https://doi.org/10.48550/arxiv.2107.09443,
2+
doi = {10.48550/ARXIV.2107.09443},
3+
url = {https://arxiv.org/abs/2107.09443},
4+
author = {Zubov, Kirill and McCarthy, Zoe and Ma, Yingbo and Calisto, Francesco and Pagliarino, Valerio and Azeglio, Simone and Bottero, Luca and Luján, Emmanuel and Sulzer, Valentin and Bharambe, Ashutosh and Vinchhi, Nand and Balakrishnan, Kaushik and Upadhyay, Devesh and Rackauckas, Chris},
5+
keywords = {Mathematical Software (cs.MS), Symbolic Computation (cs.SC), FOS: Computer and information sciences, FOS: Computer and information sciences},
6+
title = {NeuralPDE: Automating Physics-Informed Neural Networks (PINNs) with Error Approximations},
7+
publisher = {arXiv},
8+
year = {2021},
9+
copyright = {Creative Commons Attribution Non Commercial Share Alike 4.0 International}
10+
}

docs/make.jl

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ makedocs(
88
clean=true,
99
doctest=false,
1010
modules=[NeuralPDE],
11-
11+
strict=[
12+
:doctest,
13+
:linkcheck,
14+
:parse_error,
15+
:example_block,
16+
# Other available options are
17+
# :autodocs_block, :cross_references, :docs_block, :eval_block, :example_block, :footnote, :meta_block, :missing_docs, :setup_block
18+
],
1219
format=Documenter.HTML( analytics = "UA-90474609-3",
1320
assets=["assets/favicon.ico"],
1421
canonical="https://neuralpde.sciml.ai/stable/"),

docs/src/examples/ode.md

+65-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,74 @@
1-
# Solving ODEs with Neural Networks
1+
# Solving ODEs with Physics-Informed Neural Networks
22

3-
The following is an example of solving a DifferentialEquations.jl
4-
`ODEProblem` with a neural network using the physics-informed neural
5-
networks approach specialized to 1-dimensional PDEs (ODEs).
3+
!!! note
64

7-
```julia
8-
using Flux, OptimizationOptimisers, OptimizationOptimJL
5+
It is highly recommended you first read the [solving ordinary differential
6+
equations with DifferentialEquations.jl tutorial](https://diffeq.sciml.ai/stable/tutorials/ode_example/)
7+
before reading this tutorials.
8+
9+
This tutorial is an introduction to using physics-informed neural networks (PINNs)
10+
for solving ordinary differential equations (ODEs). In contrast to the later
11+
parts of this documentation which use the symbolic interface, here we will focus on
12+
the simplified `NNODE` which uses the `ODEProblem` specification for the ODE.
13+
Mathematically the `ODEProblem` defines a problem:
14+
15+
```math
16+
u' = f(u,p,t)
17+
```
18+
19+
for ``t \in (t_0,t_f)`` with an initial condition ``u(t_0) = u_0``. With physics-informed
20+
neural networks, we choose a neural network architecture `NN` to represent the solution `u`
21+
and seek to find parameters `p` such that `NN' = f(NN,p,t)` for all points in the domain.
22+
When this is satisfied sufficiently closely, then `NN` is thus a solution to the differential
23+
equation.
24+
25+
## Solving an ODE with NNODE
26+
27+
Let's solve the simple ODE:
28+
29+
```math
30+
u' = \cos(2\pi t)
31+
```
32+
33+
for ``t \in (0,1)`` and ``u_0 = 0`` with `NNODE`. First we define the `ODEProblem` as we would
34+
with any other DifferentialEquations.jl solver. This looks like:
35+
36+
```@example nnode1
937
using NeuralPDE
10-
# Run a solve on scalars
11-
linear = (u, p, t) -> cos(2pi * t)
38+
39+
f(u, p, t) = cos(2pi * t)
1240
tspan = (0.0f0, 1.0f0)
1341
u0 = 0.0f0
1442
prob = ODEProblem(linear, u0, tspan)
43+
```
44+
45+
Now, to define the `NNODE` solver, we must choose a neural network architecture. To do this, we
46+
will use the [Flux.jl library](https://fluxml.ai/) to define a multilayer perceptron (MLP)
47+
with one hidden layer of 5 nodes and a sigmoid activation function. This looks like:
48+
49+
```@example nnode1
1550
chain = Flux.Chain(Dense(1, 5, σ), Dense(5, 1))
16-
opt = Flux.ADAM(0.1, (0.9, 0.95))
17-
@time sol = solve(prob, NeuralPDE.NNODE(chain, opt), dt=1 / 20f0, verbose=true,
51+
```
52+
53+
Now we must choose an optimizer to define the `NNODE` solver. A common choice is `ADAM`, with
54+
a tunable rate parameter which we will set to `0.1`. In general, this rate parameter should be
55+
decreased if the solver's loss tends to be unsteady (sometimes rise "too much"), but should be
56+
as large as possible for efficnecy. Thus the definition of the `NNODE` solver is as follows:
57+
58+
```@example nnode1
59+
opt = Flux.ADAM(0.1)
60+
alg = NeuralPDE.NNODE(chain, opt)
61+
```
62+
63+
Once these pieces are together, we call `solve` just like with any other `ODEProblem` solver.
64+
Let's turn on `verbose` so we can see the loss over time during the training process:
65+
66+
```@example nnode1
67+
sol = solve(prob, NeuralPDE.NNODE(chain, opt), dt=1 / 20f0, verbose=true,
1868
abstol=1e-10, maxiters=200)
1969
```
70+
71+
And that's it: the neural network solution was computed by training the neural network and
72+
returned in the standard DifferentialEquations.jl `ODESolution` format. For more information
73+
on handling the solution, consult
74+
[the DifferentialEquations.jl solution handling section](https://diffeq.sciml.ai/stable/basics/solution/)

docs/src/index.md

+18-10
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,32 @@
22

33
[NeuralPDE.jl](https://github.com/SciML/NeuralPDE.jl)
44
NeuralPDE.jl is a solver package which consists of neural network solvers for
5-
partial differential equations using physics-informed neural networks (PINNs). This package utilizes
6-
neural stochastic differential equations to solve PDEs at a greatly increased generality
7-
compared with classical methods.
5+
partial differential equations using physics-informed neural networks (PINNs).
86

97
## Features
108

11-
- Physics-Informed Neural Networks for automated PDE solving
12-
- Deep-learning-based solvers for optimal stopping time and Kolmogorov backwards equations
9+
- Physics-Informed Neural Networks for ODE, SDE, RODE, and PDE solving
10+
- Ability to define extra loss functions to mix xDE solving with data fitting (scientific machine learning)
11+
- Automated construction of Physics-Informed loss functions from a high level symbolic interface
12+
- Sophisticated techniques like quadrature training strategies, adaptive loss functions, and neural adapters
13+
to accelerate training
14+
- Integrated logging suite for handling connections to TensorBoard
15+
- Handling of (partial) integro-differential equations and various stochastic equations
16+
- Specialized forms for solving `ODEProblem`s with neural networks
1317

1418
## Citation
1519

1620
If you use NeuralPDE.jl in your research, please cite [this paper](https://arxiv.org/abs/2107.09443):
1721

1822
```tex
19-
@article{zubov2021neuralpde,
20-
title={NeuralPDE: Automating Physics-Informed Neural Networks (PINNs) with Error Approximations},
21-
author={Zubov, Kirill and McCarthy, Zoe and Ma, Yingbo and Calisto, Francesco and Pagliarino, Valerio and Azeglio, Simone and Bottero, Luca and Luj{\'a}n, Emmanuel and Sulzer, Valentin and Bharambe, Ashutosh and others},
22-
journal={arXiv preprint arXiv:2107.09443},
23-
year={2021}
23+
@misc{https://doi.org/10.48550/arxiv.2107.09443,
24+
doi = {10.48550/ARXIV.2107.09443},
25+
url = {https://arxiv.org/abs/2107.09443},
26+
author = {Zubov, Kirill and McCarthy, Zoe and Ma, Yingbo and Calisto, Francesco and Pagliarino, Valerio and Azeglio, Simone and Bottero, Luca and Luján, Emmanuel and Sulzer, Valentin and Bharambe, Ashutosh and Vinchhi, Nand and Balakrishnan, Kaushik and Upadhyay, Devesh and Rackauckas, Chris},
27+
keywords = {Mathematical Software (cs.MS), Symbolic Computation (cs.SC), FOS: Computer and information sciences, FOS: Computer and information sciences},
28+
title = {NeuralPDE: Automating Physics-Informed Neural Networks (PINNs) with Error Approximations},
29+
publisher = {arXiv},
30+
year = {2021},
31+
copyright = {Creative Commons Attribution Non Commercial Share Alike 4.0 International}
2432
}
2533
```

docs/src/solvers/ode.md

+3-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
# ODE-Specialized Physics-Informed Neural Solver
22

3-
The ODE-specialized physics-informed neural network (PINN) solver is a
4-
method for the [DifferentialEquations.jl common interface](https://diffeq.sciml.ai/latest/)
5-
of `ODEProblem`, which generates the solution via a neural network.
6-
Thus the standard [ODEProblem](https://diffeq.sciml.ai/latest/types/ode_types/)
7-
is used, but a new algorithm, `NNODE`, is used to solve the problem.
8-
9-
The algorithm type is:
10-
11-
```julia
12-
nnode(chain,opt)
13-
```
14-
15-
where `chain` is a DiffEqFlux `sciml_train`-compatible Chain or FastChain
16-
representing a neural network, and `opt` is an optimization method
17-
for `sciml_train`. For more details, see [the DiffEqFlux documentation
18-
on `sciml_train`](https://diffeqflux.sciml.ai/dev/).
19-
20-
[Lagaris, Isaac E., Aristidis Likas, and Dimitrios I. Fotiadis. "Artificial neural networks for solving ordinary and partial differential equations." IEEE Transactions on Neural Networks 9, no. 5 (1998): 987-1000.](https://arxiv.org/pdf/physics/9705023.pdf)
3+
```@docs
4+
NNODE
5+
```

src/NeuralPDE.jl

-30
Original file line numberDiff line numberDiff line change
@@ -141,36 +141,6 @@ function Base.show(io::IO, A::ParamKolmogorovPDEProblem)
141141
show(io , A.g)
142142
end
143143

144-
"""
145-
Algorithm for solving differential equation using a neural network.
146-
Arguments:
147-
* `chain`: A Chain neural network
148-
* `opt`: The optimizer to train the neural network. Defaults to `BFGS()`.
149-
* `initθ`: The initial parameter of the neural network.
150-
* `autodiff`: The switch between automatic and numerical differentiation for
151-
the PDE operators. The reverse mode of the loss function is always AD.
152-
"""
153-
struct NNODE{C,O,P,K} <: NeuralPDEAlgorithm
154-
chain::C
155-
opt::O
156-
initθ::P
157-
autodiff::Bool
158-
kwargs::K
159-
end
160-
function NNODE(chain,opt=Optim.BFGS(),init_params = nothing;autodiff=false,kwargs...)
161-
if init_params === nothing
162-
if chain isa FastChain
163-
initθ = DiffEqFlux.initial_params(chain)
164-
else
165-
initθ,re = Flux.destructure(chain)
166-
end
167-
else
168-
initθ = init_params
169-
end
170-
NNODE(chain,opt,initθ,autodiff,kwargs)
171-
end
172-
173-
174144
include("training_strategies.jl")
175145
include("adaptive_losses.jl")
176146
include("ode_solve.jl")

src/ode_solve.jl

+65-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,63 @@
1+
"""
2+
```julia
3+
NNODE(chain,opt=Optim.BFGS(),init_params = nothing;
4+
autodiff=false,kwargs...)
5+
```
6+
7+
Algorithm for solving ordinary differential equations using a neural network. This is a specialization
8+
of the physics-informed neural network which is used as a solver for a standard `ODEProblem`.
9+
10+
## Positional Arguments
11+
12+
* `chain`: A Chain neural network
13+
* `opt`: The optimizer to train the neural network. Defaults to `BFGS()`.
14+
* `initθ`: The initial parameter of the neural network.
15+
16+
## Keyword Arguments
17+
18+
* `autodiff`: The switch between automatic and numerical differentiation for
19+
the PDE operators. The reverse mode of the loss function is always
20+
automatic differentation (via Zygote), this is only for the derivative
21+
in the loss function (the derivative with respect to time).
22+
23+
## Example
24+
25+
```julia
26+
f(u,p,t) = cos(2pi*t)
27+
tspan = (0.0f0, 1.0f0)
28+
u0 = 0.0f0
29+
prob = ODEProblem(linear, u0 ,tspan)
30+
chain = Flux.Chain(Dense(1,5,σ),Dense(5,1))
31+
opt = Flux.ADAM(0.1, (0.9, 0.95))
32+
sol = solve(prob, NeuralPDE.NNODE(chain,opt), dt=1/20f0, verbose = true,
33+
abstol=1e-10, maxiters = 200)
34+
```
35+
36+
## References
37+
38+
Lagaris, Isaac E., Aristidis Likas, and Dimitrios I. Fotiadis. "Artificial neural networks for solving
39+
ordinary and partial differential equations." IEEE Transactions on Neural Networks 9, no. 5 (1998): 987-1000.
40+
"""
41+
struct NNODE{C,O,P,K} <: NeuralPDEAlgorithm
42+
chain::C
43+
opt::O
44+
initθ::P
45+
autodiff::Bool
46+
kwargs::K
47+
end
48+
function NNODE(chain,opt=Optim.BFGS(),init_params = nothing;autodiff=false,kwargs...)
49+
if init_params === nothing
50+
if chain isa FastChain
51+
initθ = DiffEqFlux.initial_params(chain)
52+
else
53+
initθ,re = Flux.destructure(chain)
54+
end
55+
else
56+
initθ = init_params
57+
end
58+
NNODE(chain,opt,initθ,autodiff,kwargs)
59+
end
60+
161
function DiffEqBase.solve(
262
prob::DiffEqBase.AbstractODEProblem,
363
alg::NNODE,
@@ -28,19 +88,20 @@ function DiffEqBase.solve(
2888
if chain isa FastChain
2989
#The phi trial solution
3090
if u0 isa Number
31-
phi = (t,θ) -> u0 + (t-tspan[1])*first(chain(adapt(DiffEqBase.parameterless_type(θ),[t]),θ))
91+
phi = (t,θ) -> u0 + (t-tspan[1]) * first(chain(adapt(parameterless_type(θ),[t]),θ))
3292
else
33-
phi = (t,θ) -> u0 + (t-tspan[1]) * chain(adapt(DiffEqBase.parameterless_type(θ),[t]),θ)
93+
phi = (t,θ) -> u0 + (t-tspan[1]) * chain(adapt(parameterless_type(θ),[t]),θ)
3494
end
3595
else
3696
_,re = Flux.destructure(chain)
3797
#The phi trial solution
3898
if u0 isa Number
39-
phi = (t,θ) -> u0 + (t-tspan[1])*first(re(θ)(adapt(DiffEqBase.parameterless_type(θ),[t])))
99+
phi = (t,θ) -> u0 + (t-tspan[1])*first(re(θ)(adapt(parameterless_type(θ),[t])))
40100
else
41-
phi = (t,θ) -> u0 + (t-tspan[1]) * re(θ)(adapt(DiffEqBase.parameterless_type(θ),[t]))
101+
phi = (t,θ) -> u0 + (t-tspan[1]) * re(θ)(adapt(parameterless_type(θ),[t]))
42102
end
43103
end
104+
44105
try
45106
phi(t0 , initθ)
46107
catch err

0 commit comments

Comments
 (0)