Skip to content

Commit

Permalink
Merge pull request #34 from jrenaud90/v0.7.0
Browse files Browse the repository at this point in the history
v0.7.0
  • Loading branch information
jrenaud90 authored Aug 28, 2023
2 parents 5af85bc + 72dbc87 commit 3c63364
Show file tree
Hide file tree
Showing 40 changed files with 2,134 additions and 24,337 deletions.
3 changes: 2 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[run]
plugins = Cython.Coverage
source = CyRK
omit =
Tests/*
CyRK/cy/_cyrk.pyx
2 changes: 1 addition & 1 deletion .github/workflows/push_tests_ubun.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pytest pytest-cov
python -m pip install pytest pytest-cov cython
- name: Install package
run: |
python -m pip install . -v
Expand Down
119 changes: 80 additions & 39 deletions Benchmarks/CyRK - SciPy Comparison.ipynb

Large diffs are not rendered by default.

Binary file modified Benchmarks/CyRK_CySolver.pdf
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Benchmarks/CyRK_cyrk_ode.pdf
Binary file not shown.
Binary file modified Benchmarks/CyRK_numba.pdf
Binary file not shown.
Binary file modified Benchmarks/SciPy.pdf
Binary file not shown.
File renamed without changes
36 changes: 36 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,42 @@

## 2023

### v0.7.0

Major Changes
- Added support for Cython 3.0.0
- Added `noexcept` to pure cython functions to avoid a potential python error check.

New Features
- Added the ability to pass arrayed versions of rtol and atol to both the numba and cython-based solvers (cyrk_ode and CySolver).
- For both solvers, you can pass the optional argument "rtols" and/or "atols". These must be C-contiguous numpy arrays with float64 dtypes. They must have the same size as y0.
- Added tests to check functionality for all solvers.
- This resolves [https://github.com/jrenaud90/CyRK/issues/31][Issue 31].
- Added new optional argument to all solvers `max_num_steps` which allows the user to control how many steps the solver is allowed to take.
- If exceeded the integration with fail (softly).
- Defaults to 95% of `sys.maxsize` (depends on system architecture).
- New `CySolver.update_constants` method allows for significant speed boosts for certain differential equations.
- See test diffeqs, which have been updated to use this feature, for examples.
co
Other Changes
- Improved documentation for most functions and classes.
- To make more logical sense with the wording, `CySolver.size_growths` now gives one less than the solver's growths attribute.
- Cleaned up status codes and created new status code description document under "Documentation/Status and Error Codes.md"
- Fixed compile warning related to NPY_NO_DEPRECATED_API.
- Converted RK variable lengths to Py_ssize_t types.
- Changed default tolerances to match scipy: rtol=1.0e-3, atol=1.0e-6.

Performance
- Various minor performance gains for cython-based solvers.
- Moved key loops in `CySolver` into self-contained method so that gil can be released.
- New `CySolver.update_constants` method allows for significant speed boosts for certain differential equations.

Bug Fixes:
- Fixed potential seg fault when accessing `CySolver`'s arg_array_view.
- Fixed potential issue where `CySolver`'s first step size may not be reset when variables that affect it are.
- Fixed missed declaration in `cyrk_ode`.
- Fixed bug where the state reset flag was not being passed from `CySolver.solve` wrapper method.

#### v0.6.2
New Features
- Added `auto_solve` key word to `CySolver` class. This flag defaults to True. If True, then the solver will automatically call `self.solve()` after initialization.
Expand Down
8 changes: 4 additions & 4 deletions CyRK/_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ def test_cysolver():
from CyRK.cy.cysolvertest import CySolverTester

# TODO: Currently CySolver only works with floats not complex
CySolverTesterInst = CySolverTester(time_span, np.asarray(np.real(initial_conds), dtype=np.float64))
CySolverTesterInst = CySolverTester(time_span, np.asarray(np.real(initial_conds), dtype=np.float64, order='C'))
CySolverTesterInst.solve()

assert CySolverTesterInst.success
assert type(CySolverTesterInst.solution_t) == np.ndarray
assert type(CySolverTesterInst.solution_y) == np.ndarray
assert CySolverTesterInst.solution_y.shape[0] == 2
assert type(CySolverTesterInst.t) == np.ndarray
assert type(CySolverTesterInst.y) == np.ndarray
assert CySolverTesterInst.y.shape[0] == 2

print("CyRK's CySolver was tested successfully.")
14 changes: 7 additions & 7 deletions CyRK/array/interp.pxd
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# distutils: language = c++

cdef Py_ssize_t binary_search_with_guess(double key, double[:] array, Py_ssize_t length, Py_ssize_t guess) nogil
cdef Py_ssize_t binary_search_with_guess(double key, double[:] array, Py_ssize_t length, Py_ssize_t guess) noexcept nogil

cpdef (double, Py_ssize_t) interpj(double desired_x, double[:] x_domain, double[:] dependent_values,
Py_ssize_t provided_j = *) nogil
Py_ssize_t provided_j = *) noexcept nogil

cpdef (double complex, Py_ssize_t) interp_complexj(double desired_x, double[:] x_domain,
double complex[:] dependent_values, Py_ssize_t provided_j = *) nogil
double complex[:] dependent_values, Py_ssize_t provided_j = *) noexcept nogil

cpdef double interp(double desired_x, double[:] x_domain, double[:] dependent_values,
Py_ssize_t provided_j = *) nogil
Py_ssize_t provided_j = *) noexcept nogil

cpdef double complex interp_complex(double desired_x, double[:] x_domain, double complex[:] dependent_values,
Py_ssize_t provided_j = *) nogil
Py_ssize_t provided_j = *) noexcept nogil

cpdef void interp_array(double[:] desired_x_array, double[:] x_domain, double[:] dependent_values,
double[:] desired_dependent_array) nogil
double[:] desired_dependent_array) noexcept nogil

cpdef void interp_complex_array(double[:] desired_x_array, double[:] x_domain, double complex[:] dependent_values,
double complex[:] desired_dependent_array) nogil
double complex[:] desired_dependent_array) noexcept nogil
14 changes: 7 additions & 7 deletions CyRK/array/interp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ EPS = np.finfo(dtype=np.float64).eps
cdef Py_ssize_t LIKELY_IN_CACHE_SIZE = 8


cdef Py_ssize_t binary_search_with_guess(double key, double[:] array, Py_ssize_t length, Py_ssize_t guess) nogil:
cdef Py_ssize_t binary_search_with_guess(double key, double[:] array, Py_ssize_t length, Py_ssize_t guess) noexcept nogil:
""" Binary search with guess.
Based on `numpy`'s `binary_search_with_guess` function.
Expand Down Expand Up @@ -94,7 +94,7 @@ cdef Py_ssize_t binary_search_with_guess(double key, double[:] array, Py_ssize_t


cpdef (double, Py_ssize_t) interpj(double desired_x, double[:] x_domain, double[:] dependent_values,
Py_ssize_t provided_j = -1) nogil:
Py_ssize_t provided_j = -1) noexcept nogil:
""" Interpolation function for floats. This function will return the index that it found during interpolation.
Provided a domain, `x_domain` and a dependent array `dependent_values` search domain for value closest to
Expand Down Expand Up @@ -186,7 +186,7 @@ cpdef (double, Py_ssize_t) interpj(double desired_x, double[:] x_domain, double[


cpdef (double complex, Py_ssize_t) interp_complexj(double desired_x, double[:] x_domain,
double complex[:] dependent_values, Py_ssize_t provided_j = -1) nogil:
double complex[:] dependent_values, Py_ssize_t provided_j = -1) noexcept nogil:
""" Interpolation function for complex numbers.
Provided a domain, `desired_x` and a dependent array `dependent_values` search domain for value closest to
Expand Down Expand Up @@ -305,7 +305,7 @@ cpdef (double complex, Py_ssize_t) interp_complexj(double desired_x, double[:] x
return result, j_out


cpdef double interp(double desired_x, double[:] x_domain, double[:] dependent_values, Py_ssize_t provided_j = -1) nogil:
cpdef double interp(double desired_x, double[:] x_domain, double[:] dependent_values, Py_ssize_t provided_j = -1) noexcept nogil:
""" Interpolation function for floats.
Provided a domain, `x_domain` and a dependent array `dependent_values` search domain for value closest to
Expand Down Expand Up @@ -391,7 +391,7 @@ cpdef double interp(double desired_x, double[:] x_domain, double[:] dependent_va


cpdef double complex interp_complex(double desired_x, double[:] x_domain,
double complex[:] dependent_values, Py_ssize_t provided_j = -1) nogil:
double complex[:] dependent_values, Py_ssize_t provided_j = -1) noexcept nogil:
""" Interpolation function for complex numbers.
Provided a domain, `desired_x` and a dependent array `dependent_values` search domain for value closest to
Expand Down Expand Up @@ -505,7 +505,7 @@ cpdef double complex interp_complex(double desired_x, double[:] x_domain,


cpdef void interp_array(double[:] desired_x_array, double[:] x_domain, double[:] dependent_values,
double[:] desired_dependent_array) nogil:
double[:] desired_dependent_array) noexcept nogil:

# Array variables
cdef Py_ssize_t index
Expand Down Expand Up @@ -575,7 +575,7 @@ cpdef void interp_array(double[:] desired_x_array, double[:] x_domain, double[:]


cpdef void interp_complex_array(double[:] desired_x_array, double[:] x_domain, double complex[:] dependent_values,
double complex[:] desired_dependent_array) nogil:
double complex[:] desired_dependent_array) noexcept nogil:

# Array variables
cdef Py_ssize_t index
Expand Down
Loading

0 comments on commit 3c63364

Please sign in to comment.