Skip to content

Commit 3c6975e

Browse files
authored
Address ruff linter remarks (#537)
Pre-requisite for #538
1 parent 652365e commit 3c6975e

File tree

5 files changed

+145
-81
lines changed

5 files changed

+145
-81
lines changed

docs/conf.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,32 @@
88

99
import os
1010

11-
project = 'Parallel Programming Course'
12-
copyright = '2025, Learning Process'
13-
author = 'Learning Process'
11+
project = "Parallel Programming Course"
12+
copyright = "2025, Learning Process"
13+
author = "Learning Process"
1414

1515
# -- General configuration ---------------------------------------------------
1616
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
1717

1818
extensions = [
19-
'breathe',
19+
"breathe",
2020
]
2121

2222
breathe_projects = {
2323
"ParallelProgrammingCourse": os.path.join(os.path.dirname(__file__), "..", "xml"),
2424
}
2525
breathe_default_project = "ParallelProgrammingCourse"
2626

27-
templates_path = ['_templates']
28-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
29-
locale_dirs = ['locale']
27+
templates_path = ["_templates"]
28+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
29+
locale_dirs = ["locale"]
3030
gettext_compact = False
3131

3232
# -- Options for HTML output -------------------------------------------------
3333
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
3434

35-
html_theme = 'sphinx_rtd_theme'
36-
html_static_path = ['_static']
35+
html_theme = "sphinx_rtd_theme"
36+
html_static_path = ["_static"]
3737

3838
html_sidebars = {
3939
"**": [

scoreboard/main.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,54 @@
55
import csv
66
from jinja2 import Environment, FileSystemLoader
77

8-
task_types = ['all', 'mpi', 'omp', 'seq', 'stl', 'tbb']
8+
task_types = ["all", "mpi", "omp", "seq", "stl", "tbb"]
99

10-
tasks_dir = Path('tasks')
10+
tasks_dir = Path("tasks")
1111

1212
directories = defaultdict(dict)
1313

1414
if tasks_dir.exists() and tasks_dir.is_dir():
1515
for task_name_dir in tasks_dir.iterdir():
16-
if task_name_dir.is_dir() and task_name_dir.name not in ['common']:
16+
if task_name_dir.is_dir() and task_name_dir.name not in ["common"]:
1717
task_name = task_name_dir.name
1818
for task_type in task_types:
1919
task_type_dir = task_name_dir / task_type
2020
if task_type_dir.exists() and task_type_dir.is_dir():
2121
if task_name.endswith("_disabled"):
22-
clean_task_name = task_name[:-len("_disabled")]
22+
clean_task_name = task_name[: -len("_disabled")]
2323
directories[clean_task_name][task_type] = "disabled"
2424
else:
2525
directories[task_name][task_type] = "done"
2626

2727
config_path = Path(__file__).parent / "data" / "threads-config.yml"
2828
assert config_path.exists(), f"Config file not found: {config_path}"
29-
with open(config_path, 'r') as file:
29+
with open(config_path, "r") as file:
3030
cfg = yaml.safe_load(file)
3131
assert cfg, "Configuration is empty"
3232
plagiarism_config_path = Path(__file__).parent / "data" / "plagiarism.yml"
33-
with open(plagiarism_config_path, 'r') as file:
33+
with open(plagiarism_config_path, "r") as file:
3434
plagiarism_cfg = yaml.safe_load(file)
3535
assert plagiarism_cfg, "Plagiarism configuration is empty"
3636

3737
env = Environment(loader=FileSystemLoader(Path(__file__).parent / "templates"))
3838

3939

40-
perf_stat_file_path = Path(__file__).parent.parent / "build" / "perf_stat_dir" / "task_run_perf_table.csv"
40+
perf_stat_file_path = (
41+
Path(__file__).parent.parent / "build" / "perf_stat_dir" / "task_run_perf_table.csv"
42+
)
4143

4244
# Read and parse performance statistics CSV
4345
perf_stats = dict()
4446
if perf_stat_file_path.exists():
45-
with open(perf_stat_file_path, 'r', newline='') as csvfile:
47+
with open(perf_stat_file_path, "r", newline="") as csvfile:
4648
reader = csv.DictReader(csvfile)
4749
for row in reader:
48-
perf_stats[row['Task']] = {
49-
"seq": row['SEQ'],
50-
"omp": row['OMP'],
51-
"tbb": row['TBB'],
52-
"stl": row['STL'],
53-
"all": row['ALL'],
50+
perf_stats[row["Task"]] = {
51+
"seq": row["SEQ"],
52+
"omp": row["OMP"],
53+
"tbb": row["TBB"],
54+
"stl": row["STL"],
55+
"all": row["ALL"],
5456
"mpi": "N/A",
5557
}
5658
else:
@@ -99,12 +101,12 @@
99101
template = env.get_template("index.html.j2")
100102
html_content = template.render(task_types=task_types, rows=rows)
101103

102-
parser = argparse.ArgumentParser(description='Generate HTML scoreboard.')
103-
parser.add_argument('-o', '--output', type=str, required=True, help='Output file path')
104+
parser = argparse.ArgumentParser(description="Generate HTML scoreboard.")
105+
parser.add_argument("-o", "--output", type=str, required=True, help="Output file path")
104106
args = parser.parse_args()
105107

106108
output_file = Path(args.output) / "index.html"
107-
with open(output_file, 'w') as file:
109+
with open(output_file, "w") as file:
108110
file.write(html_content)
109111

110112
print(f"HTML page generated at {output_file}")

scripts/create_perf_table.py

Lines changed: 73 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
import csv
66

77
parser = argparse.ArgumentParser()
8-
parser.add_argument('-i', '--input', help='Input file path (logs of perf tests, .txt)', required=True)
9-
parser.add_argument('-o', '--output', help='Output file path (path to .xlsx table)', required=True)
8+
parser.add_argument(
9+
"-i", "--input", help="Input file path (logs of perf tests, .txt)", required=True
10+
)
11+
parser.add_argument(
12+
"-o", "--output", help="Output file path (path to .xlsx table)", required=True
13+
)
1014
args = parser.parse_args()
1115
logs_path = os.path.abspath(args.input)
1216
xlsx_path = os.path.abspath(args.output)
@@ -19,7 +23,7 @@
1923
logs_file = open(logs_path, "r")
2024
logs_lines = logs_file.readlines()
2125
for line in logs_lines:
22-
pattern = r'tasks[\/|\\](\w*)[\/|\\](\w*):(\w*):(-*\d*\.\d*)'
26+
pattern = r"tasks[\/|\\](\w*)[\/|\\](\w*):(\w*):(-*\d*\.\d*)"
2327
result = re.findall(pattern, line)
2428
if len(result):
2529
task_name = result[0][1]
@@ -31,7 +35,7 @@
3135
result_tables[perf_type][task_name][ttype] = -1.0
3236

3337
for line in logs_lines:
34-
pattern = r'tasks[\/|\\](\w*)[\/|\\](\w*):(\w*):(-*\d*\.\d*)'
38+
pattern = r"tasks[\/|\\](\w*)[\/|\\](\w*):(\w*):(-*\d*\.\d*)"
3539
result = re.findall(pattern, line)
3640
if len(result):
3741
task_type = result[0][0]
@@ -45,37 +49,72 @@
4549

4650

4751
for table_name in result_tables:
48-
workbook = xlsxwriter.Workbook(os.path.join(xlsx_path, table_name + '_perf_table.xlsx'))
52+
workbook = xlsxwriter.Workbook(
53+
os.path.join(xlsx_path, table_name + "_perf_table.xlsx")
54+
)
4955
worksheet = workbook.add_worksheet()
50-
worksheet.set_column('A:Z', 23)
51-
right_bold_border = workbook.add_format({'bold': True, 'right': 2, 'bottom': 2})
52-
bottom_bold_border = workbook.add_format({'bold': True, 'bottom': 2})
56+
worksheet.set_column("A:Z", 23)
57+
right_bold_border = workbook.add_format({"bold": True, "right": 2, "bottom": 2})
58+
bottom_bold_border = workbook.add_format({"bold": True, "bottom": 2})
5359
cpu_num = os.environ.get("PPC_NUM_PROC")
5460
if cpu_num is None:
55-
raise EnvironmentError("Required environment variable 'PPC_NUM_PROC' is not set.")
61+
raise EnvironmentError(
62+
"Required environment variable 'PPC_NUM_PROC' is not set."
63+
)
5664
cpu_num = int(cpu_num)
5765
worksheet.write(0, 0, "cpu_num = " + str(cpu_num), right_bold_border)
5866

5967
it = 1
6068
for type_of_task in list_of_type_of_tasks:
61-
worksheet.write(0, it, "T_" + type_of_task + "(" + str(cpu_num) + ")", bottom_bold_border)
69+
worksheet.write(
70+
0, it, "T_" + type_of_task + "(" + str(cpu_num) + ")", bottom_bold_border
71+
)
6272
it += 1
63-
worksheet.write(0, it, "S(" + str(cpu_num) + ")" + " = " +
64-
"T_seq(" + str(cpu_num) + ")" + " / " +
65-
"T_" + type_of_task + "(" + str(cpu_num) + ")", bottom_bold_border)
73+
worksheet.write(
74+
0,
75+
it,
76+
"S("
77+
+ str(cpu_num)
78+
+ ")"
79+
+ " = "
80+
+ "T_seq("
81+
+ str(cpu_num)
82+
+ ")"
83+
+ " / "
84+
+ "T_"
85+
+ type_of_task
86+
+ "("
87+
+ str(cpu_num)
88+
+ ")",
89+
bottom_bold_border,
90+
)
6691
it += 1
67-
worksheet.write(0, it, "Eff(" + str(cpu_num) + ")" + " = " +
68-
"S(" + str(cpu_num) + ")" + " / " + str(cpu_num), right_bold_border)
92+
worksheet.write(
93+
0,
94+
it,
95+
"Eff("
96+
+ str(cpu_num)
97+
+ ")"
98+
+ " = "
99+
+ "S("
100+
+ str(cpu_num)
101+
+ ")"
102+
+ " / "
103+
+ str(cpu_num),
104+
right_bold_border,
105+
)
69106
it += 1
70107

71108
it = 1
72109
for task_name in list(set(set_of_task_name)):
73-
worksheet.write(it, 0, task_name, workbook.add_format({'bold': True, 'right': 2}))
110+
worksheet.write(
111+
it, 0, task_name, workbook.add_format({"bold": True, "right": 2})
112+
)
74113
it += 1
75114

76115
it_i = 1
77116
it_j = 1
78-
right_border = workbook.add_format({'right': 2})
117+
right_border = workbook.add_format({"right": 2})
79118
for task_name in list(set(set_of_task_name)):
80119
for type_of_task in list_of_type_of_tasks:
81120
if task_name not in result_tables[table_name].keys():
@@ -104,19 +143,27 @@
104143
it_j += 1
105144
workbook.close()
106145
# Dump CSV for performance times
107-
csv_file = os.path.join(xlsx_path, table_name + '_perf_table.csv')
108-
with open(csv_file, 'w', newline='') as csvfile:
146+
csv_file = os.path.join(xlsx_path, table_name + "_perf_table.csv")
147+
with open(csv_file, "w", newline="") as csvfile:
109148
writer = csv.writer(csvfile)
110149
# Write header: Task, SEQ, OMP, TBB, STL, ALL
111-
writer.writerow(['Task', 'SEQ', 'OMP', 'TBB', 'STL', 'ALL'])
150+
writer.writerow(["Task", "SEQ", "OMP", "TBB", "STL", "ALL"])
112151
for task_name in sorted(result_tables[table_name].keys()):
113-
seq_time = result_tables[table_name][task_name]['seq']
152+
seq_time = result_tables[table_name][task_name]["seq"]
114153
row = [
115154
task_name,
116-
1.0 if seq_time != 0 else '?',
117-
(result_tables[table_name][task_name]['omp'] / seq_time) if seq_time != 0 else '?',
118-
(result_tables[table_name][task_name]['tbb'] / seq_time) if seq_time != 0 else '?',
119-
(result_tables[table_name][task_name]['stl'] / seq_time) if seq_time != 0 else '?',
120-
(result_tables[table_name][task_name]['all'] / seq_time) if seq_time != 0 else '?',
155+
1.0 if seq_time != 0 else "?",
156+
(result_tables[table_name][task_name]["omp"] / seq_time)
157+
if seq_time != 0
158+
else "?",
159+
(result_tables[table_name][task_name]["tbb"] / seq_time)
160+
if seq_time != 0
161+
else "?",
162+
(result_tables[table_name][task_name]["stl"] / seq_time)
163+
if seq_time != 0
164+
else "?",
165+
(result_tables[table_name][task_name]["all"] / seq_time)
166+
if seq_time != 0
167+
else "?",
121168
]
122169
writer.writerow(row)

0 commit comments

Comments
 (0)