Python wrapper of LSODA (solving ODEs) which can be called from within numba functions.
Project description
NumbaLSODA
NumbaLSODA
is a python wrapper to the LSODA method in ODEPACK, which is for solving ordinary differential equation initial value problems. LSODA was originally written in Fortran. NumbaLSODA
is a wrapper to a C++ re-write of the original code: https://github.com/dilawar/libsoda
This package is very similar to scipy.integrate.solve_ivp
(see here), when you set method = 'LSODA'
. But, scipy.integrate.solve_ivp
invokes the python interpreter every time step which can be slow. Also, scipy.integrate.solve_ivp
can not be used within numba jit-compiled python functions. In contrast, NumbaLSODA
never invokes the python interpreter during integration and can be used within a numba compiled function which makes NumbaLSODA
a lot faster than scipy for most problems (see benchmark
folder).
Installation
NumbaLSODA
should work on Windows, Linux, or MacOS. Install with pip:
python -m pip install NumbaLSODA
Basic usage
from NumbaLSODA import lsoda_sig, lsoda
from numba import njit, cfunc
import numpy as np
@cfunc(lsoda_sig)
def rhs(t, u, du, p):
du[0] = u[0]-u[0]*u[1]
du[1] = u[0]*u[1]-u[1]*p[0]
funcptr = rhs.address # address to ODE function
u0 = np.array([5.,0.8]) # Initial conditions
data = np.array([1.0]) # data you want to pass to rhs (data == p in the rhs).
t_eval = np.linspace(0.0,50.0,1000) # times to evaluate solution
usol, success = lsoda(funcptr, u0, t_eval, data = data)
# usol = solution
# success = True/False
The variables u
, du
and p
in the rhs
function are pointers to an array of floats. Therefore, operations like np.sum(u)
or len(u)
will not work. However, you can use the function nb.carray()
to make a numpy array out of the pointers. For example:
import numba as nb
@cfunc(lsoda_sig)
def rhs(t, u, du, p):
u_ = nb.carray(u, (2,))
p_ = nb.carray(p, (1,))
# ... rest of rhs goes here using u_ and p_
Above, u_
and p_
are numpy arrays build out of u
and p
, and so functions like np.sum(u_)
will work.
Also, note lsoda
can be called within a jit-compiled numba function (see below). This makes it much faster than scipy if a program involves many integrations in a row.
@njit
def test():
usol, success = lsoda(funcptr, u0, t_eval, data = data)
return usol
usol = test() # this works!
@njit
def test_sp():
sol = solve_ivp(f_scipy, t_span, u0, t_eval = t_eval, method='LSODA')
return sol
sol = test_sp() # this does not work :(
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for NumbaLSODA-0.1.6-pp37-pypy37_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53b2706551e75fd6f4cd5c2d58ccfdcf145cf7969aa1126e51dd5d98ea6c4b1e |
|
MD5 | 3b8dda13780da970c2b6002f053d6420 |
|
BLAKE2b-256 | a991f9a0a7a5838a3c575893c118575bb15ab7a6fa32402a90ac16107b9d119e |
Hashes for NumbaLSODA-0.1.6-pp37-pypy37_pp73-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3633fc32a04bf382e14de5ff863d8a886fe3240504034319f0d43aec962c3ca7 |
|
MD5 | 130c2d6b34906a3fe6923400960641f6 |
|
BLAKE2b-256 | 4dfba7d5cc0790ff9b441e1f7e12456b925e6c36fe139b106d4fd00a99db9a91 |
Hashes for NumbaLSODA-0.1.6-pp37-pypy37_pp73-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf8abd46729a3fd95858e414cb435fabc420c2e8096fb1b40916e23e890db1c9 |
|
MD5 | 68027db1829124ce7d6ed3c5850313d9 |
|
BLAKE2b-256 | 9f1bf6a73e9e2108ccf3d009250887570541a9041146b157186461fa8146d1d9 |
Hashes for NumbaLSODA-0.1.6-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bae9f86fb4c34e03132c043f6c1b968edc288245e30264cd0e961ec119b14649 |
|
MD5 | 9672376197720986a753572a9ec2e4fa |
|
BLAKE2b-256 | 8142dc62a1668cc8bf1c8c750e4fb86bd491848eb41977bc44a5b6d66bda77e8 |
Hashes for NumbaLSODA-0.1.6-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce78a4c21e8abc39e81c94eda61ea8dc175454c613c612afb7b3f91626e229fb |
|
MD5 | 4c38589d396186d7c4ff244f102f40a5 |
|
BLAKE2b-256 | cb0d09ce6bc47046b5ab7782ecb9d5a82e4478d419ef1cbd6401b99b224f5506 |
Hashes for NumbaLSODA-0.1.6-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45fac0f266d37775ae04e7897b0dae0c379cfb4b7bdb424ff14c9eb22803afd7 |
|
MD5 | 36599af399691734c95c9544db573aaa |
|
BLAKE2b-256 | 6d2f811696328d2dfe120ba87310d0b664c2931360b9f141bd097debea2c5798 |
Hashes for NumbaLSODA-0.1.6-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cfed42908bb7367bdebfeed812c9ed9a2fe02686f2cabf3d4b2d9ff277ed99cd |
|
MD5 | a5de7c1e757a5a147539b6596a174300 |
|
BLAKE2b-256 | 822b0ea701e56b0b83388c0ea9f00b20c0560665a534ed38f22e0607124d93a1 |
Hashes for NumbaLSODA-0.1.6-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4756a2a55e7a7debd39b6d6a6f265d5e084c85b5683b6d0e8f1b840e4f7c04c9 |
|
MD5 | e89538d3f5ff4aadcce9c62e4be77176 |
|
BLAKE2b-256 | 7c4679d22b5774eb3b7f4cd36c59aca1dd45186438cf599791d0084b53de8c1a |
Hashes for NumbaLSODA-0.1.6-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe3fc005561fea07202b9d0732b06c641e2c734e4df4ca4e29f82f2243868751 |
|
MD5 | 79963b23a21f00938a73f288c3e5074a |
|
BLAKE2b-256 | dc14d7eee2ff396c47f23f8962ab6c0184609e9126995e43c8e4ce49420e3541 |
Hashes for NumbaLSODA-0.1.6-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 134c8622d3867da20ef6e6d1675e8c57f9f4323e8d08d6ee56d82f84f08840c5 |
|
MD5 | a674e53a19f418ec571cf7b47249c816 |
|
BLAKE2b-256 | c2bf940bb79151b29907039eb9fca67d8c797fc85083607ebbd88fbdfd0a0c83 |
Hashes for NumbaLSODA-0.1.6-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 290be18fccdffbc2e504475f9837332defb57c808ffc7e00f7c75ae7de5e1248 |
|
MD5 | b7fb6ecc34cfe0db62d1c6299388a3b0 |
|
BLAKE2b-256 | cd6be7c6850d43a2d7bbed5cb4342367075b50eeac097fbc681310b1308bed6a |
Hashes for NumbaLSODA-0.1.6-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41ac942a6e31e093f6811eee93d7c2178b8e953dbc84ea14d86f3b4d38aeb66d |
|
MD5 | d4d5ffbc3ac87ef81e2be2ed1c015277 |
|
BLAKE2b-256 | bec9516f5f0b0f7333b0241f22a73cf9b00a59e22b4675fbd6aa0f79312fc7cb |
Hashes for NumbaLSODA-0.1.6-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0953840c7eb5637baea3dda5524a1d94b3a886966090cde50df729c69d7980de |
|
MD5 | 57e89eaf1459e4b89f4604c1c278a252 |
|
BLAKE2b-256 | 17b8021759e0d3d51d95ab2587b54b5697c26175016b63065ae1283b7dc4a73a |
Hashes for NumbaLSODA-0.1.6-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe8c23228400a928c7bce0d6c0d24bbe243fbc31538fd266c3c6d20d5364f5f3 |
|
MD5 | ded2a241173c285483fc870b5f6e88d3 |
|
BLAKE2b-256 | 12699cc02e7ad826e139758723cacc3f98fb29db0e46f7281d1bfec7a6b557af |
Hashes for NumbaLSODA-0.1.6-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c6cce7fb49f55ab2ff61ce2bdb90c9242855eadc2efd55a03d3b156b643593a |
|
MD5 | f4e19eb2a39480e1f6175f548ff6f1ff |
|
BLAKE2b-256 | be8029d22dfbc7fe6f8c246c7797ff3fd36cb732795a191612542211bfb0e1e8 |
Hashes for NumbaLSODA-0.1.6-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9dbb91c2de800954d866ced67fc9a50975b44a8456b8522432a4128f2ac80345 |
|
MD5 | 1311cc5ef5cd95f8c3b31c57a5adc3f1 |
|
BLAKE2b-256 | b4c4f7a3952ae6e41deb49a7a9be65eec5fe1fd9271f6b4a3624bbeffef33b5f |
Hashes for NumbaLSODA-0.1.6-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 032d38dd893cc3ac5374cafb8a502ae7d9d6733fb426bb3cd355b815358e5501 |
|
MD5 | dad82dbe9dc91c2ca619f8a42f2c9136 |
|
BLAKE2b-256 | f988352a366b2f410a5a18ea789a4ffc9ea40e8820fae8d347cf9baa8724e3ff |
Hashes for NumbaLSODA-0.1.6-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4fbc3c08fc08b4bad855d555a300d837791d3eee4c58df85992e62b3797e743 |
|
MD5 | f90725e059d8bfa6c4ca61f8ff22b301 |
|
BLAKE2b-256 | 83b0dcd76f989ba59edf26e8f50787eabdd5faf702c59b691e8b101b65d311c4 |
Hashes for NumbaLSODA-0.1.6-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5dd986adee8207475f779af28aba91882c52a6108a25306d972fa67109fe55c |
|
MD5 | 27ceec2d976ed4d406f2e087dc5a61cb |
|
BLAKE2b-256 | 0f7c0ccc439f5a17c247b29bcfa5c1e0087205f04502a73b00f85bc9a134e629 |
Hashes for NumbaLSODA-0.1.6-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c60016d9dc37b9a73ed3cf8881f0282e01bcd6f9da471e15e30a07abe425c9a2 |
|
MD5 | de68532ed8421271f04a08c24e508208 |
|
BLAKE2b-256 | b61c85e74f88e692775d07155cd7ab2d6a9703bbe9951c2ea0d09d075e982d80 |
Hashes for NumbaLSODA-0.1.6-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 564e3bc49498298ee1a2876a23b2a81fda766543379166c9a71ce274926f7d36 |
|
MD5 | 92b16df94c8c3c5674df7d8c69f37bfb |
|
BLAKE2b-256 | bbe11b006f66672c8f4ebfff411bb8b14e4370e28c0a4e8e0f911e46b10ac83b |
Hashes for NumbaLSODA-0.1.6-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35b7394f8b0d5dd0cda7c1f2ee619d308d43158b3be8b0de72ce0e2427e1ac16 |
|
MD5 | 4e88bfdacfe9b6db60bc87f221c41f46 |
|
BLAKE2b-256 | c519af185ff26d0df86a4c6ae4fc82a6407daf1db7ea6fa49f13b54c1e2d9bab |
Hashes for NumbaLSODA-0.1.6-cp37-cp37m-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 610b78163ec263d049d32d612e4d6d6f568d6a84b9f6d56b59004058a75bdae0 |
|
MD5 | b7d6ca9e3b17504da6ea649947fac67b |
|
BLAKE2b-256 | 9b393f5941416d4a90d318aaa8e6afd1efa370a6351296ef4c4843f5ebf8795b |
Hashes for NumbaLSODA-0.1.6-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c12ec06ccbb190658e8caa9c7d9692af69d8cffb41b86d0307b4f4d2df7aae41 |
|
MD5 | 0191d74b9432259eb5ae0b150c5be2d1 |
|
BLAKE2b-256 | dae851435d06c480887494d4ac0f8b04ac5819d4c9a18193bdc6ee79958c907f |
Hashes for NumbaLSODA-0.1.6-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 137112851d0a7f3282a87a5cd48b8f072870cd84ee62f990e7dc433222fc629c |
|
MD5 | 2813557a6ea62301a6dec1f132d7eab0 |
|
BLAKE2b-256 | 853588dbf186de54cbe9a4cd5c13d37506fa1159bb45c5f4d116d80fc65a5ca0 |
Hashes for NumbaLSODA-0.1.6-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e771a9a521490a54921f3785ba725d0268340519f5f8be412693d5003e558a6 |
|
MD5 | 942109f99ace33b96063ac1f1cd0368d |
|
BLAKE2b-256 | 44b61eba153debe111915737071af4372565b43ed9d92af85bda129690381240 |
Hashes for NumbaLSODA-0.1.6-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfa036cbdb3f86bafa9dd23017d0a16b32517e3882bd40ac34f1f5d81e31e673 |
|
MD5 | 709a4ea0fa0a6c778e1da27fed1e6c1f |
|
BLAKE2b-256 | 4661b9f5d05593e7e30ed4003de6ac490df0175b4a800018db760055a713a2bf |
Hashes for NumbaLSODA-0.1.6-cp36-cp36m-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 682cd320a53e792c86b733937afca5a9035c0ace3d02c1a55775ca31f765cfcd |
|
MD5 | c14aea4c4b265c8d89213d2564470ca6 |
|
BLAKE2b-256 | 6f6565db6e819a438b822392be556605d99043fe4a339e175421fdc6bb0c74a0 |
Hashes for NumbaLSODA-0.1.6-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07416f52b84a8fd512401601d445832e146b67ba71a26670f95e0d7fc9d9a5e5 |
|
MD5 | 4af0f93c1288d7e3d576cb5567d0a1f8 |
|
BLAKE2b-256 | b1bab4a406fbcb748146f401b046eb71670a43c555042f82e52eff8c56193510 |