DifferentialEquations.jl with PyTorch.
Project description
diffeqtorch
Bridges DifferentialEquations.jl
with PyTorch. Besides benefitting from the huge range of solvers available in DifferentialEquations.jl
, this allows taking gradients through solvers using local sensitivity analysis/auto-diff. The package has only been tested with ODE problems, and in particular, automatic differentiation is only supported for ODEs using ForwardDiff.jl
. This can be extended in the future, contributions are welcome.
Examples
- Simple ODE problem to demonstrate the interface and confirm gradients with analytical solution
- SIR model for a slighlty more complicated model with numerical gradient checking
- Hodgkin-Huxley model for a realistic example from Neuroscience
Installation
Prerequisites for using diffeqtorch
are installation of Julia and Python. Note that the binary directory of julia
needs to be in your PATH
.
Install diffeqtorch
:
$ pip install diffeqtorch
$ export JULIA_SYSIMAGE_DIFFEQTORCH="$HOME/.julia_sysimage_diffeqtorch.so"
$ python -c "from diffeqtorch.install import install_and_test; install_and_test()"
We recommend using a custom Julia system image containing dependencies. By setting the environment variable JULIA_SYSIMAGE_DIFFEQTORCH
, an image will be created and used automatically. This may take a while but will improve speed afterwards.
Usage
from diffeqtorch import DiffEq
f = """
function f(du,u,p,t)
du[1] = p[1] * u[1]
end
"""
de = DiffEq(f)
u0 = torch.tensor([1.])
tspan = torch.tensor([0., 3.])
p = torch.tensor([1.01])
u, t = de(u0, tspan, p)
See also help(DiffEq)
and examples provided in notebooks/
.
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file diffeqtorch-1.0.1.tar.gz
.
File metadata
- Download URL: diffeqtorch-1.0.1.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 405edd3ae1fefe9fe2455ea3d2746c3c77338050ebfc047981fe0a0171d279bf |
|
MD5 | 0c8f50b8bd83b47e78bad0b5b66c5dfe |
|
BLAKE2b-256 | de370c79655c5b2e07b6c0902064375ae227182ea62a4868e12d5e49aade124e |
File details
Details for the file diffeqtorch-1.0.1-py2.py3-none-any.whl
.
File metadata
- Download URL: diffeqtorch-1.0.1-py2.py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | de484ab7bc833ce44c9bf1bd44d965ae6fd25bc70547bce1f35ba180d85bd21c |
|
MD5 | 899029a25058cc4fb3e33e7ce569e2b3 |
|
BLAKE2b-256 | c41406a85b2488c4c978bab3d498c0808e141ae47eb4458c9f10803f4f6581fb |