Skip to content

Commit fd314f3

Browse files
make format-py
1 parent 09108db commit fd314f3

File tree

6 files changed

+36
-39
lines changed

6 files changed

+36
-39
lines changed

vtr_flow/scripts/download_noc_mlp.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import shutil
1818
import errno
1919

20+
2021
class ExtractionError(Exception):
2122
"""
2223
Raised when extracting the downlaoded file fails
@@ -39,8 +40,9 @@ def parse_args():
3940
does nothing (unless --force is specified).
4041
"""
4142
)
42-
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter,
43-
description=description)
43+
parser = argparse.ArgumentParser(
44+
formatter_class=argparse.ArgumentDefaultsHelpFormatter, description=description
45+
)
4446

4547
parser.add_argument(
4648
"--vtr_flow_dir",
@@ -132,7 +134,7 @@ def extract_to_vtr_flow_dir(args, tar_gz_filename):
132134
raise ExtractionError("{} should be a directory".format(directory))
133135

134136
# Create a temporary working directory
135-
tmpdir = tempfile.mkdtemp(suffix="download_NoC_MLP", dir= os.path.abspath("."))
137+
tmpdir = tempfile.mkdtemp(suffix="download_NoC_MLP", dir=os.path.abspath("."))
136138
try:
137139
# Extract the contents of the .tar.gz archive directly into the destination directory
138140
with tarfile.open(tar_gz_filename, "r:gz") as tar:

vtr_flow/scripts/download_titan.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ def parse_args():
4141
does nothing (unless --force is specified).
4242
"""
4343
)
44-
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter,
45-
description=description)
44+
parser = argparse.ArgumentParser(
45+
formatter_class=argparse.ArgumentDefaultsHelpFormatter, description=description
46+
)
4647

4748
parser.add_argument(
4849
"--titan_version", default="2.0.0", help="Titan release version to download"

vtr_flow/scripts/python_libs/vtr/log_parse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, name, filename, regex_str, default_value=None):
2525
self._filename = filename
2626
# Look for the specified pattern somewhere in the line, but any characters
2727
# can occur before and after it. Detailed in GitHub Issue #2743.
28-
self._regex = re.compile(f'^.*{regex_str}.*$')
28+
self._regex = re.compile(f"^.*{regex_str}.*$")
2929
self._default_value = default_value
3030

3131
def name(self):

vtr_flow/scripts/python_libs/vtr/task.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __init__(
5555
pad_file=None,
5656
additional_files=None,
5757
additional_files_list_add=None,
58-
circuit_constraint_list_add=None
58+
circuit_constraint_list_add=None,
5959
):
6060
self.task_name = task_name
6161
self.config_dir = config_dir
@@ -82,9 +82,9 @@ def __init__(
8282
self.pad_file = pad_file
8383
self.additional_files = additional_files
8484
self.additional_files_list_add = additional_files_list_add
85-
self.circuit_constraints = parse_circuit_constraint_list(circuit_constraint_list_add,
86-
self.circuits,
87-
self.archs)
85+
self.circuit_constraints = parse_circuit_constraint_list(
86+
circuit_constraint_list_add, self.circuits, self.archs
87+
)
8888

8989

9090
# pylint: enable=too-few-public-methods
@@ -306,9 +306,8 @@ def check_include_fields(config_file, key_values):
306306
)
307307
)
308308

309-
def parse_circuit_constraint_list(
310-
circuit_constraint_list, circuits_list, arch_list
311-
) -> dict:
309+
310+
def parse_circuit_constraint_list(circuit_constraint_list, circuits_list, arch_list) -> dict:
312311
"""
313312
Parse the circuit constraints passed in via the config file.
314313
Circuit constraints are expected to have the following syntax:
@@ -342,38 +341,39 @@ def parse_circuit_constraint_list(
342341
# Parse the circuit constraint list
343342
for circuit_constraint in circuit_constraint_list:
344343
# Remove the round brackets.
345-
if circuit_constraint[0] != '(' or circuit_constraint[-1] != ')':
346-
raise VtrError(f"Circuit constraint syntax error: \"{circuit_constraint}\"")
344+
if circuit_constraint[0] != "(" or circuit_constraint[-1] != ")":
345+
raise VtrError(f'Circuit constraint syntax error: "{circuit_constraint}"')
347346
circuit_constraint = circuit_constraint[1:-1]
348347
# Split the circuit and the constraint
349-
split_constraint_line = circuit_constraint.split(',')
348+
split_constraint_line = circuit_constraint.split(",")
350349
if len(split_constraint_line) != 2:
351-
raise VtrError(f"Circuit constraint has too many arguments: \"{circuit_constraint}\"")
350+
raise VtrError(f'Circuit constraint has too many arguments: "{circuit_constraint}"')
352351
circuit = split_constraint_line[0].strip()
353352
constraint = split_constraint_line[1].strip()
354353
# Check that the circuit actually exists.
355354
if circuit not in circuits_list:
356-
raise VtrError(f"Cannot constrain circuit \"{circuit}\", circuit has not been added")
355+
raise VtrError(f'Cannot constrain circuit "{circuit}", circuit has not been added')
357356
# Parse the constraint
358357
split_constraint = constraint.split("=")
359358
if len(split_constraint) != 2:
360-
raise VtrError(f"Circuit constraint syntax error: \"{circuit_constraint}\"")
359+
raise VtrError(f'Circuit constraint syntax error: "{circuit_constraint}"')
361360
constr_key = split_constraint[0].strip()
362361
constr_val = split_constraint[1].strip()
363362
# Check that the constr_key is valid.
364363
if constr_key not in circuit_constraint_keys:
365-
raise VtrError(f"Invalid constraint \"{constr_key}\" used on circuit \"{circuit}\"")
364+
raise VtrError(f'Invalid constraint "{constr_key}" used on circuit "{circuit}"')
366365
# In the case of arch constraints, make sure this arch exists.
367366
if constr_key == "arch" and constr_val not in arch_list:
368-
raise VtrError(f"Cannot constrain arch \"{constr_key}\", arch has not been added")
367+
raise VtrError(f'Cannot constrain arch "{constr_key}", arch has not been added')
369368
# Make sure this circuit is not already constrained with this constr_arg
370369
if res_circuit_constraints[circuit][constr_key] is not None:
371-
raise VtrError(f"Circuit \"{circuit}\" cannot be constrained more than once")
370+
raise VtrError(f'Circuit "{circuit}" cannot be constrained more than once')
372371
# Add the constraint for this circuit
373372
res_circuit_constraints[circuit][constr_key] = constr_val
374373

375374
return res_circuit_constraints
376375

376+
377377
def shorten_task_names(configs, common_task_prefix):
378378
"""
379379
Shorten the task names of the configs by remove the common task prefix.
@@ -582,10 +582,7 @@ def create_jobs(args, configs, after_run=False) -> List[Job]:
582582
work_dir = get_work_dir_addr(arch, circuit, noc_traffic)
583583

584584
run_dir = (
585-
str(
586-
Path(get_latest_run_dir(find_task_dir(config, args.alt_tasks_dir)))
587-
/ work_dir
588-
)
585+
str(Path(get_latest_run_dir(find_task_dir(config, args.alt_tasks_dir))) / work_dir)
589586
if after_run
590587
else str(
591588
Path(get_next_run_dir(find_task_dir(config, args.alt_tasks_dir))) / work_dir
@@ -779,6 +776,7 @@ def ret_expected_vpr_status(arch, circuit, golden_results, script_params=None):
779776

780777
return golden_metrics["vpr_status"]
781778

779+
782780
def apply_cmd_line_circuit_constraints(cmd, circuit, config):
783781
"""
784782
Apply the circuit constraints to the command line. If the circuit is not
@@ -793,6 +791,7 @@ def apply_cmd_line_circuit_constraints(cmd, circuit, config):
793791
if circuit_vpr_constraints is not None:
794792
cmd += ["--read_vpr_constraints", circuit_vpr_constraints]
795793

794+
796795
def resolve_vtr_source_file(config, filename, base_dir=""):
797796
"""
798797
Resolves an filename with a base_dir

vtr_flow/scripts/python_libs/vtr/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,15 @@ def run_system_command(
154154
# or RR graph files to VPR. PWD environment variable is updated
155155
# manually to prevent capnproto from throwing exceptions.
156156
modified_environ = os.environ.copy()
157-
modified_environ['PWD'] = str(temp_dir)
157+
modified_environ["PWD"] = str(temp_dir)
158158

159159
proc = subprocess.Popen(
160160
cmd,
161161
stdout=subprocess.PIPE, # We grab stdout
162162
stderr=stderr, # stderr redirected to stderr
163163
universal_newlines=True, # Lines always end in \n
164164
cwd=str(temp_dir), # Where to run the command
165-
env=modified_environ
165+
env=modified_environ,
166166
)
167167

168168
# Read the output line-by-line and log it

vtr_flow/scripts/tuning_runs/control_runs.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ def parse_results(input_path):
4646
Parse the output results
4747
"""
4848
# Find the runXXX directory with the largest XXX
49-
run_dirs = [
50-
d for d in os.listdir(input_path) if d.startswith("run") and d[3:].isdigit()
51-
]
49+
run_dirs = [d for d in os.listdir(input_path) if d.startswith("run") and d[3:].isdigit()]
5250
if not run_dirs:
5351
print("No runXXX directories found in the specified input path.")
5452
sys.exit(1)
@@ -63,9 +61,9 @@ def parse_results(input_path):
6361
sys.exit(1)
6462

6563
# Read the parse_results.txt file and write to full_res.csv
66-
with open(
67-
os.path.join(largest_run_path, "parse_results.txt"), "r"
68-
) as txt_file, open(full_res_csv_path, "w", newline="") as csv_file:
64+
with open(os.path.join(largest_run_path, "parse_results.txt"), "r") as txt_file, open(
65+
full_res_csv_path, "w", newline=""
66+
) as csv_file:
6967
reader = csv.reader(txt_file, delimiter="\t")
7068
writer = csv.writer(csv_file)
7169

@@ -97,9 +95,7 @@ def parse_results(input_path):
9795
print("Generated average seed results")
9896

9997
# Generate gmean_res.csv
100-
generate_geomean_res_csv(
101-
os.path.join(largest_run_path, "avg_seed.csv"), largest_run_path
102-
)
98+
generate_geomean_res_csv(os.path.join(largest_run_path, "avg_seed.csv"), largest_run_path)
10399
print("Generated geometric average results over all the circuits")
104100

105101
generate_xlsx(largest_run_path)
@@ -147,8 +143,7 @@ def parse_script_params(script_params):
147143
j = i + key_length
148144

149145
while j < len(parts) and not any(
150-
parts[j : j + len(k.split("_"))] == k.split("_")
151-
for k in PARAMS_DICT
146+
parts[j : j + len(k.split("_"))] == k.split("_") for k in PARAMS_DICT
152147
):
153148
value_parts.append(parts[j])
154149
j += 1

0 commit comments

Comments
 (0)