diff --git a/milabench/config.py b/milabench/config.py index 4f246561c..2b0f15299 100644 --- a/milabench/config.py +++ b/milabench/config.py @@ -108,6 +108,10 @@ def build_matrix_bench(all_configs): for name, bench_config in all_configs.items(): for k, v in expand_matrix(name, bench_config): + + if k in expanded_config: + raise ValueError("Bench name is not unique") + expanded_config[k] = v return expanded_config diff --git a/milabench/report.py b/milabench/report.py index 5d7d32057..80df4eca2 100644 --- a/milabench/report.py +++ b/milabench/report.py @@ -128,7 +128,7 @@ def text(self, x): if not self.stdout: return if isinstance(x, DataFrame): - self._text(x.to_string(formatters=_formatters)) + self._text(pandas_to_string(x, formatters=_formatters)) else: self._text(str(x)) @@ -300,9 +300,39 @@ def _score(column): out.finalize() +def pandas_to_string(df, formatters): + """Default stdout printer does not insert a column sep which makes it hard to retranscribe results elsewhere. + to_csv does not align the output. + """ + from collections import defaultdict + columns = df.columns.tolist() + + sep = " | " + lines = [] + col_size = defaultdict(int) + + for index, row in df.iterrows(): + line = [f'{index:<30}'] + for col, val in zip(columns, row): + fmt = formatters.get(col) + val = fmt(val) + col_size[col] = max(col_size[col], len(val)) + line.append(val) + + lines.append(sep.join(line)) + + def fmtcol(col): + size = col_size[col] + return f"{col:>{size}}" + + header = sep.join([f"{'bench':<30}"] + [fmtcol(col) for col in columns]) + + return "\n".join([header] + lines) + + _formatters = { + "fail": "{:4.0f}".format, "n": "{:.0f}".format, - "fail": "{:.0f}".format, "std": "{:10.2f}".format, "iqr": "{:10.2f}".format, "perf": "{:10.2f}".format, @@ -314,8 +344,9 @@ def _score(column): "std%": "{:6.1%}".format, "sem%": "{:6.1%}".format, "iqr%": "{:6.1%}".format, - "weight": "{:4.2f}".format, - "peak_memory": "{:.0f}".format, + "score": "{:10.2f}".format, + "weight": "{:5.2f}".format, + "peak_memory": "{:11.0f}".format, 0: "{:.0%}".format, 1: "{:.0%}".format, 2: "{:.0%}".format,