PINA
Physics-Informed Neural networks for Advanced modeling
**PINA** is a Physics-Informed Neural networks for Advanced modeling The project is written primarily in Python, distributed under the MIT License license, first published in 2021. Key topics include: deep-learning, differential-equations, equation-learning, hacktoberfest, lightining.
PINA provides an intuitive framework for defining, experimenting with, and solving complex problems using Neural Networks, Physics-Informed Neural Networks (PINNs), Neural Operators, and more.
-
Modular Architecture: Designed with modularity in mind and relying on powerful yet composable abstractions, PINA allows users to easily plug, replace, or extend components, making experimentation and customization straightforward.
-
Scalable Performance: With native support for multi-device training, PINA handles large datasets efficiently, offering performance close to hand-crafted implementations with minimal overhead.
-
Highly Flexible: Whether you're looking for full automation or granular control, PINA adapts to your workflow. High-level abstractions simplify model definition, while expert users can dive deep to fine-tune every aspect of the training and inference process.
<img src="https://github.com/mathLab/PINA/blob/master/readme/applications.gif" alt="PINA pipeline" style="max-width: 100%; height: auto; margin-top: 20px;" />
<hr/> <details> <summary> <h2>Installation</h2> <a href="https://pypi.org/project/pina-mathlab/"> <img align="center" height="20" src="https://img.shields.io/pypi/v/pina-mathlab?style=for-the-badge&logo=pypi&logoColor=white"> </a> </summary> <h3>Install a stable release</h3> <pre><code>pip install "pina-mathlab"</code></pre> <h3>Install from source</h3> <pre><code>git clone https://github.com/mathLab/PINA cd PINA git checkout master pip install . </code></pre> <summary>Install with extra dependencies</summary> <p> To install additional packages required for development, tests, docs, or tutorials: </p> <pre><code>pip install "pina-mathlab[extras]"</code></pre> <p>Available extras:</p> <ul> <li><code>dev</code> for development purposes</li> <li><code>test</code> for running tests locally</li> <li><code>doc</code> for building documentation locally</li> <li><code>tutorial</code> for running tutorials</li> </ul> <hr/> </details> <details> <summary> <h2>Getting started with PINA</h2> <a href="https://mathlab.github.io/PINA/"> <img align="center" height="20" src="https://img.shields.io/badge/documentation-fa9900?style=for-the-badge&logo=readthedocs&labelColor=555"></a> <a href="API_scheme.md"> <img align="center" height="20" src="https://img.shields.io/badge/API%20Scheme-fa9900?style=for-the-badge"> </a> </summary> <p> Solving a differential problem in <b>PINA</b> follows a clean four-step pipeline: </p> <ol> <li> Define the problem and constraints using the <a href="https://mathlab.github.io/PINA/_rst/_code.html#problems"><b>Problem API</b></a>. </li> <li> Design your model using PyTorch, PyTorch Geometric, or import from the <a href="https://mathlab.github.io/PINA/_rst/_code.html#models"><b>Model API</b></a>. </li> <li> Select or build a Solver using the <a href="https://mathlab.github.io/PINA/_rst/_code.html#solvers"><b>Solver API</b></a>. </li> <li> Train with the <a href="https://mathlab.github.io/PINA/_rst/trainer.html"><b>Trainer API</b></a>, powered by PyTorch Lightning. </li> </ol><p> Want to dive deeper? Check out the official <a href="https://github.com/mathLab/PINA/tree/master/tutorials#pina-tutorials"><b>Tutorials</b></a>. </p> <hr/> </details> <details> <summary> <h2>PINA by Examples</h2> <a href="https://github.com/mathLab/PINA/blob/master/tutorials/README.md"> <img align="center" height="20" src="https://img.shields.io/badge/tutorial-fa9900?style=for-the-badge&logo=jupyter&logoColor=white&labelColor=555"> </a> </summary> <details> <summary><h3>Data-Driven Modeling Example</h3></summary>mermaidflowchart LR STEP1["<h2>Problem and Data</h2> Define the mathematical problem<br>Identify constraints or import data"] STEP2["<h2>Model Design</h2> Build a PyTorch module Choose or customize a model"] STEP3["<h2>Solver Selection</h2> Use available solvers or define your own strategy"] STEP4["<h2>Training</h2> Optimize the model with PyTorch Lightning"] STEP1 e1@--> STEP2 STEP2 e2@--> STEP3 STEP3 e3@--> STEP4 e1@{ animate: true } e2@{ animate: true } e3@{ animate: true }
<hr/> </details> <details> <summary><h3>Physics-Informed Example</h3></summary> <p> Consider the following differential problem: </p>pythonimport torch from pina import Trainer from pina.model import FeedForward from pina.solver import SupervisedSolver from pina.problem.zoo import SupervisedProblem input_tensor = torch.rand((10, 1)) target_tensor = input_tensor.pow(3) # Step 1. Define problem problem = SupervisedProblem(input_tensor, target_tensor) # Step 2. Define model model = FeedForward(input_dimensions=1, output_dimensions=1, layers=[64, 64]) # Step 3. Define solver solver = SupervisedSolver(problem, model, use_lt=False) # Step 4. Train trainer = Trainer(solver, max_epochs=1000, accelerator="gpu") trainer.train()
$$
\begin{cases}
\frac{d}{dx}u(x) &= u(x) \quad x \in(0,1)\
u(x=0) &= 1
\end{cases}
$$
<hr/> </details> </details> <details> <summary> <h2>Contributing & Community</h2> <img align="center" height="20" src="https://img.shields.io/github/contributors/mathlab/pina?style=for-the-badge"> </summary> <p> We would love to develop PINA together with the community. A great place to start is the list of <a href="https://github.com/mathLab/PINA/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22"> <b>good-first-issue</b> </a> issues. </p> <p> If you would like to contribute, please read the <a href="CONTRIBUTING.md"><b>Contributing Guide</b></a>. </p> <p align="center"> <a href="https://github.com/mathLab/PINA/graphs/contributors"> <img src="https://contrib.rocks/image?repo=mathLab/PINA" alt="Contributors" style="max-width: 100%; height: auto;" /> </a> </p> <p align="center"> Made with <a href="https://contrib.rocks/">contrib.rocks</a>. </p> <hr/> </details> <details> <summary> <h2>Citation</h2> <a href="https://doi.org/10.21105/joss.05352"> <img align="center" height="20" src="https://img.shields.io/badge/JOSS-10.21105/JOSS.05352-blue?logo=open-access&style=for-the-badge&logoColor=white"> </a> </summary> <p> If <b>PINA</b> has been significant in your research and you would like to acknowledge it, please cite: </p> <pre><code>Coscia, D., Ivagnes, A., Demo, N., & Rozza, G. (2023). Physics-Informed Neural networks for Advanced modeling. Journal of Open Source Software, 8(87), 5352.</code></pre> <p>Or in BibTeX format:</p> <pre><code>@article{coscia2023physics, title={Physics-Informed Neural networks for Advanced modeling}, author={Coscia, Dario and Ivagnes, Anna and Demo, Nicola and Rozza, Gianluigi}, journal={Journal of Open Source Software}, volume={8}, number={87}, pages={5352}, year={2023} }</code></pre> </details>pythonfrom pina import Trainer, Condition from pina.problem import SpatialProblem from pina.operator import grad from pina.solver import PINN from pina.model import FeedForward from pina.domain import CartesianDomain from pina.equation import Equation, FixedValue def ode_equation(input_, output_): u_x = grad(output_, input_, components=["u"], d=["x"]) u = output_.extract(["u"]) return u_x - u class SimpleODE(SpatialProblem): output_variables = ["u"] spatial_domain = CartesianDomain({"x": [0, 1]}) domains = { "x0": CartesianDomain({"x": 0.0}), "D": CartesianDomain({"x": [0, 1]}), } conditions = { "bound_cond": Condition(domain="x0", equation=FixedValue(1.0)), "phys_cond": Condition(domain="D", equation=Equation(ode_equation)), } # Step 1. Define problem problem = SimpleODE() problem.discretise_domain(n=100, mode="grid", domains=["D", "x0"]) # Step 2. Define model model = FeedForward(input_dimensions=1, output_dimensions=1, layers=[64, 64]) # Step 3. Define solver solver = PINN(problem, model) # Step 4. Train trainer = Trainer(solver, max_epochs=1000, accelerator="gpu") trainer.train()
Contributors
Showing top 12 contributors by commit count.
