Skip to content

Commit

Permalink
Update pi-deeponet example.
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelburbulla committed May 11, 2023
1 parent 60595e8 commit 714ab66
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
28 changes: 17 additions & 11 deletions docs/demos/operator/pideeponet_poisson1d.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ for the one-dimensional Poisson problem

with zero Dirichlet boundary conditions :math:`u(0) = u(1) = 0`.

The source term :math:`f` is supposed to be an arbitrary continuous function.
We choose polynomials of degree three.
The source term :math:`f` is supposed to be an arbitrary continuous function,
we choose polynomials of degree three.


Implementation
Expand Down Expand Up @@ -50,8 +50,9 @@ First, we define the PDE with boundary conditions and the domain:
)
Next, we specify the function space for :math:`f` using a Power series and the corresponding evaluation points. Together with
the PDE, the function space is used to define a PDEOperator ``dde.data.PDEOperatorCartesianProd`` that incorporates the PDE into
Next, we specify the function space for :math:`f` and the corresponding evaluation points.
Together with the PDE, the function space is used to define a
PDEOperator ``dde.data.PDEOperatorCartesianProd`` that incorporates the PDE into
the loss function.

.. code-block:: python
Expand All @@ -70,7 +71,7 @@ the loss function.
)
Next, we define a DeepONet ``dde.nn.DeepONetCartesianProd``.
The DeepONet can be defined using ``dde.nn.DeepONetCartesianProd``.
The branch net is chosen as a fully connected neural network of size ``[m, 32, p]`` where ``p=32``,
and the the trunk net is a fully connected neural network of size ``[dim_x, 32, p]``.

Expand All @@ -86,16 +87,21 @@ and the the trunk net is a fully connected neural network of size ``[dim_x, 32,
)
We define a ``Model``, and then train the model with Adam and learning rate 0.001 for 5000 iterations:
We define a ``Model`` and train it with L-BFGS (pytorch) or Adam:

.. code-block:: python
model = dde.Model(pde_op, net)
model.compile("adam", lr=0.001, metrics=["l2 relative error"])
model.train(iterations=5000)
Finally, the trained model can be used to solve the Poisson equation for arbitrary source terms :math:`f`.
if dde.backend.backend_name == "pytorch":
dde.optimizers.set_LBFGS_options(maxiter=1000)
model.compile("L-BFGS", metrics=["l2 relative error"])
model.train()
else:
model.compile("adam", lr=0.001, metrics=["l2 relative error"])
model.train(iterations=10000)
Finally, the trained model can be used to predict the solution of the Poisson
equation for any admissible source term :math:`f`.

![](pideeponet_poisson1d.png)

Expand Down
10 changes: 7 additions & 3 deletions examples/operator/pideeponet_poisson1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,16 @@ def boundary(_, on_boundary):
kernel_initializer="Glorot normal",
)


# Define and train model
model = dde.Model(pde_op, net)
model.compile("adam", lr=0.001, metrics=["l2 relative error"])
model.train(iterations=5000)

if dde.backend.backend_name == "pytorch":
dde.optimizers.set_LBFGS_options(maxiter=1000)
model.compile("L-BFGS", metrics=["l2 relative error"])
model.train()
else:
model.compile("adam", lr=0.001, metrics=["l2 relative error"])
model.train(iterations=10000)

# Plot realisations of f(x)
n = 3
Expand Down

0 comments on commit 714ab66

Please sign in to comment.