Skip to content

Commit

Permalink
Added large Neq test
Browse files Browse the repository at this point in the history
  • Loading branch information
jrenaud90 committed Dec 2, 2024
1 parent 814c3c9 commit 1ef7883
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Tests:
* Fixed tests where additional args were not being used.
* Fixed issue with diffeq test 5.
* This fixes GitHub Issue [#67](https://github.com/jrenaud90/CyRK/issues/67)
* Added tests to solve large number of diffeqs simultaneously to try to catch issues related to GitHub issue [#78](https://github.com/jrenaud90/CyRK/issues/78).

Documentation:
* Updated the "Advanced CySolver.md" documentation that was out of date.
Expand Down
22 changes: 22 additions & 0 deletions Tests/D_PySolver_Tests/test_c_pysolve_large_Neq.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest
import numpy as np
import numba as nb
from CyRK import pysolve_ivp
import math

# define base system
y_0 = 1
t_span = (0.0, 8.0)
@nb.njit("void(f8[::1], f8, f8[::1])")
def cy_diffeq(dy, t, y):
for i in range(y.size):
dy[i] = -y[i]/2 + 2*math.sin(3*t)


@pytest.mark.parametrize('Neqs', (2**20, 2**21, 2**22))
def test_pysolve_large_neqs(Neqs):
""" Tests CyRK's ability to simultaneously solve many copies of this system. """
y0 = np.full(Neqs, y_0, dtype=np.float64)
# For large Neq we need to increase the max_ram_MB limit.
result = pysolve_ivp(cy_diffeq, t_span, y0, method="RK45", rtol=1e-7, atol=1e-7, pass_dy_as_arg=True, max_ram_MB=8_000)
assert result.success
122 changes: 122 additions & 0 deletions Tests/Large System Sizes.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "ec2c0de3-c8e5-4c21-a0ab-76bdf0df87a4",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import numba as nb\n",
"from CyRK import pysolve_ivp\n",
"import math\n",
"\n",
"# define base system\n",
"y_0 = 1\n",
"t_span = (0.0, 8.0)\n",
"@nb.njit(\"void(f8[::1], f8, f8[::1])\")\n",
"def cy_diffeq(dy, t, y):\n",
" for i in range(y.size):\n",
" dy[i] = -y[i]/2 + 2*math.sin(3*t)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "4b5215bf-6373-41a9-a2ea-bbeaeb600b00",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2097152\n",
"True Integration completed without issue.\n",
"Steps Required: 61\n"
]
}
],
"source": [
"# simultaneously solve many copies of this system\n",
"Neqs = 2**21\n",
"print(Neqs)\n",
"y0 = np.full(Neqs, y_0, dtype=np.float64)\n",
"result = pysolve_ivp(cy_diffeq, t_span, y0, method=\"RK45\", rtol=1e-7, atol=1e-7, pass_dy_as_arg=True)\n",
"print(result.success, result.message)\n",
"print(\"Steps Required:\", result.steps_taken)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "43b00850-8d6d-4726-851b-dd1f0aef26cf",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4194304\n",
"False Maximum number of steps (set by system architecture) exceeded during integration.\n",
"Steps Required: 58\n"
]
}
],
"source": [
"Neqs = 2**22\n",
"print(Neqs)\n",
"y0 = np.full(Neqs, y_0, dtype=np.float64)\n",
"result_larger = pysolve_ivp(cy_diffeq, t_span, y0, method=\"RK45\", rtol=1e-7, atol=1e-7, pass_dy_as_arg=True)\n",
"print(result_larger.success, result_larger.message)\n",
"print(\"Steps Required:\", result_larger.steps_taken)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "d1d1ec35-82f0-4d89-8b2d-af584f8b0b69",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4194304\n",
"True Integration completed without issue.\n",
"Steps Required: 61\n"
]
}
],
"source": [
"Neqs = 2**22\n",
"print(Neqs)\n",
"y0 = np.full(Neqs, y_0, dtype=np.float64)\n",
"result_more_steps = pysolve_ivp(cy_diffeq, t_span, y0, method=\"RK45\", rtol=1e-7, atol=1e-7, pass_dy_as_arg=True, max_ram_MB=8_000)\n",
"print(result_more_steps.success, result_more_steps.message)\n",
"print(\"Steps Required:\", result_more_steps.steps_taken)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 1ef7883

Please sign in to comment.