Side by side comparison of two configurations#

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.

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())
                       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

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.

configs = dict(EXPORT=dict(exporter="export", opt="O2"), DYNAMO=dict(exporter="dynamo", opt="O2"))
sbs, sbs_agg, sbs_col = cube.sbs(configs)

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,

  • EXPORT<DYNAMO, EXPORT==DYNAMO, EXPORT>DYNAMO: comparison,

  • EXPORT*(EXPORT∧DYNAMO), DYNAMO*(EXPORT∧DYNAMO): the value when both are available, 0 otherwise.

print(sbs.columns.tolist())
print(sbs.loc["time_latency"])
[('DYNAMO', 'dynamo'), ('EXPORT', 'export'), ('∅EXPORT∧∅DYNAMO', ''), ('∅EXPORT∧DYNAMO', ''), ('EXPORT∧∅DYNAMO', ''), ('EXPORT∧DYNAMO', ''), ('EXPORT<DYNAMO', ''), ('EXPORT==DYNAMO', ''), ('EXPORT>DYNAMO', ''), ('EXPORT*(EXPORT∧DYNAMO)', ''), ('DYNAMO*(EXPORT∧DYNAMO)', '')]
CONF                  DYNAMO EXPORT ∅EXPORT∧∅DYNAMO ∅EXPORT∧DYNAMO EXPORT∧∅DYNAMO EXPORT∧DYNAMO EXPORT<DYNAMO EXPORT==DYNAMO EXPORT>DYNAMO 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

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.

print(sbs_agg)
CONF                       DYNAMO    EXPORT ∅EXPORT∧∅DYNAMO ∅EXPORT∧DYNAMO EXPORT∧∅DYNAMO EXPORT∧DYNAMO EXPORT<DYNAMO EXPORT==DYNAMO EXPORT>DYNAMO 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

The third dataframe moves the metrics into the columns, one row per model and date.

print(sbs_col.index.names, sbs_col.columns.names)
print(sbs_col["time_latency"][["EXPORT", "DYNAMO"]])
['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

Excel#

data_cube.DataCube.to_excel() adds the side by side in dedicated sheets with sbs=configs.

cube.to_excel("report.xlsx", views=["time_latency"], sbs=configs)

Plot#

Latency of both exporters for every model and date.

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()
time_latency, EXPORT vs DYNAMO

Total running time of the script: (0 minutes 0.111 seconds)

Gallery generated by Sphinx-Gallery