-
Notifications
You must be signed in to change notification settings - Fork 30
/
pass_rate_to_csv.py
executable file
·48 lines (40 loc) · 1.46 KB
/
pass_rate_to_csv.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
#!/usr/bin/env python3
#
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: MIT
# Author : Nathaniel Pinckney, NVIDIA
#
import csv
import re
import subprocess
# Execute the find command and capture the output
command = "find . -name 'summary.txt' | xargs grep pass_rate | sort"
result = subprocess.run(command, shell=True, capture_output=True, text=True)
# Get the output from the command
data = result.stdout
# Parse the output data
pattern = re.compile(r'\./build_(\S+)_(\S+)_shots(\d+)_n(\d+)/summary\.txt:pass_rate\s+=\s+(\d+\.\d+)')
matches = pattern.findall(data)
# Organize data into a dictionary
results = {}
for match in matches:
task, model, shots, samples, pass_rate = match
# task_model = f"{task}_{model}"
task_model = f"{model}"
if task_model not in results:
results[task_model] = {}
results[task_model][f"{task}_shots{shots}_n{samples}"] = pass_rate
# Get all possible column names
columns = set()
for task_model, data in results.items():
columns.update(data.keys())
columns = sorted(columns)
# Write to CSV
with open('pass_rates.csv', 'w', newline='') as csvfile:
csvwriter = csv.writer(csvfile)
header = ['Model'] + columns
csvwriter.writerow(header)
for task_model, data in results.items():
row = [task_model] + [data.get(col, '') for col in columns]
csvwriter.writerow(row)
print("CSV file 'pass_rates.csv' created successfully.")