Skip to main content

PINNForge

PyPI version License: MIT
Solve partial differential equations in 3 lines of code.

PINNForge demo

PINNForge is a lightweight wrapper around PyTorch that handles the boilerplate code of Physics-Informed Neural Networks so you can focus on the physics.

Install

pip install pinnforge

Quick Start

from pinnforge import solve_pde

result = solve_pde("heat", epochs=5000)
print(f"Relative L2 error: {result['metrics']['relative_l2_error']:.2e}")
# Relative L2 error: 3.42e-02

The library automatically builds the network, generates training points, trains, validates, and returns metrics.

Why PINNForge?

Setting up a PINN in the standard tooling requires 25+ lines of boilerplate before you see your first result. PINNForge does it in 3.

Side-by-side: solving the 1D Heat equation

PINNForge (3 lines) DeepXDE (~25 lines)
from pinnforge import solve_pde

result = solve_pde("heat", epochs=5000)
print(result['metrics']['relative_l2_error'])

Everything else is handled by the library.

import deepxde as dde
import numpy as np

def pde(x, y):
    dy_t = dde.grad.jacobian(y, x, i=0, j=1)
    dy_xx = dde.grad.hessian(y, x, i=0, j=0)
    return dy_t - dy_xx

geom = dde.geometry.Interval(0, 1)
timedomain = dde.geometry.TimeDomain(0, 1)
geomtime = dde.geometry.GeometryXTime(geom, timedomain)

def boundary(x, on_boundary):
    return on_boundary

def initial(x):
    return np.sin(np.pi * x[:, 0:1])

bc = dde.icbc.DirichletBC(geomtime, lambda x: 0, boundary)
ic = dde.icbc.IC(geomtime, initial, lambda _, on_initial: on_initial)

data = dde.data.TimePDE(
    geomtime, pde, [bc, ic],
    num_domain=2000, num_boundary=100, num_initial=100,
)

net = dde.nn.FNN([2] + [64] * 3 + [1], "tanh", "Glorot normal")
model = dde.Model(data, net)
model.compile("adam", lr=1e-3)
model.train(epochs=15000)
model.compile("L-BFGS")
losshistory, train_state = model.train()

# Then write validation and plotting code yourself

The setup is 9x longer and you still need to write your own validation and plots after training.

Feature comparison

Features that PINNForge has that DeepXDE and PINNs-Torch do not:
    -One-line solve API
    -Symbolic PDE definition (SymPy)
    -Automatically generated validation metrics and plots
    -Built in numerical solvers

However, DeepXDE is multi-backend, is better for 3D+ problem, and tested since 2019 which are advantages over PINNForge. PINNForge trades depth for ease of use and time-to-result. If you need complex PDEs or 3D problems, use DeepXDE. If you want to try an idea in 5 minutes with minimal code, use PINNForge.

What's Included

  • solve_pde(): one-line API for common PDEs (Heat and Burgers, wave is on the list)
  • AutoPINN: configurable solver with auto-selected hyperparameters
  • PINN: the underlying neural network module
  • SymbolicPDE: define custom PDEs using SymPy math notation
  • NumericalSolver: finite-difference reference solutions
  • ExperimentLogger: automatic training metrics and checkpoint logging

Custom PDEs with SymPy

For problems not in the built-in registry, define them symbolically:

import sympy as sp
from pinnforge import AutoPINN

x, t = sp.symbols('x t')
u = sp.Function('u')(x, t)
equation = sp.diff(u, t) + u * sp.diff(u, x) - 0.01 * sp.diff(u, x, 2)

solver = AutoPINN.from_symbolic(equation, [x, t], u)
result = solver.solve()

u has to be a sp.Function of x and t. A plain symbol has no derivatives, so sp.diff would quietly return 0. Only u_t, u_x and u_xx can show up in the equation, and the initial condition defaults to sin(pi x) with zero boundaries unless you pass your own to SymbolicPDE.

Metrics only come back when there is something to compare against, so custom PDEs return an empty dict.

Validation

solve_pde checks the result on a grid after training. Heat is compared to its exact solution. Burgers has no closed form for this setup, so it is compared to a finite difference reference (implicit, on a fine grid). Custom symbolic PDEs skip validation.

Known Limitations (v0.2.1)

  • Wave equation does not run. The residual needs u_tt and PINN.loss_pde only computes first derivatives in time, so WaveEquation.residual raises NotImplementedError for now.
  • Fourier features were rewritten in v0.2.1 but are still off by default. The old version only used 2 random frequencies for a 2D input and threw away the raw coordinates, which is the likely reason training collapsed in #1. It now uses 64 by default and keeps x and t. I have not benchmarked it against the plain network yet, so it stays opt-in.
  • Adaptive loss weighting is off by default. The weights are now balanced from gradient sizes and no longer trained by the optimizer (they were before, which defeated the point). Needs benchmarking too.
  • Adaptive activation (SA-PINN) is off by default.
  • precision in AutoConfig is not applied yet. Everything runs in float32.
  • Only 1D problems are supported. Multi-dimensional PDEs are planned.
  • No CLI yet. Everything is Python-only.

See CHANGELOG.md for what changed in each version.

Contributing

This is a new project and there are several tasks that would help a lot. If you're looking for a place to contribute to SciML tooling, help is greatly appreciated

Good First Issues

Task Difficulty Description
Wave equation Medium Compute u_tt in PINN.loss_pde (or pass it to the residual) and write a real WaveEquation.residual with a test against the d'Alembert solution.
Add a quickstart notebook Easy Create examples/quickstart.ipynb that walks through the 3-line API and shows results inline.
Improve error messages Easy Several places raise generic errors. Add context-specific messages for common failure modes.

Larger Contributions Welcome

Task Difficulty Description
Benchmark Fourier features Medium The mapping was rewritten in v0.2.1. Run Burgers and Heat with and without it over a few seeds and scales and post the errors on #1.
L-BFGS fine-tuning Medium Adding L-BFGS as a second-stage optimizer like DeepXDE does would improve final accuracy by 10x.
2D PDE support Hard Currently limited to 1D spatial domains. Requires changes to pdes.py, data.py, and the PINN class.
JAX backend Hard Optional JAX backend for 5-10x faster training. See jinns for reference.
Adaptive sampling (RAR) Medium Residual-based adaptive refinement. Sample new collocation points where the PDE residual is highest.

How to Contribute

  1. Fork the repo
  2. Create a feature branch (git checkout -b fix-fourier-features)
  3. Make your changes
  4. Run pytest tests/ -v and make sure everything passes
  5. Open a Pull Request

See CONTRIBUTING.md for the full guide. First-time contributors are very welcome — if you're unsure where to start, open an issue and ask.

Tech Stack

  • Python 3.8+
  • PyTorch
  • SymPy
  • NumPy / SciPy

License

MIT — see LICENSE.

Acknowledgments

Built on the original Physics-Informed Neural Networks formulation by Raissi, Perikaris, and Karniadakis (2019). Inspired by the usability goals of DeepXDE but with a focus on time-to-first-result.

Metadata

Release files for pinnforge 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pinnforge 0.2.1
File Size Uploaded Provenance Actions
pinnforge-0.2.1.tar.gz 31.6 kB Without provenance Details for pinnforge-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pinnforge 0.2.1
File Interpreter ABI Platform Actions
pinnforge-0.2.1-py3-none-any.whl Python 3 none any Details for pinnforge-0.2.1-py3-none-any.whl

Total release size: 64.0 kB

Release files / pinnforge-0.2.1.tar.gz

Download URL pinnforge-0.2.1.tar.gz
Size 31.6 kB
Tags Source
SHA-256 checksum
How to use checksums
867d098c69fae006b96b0ded0564a3f5367315587889a9078bd1b45d5cacd4f9
BLAKE2b-256 checksum
How to use checksums
f2e142859b14ea47421c14414c650f445451b546480fa8c59574ffdb65dd9527
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / pinnforge-0.2.1-py3-none-any.whl

Download URL pinnforge-0.2.1-py3-none-any.whl
Size 32.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
62cc02431267b796773532789526f59ef0819aa3ef569dba376cacac5dfba497
BLAKE2b-256 checksum
How to use checksums
62211088c10921ba057e031b62ccc2e5433349f4b75d5384983d8258774bcc20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for pinnforge 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page