pinnrl — PINNs + Reinforcement Learning for PDEs

This was my master’s thesis for the M.S. in Mathematical Modeling, Research, Statistics and Computation (University of the Basque Country). It grew into an open-source library, pinnrl, published on PyPI.

“Solve PDEs with neural networks that learn where to look.”

The problem

Physics-Informed Neural Networks (PINNs) solve partial differential equations by minimizing the physics residual at a set of collocation points. The catch is where those points go. Uniform or random sampling wastes compute on smooth, easy regions while undersampling exactly the places that matter — shocks, steep gradients, and sharp fronts — which is why plain PINNs struggle on problems like Burgers’ equation.

The approach

Instead of hand-tuning the sampling, I framed point placement as a sequential decision problem. A Deep Q-Network (DQN) agent observes the current residual field and learns a policy that concentrates collocation points where the physics residual is highest, adapting as training progresses. The result is a mesh-free solver that puts its resolution where the physics is hard, without a human deciding that in advance.

What the library does

  • 9 PDEs out of the box: Heat, Wave, Burgers, KdV, Convection, Allen–Cahn, Cahn–Hilliard, Black–Scholes, and Pendulum.
  • 7 network architectures to compare: FeedForward, ResNet, SIREN, Fourier Features, Fourier Neural Operator, Self-Attention, and Autoencoder.
  • Live 3D dashboard (Dash) that renders the solution and residual surfaces in real time during training.
  • Inverse problems: recovering PDE parameters from sparse observations.
  • Adaptive loss weighting that automatically re-balances the physics, boundary, and initial-condition terms.
  • Validation built in: analytical solutions for L2 and max-error checks, plus benchmark datasets via The Well integration.

Built with PyTorch, packaged for PyPI, and Docker-ready.