-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c058f5e
commit 48c762b
Showing
4 changed files
with
108 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,64 @@ | ||
# Physics informed Neural Operator ODEs Solvers | ||
|
||
## some example TODO | ||
This tutorial is an introduction to using physics-informed neural operator (PINOs) for solving family of parametric ordinary diferential equations (ODEs). | ||
|
||
|
||
## Solving a family of parametric ODE. | ||
|
||
```@example pino | ||
using Test | ||
using OrdinaryDiffEq, OptimizationOptimisers | ||
using Lux | ||
using Statistics, Random | ||
using NeuralOperators | ||
using NeuralPDE | ||
linear_analytic = (u0, p, t) -> u0 + sin(p * t) / (p) | ||
linear = (u, p, t) -> cos(p * t) | ||
tspan = (0.0f0, 2.0f0) | ||
u0 = 0.0f0 | ||
``` | ||
|
||
Generate a dataset for learning a given family of ODEs where the parameter 'a' is varied. The dataset is generated by solving the ODE for different values of 'a' and storing the solutions. The dataset is then used to train the PINO model: | ||
* input data: set of parameters 'a', | ||
* output data: set of solutions u(t){a} corresponding parameter 'a'. | ||
|
||
```@example pino | ||
t0, t_end = tspan | ||
instances_size = 50 | ||
range_ = range(t0, stop = t_end, length = instances_size) | ||
ts = reshape(collect(range_), 1, instances_size) | ||
batch_size = 50 | ||
as = [Float32(i) for i in range(0.1, stop = pi / 2, length = batch_size)] | ||
u_output_ = zeros(Float32, 1, instances_size, batch_size) | ||
prob_set = [] | ||
for (i, a_i) in enumerate(as) | ||
prob = ODEProblem(ODEFunction(linear, analytic = linear_analytic), u0, tspan, a_i) | ||
sol1 = solve(prob, Tsit5(); saveat = 0.0204) | ||
reshape_sol = Float32.(reshape(sol1(range_).u', 1, instances_size, 1)) | ||
push!(prob_set, prob) | ||
u_output_[:, :, i] = reshape_sol | ||
end | ||
train_set = TRAINSET(prob_set, u_output_); | ||
``` | ||
|
||
Here it used the PINO method to train the given family of parametric ODEs. | ||
|
||
```@example pino | ||
prob = ODEProblem(linear, u0, tspan, 0) | ||
flat_no = FourierNeuralOperator(ch = (2, 16, 16, 16, 16, 16, 32, 1), modes = (16,), | ||
σ = gelu) | ||
opt = OptimizationOptimisers.Adam(0.03) | ||
alg = PINOODE(flat_no, opt, train_set; is_data_loss = true, is_physics_loss = true) | ||
pino_solution = solve(prob, alg, verbose = false, maxiters = 1000) | ||
predict = pino_solution.predict | ||
ground = u_output_ | ||
``` | ||
|
||
Now let's compare the predictions from the learned operator with the ground truth solution which is obtained early by numerically solving the parametric ODE. Where 'i' is the index of the parameter 'a' in the dataset. | ||
|
||
```@example pino | ||
plot(predict[1, :, i], label = "Predicted") | ||
plot!(ground[1, :, i], label = "Ground truth") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters