Skip to content

Commit b0bd97e

Browse files
committed
first sbs
1 parent 927abe0 commit b0bd97e

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

_unittests/ut_helpers/test_log_helper.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,55 @@ def test_historical_cube_time_mask(self):
470470
cube = CubeLogs(df, keys=["^m_*", "exporter"], time="date").load()
471471
cube.to_excel(output, views=["time_p"], time_mask=True, verbose=1)
472472

473+
def test_cube_sbs(self):
474+
df = pandas.DataFrame(
475+
[
476+
dict(
477+
date="2025/01/01",
478+
time_p=0.51,
479+
exporter="E1",
480+
opt="O",
481+
perf=3.7,
482+
m_name="A",
483+
m_cls="CA",
484+
),
485+
dict(
486+
date="2025/01/01",
487+
time_p=0.51,
488+
perf=3.4,
489+
exporter="E2",
490+
opt="O",
491+
m_name="A",
492+
m_cls="CA",
493+
),
494+
dict(
495+
date="2025/01/01",
496+
time_p=0.71,
497+
perf=3.5,
498+
exporter="E2",
499+
opt="O",
500+
m_name="B",
501+
m_cls="CA",
502+
),
503+
dict(
504+
date="2025/01/01",
505+
time_p=0.71,
506+
perf=3.6,
507+
exporter="E2",
508+
opt="K",
509+
m_name="B",
510+
m_cls="CA",
511+
),
512+
]
513+
)
514+
cube = CubeLogs(
515+
df, keys=["^m_*", "exporter", "opt"], values=["time_p", "perf"], time="date"
516+
).load()
517+
sbs = cube.sbs([dict(exporter="E1", opt="O"), dict(exporter="E2", opt="O")])
518+
self.assertEqual(sbs.shape, (4, 2))
519+
self.assertEqual(sbs.index.names, ["METRICS", "m_name"])
520+
self.assertEqual(sbs.columns.names, ["exporter"])
521+
473522

474523
if __name__ == "__main__":
475524
unittest.main(verbosity=2)

onnx_diagnostic/helpers/log_helper.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,43 @@ def cube_time(self, fill_other_dates: bool = False, threshold: float = 1.2) -> "
12481248
)
12491249
return self.clone(data=dgr.reset_index(drop=False))
12501250

1251+
def sbs(self, configs: Sequence[Dict[str, Any]]) -> pandas.DataFrame:
1252+
"""
1253+
Creates a side-by-side for two configurations.
1254+
Every configuration a dictionary column:value which filters in
1255+
the rows to keep in order to compute the side by side.
1256+
"""
1257+
set_keys_time = set(self.keys_time)
1258+
columns_index = None
1259+
datas = []
1260+
for conf in configs:
1261+
if columns_index is None:
1262+
columns_index = list(conf.keys())
1263+
assert (
1264+
set(columns_index) <= set_keys_time
1265+
), f"Configuration {conf} includes columns outside the keys."
1266+
else:
1267+
assert set(columns_index) == set(conf), (
1268+
f"Every conf should share the same keys but conf={conf} "
1269+
f"is different from {set(columns_index)}"
1270+
)
1271+
data = self.data
1272+
for k, v in conf.items():
1273+
data = data[data[k] == v]
1274+
assert data.shape[0] > 0, f"No rows found for conf={conf}"
1275+
datas.append((conf, data))
1276+
1277+
new_data = pandas.concat([d[1] for d in datas], axis=0)
1278+
cube = self.clone(new_data)
1279+
key_index = [c for c in self.keys_time if c not in set(columns_index)]
1280+
view = CubeViewDef(key_index=key_index, name="sbs", values=cube.values)
1281+
res = cube.view(view)
1282+
res = res.stack("METRICS", future_stack=True)
1283+
res = res.reorder_levels(
1284+
[res.index.nlevels - 1, *list(range(res.index.nlevels - 1))]
1285+
).sort_index()
1286+
return res
1287+
12511288

12521289
class CubeLogsPerformance(CubeLogs):
12531290
"""

0 commit comments

Comments
 (0)