-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |