Skip to content

Commit

Permalink
benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
alanlujan91 committed Nov 7, 2024
1 parent 0b9a5e4 commit 5c97e36
Show file tree
Hide file tree
Showing 11 changed files with 387 additions and 103 deletions.
13 changes: 2 additions & 11 deletions papers/alan_lujan/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -488,23 +488,14 @@ The benchmarks were conducted using the following setup:

The first set of benchmarks compares the performance of `multinterp` with `scipy.interpolate.RegularGridInterpolator`, a widely-used interpolation library in the scientific Python ecosystem. The benchmarks were conducted for both 2D and 3D grids, and the results are presented in the following figures.

```{embed} #fig:performance_comparison_2d
```{embed} #fig:multivariate_speed_2d
:remove-input: true
```
```{embed} #fig:performance_comparison_3d
:remove-input: true
```

### Backend Comparison

The second set of benchmarks compares the performance of different backends in `multinterp`. The benchmarks were conducted for both 2D and 3D grids, and the results are presented in the following figures.

```{embed} #fig:backend_comparison_2d
:remove-input: true
```

```{embed} #fig:backend_comparison_3d
```{embed} #fig:multivariate_speed_3d
:remove-input: true
```

Expand Down
23 changes: 10 additions & 13 deletions papers/alan_lujan/notebooks/Curvilinear_Interpolation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
},
{
"cell_type": "markdown",
"metadata": {
"lines_to_next_cell": 2
},
"metadata": {},
"source": [
"Suppose we have a collection of values for an unknown function along with their respective coordinate points. For illustration, assume the values come from the following function:\n"
"Suppose we have a collection of values for an unknown function along with their respective coordinate points. For illustration, assume the values come from the following function:\n",
"\n"
]
},
{
Expand Down Expand Up @@ -231,7 +230,7 @@
}
],
"source": [
"#| label: fig:curvilinear_original\n",
"# | label: fig:curvilinear_original\n",
"\n",
"plt.imshow(function_1(grid_x, grid_y).T, extent=(0, 1, 0, 1), origin=\"lower\")\n",
"plt.plot(rand_x.flat, rand_y.flat, \"ok\", ms=2, label=\"input points\")\n",
Expand Down Expand Up @@ -271,7 +270,7 @@
}
],
"source": [
"#| label: fig:curvilinear_result\n",
"# | label: fig:curvilinear_result\n",
"\n",
"fig, axs = plt.subplots(1, 3, figsize=(9, 6))\n",
"titles = [\"Original\", \"WarpedInterp\", \"CurvilinearInterp\"]\n",
Expand All @@ -289,18 +288,16 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"In short, `multinterp`'s `Warped2DInterp` and `Curvilinear2DInterp` classes are useful for interpolating functions on curvilinear grids which have a quadrilateral structure but are not perfectly rectangular.\n"
"In short, `multinterp`'s `Warped2DInterp` and `Curvilinear2DInterp` classes are useful for interpolating functions on curvilinear grids which have a quadrilateral structure but are not perfectly rectangular.\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
"jupytext": {
"formats": "ipynb,py:percent"
"formats": "ipynb,md"
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
Expand Down
10 changes: 8 additions & 2 deletions papers/alan_lujan/notebooks/Curvilinear_Interpolation.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
jupyter:
jupytext:
formats: ipynb,md
text_representation:
extension: .md
format_name: markdown
Expand Down Expand Up @@ -32,7 +33,7 @@ def function_1(x, y):
return x * (1 - x) * np.cos(4 * np.pi * x) * np.sin(4 * np.pi * y**2) ** 2
```

The points are randomly scattered in the unit square and therefore have no regular structure. This is achieved by randomly shifting a well structured grid at every point.
The points are randomly scattered in the unit square and therefore have no regular structure. This is achieved by randomly shifting a well structured grid at every point.


```python
Expand Down Expand Up @@ -93,6 +94,8 @@ Now we can compare the results of the interpolation with the original function.


```python
# | label: fig:curvilinear_original

plt.imshow(function_1(grid_x, grid_y).T, extent=(0, 1, 0, 1), origin="lower")
plt.plot(rand_x.flat, rand_y.flat, "ok", ms=2, label="input points")
plt.title("Original")
Expand All @@ -104,6 +107,8 @@ Then, we can look at the result for each method of interpolation and compare it


```python
# | label: fig:curvilinear_result

fig, axs = plt.subplots(1, 3, figsize=(9, 6))
titles = ["Original", "WarpedInterp", "CurvilinearInterp"]
grids = [function_1(grid_x, grid_y), warped_grid, curvilinear_grid]
Expand All @@ -117,7 +122,8 @@ plt.show()
```


In short, `multinterp`'s `Warped2DInterp` and `Curvilinear2DInterp` classes are useful for interpolating functions on curvilinear grids which have a quadrilateral structure but are not perfectly rectangular.
In short, `multinterp`'s `Warped2DInterp` and `Curvilinear2DInterp` classes are useful for interpolating functions on curvilinear grids which have a quadrilateral structure but are not perfectly rectangular.




5 changes: 4 additions & 1 deletion papers/alan_lujan/notebooks/Multivalued_Interpolation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
}
],
"source": [
"#| label: fig:multivalued\n",
"# | label: fig:multivalued\n",
"\n",
"mult_interp = MultivaluedInterp(z_mat, [x_grid, y_grid], backend=\"cupy\")\n",
"z_mult_interp = mult_interp(x_new, y_new).get()\n",
Expand Down Expand Up @@ -130,6 +130,9 @@
}
],
"metadata": {
"jupytext": {
"formats": "ipynb,md"
},
"kernelspec": {
"display_name": "multinterp-dev",
"language": "python",
Expand Down
8 changes: 7 additions & 1 deletion papers/alan_lujan/notebooks/Multivalued_Interpolation.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
jupyter:
jupytext:
formats: ipynb,md
text_representation:
extension: .md
format_name: markdown
Expand All @@ -22,6 +23,7 @@ from multinterp.rectilinear._multi import MultivaluedInterp

Consider the following multivalued function:


```python
def squared_coords(x, y):
return x**2 + y**2
Expand All @@ -35,7 +37,8 @@ def multivalued_func(x, y):
return np.array([squared_coords(x, y), trig_func(x, y)])
```

As before, we can generate values on a sample input grid, and create a grid of query points.
As before, we can generate values on a sample input grid, and create a grid of query points.


```python
x_grid = np.geomspace(1, 11, 1000) - 1
Expand All @@ -53,7 +56,10 @@ x_new, y_new = np.meshgrid(

`MultivaluedInterp` can easily interpolate the function at the query points and avoid repeated calculations.


```python
# | label: fig:multivalued

mult_interp = MultivaluedInterp(z_mat, [x_grid, y_grid], backend="cupy")
z_mult_interp = mult_interp(x_new, y_new).get()
z_true = multivalued_func(x_new, y_new)
Expand Down
Loading

0 comments on commit 5c97e36

Please sign in to comment.