All Projects → analysiscenter → pydens

analysiscenter / pydens

Licence: Apache-2.0 license
PyDEns is a framework for solving Ordinary and Partial Differential Equations (ODEs & PDEs) using neural networks

Programming Languages

Jupyter Notebook
11667 projects
python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to pydens

Differentialequations.jl
Multi-language suite for high-performance solvers of differential equations and scientific machine learning (SciML) components
Stars: ✭ 2,023 (+906.47%)
Mutual labels:  ode, partial-differential-equations, differential-equations
heyoka.py
Python library for ODE integration via Taylor's method and LLVM
Stars: ✭ 45 (-77.61%)
Mutual labels:  ode, differential-equations, ode-solver
numerics
library of numerical methods using Armadillo
Stars: ✭ 17 (-91.54%)
Mutual labels:  partial-differential-equations, differential-equations, numerical-methods
FOODIE
Fortran Object-Oriented Differential-equations Integration Environment, FOODIE
Stars: ✭ 109 (-45.77%)
Mutual labels:  ode, differential-equations, numerical-methods
godesim
ODE system solver made simple. For IVPs (initial value problems).
Stars: ✭ 19 (-90.55%)
Mutual labels:  ode, differential-equations, ode-solver
SciMLBenchmarks.jl
Benchmarks for scientific machine learning (SciML) software and differential equation solvers
Stars: ✭ 195 (-2.99%)
Mutual labels:  ode, partial-differential-equations, differential-equations
heyoka
C++ library for ODE integration via Taylor's method and LLVM
Stars: ✭ 151 (-24.88%)
Mutual labels:  ode, differential-equations, ode-solver
owl ode
Owl's Differential Equation Solvers
Stars: ✭ 24 (-88.06%)
Mutual labels:  ode, differential-equations, ode-solver
odex-js
Bulirsch-Stoer integration of systems of ordinary differential equations in JavaScript
Stars: ✭ 52 (-74.13%)
Mutual labels:  ode, differential-equations, ode-solver
FLINT
Fortran Library for numerical INTegration of differential equations
Stars: ✭ 37 (-81.59%)
Mutual labels:  ode, differential-equations
MultiScaleArrays.jl
A framework for developing multi-scale arrays for use in scientific machine learning (SciML) simulations
Stars: ✭ 63 (-68.66%)
Mutual labels:  ode, differential-equations
DiffEqUncertainty.jl
Fast uncertainty quantification for scientific machine learning (SciML) and differential equations
Stars: ✭ 61 (-69.65%)
Mutual labels:  ode, differential-equations
FinEtools.jl
Finite Element tools in Julia
Stars: ✭ 126 (-37.31%)
Mutual labels:  partial-differential-equations, numerical-methods
QuantPDE
A high-performance, open-source, header-only C++(>=11) library for pricing derivatives.
Stars: ✭ 42 (-79.1%)
Mutual labels:  partial-differential-equations, numerical-methods
odepack
Work in Progress to refactor and modernize the ODEPACK Library
Stars: ✭ 30 (-85.07%)
Mutual labels:  ode, ode-solver
numerical-methods-python
Numerical methods implementation in Python.
Stars: ✭ 65 (-67.66%)
Mutual labels:  differential-equations, numerical-methods
GlobalSensitivity.jl
Robust, Fast, and Parallel Global Sensitivity Analysis (GSA) in Julia
Stars: ✭ 30 (-85.07%)
Mutual labels:  ode, differential-equations
dae-cpp
A simple but powerful C++ DAE (Differential Algebraic Equation) solver
Stars: ✭ 33 (-83.58%)
Mutual labels:  ode, differential-equations
DiffEqDevTools.jl
Benchmarking, testing, and development tools for differential equations and scientific machine learning (SciML)
Stars: ✭ 37 (-81.59%)
Mutual labels:  ode, differential-equations
Sundials.jl
Julia interface to Sundials, including a nonlinear solver (KINSOL), ODE's (CVODE and ARKODE), and DAE's (IDA) in a SciML scientific machine learning enabled manner
Stars: ✭ 167 (-16.92%)
Mutual labels:  ode, differential-equations

License Python PyTorch Run Status

PyDEns

PyDEns is a framework for solving Ordinary and Partial Differential Equations (ODEs & PDEs) using neural networks. With PyDEns one can solve

This page outlines main capabilities of PyDEns. To get an in-depth understanding we suggest you to also read the tutorial.

Getting started with PyDEns: solving common PDEs

Let's solve poisson equation

using simple feed-forward neural network. Let's start by importing Solver-class along with other needed libraries:

from pydens import Solver, NumpySampler
import numpy as np
import torch

You can now set up a PyDEns-model for solving the task at hand. For this you need to supply the equation into a Solver-instance. Note the use of differentiation token D:

# Define the equation as a callable.
def pde(f, x, y):
    return D(D(f, x), x) + D(D(f, y), y) - 5 * torch.sin(np.pi * (x + y))

# Supply the equation, initial condition, the number of variables (`ndims`)
# and the configration of neural network in Solver-instance.
solver = Solver(equation=pde, ndims=2, boundary_condition=1,
                layout='fa fa fa f', activation='Tanh', units=[10, 12, 15, 1])

Note that we defined the architecture of the neural network by supplying layout, activation and units parameters. Here layout configures the sequence of layers: fa fa fa f stands for fully connected architecture with four layers and three activations. In its turn, units and activation cotrol the number of units in dense layers and activation-function. When defining neural network this way use ConvBlock from BatchFlow.

It's time to run the optimization procedure

solver.fit(batch_size=100, niters=1500)

in a fraction of second we've got a mesh-free approximation of the solution on [0, 1]X[0, 1]-square:

Going deeper into PyDEns-capabilities

PyDEns allows to do much more than just solve common PDEs: it also deals with (i) parametric families of PDEs and (ii) PDEs with trainable coefficients.

Solving parametric families of PDEs

Consider a family of ordinary differential equations

Clearly, the solution is a sin wave with a phase parametrized by ϵ:

Solving this problem is just as easy as solving common PDEs. You only need to introduce parameter e in the equation and supply the number of parameters (nparams) into a Solver-instance:

def odeparam(f, x, e):
    return D(f, x) - e * np.pi * torch.cos(e * np.pi * x)

# One for argument, one for parameter
s = NumpySampler('uniform') & NumpySampler('uniform', low=1, high=5)

solver = Solver(equation=odeparam, ndims=1, nparams=1, initial_condition=1)
solver.fit(batch_size=1000, sampler=s, niters=5000, lr=0.01)
# solving the whole family takes no more than a couple of seconds!

Check out the result:

Solving PDEs with trainable coefficients

With PyDEns things can get even more interesting! Assume that the initial state of the system is unknown and yet to be determined:

Of course, without additional information, the problem is undefined. To make things better, let's fix the state of the system at some other point:

Setting this problem requires a slightly more complex configuring. Note the use of V-token, that stands for trainable variable, in the initial condition of the problem. Also pay attention to the additional constraint supplied into the Solver instance. This constraint binds the final solution to zero at t=0.5:

def odevar(u, t):
    return D(u, t) - 2 * np.pi * torch.cos(2 * np.pi * t)
def initial(*args):
    return V('init', data=torch.Tensor([3.0]))

solver = Solver(odevar, ndims=1, initial_condition=initial,
                constraints=lambda u, t: u(torch.tensor([0.5])))

When tackling this problem, pydens will not only solve the equation, but also adjust the variable (initial condition) to satisfy the additional constraint. Hence, model-fitting comes in two parts now: (i) solving the equation and (ii) adjusting initial condition to satisfy the additional constraint. Inbetween the steps we need to freeze layers of the network to adjust only the adjustable variable:

solver.fit(batch_size=150, niters=100, lr=0.05)
solver.model.freeze_layers(['fc1', 'fc2', 'fc3'], ['log_scale'])
solver.fit(batch_size=150, niters=100, lr=0.05)

Check out the results:

Installation

First of all, you have to manually install pytorch, as you might need a certain version or a specific build for CPU / GPU.

Stable python package

With modern pipenv

pipenv install pydens

With old-fashioned pip

pip3 install pydens

Development version

pipenv install git+https://github.com/analysiscenter/pydens.git
pip3 install git+https://github.com/analysiscenter/pydens.git

Installation as a project repository:

Do not forget to use the flag --recursive to make sure that BatchFlow submodule is also cloned.

git clone --recursive https://github.com/analysiscenter/pydens.git

In this case you need to manually install the dependencies.

Citing PyDEns

Please cite PyDEns if it helps your research.

Roman Khudorozhkov, Sergey Tsimfer, Alexander Koryagin. PyDEns framework for solving differential equations with deep learning. 2019.
@misc{pydens_2019,
  author       = {Khudorozhkov R. and Tsimfer S. and Koryagin. A.},
  title        = {PyDEns framework for solving differential equations with deep learning},
  year         = 2019
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].