forked from ChrisCummins/CompilerGym
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo.py
65 lines (48 loc) · 1.62 KB
/
info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import os
import sys
from pathlib import Path
from typing import List
import pandas as pd
from llvm_autotuning.experiment import Experiment
from pydantic import ValidationError
from typer import Typer
from compiler_gym.util.statistics import geometric_mean
app = Typer()
def experiments_from_paths(log_dirs: List[Path]) -> List[Experiment]:
experiments: List[Experiment] = []
for path in log_dirs:
try:
experiments += Experiment.from_logsdir(Path(path).expanduser())
except ValidationError as e:
print(e, file=sys.stderr)
sys.exit(1)
return experiments
@app.command()
def info(
log_dirs: List[Path] = ["~/logs/compiler_gym/gcc_autotuning"],
):
dfs: List[pd.DataFrame] = []
for path in log_dirs:
path = Path(path).expanduser()
for root, _, files in os.walk(path):
if "results.csv" not in files:
continue
root = Path(root)
df = pd.read_csv(root / "results.csv")
if not df.size:
continue
df["timestamp"] = "-".join([root.parent.name, root.name])
dfs.append(df)
if not dfs:
print("No results")
df = pd.concat(dfs)
df = df.groupby(["timestamp", "search"])[["scaled_size"]].agg(geometric_mean)
df = df.rename(columns={"scaled_size": "geomean_reward"})
pd.set_option("display.max_rows", None)
print(df)
if __name__ == "__main__":
app()