Giter Site home page Giter Site logo

torchphysics's Introduction

TorchPhysics

TorchPhysics is a Python library of (mesh-free) deep learning methods to solve differential equations. You can use TorchPhysics e.g. to

  • solve ordinary and partial differential equations
  • train a neural network to approximate solutions for different parameters
  • solve inverse problems and interpolate external data

The following approaches are implemented using high-level concepts to make their usage as easy as possible:

  • physics-informed neural networks (PINN)1
  • QRes2
  • the Deep Ritz method3
  • DeepONets4 and Physics-Informed DeepONets5

We aim to also include further implementations in the future.

TorchPhysics is build upon the machine learning library PyTorch.

Features

The Goal of this library is to create a basic framework that can be used in many different applications and with different deep learning methods. To this end, TorchPhysics aims at a:

  • modular and expandable structure
  • easy to understand code and clean documentation
  • intuitive and compact way to transfer the mathematical problem into code
  • reliable and well tested code basis

Some built-in features are:

  • mesh free domain generation. With pre implemented domain types: Point, Interval, Parallelogram, Circle, Triangle and Sphere
  • loading external created objects, thanks to a soft dependency on Trimesh and Shapely
  • creating complex domains with the boolean operators Union, Cut and Intersection and higher dimensional objects over the Cartesian product
  • allowing interdependence of different domains, e.g. creating moving domains
  • different point sampling methods for every domain: RandomUniform, Grid, Gaussian, Latin hypercube, Adaptive and some more for specific domains
  • different operators to easily define a differential equation
  • pre implemented fully connected neural network and easy implementation of additional model structures
  • sequentially or parallel evaluation/training of different neural networks
  • normalization layers and adaptive weights6 to speed up the training process
  • powerful and versatile training thanks to PyTorch Lightning
    • many options for optimizers and learning rate control
    • monitoring the loss of individual conditions while training

Getting Started

To learn the functionality and usage of TorchPhysics we recommend to have a look at the following sections:

Installation

TorchPhysics reqiueres the follwing dependencies to be installed:

Installing TorchPhysics with pip, automatically downloads everything that is needed:

pip install torchphysics

Additionally, to use the Shapely and Trimesh functionalities, install the library with the option all:

pip install torchphysics[all]

If you want to add functionalities or modify the code. We recommend copying the repository and installing it locally:

git clone https://github.com/boschresearch/torchphysics 
cd path_to_torchphysics_folder
pip install .[all]

About

TorchPhysics was originally developed by Nick Heilenkötter and Tom Freudenberg, as part of a seminar project at the University of Bremen, in cooperation with the Robert Bosch GmbH. Special thanks belong to Felix Hildebrand, Uwe Iben, Daniel Christopher Kreuter and Johannes Mueller, at the Robert Bosch GmbH, for support and supervision while creating this library.

Contribute

If you are missing a feature or detect a bug or unexpected behaviour while using this library, feel free to open an issue or a pull request in GitHub or contact the authors. Since we developed the code as a student project during a seminar, we cannot guarantee every feature to work properly. However, we are happy about all contributions since we aim to develop a reliable code basis and extend the library to include other approaches.

License

TorchPhysics uses an Apache License, see the LICENSE file.

Bibliography


  1. Raissi, Perdikaris und Karniadakis, “Physics-informed neuralnetworks: A deep learning framework for solving forward and inverse problems involving nonlinear partial differential equations”, 2019.

  2. Bu and Karpatne, “Quadratic Residual Networks: A New Class of Neural Networks for Solving Forward and Inverse Problems in Physics Involving PDEs”, 2021

  3. E and Yu, "The Deep Ritz method: A deep learning-based numerical algorithm for solving variational problems", 2017

  4. Lu, Jin and Karniadakis, “DeepONet: Learning nonlinear operators for identifying differential equations based on the universal approximation theorem of operators”, 2020

  5. Wang, Wang and Perdikaris, “Learning the solution operator of parametric partial differential equations with physics-informed DeepOnets”, 2021

  6. McClenny und Braga-Neto, “Self-Adaptive Physics-Informed NeuralNetworks using a Soft Attention Mechanism”, 2020

torchphysics's People

Contributors

dkreuter avatar johannes-mueller avatar kenaj123 avatar nheilenkoetter avatar tomf98 avatar uwe-iben avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

torchphysics's Issues

inverse problem example

Hi

Thanks for releasing the nice package. I'm interested in solving an inverse problem using deeponet. I wonder if you can provide some minimal example, for example, on the ODE problem that you already solved.

A.

Import issues

Getting these errors for imports. The directory doesnt have the required files. Followed the instructions for the installation
'cannot import name 'Variable' from 'torchphysics.problem''

`sample_points()` error when sampling from a composite domain

Thanks for the nice library! I was writing a similar code to solve my inverse problem with PINNs when I stumbled upon your project, and decided to try using it, since it has nice sampling, domain creation, and conditions logic. However, I encounter a problem in a simple situation when I try to obtain points from a 2d domain which is a CutDomain:

import torchphysics as tp

X = tp.spaces.R2("x")
R = tp.domains.Parallelogram(X, [0, 0], [3, 0], [0, 3])
A = tp.domains.Parallelogram(X, [1, 1], [2, 1], [2, 2])
O = R - A

sampler = tp.samplers.RandomUniformSampler(O, n_points=100)

pts = sampler.sample_points()

This gives the assertion error in __torch_function__: assert len(spaces) > 0, asserted here.

Expected behavior:

Have 100 points from domain O, which is a subtraction of A from R.

Observed behavior:

sample_points() call runs sample_domain_uniform() and inside _random_points_inside() when there should be a check of what points belong to the region, there is a eventually a line torch.repeat_interleave(params, n, dim=0), which fails for params = Points.empty()

I would try to fix this issue myself, but I cannot understand the point of the function _repeat_params, and of the assertion. Perhaps you can help clarifying the issue of what the code tries to check and why? Then I'd be able to write up a working version of the code for the case of 2d regions.

Also, I stumbled somewhere that it might be not supported to sample from domains like that? Is that so?

DeepONet support of multiple outputs

Hi

In my use case, I'd like to output at multiple sensor locations. I wonder if this is supported by Torchphysics' deeponet implementation. The output variable would have dimensions of [T, L], where T corresponds to the times defined in Trunknet coordinates, while L is the number of sensors. Thank you.

A.

DeepONet Example not working.

Hi,
I'm currently trying to get the DeepONet example working (ode.ipynb)

If I run the example, I get
'No supported gpu backend found!'
but if I remove this line:
os.environ["CUDA_VISIBLE_DEVICES"] = "3"

and update the constructor call of trainer by replacing gpus=-1 with:
accelerator='gpu', strategy="dp", devices=1,
I at least got it to Train.

It then crashes in this line:
out = model(grid_points).as_tensor.detach()[0]
with the Error:
RuntimeError: expand(torch.FloatTensor{[1, 30]}, size=[30]): the number of sizes provided (1) must be greater or equal to the number of dimensions in the tensor (2)

Can anyone give me advice on how to get this running?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.