Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ver0.11.0 #68

Merged
merged 8 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 5 additions & 22 deletions Benchmarks/Accuracy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,15 @@
"metadata": {},
"outputs": [],
"source": [
"from CyRK import pysolve_ivp, cyrk_ode\n",
"from CyRK import pysolve_ivp\n",
"from scipy.integrate import solve_ivp"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "a1305367",
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand Down Expand Up @@ -128,7 +126,6 @@
"rtols = [1.0e-5, 1.0e-7, 1.0e-9, 1.0e-11]\n",
"\n",
"integration_method = 'RK45'\n",
"rk_method = 1\n",
"t_span = (0., 10.)\n",
"t_eval = np.linspace(0.0, 10.0, 100)\n",
"\n",
Expand All @@ -142,21 +139,16 @@
" scipy_sol = solve_ivp(diffeq_accuracy_3, t_span, y0, rtol=rtol, atol=atol, method=integration_method)\n",
" scipy_teval = solve_ivp(diffeq_accuracy_3, t_span, y0, rtol=rtol, atol=atol, method=integration_method, t_eval=t_eval)\n",
" \n",
" cyrk_sol = cyrk_ode(diffeq_accuracy_2, t_span, y0, rtol=rtol, atol=atol, rk_method=rk_method, raise_warnings=False)\n",
" cyrk_teval = cyrk_ode(diffeq_accuracy_2, t_span, y0, rtol=rtol, atol=atol, rk_method=rk_method, t_eval=t_eval, raise_warnings=False)\n",
" \n",
" pysolve_sol = pysolve_ivp(diffeq_accuracy, t_span, y0, rtol=rtol, atol=atol, method=integration_method, dense_output=True, pass_dy_as_arg=True)\n",
" pysolve_teval = pysolve_ivp(diffeq_accuracy, t_span, y0, rtol=rtol, atol=atol, method=integration_method, t_eval=t_eval, pass_dy_as_arg=True)\n",
" print(pysolve_sol.t.shape)\n",
" chi_sci_sol = np.nansum((scipy_sol.y - correct_answer(scipy_sol.t, c1, c2))**2 / correct_answer(scipy_sol.t, c1, c2))\n",
" chi_crykode_sol = np.nansum((cyrk_sol[1] - correct_answer(cyrk_sol[0], c1, c2))**2 / correct_answer(cyrk_sol[0], c1, c2))\n",
" chi_pysolve_sol = np.nansum((pysolve_sol.y - correct_answer(pysolve_sol.t, c1, c2))**2 / correct_answer(pysolve_sol.t, c1, c2))\n",
" \n",
" print(f\"SciPy (sol)\\t|\\tPySolve (sol)\\t|\\tcyrk_ode (sol)\")\n",
" print(f\"{chi_sci_sol:0.5e}\\t|\\t{chi_pysolve_sol:0.5e}\\t|\\t{chi_crykode_sol:0.5e}\")\n",
" print(f\"SciPy (sol)\\t|\\tPySolve (sol)\")\n",
" print(f\"{chi_sci_sol:0.5e}\\t|\\t{chi_pysolve_sol:0.5e}\")\n",
" \n",
" chi_sci_teval = np.nansum((scipy_teval.y - correct_answer(scipy_teval.t, c1, c2))**2 / correct_answer(scipy_teval.t, c1, c2))\n",
" chi_crykode_teval = np.nansum((cyrk_teval[1] - correct_answer(cyrk_teval[0], c1, c2))**2 / correct_answer(cyrk_teval[0], c1, c2))\n",
" chi_pysolve_teval = np.nansum((pysolve_teval.y - correct_answer(pysolve_teval.t, c1, c2))**2 / correct_answer(pysolve_teval.t, c1, c2))\n",
" dense_sol = pysolve_sol(t_eval)\n",
" chi_pysolve_dense = np.nansum((dense_sol - correct_answer(t_eval, c1, c2))**2 / correct_answer(t_eval, c1, c2))\n",
Expand Down Expand Up @@ -202,24 +194,15 @@
"# ax5.scatter(pysolve_sol.t, np.zeros_like(scipy_sol.t), c='purple', s=5)\n",
"# ax5.set(title=\"SciPy (sol) - pysolve\")\n",
" \n",
"# fig5, ax5 = plt.subplots()\n",
"# ax5.plot(cyrk_sol[0], (cyrk_sol[1][0] - pysolve_sol.y[0]) / cyrk_sol[1][0], c='b')\n",
"# ax5.plot(cyrk_sol[0], (cyrk_sol[1][1] - pysolve_sol.y[1]) / cyrk_sol[1][1], c='r')\n",
"# ax5.scatter(scipy_sol.t, np.zeros_like(scipy_sol.t), c='g', s=1)\n",
"# ax5.scatter(pysolve_sol.t, np.zeros_like(scipy_sol.t), c='purple', s=5)\n",
"# ax5.set(title=\"cyrk_ode - pysolve_sol\")\n",
" \n",
"# sci_step_size = np.diff(scipy_sol.t)\n",
"# solpy_step_size = np.diff(pysolve_sol.t)\n",
"# cyrk_step_size = np.diff(cyrk_sol[0])\n",
" \n",
"# fig5, ax5 = plt.subplots()\n",
"# # ax5.plot(scipy_sol.t, (scipy_sol.y[0] - pysolve_sol.y[0]) / scipy_sol.y[0], c='b', ls=':')\n",
"# # ax5.plot(scipy_sol.t, (scipy_sol.y[1] - pysolve_sol.y[1]) / scipy_sol.y[1], c='r', ls=':')\n",
"# ax5b = ax5.twinx()\n",
"# ax5b.plot(scipy_sol.t[1:], sci_step_size, c='b', marker='.')\n",
"# ax5b.plot(pysolve_sol.t[1:], solpy_step_size, c='r', marker='.')\n",
"# # ax5b.plot(cyrk_sol[0][1:], cyrk_step_size, c='orange', marker='.')\n",
"# ax5b.set(ylim=(0.3, 0.4))\n",
"# plt.show()\n",
" \n",
Expand Down Expand Up @@ -444,7 +427,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
220 changes: 101 additions & 119 deletions Benchmarks/CyRK - SciPy Comparison.ipynb

Large diffs are not rendered by default.

Binary file modified Benchmarks/CyRK_CySolver.pdf
Binary file not shown.
Binary file modified Benchmarks/CyRK_PySolver (njit).pdf
Binary file not shown.
Binary file modified Benchmarks/CyRK_PySolver.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_numba.pdf
Binary file not shown.
Binary file modified Benchmarks/SciPy.pdf
Binary file not shown.
31 changes: 31 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,37 @@

## 2024

#### v0.11.0 (2024-NNN)

New:
* `WrapCySolverResult` result class now provides user access to attribute `num_y`.

Removed:
* Removed previous `cyrk_ode` and older version of the `CySolver` class-based solver.
* The functionality of `cyrk_ode` is now handled by the new (as of v0.10.0) `pysolve_ivp` function.
* The functionality of `CySolver` is partly handled by the new (as of v0.10.0) `cysolve_ivp` function.
* Note that the new cysolve_ivp is a functional approach. A class based approach like the older CySolver class supported is no longer available but could be easy to implement. If there is interest please create a Github issue for it.

Refactors:
* Refactored the new cysolver and pysolver files to remove "New". This will break imports based on previous versions.
* Broke up cysolver and pysolver into different files to isolate each other's code.

Other:
* Changed the default ordering for diffeq function inputs to follow the scheme dydt(dy, t, y); previously it was dydt(t, y, dy). This affects the `cy2nb` and `nb2cy` helper functions.
* Updated performance module to use new methods over old.

Demos:
* Fixed typo in the type of the mixed-type args container.
* Updated to work with new refactoring.

Tests:
* Updated tests to use pysolver where cyrk_ode was used.
* Changed tolerances and other inputs to try to make some tests faster.

Dependencies:
* Tested that CyRK works with numpy v2.X; but a lot of other packages don't right now. So setting it as upper limit.
* Tested that CyRK can not work with Python 3.13 yet due to numba dependence. See issue

#### v0.10.2 (2024-11-05)

New:
Expand Down
2 changes: 1 addition & 1 deletion CyRK/__init__.pxd
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from CyRK.cy.cysolverNew cimport cysolve_ivp, cysolve_ivp_gil, DiffeqFuncType, PreEvalFunc, CySolverResult, WrapCySolverResult, CySolverBase, CySolveOutput, RK23_METHOD_INT, RK45_METHOD_INT, DOP853_METHOD_INT
from CyRK.cy.cysolver_api cimport cysolve_ivp, cysolve_ivp_gil, DiffeqFuncType, PreEvalFunc, CySolverResult, WrapCySolverResult, CySolverBase, CySolveOutput, RK23_METHOD_INT, RK45_METHOD_INT, DOP853_METHOD_INT
from CyRK.cy.helpers cimport interpolate_from_solution_list
6 changes: 2 additions & 4 deletions CyRK/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
# Import numba solver
from .nb.nbrk import nbsolve_ivp

# Import cython solver
from CyRK.cy.cyrk import cyrk_ode

# Import helper functions
from .helper import nb2cy, cy2nb

# Import test functions
from ._test import test_nbrk, test_cysolver, test_pysolver

# Import python solver
from CyRK.cy.cysolverNew import pysolve_ivp
from CyRK.cy.cysolver_api import WrapCySolverResult
from CyRK.cy.pysolver import pysolve_ivp
2 changes: 1 addition & 1 deletion CyRK/_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_pysolver():

def test_cysolver():

from CyRK.cy.cysolverNew_test import cytester
from CyRK.cy.cysolver_test import cytester

result = cytester(0,
time_span,
Expand Down
55 changes: 0 additions & 55 deletions CyRK/cy/common.pxd

This file was deleted.

Loading
Loading