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.5-pp37-pypy37_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 729de0133bf7a718b126e62d6ad7bf293b22b011645be9d047ac91d456f4fb02 |
|
MD5 | 5e29548b96567281f1afba7ca312ad51 |
|
BLAKE2b-256 | c30f0a2e77a52cb4b6b13098c41e5b91e78d7802b5063dfa996f2806e9b8bf7f |
Hashes for NumbaLSODA-0.1.5-pp37-pypy37_pp73-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31e553e34ae921dd7b53b10cc918fa8bbbecb017f4aebca2ad3938ff823a28a7 |
|
MD5 | 3c13ef4b2712ca55481a107b5227865c |
|
BLAKE2b-256 | 5097c23db8f72413524d6019bc2f72b76de85c2cc57f0f8d93728a94973325b9 |
Hashes for NumbaLSODA-0.1.5-pp37-pypy37_pp73-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38cc73a7b67ee17c1915c35efbe7f2f87666da88c6bbcb2c2e803d4eb3e9848c |
|
MD5 | ec8912268245b24d129691e8cb849eaf |
|
BLAKE2b-256 | 0457fe3542e2000fa78232df3fd2fd99ba983e99669ffb6c54c4289610fcab88 |
Hashes for NumbaLSODA-0.1.5-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 569fd46d95dc477106a9212fc46c2ac8acb5e6810ebffcfe2b7249f029040cfa |
|
MD5 | 1776ea509e8eab94770f1d6a3db50733 |
|
BLAKE2b-256 | 2b982caf23f057ee05a04a53d09d29f7bf6af033e38d4b6cde5ad7c8c724553d |
Hashes for NumbaLSODA-0.1.5-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b4102b2b9b32a5673b24af1442bf5ffad99b5d1a6da29be743a6b2d8c5db692 |
|
MD5 | e74c588e37d4b3dd178b164fd4b94cab |
|
BLAKE2b-256 | c90ef9b388382a216f9cda0da4d9eb87bda55765159c855f769f8623f4319e06 |
Hashes for NumbaLSODA-0.1.5-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a8580b43ce63488800e5becd6000a0e5269977ea9312f9a44b5a58f269d9c0a |
|
MD5 | f7cec6654e5a5e9dafff31ce0194ebd9 |
|
BLAKE2b-256 | 7fb750a43554e79b116cf7505826c8872cf43ef6ecd3d8491511c4ee8087906a |
Hashes for NumbaLSODA-0.1.5-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba4df4300ffc1a4fae246f5a0a8c47218dda2cda0459a2569ff678362cb361e9 |
|
MD5 | 3f496c4c08327148570eaaa2a71c894b |
|
BLAKE2b-256 | cc7cc6174f3d01449a90bd0442c2d12f3bfc5e26b2acd7e7d6bb3717ad0ff6ea |
Hashes for NumbaLSODA-0.1.5-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86dffd1d380ae71693f4148ac89bd6b50daaba9e60f4024041dbd586ddddedf6 |
|
MD5 | 7fdfef1b613efe2fc5c93f3696a8b4d7 |
|
BLAKE2b-256 | b84bcaa70ebbf4bfd130a7b7eae9bd8fe4e129a8d9b2927cbe836a0d138ad6da |
Hashes for NumbaLSODA-0.1.5-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4414df2789e17dea89efcdc6eccb7cbb6412b1d0a460ec07aeed310a8adc89eb |
|
MD5 | a585f1d2e227c9cc3de05b5be465fa51 |
|
BLAKE2b-256 | 81e1672ab6642e0fa0d0a3e296962cd2bb09638a671ef3b3d6341632790d2619 |
Hashes for NumbaLSODA-0.1.5-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c77f019de77df602ceff01e65af61c4d8bfd116f6322a76cd84df15a9ecf12b5 |
|
MD5 | fe7372be6f10997213ebaced0f6caae7 |
|
BLAKE2b-256 | 626ef70fecc6dec2f910735ddc448ac3e9701d5205579a8bcce6ee6d4f11e540 |
Hashes for NumbaLSODA-0.1.5-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a8b497def126e2b20f4875a0698896debf171309c6984b4e1390c75138d3b8b |
|
MD5 | 87c1f20a1bb4215e568253f0df563e89 |
|
BLAKE2b-256 | 9713f7c89386938b4a4a85a11e046368b511d383535161a94c9ddcb1b79a5a45 |
Hashes for NumbaLSODA-0.1.5-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f73687659710e186158fdbe11478bf1cd1d19eb25f083f6d352d748a79393bbb |
|
MD5 | feb75bc74609d911e381962892c29686 |
|
BLAKE2b-256 | 8c73aa423264637f4bcebf446f4f39329edb35ffcab9b02360538f3ecba3288b |
Hashes for NumbaLSODA-0.1.5-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2363e3145434cdfaa7b8ae37a67f3742cd1b3037ee94c6910d8c2ac87f8248a5 |
|
MD5 | 73f43d1e6c4c576ed0e7e724e64be96e |
|
BLAKE2b-256 | 16070cec1a7df21ed008c9f821402a8629ebff05055c529037e9f8b11a49e390 |
Hashes for NumbaLSODA-0.1.5-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3123509664936f49761e42d9d70f7edbab61fa6e6b07dea9bad51a36ad984d7d |
|
MD5 | 7a7d1d757323aa75c5648c64b79577dc |
|
BLAKE2b-256 | c224264215a28c29df299ba2c43dcb9f8a2e15a691b7ec9306d7372edd95ceb0 |
Hashes for NumbaLSODA-0.1.5-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 302863218be8eede9bf7cdd7c911028fdf6281436fdd9d6573e02e035687a381 |
|
MD5 | 388225d1bc8f68aeb58b5783fa41b7f1 |
|
BLAKE2b-256 | b0cbab2e55bf8644d6cfd3e0a9c015ecfcee8ed8298c93ca0d01740cfa90c425 |
Hashes for NumbaLSODA-0.1.5-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ffab70067f8bb16595a1301a7b4cba24b22c00fab484eec06c8333f5cbe3335 |
|
MD5 | e96a1d30cf35ac92b687885cedbd27ce |
|
BLAKE2b-256 | db5e779941a60d91c8e09ac82c7e8ef41eac48fe7bba17e91f885e27ff33c48b |
Hashes for NumbaLSODA-0.1.5-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2416e33f5c2afd524279291c6f086c2fc820e47d1b0b05d5bf5592c4aaaa6038 |
|
MD5 | d8b391cdb57c9c7b7485cbfd01629f48 |
|
BLAKE2b-256 | cc4e89a15876ef18a335193847728e03e6801e8bea44cb82ac9118c2e8c19da0 |
Hashes for NumbaLSODA-0.1.5-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77cd56a7208167d7a75d06de74e973bea902392de1afe211c6d0d6235b38c5eb |
|
MD5 | 5631995863e8f3cbec48a209edf71a0b |
|
BLAKE2b-256 | c15e6302f0ed97dc36cd35555fc0c9a7948c1da6ff95cbba8c565e6cc7fca7fd |
Hashes for NumbaLSODA-0.1.5-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d3ba5abf239c54cb779436735c9fcc7bd46569f74e14845161e86943ab9240c |
|
MD5 | 89fce2feac76082df98c9545635ab39b |
|
BLAKE2b-256 | c1b38a29df0d357cb98361d5760b5cd089ae1888c33f016468db78da7f573009 |
Hashes for NumbaLSODA-0.1.5-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 910d2b65ab8f9818643f6550f98ac0eb2f93a8fd096d653818d91282d7cd4280 |
|
MD5 | 36877f0883b2f7790d72b2867ae7e3fa |
|
BLAKE2b-256 | 2fa061118ce71f7b2e6ab1d7e7db9e3d73d89f4c6190976767dec5470c7133b8 |
Hashes for NumbaLSODA-0.1.5-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4449c783a33e555575b43a9252714e9d6e4b83ef4a7a580889a85246f2587c6 |
|
MD5 | 8788e7b227aab96586a18a1b6474e1a5 |
|
BLAKE2b-256 | 04d03788b92569fdff24f7078ed5089b2d0fcd856930330f7a0d46ebce96ca1c |
Hashes for NumbaLSODA-0.1.5-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed12101bba6c5ffd164c0573d6a334c21afeaa2e847535a9545ef01d05a6cf90 |
|
MD5 | c5f8c809209a09ba4277ae52658625a1 |
|
BLAKE2b-256 | 98b951c111533518f698b1e5ed7dd7a82649741a982ae1f1b7e409df73946df1 |
Hashes for NumbaLSODA-0.1.5-cp37-cp37m-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb60411b12e010cb9bec60d6b784c2959c6b5d170fa67e0f0c563cd6cc633e69 |
|
MD5 | 758f2075ab12a078bbbc04483b1ba394 |
|
BLAKE2b-256 | 53d8c6709984b595309e9ed76a31cafb21031de22b8b8727d99de628509449a6 |
Hashes for NumbaLSODA-0.1.5-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12ccf02a3d176aa17ad2906483ce342030851e8970f76be74080ca54d896bbf7 |
|
MD5 | f0ea3877abc9c3d2801c5d4666832d00 |
|
BLAKE2b-256 | 58515293944140a57cc49ee00d741763a930d6254f0158f05f75b1efdf7fb4ae |
Hashes for NumbaLSODA-0.1.5-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4942cfc7e58250ab0c44fe6b1cb6c6a82620006ed109defe2a951a5965a8125 |
|
MD5 | c9ad273d74e295cb102a0e93617a1f72 |
|
BLAKE2b-256 | cf447e6ea60f6c207a11b754dbccf0f2cb20632ad74868a47fcf0eeb9034427d |
Hashes for NumbaLSODA-0.1.5-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4648741622d425b4ffa54e25e4cbd4c613f20e6b25b1ab761e8b63d587bec370 |
|
MD5 | 6612d86775343146c0d7d26d851dfa77 |
|
BLAKE2b-256 | bef942c02ec1a6b76194fc7f7280638020e963bba36151aa11aa2229ff39c009 |
Hashes for NumbaLSODA-0.1.5-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | deae6df3fb1c0e5faa75a1689a2ab9fba7bf918427631e8af229e90a0c765ed2 |
|
MD5 | 2535843b1fe06376835ec8be247c7cdc |
|
BLAKE2b-256 | 7158ae767aa2d4e1a0905a4dd9118cb0f2d7e559660318c1008afad651cd95bd |
Hashes for NumbaLSODA-0.1.5-cp36-cp36m-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6541e12d4ff8d4dfbae4b35ce5ca875ae1e09b6cfad4bdff762d6139b3d61c7c |
|
MD5 | 004f9b2ee8d81a7cb941395423881ce4 |
|
BLAKE2b-256 | b3bec9a1734b7dcba1a5bf1813e1584cefc9989d466e335fb29d6d7790ccebb0 |
Hashes for NumbaLSODA-0.1.5-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7aa4736370a4a23330188401067efeeade4238552ae8a15001322beeeeea76d |
|
MD5 | eb3817a4d59507faa38de679c8aae367 |
|
BLAKE2b-256 | 339cec2e47cef426b3458cef0828dce5b9530f1f12e9166f5316558d7d4eb0f0 |