Skip to main content

Runge-Kutta ODE Integrator Implemented in Cython and Numba.

Project description

CyRK


Documentation | GitHub

CyRK Version 0.16.0 Alpha

Runge-Kutta ODE Integrator Implemented in Cython and Numba

CyRK provides fast integration tools to solve systems of ODEs using an adaptive time stepping scheme. CyRK can accept differential equations that are written in pure Python, njited numba, or cython-based cdef functions. These kinds of functions are generally easier to implement than pure c functions and can be used in existing Python software. Using CyRK can speed up development time while avoiding the slow performance that comes with using pure Python-based solvers like SciPy's solve_ivp.

The purpose of this package is to provide some functionality of scipy's solve_ivp with greatly improved performance.

Currently, CyRK's numba-based (njit-safe) implementation is 8--60x faster than scipy's solve_ivp function. The cython-based pysolve_ivp function that works with python (or njit'd) functions is 10-40x faster than scipy. The cython-based cysolver_ivp function that works with cython-based cdef functions is 40-300+x faster than scipy.

An additional benefit of the two cython implementations is that they are pre-compiled. This avoids most of the start-up performance hit experienced by just-in-time compilers like numba.

CyRK Performance Graphic

Supported Features

CyRK's pysolve_ivp (which works with pure python functions) and cysolve_ivp (which works with cython compiled functions) shares many of the same features as SciPy's solve_ivp:

  • Triggerable events to track certain events or cause a early termination.
  • Adaptive step size solver that uses relative and absolute error of the ODE to increase or decrease the step size as needed.
  • Dense output to create callable functions to interpolate an ODE's solution between solution steps. Allowing user to take advantage of the much more efficient adaptive step size solver.
  • A user-provided time domain or t_eval can be given to the solver to find solutions at specific time steps.

Note: nbsolve_ivp has a much more limited feature set than cysolve_ivp and pysolve_ivp. The latter methods are recommended where possible.

Supported Integrators

Currently, CyRK supports the following integration methods:

  • "RK23" - Explicit Runge-Kutta method of order 3(2).
  • "RK45" - Explicit Runge-Kutta method of order 5(4)
  • "DOP853" - Explicit Runge-Kutta method of order 8. Error is controlled using a combination of 5th and 3rd order interpolators.

More methods will be added as the need arises. We are always looking for contributors if you'd like to see your favorite method added to CyRK!

Additional Features

In additional to improved performance, CyRK offers a few additional features that SciPy does not:

  • Ability to capture extra outputs during integration so a user can record other parameters instead of just the dependent variables without having to make repeat calls to the differential equations.
  • Ability to reuse solvers when the previous result is no longer needed or has been recorded (improving performance, particularly for problems with small integration domain sizes).
  • CyRK provides a robust integration diagnostic feedback system to identify and help remedy issues with an ODE solution.

Limitations

There are some features that SciPy has that CyRK currently does not. A non-exhaustive list is:

  • A number of integrator methods are missing, particularly implicit approaches.
  • cysolve_ivp and pysolve_ivp can only work with ODEs of double-precision floating point numbers. So complex numbers are not directly supported but systems of ODEs of complex numbers can be converted to systems of doubles for use with CyRK.

Installation

CyRK has been tested on Python 3.9--3.13; Windows, Ubuntu, and MacOS.

Install via pip:

pip install CyRK

conda:

conda install -c conda-forge CyRK

mamba:

mamba install cyrk

If not installing from a wheel, CyRK will attempt to install Cython and Numpy in order to compile the source code. A "C++ 20" compatible compiler is required. Compiling CyRK has been tested on the latest versions of Windows, Ubuntu, and MacOS. Your milage may vary if you are using a older or different operating system. If on MacOS you will likely need a non-default compiler in order to compile the required openMP package. See the "Installation Troubleshooting" below. After everything has been compiled, cython will be uninstalled and CyRK's runtime dependencies (see the pyproject.toml file for the latest list) will be installed instead.

A new installation of CyRK can be tested quickly by running the following from a python console.

from CyRK import test_pysolver, test_cysolver, test_nbrk
test_pysolver()
# Should see "CyRK's PySolver was tested successfully."
test_cysolver()
# Should see "CyRK's CySolver was tested successfully."
test_nbrk()
# Should see "CyRK's nbrk_ode was tested successfully."

Installation Troubleshooting

Please report installation issues. We will work on a fix and/or add workaround information here.

  • If you see a "Can not load module: CyRK.cy" or similar error then the cython extensions likely did not compile during installation. Try running pip install CyRK --no-binary="CyRK" to force python to recompile the cython extensions locally (rather than via a prebuilt wheel).

  • On MacOS: If you run into problems installing CyRK then reinstall using the verbose flag (pip install -v .) to look at the installation log. If you see an error that looks like "clang: error: unsupported option '-fopenmp'" then you are likely using the default compiler or other compiler that does not support OpenMP. Read more about this issue here and the steps taken here. A fix for this issue is to use llvm's clang compiler. This can be done by doing the following in your terminal before installing CyRK.

brew install llvm
brew install libomp

# If on ARM64 (Apple Silicon) then do:
export LDFLAGS="-L/opt/homebrew/opt/llvm/lib"
export CPPFLAGS="-I/opt/homebrew/opt/llvm/include"
export LDFLAGS="-L/opt/homebrew/opt/libomp/lib"
export CPPFLAGS="-I/opt/homebrew/opt/libomp/include"
export CC=/opt/homebrew/opt/llvm/bin/clang
export CXX=/opt/homebrew/opt/llvm/bin/clang++
# Otherwise change these directories to:
export LDFLAGS="-L/usr/local/opt/llvm/lib"
export CPPFLAGS="-I/usr/local/opt/llvm/include"
export LDFLAGS="-L/usr/local/opt/libomp/lib"
export CPPFLAGS="-I/usr/local/opt/libomp/include"
export CC=/usr/local/opt/llvm/bin/clang
export CXX=/usr/local/opt/llvm/bin/clang++

pip install CyRK --no-binary="CyRK"

Development and Testing Dependencies

If you intend to work on CyRK's code base you will want to install the following dependencies in order to run CyRK's test suite and experimental notebooks.

conda install pytest scipy matplotlib jupyter

conda install can be replaced with pip install if you prefer.

Using CyRK

To learn how to use CyRK, please reference our detailed documentation on Read the Docs!

Read the Docs: CyRK Documentation

Citing CyRK

It is great to see CyRK used in other software or in scientific studies. We ask that you cite back to CyRK's GitHub website so interested parties can learn about this package.

It would also be great to hear about the work being done with CyRK and add your project to the list below, so get in touch!

Renaud, Joe P. (2022). CyRK - ODE Integrator Implemented in Cython and Numba. Zenodo. https://doi.org/10.5281/zenodo.7093266

In addition to citing CyRK, please consider citing SciPy and its references for the specific Runge-Kutta model that was used in your work. CyRK is largely an adaptation of SciPy's functionality. Find more details here.

Pauli Virtanen, Ralf Gommers, Travis E. Oliphant, Matt Haberland, Tyler Reddy, David Cournapeau, Evgeni Burovski, Pearu Peterson, Warren Weckesser, Jonathan Bright, Stéfan J. van der Walt, Matthew Brett, Joshua Wilson, K. Jarrod Millman, Nikolay Mayorov, Andrew R. J. Nelson, Eric Jones, Robert Kern, Eric Larson, CJ Carey, İlhan Polat, Yu Feng, Eric W. Moore, Jake VanderPlas, Denis Laxalde, Josef Perktold, Robert Cimrman, Ian Henriksen, E.A. Quintero, Charles R Harris, Anne M. Archibald, Antônio H. Ribeiro, Fabian Pedregosa, Paul van Mulbregt, and SciPy 1.0 Contributors. (2020) SciPy 1.0: Fundamental Algorithms for Scientific Computing in Python. Nature Methods, 17(3), 261-272.

Projects using CyRK

Don't see your project here? Create a GitHub issue or otherwise get in touch!

Contribute to CyRK

Please look here for an up-to-date list of contributors to the CyRK package.

CyRK is open-source and is distributed under the Creative Commons Attribution-ShareAlike 4.0 International license. You are welcome to fork this repository and make any edits with attribution back to this project (please see the Citing CyRK section).

  • We encourage users to report bugs or feature requests using GitHub Issues.
  • If you would like to contribute but don't know where to start, check out the good first issue tag on GitHub.
  • Users are welcome to submit pull requests and should feel free to create them before the final code is completed so that feedback and suggestions can be given early on.

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

cyrk-0.16.1.tar.gz (103.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

cyrk-0.16.1-cp313-cp313-win_amd64.whl (865.3 kB view details)

Uploaded CPython 3.13Windows x86-64

cyrk-0.16.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (8.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

cyrk-0.16.1-cp313-cp313-macosx_12_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.13macOS 12.0+ ARM64

cyrk-0.16.1-cp312-cp312-win_amd64.whl (866.6 kB view details)

Uploaded CPython 3.12Windows x86-64

cyrk-0.16.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (8.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

cyrk-0.16.1-cp312-cp312-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cyrk-0.16.1-cp311-cp311-win_amd64.whl (859.6 kB view details)

Uploaded CPython 3.11Windows x86-64

cyrk-0.16.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (8.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

cyrk-0.16.1-cp311-cp311-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

cyrk-0.16.1-cp310-cp310-win_amd64.whl (861.6 kB view details)

Uploaded CPython 3.10Windows x86-64

cyrk-0.16.1-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (8.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

cyrk-0.16.1-cp310-cp310-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

cyrk-0.16.1-cp39-cp39-win_amd64.whl (863.7 kB view details)

Uploaded CPython 3.9Windows x86-64

cyrk-0.16.1-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (8.2 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

cyrk-0.16.1-cp39-cp39-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

Details for the file cyrk-0.16.1.tar.gz.

File metadata

  • Download URL: cyrk-0.16.1.tar.gz
  • Upload date:
  • Size: 103.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for cyrk-0.16.1.tar.gz
Algorithm Hash digest
SHA256 12870d767a8aeaeab19c46e250a87cf371af1824927231a10aa1b51e31025f9f
MD5 6b7dc9dabe88e4f5996ea7be2db71f59
BLAKE2b-256 304a59c5cfd243345e404e1275b4f7088bcb5b52b07d735f968cc39a6e9e54ee

See more details on using hashes here.

File details

Details for the file cyrk-0.16.1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: cyrk-0.16.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 865.3 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for cyrk-0.16.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 4ad50bc095c71bb4fef032c2f0ae07f1808fd35cf5026fc08b284dc7279322b7
MD5 505755cb946a70a85d5eb024f3e0e1c0
BLAKE2b-256 412283454e27755e3d2ce4daf9b8fc3f897270cad866702920f9ff8182d0c8f7

See more details on using hashes here.

File details

Details for the file cyrk-0.16.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cyrk-0.16.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2d611fd77f0d86310873996449c7bebec105db39fb92e9d0b638243e2fa22c8e
MD5 59284c386fd56be07657847c73f4046c
BLAKE2b-256 941589158f300780c2aeb93a5ad65853925598b87661637214e38531344593ca

See more details on using hashes here.

File details

Details for the file cyrk-0.16.1-cp313-cp313-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for cyrk-0.16.1-cp313-cp313-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 a5de6d38122cadcb25b48b57bfb5776150e6742901289ee18995424b77a71879
MD5 16352959f08274f5edc8d77bb2e08a5d
BLAKE2b-256 bb7d2a92283886d86a20e79b6653eaf52a6499d30b6d39b78bb4f81291eccbc8

See more details on using hashes here.

File details

Details for the file cyrk-0.16.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: cyrk-0.16.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 866.6 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for cyrk-0.16.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 685f0b377dba1b8ddd9305c65df4f345b1628c20eea117f34e4c42a6c7103c57
MD5 6ccc087973112c867e72661674ad7dea
BLAKE2b-256 de1c0989b83f0e29baad1ee7226aabc8b388cd115da24ae072ce6f690b3164c8

See more details on using hashes here.

File details

Details for the file cyrk-0.16.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cyrk-0.16.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 56e9d747d069956b2aa34360d2f882d5aea1594d70787a8e7ecd5bc69fa6542f
MD5 c14bf72e998901a927dc52f9bbb927fe
BLAKE2b-256 f33b1ddb0c5ea4bff80e62dbe93247e55d5dd0846b3736a5f669d0e90ab75bbe

See more details on using hashes here.

File details

Details for the file cyrk-0.16.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cyrk-0.16.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 588164ab1b1ac0fc0509580dc7420b863050a0db77327365bcd3dd09d4a69c16
MD5 13492b4edf0c7f5121342b392c332b9d
BLAKE2b-256 a3a6a124c2b94819f74b2bab16674f6b534c4f26c4d9f576a5f6957fc2116a31

See more details on using hashes here.

File details

Details for the file cyrk-0.16.1-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: cyrk-0.16.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 859.6 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for cyrk-0.16.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f0f89f3290632f5a1bcb1c3626256a75d038c351589e2ebd8cabe3266787b15c
MD5 f3b162cfd603d912b7fa481504493bc2
BLAKE2b-256 ab5f97008380a170b504a2a82d6312f5042fd3b38a327b1eb6f91854e909ac27

See more details on using hashes here.

File details

Details for the file cyrk-0.16.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cyrk-0.16.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ee345061bd63d1be43f2c70b41002506d8182a044d3b960ce69dc8f521d2278b
MD5 2b950bd20d397c2a8dd82f04970527cf
BLAKE2b-256 7d6619df5e9c2f591ec86783265323ec3fc269467e61bfc9a80c28fc4b7e8e3e

See more details on using hashes here.

File details

Details for the file cyrk-0.16.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cyrk-0.16.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4f8d25035c273ea48cacd0f7249b612c48454c0bab79824fbfddc1de1c80df15
MD5 a38e00070c5c50a548fca2dd3e1db6ca
BLAKE2b-256 8b5df2cc40bbc36a17d21c8e79cbfca376461bf021cac2ef086c47e72bc482bb

See more details on using hashes here.

File details

Details for the file cyrk-0.16.1-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: cyrk-0.16.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 861.6 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for cyrk-0.16.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f2b766ad9eb51a6da1395caad9b75126be56545639bdaa73432a16546ee989c3
MD5 39408afcf43e5b651554d292e60030fe
BLAKE2b-256 0b0c51173c5a98a2dde57c66cab7221d165b54b3249db9799d1f2d5e1ace50c4

See more details on using hashes here.

File details

Details for the file cyrk-0.16.1-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cyrk-0.16.1-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 66d27fa954bfc4e1db82579ff0bfe1a98c9c99c1e83c7de4e6b108ba71c20031
MD5 66b40b42bd1fdfb206a3c3441143c8e7
BLAKE2b-256 74640a986a62a4c099d2e65c2ee88d32a4c87c0c8295b5085442ec1e19949ad0

See more details on using hashes here.

File details

Details for the file cyrk-0.16.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cyrk-0.16.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7f526945af5df4b361beef04b6e56e0d37b9b05e9a2b6159529f34e30dcc721f
MD5 7608e6dd287c7c3e73a280a6260b514e
BLAKE2b-256 23c84cb4da89606e16a6853ff8d9851f5bb42fcff0b17a19b3756db3b434d291

See more details on using hashes here.

File details

Details for the file cyrk-0.16.1-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: cyrk-0.16.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 863.7 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for cyrk-0.16.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 ebec8e708c31b0f6ed70382c4fa989512ff6af2fba13349d9ab667ce48adddb5
MD5 b07d8bf502ccb91a2a53e2792c2e9c28
BLAKE2b-256 35e25f15d49c49f24cd9b385663647244a7d7acceeb01fd6bf47e87eac6ca726

See more details on using hashes here.

File details

Details for the file cyrk-0.16.1-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cyrk-0.16.1-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b46e1b49950d83daaa764e4fc82f9913ab86160b54a923e6d3985231b12ad57f
MD5 a9e9fce4c10ac3725eed7dcc4848c768
BLAKE2b-256 4ef9e6ef15f22c1fc8ae0e760141d826346782af3bad6c30ffd94b6df141f207

See more details on using hashes here.

File details

Details for the file cyrk-0.16.1-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cyrk-0.16.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5cbbcb1f09e3f150bb4068bb1d607e64ed77a3c109d373e4c42ac9d5481eea3b
MD5 96333ee6618de8aa4346ae6d543d8d7b
BLAKE2b-256 c48a877d8cd63fe8d75bc016f7acf5f85498c7e07593ff3ce1f663398270c020

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page