Written and maintained by CASRAI Editorial Board
Last updated
Physics-informed neural networks (PINNs) are neural networks trained so that their output satisfies a physical law written as a partial differential equation (PDE), in addition to fitting any observed data. This guide is for researchers who want to run a PINN for the first time: it covers what PINNs are used for, how to install the open-source DeepXDE library, a complete worked example (a one-dimensional Poisson equation) taken from the library documentation, and how to read the result. The same method is also written physics informed neural network without the hyphen.
What physics-informed neural networks are used for in research
The method was introduced by Raissi, Perdikaris and Karniadakis in “Physics Informed Deep Learning (Part I): Data-driven Solutions of Nonlinear Partial Differential Equations” (arXiv:1711.10561, submitted 28 November 2017). Their abstract describes PINNs as neural networks trained on supervised learning tasks while respecting physical laws given as general nonlinear PDEs, and as data-efficient function approximators that embed the physical law as a prior. The resulting surrogate is differentiable with respect to all input coordinates and free parameters. A companion paper, Part II, addresses the data-driven discovery of PDEs, so the approach covers two directions: solving a PDE when the equation is known (the “forward” problem, which is the example below) and inferring unknown parameters or terms from data.
How the physics enters training
In DeepXDE the physics enters through a residual function that you write: it returns the left-hand side of the PDE minus the right-hand side, evaluated on the network output using automatic differentiation. Training drives that residual toward zero at sampled points inside the domain, while boundary or initial conditions are imposed at points on the boundary. Because the network is a differentiable function of its input coordinates, derivatives such as dde.grad.hessian are computed directly on it rather than on a mesh.
Install or access (official source only)
The DeepXDE installation page (deepxde.readthedocs.io, read 2026-11-07) gives two supported routes:
pip install deepxdeconda install -c conda-forge deepxde(see updating conda if your environment manager is out of date)
For development, clone the repository from https://github.com/lululxvi/deepxde.git. DeepXDE also requires Matplotlib, NumPy, scikit-learn, scikit-optimize and SciPy. The installation page lists no required Python version.
Choose a backend
DeepXDE runs on one deep-learning backend at a time. Install the backend you want first, then select it. The documentation states this order of precedence:
- The
DDE_BACKENDenvironment variable, for exampleDDE_BACKEND=pytorch python pde.py, orexport DDE_BACKEND=pytorchon Linux (on Windows, set it in System Settings). - The file
~/.deepxde/config.json, for example{"backend": "tensorflow.compat.v1"}, which you can also write withpython -m deepxde.backend.set_default_backend BACKEND. - Automatic selection if neither is set.
Valid backend names are tensorflow.compat.v1, tensorflow, pytorch, jax and paddle.
| Backend name | Minimum requirement stated in the installation docs |
|---|---|
tensorflow.compat.v1 |
TensorFlow >= 2.7.0 (with TensorFlow 2.16 or later, keep Keras 2 by installing tf-keras and setting TF_USE_LEGACY_KERAS=1) |
tensorflow |
TensorFlow >= 2.3.0 and TensorFlow Probability >= 0.11.0 |
pytorch |
PyTorch >= 2.0.0 |
jax |
JAX, Flax and Optax |
paddle |
PaddlePaddle >= 2.6.0 |
Step-by-step: solve a 1D Poisson equation with a PINN
The example comes from the DeepXDE demo “Poisson equation in 1D with Dirichlet boundary conditions” (read 2026-11-07). The problem is -u”(x) = π² sin(πx) on [-1, 1] with u(-1) = u(1) = 0. The exact solution is u(x) = sin(πx), which lets the library report an error against the truth.
- Define the residual. Write
pde(x, y)so that it returns -u” – π² sin(πx), usingdde.grad.hessian(y, x)for the second derivative. - Define the geometry.
dde.geometry.Interval(-1, 1)is the domain. - Define the boundary condition.
dde.icbc.DirichletBC(geom, func, boundary), whereboundary(x, on_boundary)returnson_boundary. - Build the data object.
dde.data.PDE(geom, pde, bc, 16, 2, solution=func, num_test=100)uses 16 residual points inside the domain, 2 points on the boundary and 100 test points. - Build the network.
dde.nn.FNN([1] + [50]*3 + [1], "tanh", "Glorot uniform")is a feed-forward network with one input, three hidden layers of 50 neurons and one output. - Compile and train.
model.compile("adam", lr=0.001, metrics=["l2 relative error"])thenmodel.train(iterations=10000). - Save and plot.
dde.saveplot(losshistory, train_state, issave=True, isplot=True).
Assembled into one script (TensorFlow backends):
import numpy as np
import deepxde as dde
from deepxde.backend import tf # TensorFlow backends; see the table below for other backends
def pde(x, y):
dy_xx = dde.grad.hessian(y, x)
return -dy_xx - np.pi ** 2 * tf.sin(np.pi * x)
def boundary(x, on_boundary):
return on_boundary
def func(x):
return np.sin(np.pi * x)
geom = dde.geometry.Interval(-1, 1)
bc = dde.icbc.DirichletBC(geom, func, boundary)
data = dde.data.PDE(geom, pde, bc, 16, 2, solution=func, num_test=100)
net = dde.nn.FNN([1] + [50] * 3 + [1], "tanh", "Glorot uniform")
model = dde.Model(data, net)
model.compile("adam", lr=0.001, metrics=["l2 relative error"])
losshistory, train_state = model.train(iterations=10000)
dde.saveplot(losshistory, train_state, issave=True, isplot=True)
Changing the backend in the residual
Only the sine function in pde depends on the backend. The demo uses tf.sin (imported from deepxde.backend) for TensorFlow, torch.sin for PyTorch, jnp.sin for JAX and paddle.sin for PaddlePaddle. With JAX, dde.grad.hessian returns a tuple, so the demo writes dy_xx, _ = dde.grad.hessian(y, x).
Output and how to read it
- Loss history.
model.trainreturnslosshistoryandtrain_state.dde.saveplotplots the loss history and saves it whenissave=True. Falling loss means the network is satisfying the residual and boundary terms at the sampled points. - L2 relative error. Because the example passes
solution=funcandmetrics=["l2 relative error"], DeepXDE reports the relative error of the prediction against the exact solution on the test points. This metric exists only when you know the answer, as you do in a benchmark like this one. - PDE residual.
model.predict(x, operator=pde)evaluates the residual at points you choose, which shows how well the equation is satisfied away from the training points.
Troubleshooting
- Wrong or missing backend. Check the precedence order above: an environment variable overrides
~/.deepxde/config.json. Use only the five valid backend names. - TensorFlow 2.16 or later with Keras 3. The installation page says to keep Keras 2 by installing tf-keras and setting
TF_USE_LEGACY_KERAS=1. - Error from the residual under JAX. The Hessian is returned as a tuple; unpack it as
dy_xx, _. - Backend function not found in
pde. Use the sine function that matches your backend (see above).
Free alternatives and backend choices
DeepXDE is open source and backend-agnostic, so the practical choice for most users is which deep-learning framework to run it on:
| Option | How to select it | Sine function in the Poisson demo residual |
|---|---|---|
| TensorFlow (v1 compatibility) | DDE_BACKEND=tensorflow.compat.v1 |
tf.sin |
| TensorFlow 2 | DDE_BACKEND=tensorflow |
tf.sin |
| PyTorch | DDE_BACKEND=pytorch |
torch.sin |
| JAX | DDE_BACKEND=jax |
jnp.sin (Hessian returns a tuple) |
| PaddlePaddle | DDE_BACKEND=paddle |
paddle.sin |
Related CASRAI guides: Papers with Code for finding code that accompanies papers, SciPy least_squares for conventional parameter fitting, and Hugging Face Datasets for shared datasets.
FAQ
What is a physics-informed neural network?
A physics-informed neural network is a neural network trained on supervised learning tasks while respecting physical laws expressed as nonlinear PDEs, per the 2017 paper that introduced the approach (arXiv:1711.10561).
Is “physics informed neural network” the same as “physics-informed neural networks”?
Yes. Both spellings, with or without the hyphen and in singular or plural, refer to the same method.
Do I need the exact solution to train a PINN?
No. The residual and the boundary conditions drive training. The exact solution in the Poisson demo is supplied only so the library can report the L2 relative error.
Which backend should I use?
Any of the five listed in the installation docs. Pick the one matching your existing environment and satisfy its minimum version in the table above.
Sources
- DeepXDE documentation, Installation and Setup: https://deepxde.readthedocs.io/en/latest/user/installation.html (read 2026-11-07).
- DeepXDE documentation, Poisson equation in 1D with Dirichlet boundary conditions: https://deepxde.readthedocs.io/en/latest/demos/pinn_forward/poisson.1d.dirichlet.html (read 2026-11-07).
- Raissi, M., Perdikaris, P., Karniadakis, G. E., Physics Informed Deep Learning (Part I): Data-driven Solutions of Nonlinear Partial Differential Equations, arXiv:1711.10561 (read 2026-11-07).







