diff --git a/examples/speed_tests_numba_and_cython.ipynb b/examples/speed_tests_numba_and_cython.ipynb index 05c3e20..665ad7f 100644 --- a/examples/speed_tests_numba_and_cython.ipynb +++ b/examples/speed_tests_numba_and_cython.ipynb @@ -51,7 +51,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 50, "metadata": { "cellView": "form", "id": "xKirGWMNdvAs" @@ -61,6 +61,9 @@ "#@title Imports and Definitions\n", "import time\n", "import numpy as np\n", + "import plotly.graph_objects as go\n", + "\n", + "\n", "import matplotlib.pyplot as plt\n", "from plotly.subplots import make_subplots\n", "import plotly.graph_objects as go\n", @@ -84,6 +87,9 @@ "psi_n_sfmp_Cython = int_array_cache_Cython(wc.psi_n_single_fock_multiple_position)\n", "psi_n_sfmp_Numba = int_array_cache_Numba_single_fock(wn.psi_n_single_fock_multiple_position)\n", "\n", + "psi_n_mfmp_Cython = int_array_cache_Cython(wc.psi_n_multiple_fock_multiple_position)\n", + "psi_n_mfmp_Numba = int_array_cache_Numba_multiple_fock(wn.psi_n_multiple_fock_multiple_position)\n", + "\n", "%matplotlib inline" ] }, @@ -93,7 +99,7 @@ "## Performance Comparison: Mr Mustard vs. Fast Wave for Single Fock & Single Position Wavefunctions\n", "---\n", "$$$$\n", - "**Explanation:** This analysis evaluates the computational efficiency of three approaches—Mr Mustard, Fast Wave (Numba), and Fast Wave (Cython)—for calculating the squared amplitude $|\\psi_n(x)|^2$ of a Single Fock & Single Position Wavefunction $\\psi_n(x)$. The Single Fock & Single Position wavefunction, $\\psi_{i}(x)$, maps a scalar input $x$ to a scalar output. Execution times for each method are plotted to facilitate comparison.\n", + "**Explanation:** This analysis evaluates the computational efficiency of three approaches — Mr Mustard, Fast Wave (Numba), and Fast Wave (Cython)—for calculating the squared amplitude $|\\psi_n(x)|^2$ of a Single Fock & Single Position Wavefunction $\\psi_n(x)$. The Single Fock & Single Position wavefunction, $\\psi_{i}(x)$, maps a scalar input $x$ to a scalar output. Execution times for each aproach are plotted to facilitate comparison.\n", "$$$$" ], "metadata": { @@ -185,7 +191,7 @@ "$$\\psi_{i}(X_{m}) = [\\psi_{i}(x_{1}), \\psi_{i}(x_{2}), ..., \\psi_{i}(x_{m})]_{\\, m}$$\n", "$$$$\n", "\n", - "Execution times for each method are plotted to facilitate comparison.\n", + "Execution times for each aproach method are plotted to facilitate comparison.\n", "$$$$" ] }, @@ -267,7 +273,7 @@ "## Performance Comparison: Mr Mustard vs. Fast Wave for Multiple Fock & Multiple Position Wavefunctions\n", "---\n", "$$$$\n", - "**Explanation:** This analysis evaluates the computational efficiency of three approaches—Mr Mustard, Fast Wave (Numba), and Fast Wave (Cython) — for calculating of a Multiple Fock & Multiple Position Wavefunction $\\psi_{\\,0\\rightarrow n}\\big(X_{m}\\big)$. The Single Fock & Multiple Position wavefunction, $\\psi_{\\,0\\rightarrow i}\\big(X_{m}\\big)$, maps an array of position inputs $X_{m}$ to an matrix of corresponding outputs, this implies that:\n", + "**Explanation:** This analysis evaluates the computational efficiency of three approaches — Mr Mustard, Fast Wave (Numba), and Fast Wave (Cython) — for calculating the squared amplitude $|\\psi_{\\,0\\rightarrow n}\\big(X_{m}\\big)|^2$ of a Multiple Fock & Multiple Position Wavefunction $\\psi_{\\,0\\rightarrow n}\\big(X_{m}\\big)$. The Multiple Fock & Multiple Position Wavefunction, $\\psi_{\\,0\\rightarrow i}\\big(X_{m}\\big)$, maps an array of position inputs $X_{m}$ to an matrix of corresponding outputs, this implies that:\n", "\n", "$$$$\n", "$$ \\psi_{\\,0\\rightarrow i}\\big(X_{m}\\big) = \\begin{bmatrix}\n", @@ -276,18 +282,111 @@ " \\psi_{i}(x_{1}) & \\cdots & \\psi_{i}(x_{m}) \\\\\n", " \\end{bmatrix}_{(i+1) \\, \\times \\, m}$$\n", "$$$$\n", - "...\n", + "Execution times for each aproach are plotted to facilitate comparison.\n", "$$$$" ] }, { "cell_type": "code", - "source": [], + "source": [ + "n = 5 #@param\n", + "x_max = 5.0 #@param\n", + "x_min = -5.0 #@param\n", + "number_of_points = 5000 #@param\n", + "\n", + "x_values = np.linspace(x_min, x_max, number_of_points)\n", + "\n", + "start_time = time.time()\n", + "y_Psi_n_x_Fast_Wave_Cython = (abs(psi_n_mfmp_Cython(n,x_values))**2).tolist()\n", + "Fast_Wave_Cython_time = time.time() - start_time\n", + "\n", + "start_time = time.time()\n", + "y_Psi_n_x_Fast_Wave_Numba = (abs(psi_n_mfmp_Numba(n,x_values))**2).tolist()\n", + "Fast_Wave_Numba_time = time.time() - start_time\n", + "\n", + "start_time = time.time()\n", + "y_Psi_n_x_Mr_Mustard = (abs((oscillator_eigenstate(x_values*h_bar_12,n+1)*h_bar_14))**2).tolist()\n", + "Mr_Mustard_time = time.time() - start_time\n", + "\n", + "\n", + "approaches = [\"Mr Mustard\", \"Fast Wave (Numba)\", \"Fast Wave (Cython)\"]\n", + "execution_times = [Mr_Mustard_time, Fast_Wave_Numba_time, Fast_Wave_Cython_time]\n", + "\n", + "fig = go.Figure(data=[go.Bar(\n", + " x=approaches,\n", + " y=execution_times,\n", + " marker=dict(\n", + " color=['#800080', '#008000', '#FFFF00'],\n", + " )\n", + ")])\n", + "\n", + "fig.update_layout(\n", + " title=\"Runtime Comparison\",\n", + " xaxis_title=\"Approach\",\n", + " yaxis_title=\"Runtime (s)\",\n", + " bargap=0.6,\n", + " plot_bgcolor='rgba(0,0,0,0)',\n", + " paper_bgcolor='rgba(255,255,255,0.8)',\n", + " font=dict(\n", + " family=\"Courier New, monospace\",\n", + " size=18,\n", + " color=\"#7f7f7f\"\n", + " ),\n", + " width=800,\n", + " height=400\n", + ")" + ], "metadata": { - "id": "WaYYDVs6PLWq" + "id": "WaYYDVs6PLWq", + "cellView": "form", + "outputId": "d37e2558-0e0c-41a5-d849-e5fee91c8e1b", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 437 + } }, - "execution_count": null, - "outputs": [] + "execution_count": 60, + "outputs": [ + { + "output_type": "display_data", + "data": { + "text/html": [ + "\n", + "
\n", + "\n", + "