Skip to main content
v2026.11,858 entries · CC-BY 4.0
LAC HealthMedical & Research SuppliesReagents, PPE & instruments — chain-of-custody documented.Fast, traceable sourcing built for regulated research environments, from bench consumables to instrumentation.Shop lac.us CodeCASRAIlac.us

Physics-Informed Neural Networks (PINNs): DeepXDE Tutorial

Run a physics-informed neural network (PINN) with DeepXDE: install, backend choice, a 1D Poisson example and how to read the error.

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 deepxde
  • conda 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:

  1. The DDE_BACKEND environment variable, for example DDE_BACKEND=pytorch python pde.py, or export DDE_BACKEND=pytorch on Linux (on Windows, set it in System Settings).
  2. The file ~/.deepxde/config.json, for example {"backend": "tensorflow.compat.v1"}, which you can also write with python -m deepxde.backend.set_default_backend BACKEND.
  3. 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.

  1. Define the residual. Write pde(x, y) so that it returns -u” – π² sin(πx), using dde.grad.hessian(y, x) for the second derivative.
  2. Define the geometry. dde.geometry.Interval(-1, 1) is the domain.
  3. Define the boundary condition. dde.icbc.DirichletBC(geom, func, boundary), where boundary(x, on_boundary) returns on_boundary.
  4. 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.
  5. 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.
  6. Compile and train. model.compile("adam", lr=0.001, metrics=["l2 relative error"]) then model.train(iterations=10000).
  7. 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.train returns losshistory and train_state. dde.saveplot plots the loss history and saves it when issave=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=func and metrics=["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).

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Physics-Informed Neural Networks (PINNs): DeepXDE Tutorial

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →