Skip to content

Physics-Informed Neural Networks for Scientific Machine Learning in JAX

License

Notifications You must be signed in to change notification settings

chaobrain/pinnx

Repository files navigation

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/

About

Physics-Informed Neural Networks for Scientific Machine Learning in JAX

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages