Skip to content

Commit

Permalink
Criado usando o Colab
Browse files Browse the repository at this point in the history
  • Loading branch information
fobos123deimos committed Nov 18, 2024
1 parent bff869d commit ef40da1
Showing 1 changed file with 108 additions and 9 deletions.
117 changes: 108 additions & 9 deletions examples/speed_tests_numba_and_cython.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 50,
"metadata": {
"cellView": "form",
"id": "xKirGWMNdvAs"
Expand All @@ -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",
Expand All @@ -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"
]
},
Expand All @@ -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 approachesMr 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 approachesMr 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": {
Expand Down Expand Up @@ -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",
"$$$$"
]
},
Expand Down Expand Up @@ -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 approachesMr 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 approachesMr 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",
Expand All @@ -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": [
"<html>\n",
"<head><meta charset=\"utf-8\" /></head>\n",
"<body>\n",
" <div> <script src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_SVG\"></script><script type=\"text/javascript\">if (window.MathJax && window.MathJax.Hub && window.MathJax.Hub.Config) {window.MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}</script> <script type=\"text/javascript\">window.PlotlyConfig = {MathJaxConfig: 'local'};</script>\n",
" <script charset=\"utf-8\" src=\"https://cdn.plot.ly/plotly-2.35.2.min.js\"></script> <div id=\"c5eae8c7-787d-44cd-a925-1feee3e10529\" class=\"plotly-graph-div\" style=\"height:400px; width:800px;\"></div> <script type=\"text/javascript\"> window.PLOTLYENV=window.PLOTLYENV || {}; if (document.getElementById(\"c5eae8c7-787d-44cd-a925-1feee3e10529\")) { Plotly.newPlot( \"c5eae8c7-787d-44cd-a925-1feee3e10529\", [{\"marker\":{\"color\":[\"#800080\",\"#008000\",\"#FFFF00\"]},\"x\":[\"Mr Mustard\",\"Fast Wave (Numba)\",\"Fast Wave (Cython)\"],\"y\":[0.001405954360961914,0.0014638900756835938,0.0021483898162841797],\"type\":\"bar\"}], {\"template\":{\"data\":{\"histogram2dcontour\":[{\"type\":\"histogram2dcontour\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"choropleth\":[{\"type\":\"choropleth\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"histogram2d\":[{\"type\":\"histogram2d\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmap\":[{\"type\":\"heatmap\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmapgl\":[{\"type\":\"heatmapgl\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"contourcarpet\":[{\"type\":\"contourcarpet\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"contour\":[{\"type\":\"contour\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"surface\":[{\"type\":\"surface\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"mesh3d\":[{\"type\":\"mesh3d\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"scatter\":[{\"fillpattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2},\"type\":\"scatter\"}],\"parcoords\":[{\"type\":\"parcoords\",\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterpolargl\":[{\"type\":\"scatterpolargl\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"bar\":[{\"error_x\":{\"color\":\"#2a3f5f\"},\"error_y\":{\"color\":\"#2a3f5f\"},\"marker\":{\"line\":{\"color\":\"#E5ECF6\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"bar\"}],\"scattergeo\":[{\"type\":\"scattergeo\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterpolar\":[{\"type\":\"scatterpolar\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"histogram\":[{\"marker\":{\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"histogram\"}],\"scattergl\":[{\"type\":\"scattergl\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatter3d\":[{\"type\":\"scatter3d\",\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scattermapbox\":[{\"type\":\"scattermapbox\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterternary\":[{\"type\":\"scatterternary\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scattercarpet\":[{\"type\":\"scattercarpet\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"carpet\":[{\"aaxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"minorgridcolor\":\"white\",\"startlinecolor\":\"#2a3f5f\"},\"baxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"minorgridcolor\":\"white\",\"startlinecolor\":\"#2a3f5f\"},\"type\":\"carpet\"}],\"table\":[{\"cells\":{\"fill\":{\"color\":\"#EBF0F8\"},\"line\":{\"color\":\"white\"}},\"header\":{\"fill\":{\"color\":\"#C8D4E3\"},\"line\":{\"color\":\"white\"}},\"type\":\"table\"}],\"barpolar\":[{\"marker\":{\"line\":{\"color\":\"#E5ECF6\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"barpolar\"}],\"pie\":[{\"automargin\":true,\"type\":\"pie\"}]},\"layout\":{\"autotypenumbers\":\"strict\",\"colorway\":[\"#636efa\",\"#EF553B\",\"#00cc96\",\"#ab63fa\",\"#FFA15A\",\"#19d3f3\",\"#FF6692\",\"#B6E880\",\"#FF97FF\",\"#FECB52\"],\"font\":{\"color\":\"#2a3f5f\"},\"hovermode\":\"closest\",\"hoverlabel\":{\"align\":\"left\"},\"paper_bgcolor\":\"white\",\"plot_bgcolor\":\"#E5ECF6\",\"polar\":{\"bgcolor\":\"#E5ECF6\",\"angularaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"radialaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"}},\"ternary\":{\"bgcolor\":\"#E5ECF6\",\"aaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"baxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"caxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"}},\"coloraxis\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"colorscale\":{\"sequential\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"sequentialminus\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"diverging\":[[0,\"#8e0152\"],[0.1,\"#c51b7d\"],[0.2,\"#de77ae\"],[0.3,\"#f1b6da\"],[0.4,\"#fde0ef\"],[0.5,\"#f7f7f7\"],[0.6,\"#e6f5d0\"],[0.7,\"#b8e186\"],[0.8,\"#7fbc41\"],[0.9,\"#4d9221\"],[1,\"#276419\"]]},\"xaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"white\",\"automargin\":true,\"zerolinewidth\":2},\"yaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"white\",\"automargin\":true,\"zerolinewidth\":2},\"scene\":{\"xaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2},\"yaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2},\"zaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2}},\"shapedefaults\":{\"line\":{\"color\":\"#2a3f5f\"}},\"annotationdefaults\":{\"arrowcolor\":\"#2a3f5f\",\"arrowhead\":0,\"arrowwidth\":1},\"geo\":{\"bgcolor\":\"white\",\"landcolor\":\"#E5ECF6\",\"subunitcolor\":\"white\",\"showland\":true,\"showlakes\":true,\"lakecolor\":\"white\"},\"title\":{\"x\":0.05},\"mapbox\":{\"style\":\"light\"}}},\"font\":{\"family\":\"Courier New, monospace\",\"size\":18,\"color\":\"#7f7f7f\"},\"title\":{\"text\":\"Runtime Comparison\"},\"xaxis\":{\"title\":{\"text\":\"Approach\"}},\"yaxis\":{\"title\":{\"text\":\"Runtime (s)\"}},\"bargap\":0.6,\"plot_bgcolor\":\"rgba(0,0,0,0)\",\"paper_bgcolor\":\"rgba(255,255,255,0.8)\",\"width\":800,\"height\":400}, {\"responsive\": true} ).then(function(){\n",
" \n",
"var gd = document.getElementById('c5eae8c7-787d-44cd-a925-1feee3e10529');\n",
"var x = new MutationObserver(function (mutations, observer) {{\n",
" var display = window.getComputedStyle(gd).display;\n",
" if (!display || display === 'none') {{\n",
" console.log([gd, 'removed!']);\n",
" Plotly.purge(gd);\n",
" observer.disconnect();\n",
" }}\n",
"}});\n",
"\n",
"// Listen for the removal of the full notebook cells\n",
"var notebookContainer = gd.closest('#notebook-container');\n",
"if (notebookContainer) {{\n",
" x.observe(notebookContainer, {childList: true});\n",
"}}\n",
"\n",
"// Listen for the clearing of the current output cell\n",
"var outputEl = gd.closest('.output');\n",
"if (outputEl) {{\n",
" x.observe(outputEl, {childList: true});\n",
"}}\n",
"\n",
" }) }; </script> </div>\n",
"</body>\n",
"</html>"
]
},
"metadata": {}
}
]
}
],
"metadata": {
Expand Down

0 comments on commit ef40da1

Please sign in to comment.