Skip to content
forked from mathLab/PINA

Physics-Informed Neural networks for Advanced modeling

License

Notifications You must be signed in to change notification settings

FilippoOlivo/PINA

This branch is 82 commits ahead of, 126 commits behind mathLab/PINA:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

72a2e45 Β· Mar 21, 2025
Mar 21, 2025
Mar 21, 2025
Jul 19, 2023
Mar 21, 2025
Nov 17, 2023
Mar 21, 2025
Mar 21, 2025
Mar 21, 2025
Mar 18, 2022
Mar 21, 2025
Mar 21, 2025
Jul 20, 2023
Mar 21, 2025
Mar 21, 2025
Jul 21, 2023
Mar 21, 2025
Mar 21, 2025
Mar 19, 2025
Mar 21, 2025

Repository files navigation

Docs PyPi PyPi

License PyPi Joss


ZenML Logo

Solve equations, intuitively.

A simple framework to solve difficult problems with neural networks.
Explore the docs Β»

🏁 Table of Contents
  1. Introduction
  2. Quickstart
  3. Solve Your Differential Problem
  4. Contributing and Community
  5. License

πŸ€– Introduction

🀹 PINA is an open-source Python library providing an intuitive interface for solving differential equations using PINNs, NOs or both together. Based on PyTorch and PyTorchLightning, PINA offers a simple and intuitive way to formalize a specific (differential) problem and solve it using neural networks . The approximated solution of a differential equation can be implemented using PINA in a few lines of code thanks to the intuitive and user-friendly interface.

  • πŸ‘¨β€πŸ’» Formulate your differential problem in few lines of code, just translating the mathematical equations into Python

  • πŸ“„ Training your neural network in order to solve the problem

  • πŸš€ Use the model to visualize and analyze the solution!


🀸 Quickstart

Install PINA via PyPI. Python 3 is required:

pip install "pina-mathlab"

πŸ–ΌοΈ Solve Your Differential Problem

PINN is a novel approach that involves neural networks to solve supervised learning tasks while respecting any given law of physics described by general nonlinear differential equations. Proposed in Physics-informed neural networks: A deep learning framework for solving forward and inverse problems involving nonlinear partial differential equations, such framework aims to solve problems in a continuous and nonlinear settings.

Differenlty from PINNs, Neural Operators learn differential operators using supervised learning strategies. By learning the differential operator, the neural network is able to generalize across different instances of the differential equations (e.g. different forcing terms), without the need of re-training.

PINA can be used for PINN learning, Neural Operator learning, or both. Below is a simple example of PINN learning, for Neural Operator or more on PINNs look at our tutorials

πŸ”‹ 1. Formulate the Problem

First step is formalization of the problem in the PINA framework. We take as example here a simple Poisson problem, but PINA is already able to deal with multi-dimensional, parametric, time-dependent problems. Consider:

{ Ξ” u = sin ⁑ ( Ο€ x ) sin ⁑ ( Ο€ y ) in  D u = 0 in  βˆ‚ D

where D = [ 0 , 1 ] 2 is a square domain, u the unknown field, and βˆ‚ D = Ξ“ 1 βˆͺ Ξ“ 2 βˆͺ Ξ“ 3 βˆͺ Ξ“ 4 , where Ξ“ i are the boundaries of the square for i = 1 , β‹― , 4 . The translation in PINA code becomes a new class containing all the information about the domain, about the conditions and nothing more:

class Poisson(SpatialProblem):
    output_variables = ['u']
    spatial_domain = CartesianDomain({'x': [0, 1], 'y': [0, 1]})

    def laplace_equation(input_, output_):
        force_term = (torch.sin(input_.extract(['x'])*torch.pi) *
                      torch.sin(input_.extract(['y'])*torch.pi))
        laplacian_u = laplacian(output_, input_, components=['u'], d=['x', 'y'])
        return laplacian_u - force_term

    domains = {
      'g1': CartesianDomain({'x': [0, 1], 'y':  1}),
      'g2': CartesianDomain({'x': [0, 1], 'y': 0}),
      'g3': CartesianDomain({'x':  1, 'y': [0, 1]}),
      'g4': CartesianDomain({'x': 0, 'y': [0, 1]}),
      'D': CartesianDomain({'x': [0, 1], 'y': [0, 1]})
    }

    conditions = {
        'gamma1': Condition(domain='g1', equation=FixedValue(0.)),
        'gamma2': Condition(domain='g2', equation=FixedValue(0.)),
        'gamma3': Condition(domain='g3', equation=FixedValue(0.)),
        'gamma4': Condition(domain='g4', equation=FixedValue(0.)),
        'D': Condition(domain='D', equation=Equation(laplace_equation)),
    }

πŸ‘¨β€πŸ³ 2. Solve the Problem

After defining it, we want of course to solve such a problem. The only things we need is a model, in this case a feed forward network, and some samples of the domain and boundaries, here using a Cartesian grid. In these points we are going to evaluate the residuals, which is nothing but the loss of the network. We optimize the model using a solver, here a PINN. Other types of solvers are possible, such as supervised solver or GAN based solver.

# make model + solver + trainer
model = FeedForward(
    layers=[10, 10],
    func=Softplus,
    output_dimensions=len(problem.output_variables),
    input_dimensions=len(problem.input_variables)
)
optimizer = TorchOptimizer(torch.optim.Adam, lr=0.006, weight_decay=1e-8)
pinn = PINN(problem, model, optimizer=optimizer)
trainer = Trainer(pinn, max_epochs=1000, accelerator='gpu', enable_model_summary=False, batch_size=8)

# train
trainer.train()

After the training we can infer our model, save it or just plot the approximation. Below the graphical representation of the PINN approximation, the analytical solution of the problem and the absolute error, from left to right.

Poisson approximation


πŸ™Œ Contributing and Community

We would love to develop PINA together with our community! Best way to get started is to select any issue from the good-first-issue label. If you would like to contribute, please review our Contributing Guide for all relevant details.

We warmly thank all the contributors that have supported PINA so far:

Made with contrib.rocks.

πŸ“œ License

PINA is distributed under the terms of the MIT License. A complete version of the license is available in the LICENSE.rst file in this repository. Any contribution made to this project will be licensed under the MIT License.

About

Physics-Informed Neural networks for Advanced modeling

Resources

License

Code of conduct

Security policy

Citation

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 98.1%
  • TeX 1.8%
  • Shell 0.1%