Skip to main content

Physics-informed.

Project description

PINNx: Physics-Informed Neural Networks for Scientific Machine Learning in JAX

Header image of pinnx.

Build Status Documentation Status PyPI Version License

PINNx is a library for scientific machine learning and physics-informed learning in JAX. It is inspired from DeepXDE but is enhanced by our Brain Dynamics Programming (BDP) ecosystem. For example, it leverages

  • brainstate for just-in-time compilation,
  • brainunit for dimensional analysis,
  • braintools for checkpointing, loss functions, and other utilities.

Quickstart

Define a PINN with explicit variables and physical units.

import brainstate as bst
import brainunit as u
import pinnx

# geometry
geometry = pinnx.geometry.GeometryXTime(
    geometry=pinnx.geometry.Interval(-1, 1.),
    timedomain=pinnx.geometry.TimeDomain(0, 0.99)
).to_dict_point(x=u.meter, t=u.second)

uy = u.meter / u.second
v = 0.01 / u.math.pi * u.meter ** 2 / u.second

# boundary conditions
bc = pinnx.icbc.DirichletBC(lambda x: {'y': 0. * uy})
ic = pinnx.icbc.IC(lambda x: {'y': -u.math.sin(u.math.pi * x['x'] / u.meter) * uy})

# PDE equation
def pde(x, y):
    jacobian = approximator.jacobian(x)
    hessian = approximator.hessian(x)
    dy_x = jacobian['y']['x']
    dy_t = jacobian['y']['t']
    dy_xx = hessian['y']['x']['x']
    residual = dy_t + y['y'] * dy_x - v * dy_xx
    return residual

# neural network
approximator = pinnx.nn.Model(
    pinnx.nn.DictToArray(x=u.meter, t=u.second),
    pinnx.nn.FNN(
        [geometry.dim] + [20] * 3 + [1],
        "tanh",
        bst.init.KaimingUniform()
    ),
    pinnx.nn.ArrayToDict(y=uy)
)

# problem
problem = pinnx.problem.TimePDE(
    geometry,
    pde,
    [bc, ic],
    approximator,
    num_domain=2540,
    num_boundary=80,
    num_initial=160,
)

# training
trainer = pinnx.Trainer(problem)
trainer.compile(bst.optim.Adam(1e-3)).train(iterations=15000)
trainer.compile(bst.optim.LBFGS(1e-3)).train(2000, display_every=500)
trainer.saveplot(issave=True, isplot=True)

Installation

  • Install the stable version with pip:
pip install pinnx --upgrade

Documentation

The official documentation is hosted on Read the Docs: https://pinnx.readthedocs.io/

See also the BDP ecosystem

We are building the Brain Dynamics Programming ecosystem: https://ecosystem-for-brain-dynamics.readthedocs.io/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pinnx-0.0.2.post20250104-py2.py3-none-any.whl (124.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pinnx-0.0.2.post20250104-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pinnx-0.0.2.post20250104-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4adfdfb4197227a68c96f8f2e28e540b28008fa664cc8f32e338bd9965bc2b34
MD5 843db904a3d586a4d4e2fe22b9c5f6b0
BLAKE2b-256 b31229b5c8f2fe00afffc925c1c2a30dddbd97202f6cc7b357a55ef7753328b6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page