.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_data_cube_sbs.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. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_data_cube_sbs.py: .. _l-plot-data-cube-sbs: Side by side comparison of two configurations ============================================= :meth:`data_cube.DataCube.sbs` compares two (or more) configurations, each one defined by a set of key values. For every pair of configurations and every metric, it counts how many times a metric is missing in one configuration or both, how many times one is lower, equal or greater than the other, and it sums the metric over the rows where both are available. Data ++++ Two exporters are benchmarked over three models and two days. Some runs failed (empty values), and one run uses another optimization level, it is excluded by the configurations. .. GENERATED FROM PYTHON SOURCE LINES 20-52 .. code-block:: Python import io import textwrap import pandas import matplotlib.pyplot as plt from data_cube import DataCube pandas.set_option("display.width", 250) pandas.set_option("display.max_columns", 30) df = pandas.read_csv(io.StringIO(textwrap.dedent(""" date,model_name,exporter,opt,time_latency,accuracy 2025/01/01,phi3,export,O2,0.10,0.99 2025/01/01,phi3,dynamo,O2,0.12,0.99 2025/01/01,phi4,export,O2,0.20,0.98 2025/01/01,phi4,dynamo,O2,, 2025/01/01,llama,export,O2,0.31,0.97 2025/01/01,llama,dynamo,O2,0.29,0.97 2025/01/02,phi3,export,O2,0.09,0.99 2025/01/02,phi3,dynamo,O2,0.11,0.99 2025/01/02,phi4,export,O2,0.21,0.98 2025/01/02,phi4,dynamo,O2,0.19,0.98 2025/01/02,llama,export,O2,, 2025/01/02,llama,dynamo,O2,0.28,0.96 2025/01/02,llama,dynamo,O0,0.40,0.96 """))) cube = DataCube( df, time="date", keys=["model_name", "exporter", "opt"], values=["time_.*", "accuracy"] ).load() print(cube.describe()) .. rst-class:: sphx-glr-script-out .. code-block:: none dtype missing kind count min max mean sum n_values values name date datetime64[ns] 0 time 13 2025-01-01 00:00:00 2025-01-02 00:00:00 NaN NaN 2 2025-01-01 00:00:00 - 2025-01-02 00:00:00 model_name object 0 keys 13 NaN NaN NaN NaN 3 llama,phi3,phi4 exporter object 0 keys 13 NaN NaN NaN NaN 2 dynamo,export opt object 0 keys 13 NaN NaN NaN NaN 2 O0,O2 time_latency float64 2 values 11 0.09 0.4 0.209091 2.30 11 NaN accuracy float64 2 values 11 0.96 0.99 0.978182 10.76 4 NaN .. GENERATED FROM PYTHON SOURCE LINES 53-58 Side by side ++++++++++++ Every configuration has a name and a dictionary ``{key: value}`` selecting the rows it contains. All configurations must use the same keys. .. GENERATED FROM PYTHON SOURCE LINES 58-62 .. code-block:: Python configs = dict(EXPORT=dict(exporter="export", opt="O2"), DYNAMO=dict(exporter="dynamo", opt="O2")) sbs, sbs_agg, sbs_col = cube.sbs(configs) .. GENERATED FROM PYTHON SOURCE LINES 63-73 The first dataframe has one row per metric, model and date. The column level ``CONF`` contains the configuration names followed by the comparison columns: * ``∅EXPORT∧∅DYNAMO``: both values are missing, * ``∅EXPORT∧DYNAMO``, ``EXPORT∧∅DYNAMO``: only one value is missing, * ``EXPORT∧DYNAMO``: both values are available, * ``EXPORTDYNAMO``: comparison, * ``EXPORT*(EXPORT∧DYNAMO)``, ``DYNAMO*(EXPORT∧DYNAMO)``: the value when both are available, 0 otherwise. .. GENERATED FROM PYTHON SOURCE LINES 73-77 .. code-block:: Python print(sbs.columns.tolist()) print(sbs.loc["time_latency"]) .. rst-class:: sphx-glr-script-out .. code-block:: none [('DYNAMO', 'dynamo'), ('EXPORT', 'export'), ('∅EXPORT∧∅DYNAMO', ''), ('∅EXPORT∧DYNAMO', ''), ('EXPORT∧∅DYNAMO', ''), ('EXPORT∧DYNAMO', ''), ('EXPORTDYNAMO', ''), ('EXPORT*(EXPORT∧DYNAMO)', ''), ('DYNAMO*(EXPORT∧DYNAMO)', '')] CONF DYNAMO EXPORT ∅EXPORT∧∅DYNAMO ∅EXPORT∧DYNAMO EXPORT∧∅DYNAMO EXPORT∧DYNAMO EXPORTDYNAMO EXPORT*(EXPORT∧DYNAMO) DYNAMO*(EXPORT∧DYNAMO) exporter dynamo export model_name date llama 2025-01-01 0.29 0.31 0 0 0 1 0 0 1 0.31 0.29 2025-01-02 0.28 NaN 0 1 0 0 0 0 0 NaN 0.00 phi3 2025-01-01 0.12 0.10 0 0 0 1 1 0 0 0.10 0.12 2025-01-02 0.11 0.09 0 0 0 1 1 0 0 0.09 0.11 phi4 2025-01-01 NaN 0.20 0 0 1 0 0 0 0 0.00 NaN 2025-01-02 0.19 0.21 0 0 0 1 0 0 1 0.21 0.19 .. GENERATED FROM PYTHON SOURCE LINES 78-82 The second dataframe aggregates over the models for every date. The metrics are averaged, the comparison columns are summed. Summing the last two columns gives the total latency of both exporters over the models where both succeeded, a fair comparison. .. GENERATED FROM PYTHON SOURCE LINES 82-85 .. code-block:: Python print(sbs_agg) .. rst-class:: sphx-glr-script-out .. code-block:: none CONF DYNAMO EXPORT ∅EXPORT∧∅DYNAMO ∅EXPORT∧DYNAMO EXPORT∧∅DYNAMO EXPORT∧DYNAMO EXPORTDYNAMO EXPORT*(EXPORT∧DYNAMO) DYNAMO*(EXPORT∧DYNAMO) exporter dynamo export date METRICS 2025-01-01 accuracy 0.980000 0.980000 0 0 1 2 0 2 0 1.96 1.96 time_latency 0.205000 0.203333 0 0 1 2 1 0 1 0.41 0.41 2025-01-02 accuracy 0.976667 0.985000 0 1 0 2 0 2 0 1.97 1.97 time_latency 0.193333 0.150000 0 1 0 2 1 0 1 0.30 0.30 .. GENERATED FROM PYTHON SOURCE LINES 86-88 The third dataframe moves the metrics into the columns, one row per model and date. .. GENERATED FROM PYTHON SOURCE LINES 88-92 .. code-block:: Python print(sbs_col.index.names, sbs_col.columns.names) print(sbs_col["time_latency"][["EXPORT", "DYNAMO"]]) .. rst-class:: sphx-glr-script-out .. code-block:: none ['model_name', 'date'] ['METRICS', 'CONF', 'exporter'] CONF EXPORT DYNAMO exporter export dynamo model_name date llama 2025-01-01 0.31 0.29 2025-01-02 NaN 0.28 phi3 2025-01-01 0.10 0.12 2025-01-02 0.09 0.11 phi4 2025-01-01 0.20 NaN 2025-01-02 0.21 0.19 .. GENERATED FROM PYTHON SOURCE LINES 93-107 Excel +++++ :meth:`data_cube.DataCube.to_excel` adds the side by side in dedicated sheets with ``sbs=configs``. .. code-block:: python cube.to_excel("report.xlsx", views=["time_latency"], sbs=configs) Plot ++++ Latency of both exporters for every model and date. .. GENERATED FROM PYTHON SOURCE LINES 107-112 .. code-block:: Python latency = sbs.loc["time_latency"][["EXPORT", "DYNAMO"]].droplevel("exporter", axis=1) ax = latency.plot.bar(title="time_latency, EXPORT vs DYNAMO") ax.set_ylabel("seconds") plt.tight_layout() .. image-sg:: /auto_examples/images/sphx_glr_plot_data_cube_sbs_001.png :alt: time_latency, EXPORT vs DYNAMO :srcset: /auto_examples/images/sphx_glr_plot_data_cube_sbs_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.111 seconds) .. _sphx_glr_download_auto_examples_plot_data_cube_sbs.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_data_cube_sbs.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_data_cube_sbs.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_data_cube_sbs.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_