Note
Go to the end to download the full example code.
Pivot views over experiment logs#
A data_cube.DataCube loads raw logs, removes the duplicates
and builds pivot views. Keys and values are selected with regular expressions.
Data#
import io
import textwrap
import pandas
import matplotlib.pyplot as plt
from data_cube import DataCube, CubeViewDef
df = pandas.read_csv(io.StringIO(textwrap.dedent("""
date,version_python,model_name,model_exporter,time_latency,time_baseline
2025/01/01,3.13,phi3,export,0.10,0.10
2025/01/02,3.13,phi3,export,0.11,0.11
2025/01/03,3.13,phi3,export,0.09,0.11
2025/01/01,3.13,phi4,export,0.10,0.105
2025/01/02,3.13,phi4,export,0.12,0.106
2025/01/03,3.13,phi4,export,0.13,0.104
2025/01/01,3.12,phi4,dynamo,0.14,0.20
2025/01/02,3.12,phi4,dynamo,0.13,0.21
2025/01/03,3.12,phi4,dynamo,0.12,0.19
""")))
cube = DataCube(
df,
time="date",
keys=["model_.*"],
values=["time_.*"],
formulas={"speedup": lambda d: d["time_baseline"] / d["time_latency"]},
).load()
print(cube.describe())
dtype ... values
name ...
date datetime64[ns] ... 2025-01-01 00:00:00 - 2025-01-03 00:00:00
version_python float64 ... NaN
model_name object ... phi3,phi4
model_exporter object ... dynamo,export
time_latency float64 ... NaN
time_baseline float64 ... NaN
speedup float64 ... NaN
[7 rows x 10 columns]
A view#
The rows are the models, the columns are the metrics, the exporters and the dates.
view = cube.view(CubeViewDef(key_index=["model_name"], values=["speedup"]))
print(view)
METRICS speedup ...
model_exporter dynamo ...
date 2025-01-01 2025-01-02 ... 2025-01-02 2025-01-03
model_name ...
phi3 NaN NaN ... 1.000000 1.222222
phi4 1.428571 1.615385 ... 0.883333 0.800000
[2 rows x 6 columns]
Aggregation#
The speedup is averaged over the models.
agg = cube.view(
CubeViewDef(
key_index=["model_exporter"], values=["speedup"], key_agg=["model_name"], agg_args="mean"
)
)
print(agg)
date 2025-01-01 2025-01-02 2025-01-03
model_exporter METRICS
dynamo speedup 1.428571 1.615385 1.583333
export speedup 1.025000 0.941667 1.011111
Side by side#
Compares two exporters for model phi4,
see Side by side comparison of two configurations for more details.
CONF DYNAMO ... DYNAMO*(EXPORT∧DYNAMO)
model_exporter dynamo ...
date METRICS ...
2025-01-01 speedup 1.428571 ... 1.428571
time_baseline 0.200000 ... 0.200000
time_latency 0.140000 ... 0.140000
2025-01-02 speedup 1.615385 ... 1.615385
time_baseline 0.210000 ... 0.210000
time_latency 0.130000 ... 0.130000
2025-01-03 speedup 1.583333 ... 1.583333
time_baseline 0.190000 ... 0.190000
time_latency 0.120000 ... 0.120000
[9 rows x 11 columns]
Plot#
ts = cube.view(CubeViewDef(key_index=["model_name", "model_exporter"], values=["speedup"]))
ts.T.droplevel(0).plot(title="speedup over time")
plt.tight_layout()

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