.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/benchmarks/plot_modal.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_benchmarks_plot_modal.py: Benchmark Modal =============== Numerical backends performace comparison, with GPU acceleration, as run on Modal (https://modal.com) .. GENERATED FROM PYTHON SOURCE LINES 13-57 .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/benchmarks/images/sphx_glr_plot_modal_001.png :alt: plot modal :srcset: /examples/benchmarks/images/sphx_glr_plot_modal_001.png :class: sphx-glr-multi-img * .. image-sg:: /examples/benchmarks/images/sphx_glr_plot_modal_002.png :alt: plot modal :srcset: /examples/benchmarks/images/sphx_glr_plot_modal_002.png :class: sphx-glr-multi-img .. code-block:: Python import os import matplotlib.pyplot as plt import numpy as np backends = ["numpy", "scipy", "autograd", "jax", "torch"] inputs = [(b, "cpu") for b in backends] inputs += [(b, "gpu") for b in ["jax", "torch"]] t = [] plt.figure() for i in inputs: backend, device = i fname = f"modal/benchmark_{backend}_{device}.npz" arch = np.load(fname) times = arch["times"] times_all = arch["times_all"] real_nh = arch["real_nh"] nh = arch["nh"] t.append(times_all) plt.plot(real_nh, times_all, "-o", label=f"{backend} {device}") plt.legend() plt.xlabel("number of harmonics") plt.ylabel("time [s]") plt.xscale("log") plt.yscale("log") plt.figure() for j, i in enumerate(inputs): backend, device = i plt.plot(real_nh, t[0] / t[j], "-o", label=f"{backend} {device}") plt.legend() plt.xlabel("number of harmonics") plt.ylabel("speedup vs numpy") plt.xscale("log") # plt.yscale("log") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.622 seconds) **Estimated memory usage:** 519 MB .. _sphx_glr_download_examples_benchmarks_plot_modal.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/nannos/nannos.gitlab.io/doc?filepath=notebooks/examples/benchmarks/plot_modal.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_modal.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_modal.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_modal.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_