From e36c1b7c8ba62383461376c6ebd2df25eee240a4 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Sun, 30 Mar 2025 11:29:47 -0400 Subject: [PATCH 01/17] [vtr][script] add run dir to parse script --- vtr_flow/scripts/python_libs/vtr/__init__.py | 1 + .../scripts/python_libs/vtr/parse_vtr_task.py | 5 ++- vtr_flow/scripts/python_libs/vtr/util.py | 39 +++++++++++++------ 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/vtr_flow/scripts/python_libs/vtr/__init__.py b/vtr_flow/scripts/python_libs/vtr/__init__.py index 5fce29c9d63..e416ed30b30 100644 --- a/vtr_flow/scripts/python_libs/vtr/__init__.py +++ b/vtr_flow/scripts/python_libs/vtr/__init__.py @@ -21,6 +21,7 @@ verify_file, pretty_print_table, find_task_dir, + set_global_run_dir_number ) from .log_parse import ( determine_lut_size, diff --git a/vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py b/vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py index 32df9b17e07..d9a6cc9219f 100755 --- a/vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py +++ b/vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py @@ -32,6 +32,7 @@ VtrError, create_jobs, paths, + set_global_run_dir_number, ) # pylint: enable=wrong-import-position @@ -130,7 +131,7 @@ def vtr_command_argparser(prog=None): help="QoR geomeans are not computed by default", ) - parser.add_argument("-run", default=None, type=str, help="") + parser.add_argument("-run", default=None, type=int, help="Run number to parse. If not provided, the latest run will be parsed.") parser.add_argument("-revision", default="", help="Revision number") @@ -144,6 +145,8 @@ def vtr_command_main(arg_list, prog=None): """ # Load the arguments args = vtr_command_argparser(prog).parse_args(arg_list) + if args.run is not None: + set_global_run_dir_number(args.run) try: task_names = args.task diff --git a/vtr_flow/scripts/python_libs/vtr/util.py b/vtr_flow/scripts/python_libs/vtr/util.py index 7d1c7dbab11..d6e0a443612 100644 --- a/vtr_flow/scripts/python_libs/vtr/util.py +++ b/vtr_flow/scripts/python_libs/vtr/util.py @@ -22,6 +22,10 @@ from vtr import paths +# The run number passed by get_latest_run_number is the latest run number for the task if this number is None. Otherwise +# it is the run number to parse. +global_run_dir_number = None + class RawDefaultHelpFormatter( argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionHelpFormatter ): @@ -224,6 +228,13 @@ def run_system_command( # pylint: enable=too-many-arguments, too-many-instance-attributes, too-few-public-methods, too-many-locals +def set_global_run_dir_number(run_dir_number): + """ + Set the global run directory number. + """ + global global_run_dir_number + global_run_dir_number = run_dir_number + def check_cmd(command): """ @@ -563,20 +574,26 @@ def get_latest_run_number(base_dir): """ Returns the highest run number of all run directories with in base_dir """ - run_number = 1 - run_dir = Path(base_dir) / run_dir_name(run_number) + global global_run_dir_number + run_number = None + if global_run_dir_number is None: + run_number = 1 + run_dir = Path(base_dir) / run_dir_name(run_number) - if not run_dir.exists(): - # No existing run directories - return None + if not run_dir.exists(): + # No existing run directories + return None - while run_dir.exists(): - run_number += 1 - run_dir = Path(base_dir) / run_dir_name(run_number) + while run_dir.exists(): + run_number += 1 + run_dir = Path(base_dir) / run_dir_name(run_number) - # Currently one-past the last existing run dir, - # to get latest existing, subtract one - return run_number - 1 + # Currently one-past the last existing run dir, + # to get latest existing, subtract one + run_number = run_number - 1 + else: + run_number = global_run_dir_number + return run_number def run_dir_name(run_num): From aad848b60987a736982a6d06068649854f2306d7 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Mon, 31 Mar 2025 09:59:30 -0400 Subject: [PATCH 02/17] [script] remove get_latest_run_dir_number out of util --- vtr_flow/scripts/python_libs/vtr/__init__.py | 1 - vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py | 11 ++++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/vtr_flow/scripts/python_libs/vtr/__init__.py b/vtr_flow/scripts/python_libs/vtr/__init__.py index e416ed30b30..be5b486755a 100644 --- a/vtr_flow/scripts/python_libs/vtr/__init__.py +++ b/vtr_flow/scripts/python_libs/vtr/__init__.py @@ -16,7 +16,6 @@ argparse_str2bool, get_existing_run_dir, get_latest_run_dir, - get_latest_run_number, get_next_run_dir, verify_file, pretty_print_table, diff --git a/vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py b/vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py index d9a6cc9219f..b73d1dd3d2e 100755 --- a/vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py +++ b/vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py @@ -7,6 +7,7 @@ from pathlib import Path from pathlib import PurePath import sys +import os import argparse import textwrap import shutil @@ -24,7 +25,6 @@ load_pass_requirements, load_parse_results, parse_vtr_flow, - get_latest_run_number, pretty_print_table, find_task_dir, CommandError, @@ -32,7 +32,7 @@ VtrError, create_jobs, paths, - set_global_run_dir_number, + set_global_run_dir, ) # pylint: enable=wrong-import-position @@ -131,7 +131,7 @@ def vtr_command_argparser(prog=None): help="QoR geomeans are not computed by default", ) - parser.add_argument("-run", default=None, type=int, help="Run number to parse. If not provided, the latest run will be parsed.") + parser.add_argument("-run", default=None, type=str, help="Parse the specified run directory. Defaults to the latest.") parser.add_argument("-revision", default="", help="Revision number") @@ -146,7 +146,7 @@ def vtr_command_main(arg_list, prog=None): # Load the arguments args = vtr_command_argparser(prog).parse_args(arg_list) if args.run is not None: - set_global_run_dir_number(args.run) + set_global_run_dir(args.run) try: task_names = args.task @@ -527,8 +527,9 @@ def calc_geomean(args, configs): print("date\trevision", file=out) first = False lines = summary.readlines() + run_dir_name = os.path.basename(get_latest_run_dir(find_task_dir(configs[0], args.alt_tasks_dir))) print( - get_latest_run_number(find_task_dir(configs[0], args.alt_tasks_dir)), + run_dir_name, file=out, end="\t", ) From f415c18c48c89e8b5ffbec52b115e683e7668e63 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Mon, 31 Mar 2025 10:07:27 -0400 Subject: [PATCH 03/17] [script] use run dir name instead of only accepting the run dir num --- vtr_flow/scripts/python_libs/vtr/util.py | 48 ++++++++++++------------ 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/vtr_flow/scripts/python_libs/vtr/util.py b/vtr_flow/scripts/python_libs/vtr/util.py index d6e0a443612..649cb9ca5ed 100644 --- a/vtr_flow/scripts/python_libs/vtr/util.py +++ b/vtr_flow/scripts/python_libs/vtr/util.py @@ -22,9 +22,9 @@ from vtr import paths -# The run number passed by get_latest_run_number is the latest run number for the task if this number is None. Otherwise -# it is the run number to parse. -global_run_dir_number = None +# The run directory name passed by set_global_run_dir is the run directory name to parse. If it is None, +# the latest run directory will be parsed. +global_run_dir_name = None class RawDefaultHelpFormatter( argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionHelpFormatter @@ -228,12 +228,12 @@ def run_system_command( # pylint: enable=too-many-arguments, too-many-instance-attributes, too-few-public-methods, too-many-locals -def set_global_run_dir_number(run_dir_number): +def set_global_run_dir(run_dir_name): """ - Set the global run directory number. + Set the global run directory name. """ - global global_run_dir_number - global_run_dir_number = run_dir_number + global global_run_dir_name + global_run_dir_name = run_dir_name def check_cmd(command): @@ -536,12 +536,12 @@ def get_latest_run_dir(base_dir): """ Returns the run directory with the highest run number in base_dir """ - latest_run_number = get_latest_run_number(base_dir) + latest_run_dir_name = get_latest_run_dir_name(base_dir) - if latest_run_number is None: + if latest_run_dir_name is None: return None - return str(PurePath(base_dir) / run_dir_name(latest_run_number)) + return str(PurePath(base_dir) / latest_run_dir_name) def get_existing_run_dir(base_dir: str, run_dir: str) -> str: @@ -560,23 +560,24 @@ def get_next_run_number(base_dir): """ Returns the next available (i.e. non-existing) run number in base_dir """ - latest_run_number = get_latest_run_number(base_dir) - - if latest_run_number is None: - next_run_number = 1 - else: + latest_run_dir_name = get_latest_run_dir_name(base_dir) + match = re.match(r"^run(\d{3})$", latest_run_dir_name) + if match: + latest_run_number = int(match.group(1)) next_run_number = latest_run_number + 1 - - return next_run_number + return next_run_number + else: + return 1 -def get_latest_run_number(base_dir): +def get_latest_run_dir_name(base_dir): """ Returns the highest run number of all run directories with in base_dir """ - global global_run_dir_number - run_number = None - if global_run_dir_number is None: + global global_run_dir_name + if global_run_dir_name is not None: + return global_run_dir_name + else: run_number = 1 run_dir = Path(base_dir) / run_dir_name(run_number) @@ -590,10 +591,7 @@ def get_latest_run_number(base_dir): # Currently one-past the last existing run dir, # to get latest existing, subtract one - run_number = run_number - 1 - else: - run_number = global_run_dir_number - return run_number + return run_dir_name(run_number-1) def run_dir_name(run_num): From 82a6ba131ada428ec8912e619be2d55ea196b54a Mon Sep 17 00:00:00 2001 From: amin1377 Date: Mon, 31 Mar 2025 10:11:00 -0400 Subject: [PATCH 04/17] [script] rename to set_global_run_dir --- vtr_flow/scripts/python_libs/vtr/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vtr_flow/scripts/python_libs/vtr/__init__.py b/vtr_flow/scripts/python_libs/vtr/__init__.py index be5b486755a..26b79bd75ce 100644 --- a/vtr_flow/scripts/python_libs/vtr/__init__.py +++ b/vtr_flow/scripts/python_libs/vtr/__init__.py @@ -20,7 +20,7 @@ verify_file, pretty_print_table, find_task_dir, - set_global_run_dir_number + set_global_run_dir ) from .log_parse import ( determine_lut_size, From cd3c985a639caebab34d031bf411f9b2b8bd9942 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Mon, 31 Mar 2025 10:14:01 -0400 Subject: [PATCH 05/17] make format-py --- vtr_flow/scripts/python_libs/vtr/__init__.py | 2 +- vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py | 11 +++++++++-- vtr_flow/scripts/python_libs/vtr/util.py | 4 +++- vtr_flow/scripts/python_libs/vtr/vpr/vpr.py | 6 +++--- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/vtr_flow/scripts/python_libs/vtr/__init__.py b/vtr_flow/scripts/python_libs/vtr/__init__.py index 26b79bd75ce..44dc5cdd99e 100644 --- a/vtr_flow/scripts/python_libs/vtr/__init__.py +++ b/vtr_flow/scripts/python_libs/vtr/__init__.py @@ -20,7 +20,7 @@ verify_file, pretty_print_table, find_task_dir, - set_global_run_dir + set_global_run_dir, ) from .log_parse import ( determine_lut_size, diff --git a/vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py b/vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py index b73d1dd3d2e..8720a8481a1 100755 --- a/vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py +++ b/vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py @@ -131,7 +131,12 @@ def vtr_command_argparser(prog=None): help="QoR geomeans are not computed by default", ) - parser.add_argument("-run", default=None, type=str, help="Parse the specified run directory. Defaults to the latest.") + parser.add_argument( + "-run", + default=None, + type=str, + help="Parse the specified run directory. Defaults to the latest.", + ) parser.add_argument("-revision", default="", help="Revision number") @@ -527,7 +532,9 @@ def calc_geomean(args, configs): print("date\trevision", file=out) first = False lines = summary.readlines() - run_dir_name = os.path.basename(get_latest_run_dir(find_task_dir(configs[0], args.alt_tasks_dir))) + run_dir_name = os.path.basename( + get_latest_run_dir(find_task_dir(configs[0], args.alt_tasks_dir)) + ) print( run_dir_name, file=out, diff --git a/vtr_flow/scripts/python_libs/vtr/util.py b/vtr_flow/scripts/python_libs/vtr/util.py index 649cb9ca5ed..fdca802dab0 100644 --- a/vtr_flow/scripts/python_libs/vtr/util.py +++ b/vtr_flow/scripts/python_libs/vtr/util.py @@ -26,6 +26,7 @@ # the latest run directory will be parsed. global_run_dir_name = None + class RawDefaultHelpFormatter( argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionHelpFormatter ): @@ -228,6 +229,7 @@ def run_system_command( # pylint: enable=too-many-arguments, too-many-instance-attributes, too-few-public-methods, too-many-locals + def set_global_run_dir(run_dir_name): """ Set the global run directory name. @@ -591,7 +593,7 @@ def get_latest_run_dir_name(base_dir): # Currently one-past the last existing run dir, # to get latest existing, subtract one - return run_dir_name(run_number-1) + return run_dir_name(run_number - 1) def run_dir_name(run_num): diff --git a/vtr_flow/scripts/python_libs/vtr/vpr/vpr.py b/vtr_flow/scripts/python_libs/vtr/vpr/vpr.py index 50278757656..8fba5e1f4f0 100644 --- a/vtr_flow/scripts/python_libs/vtr/vpr/vpr.py +++ b/vtr_flow/scripts/python_libs/vtr/vpr/vpr.py @@ -298,9 +298,9 @@ def run_second_time( if "write_intra_cluster_router_lookahead" in second_run_args: intra_cluster_router_lookahead = second_run_args["write_intra_cluster_router_lookahead"] second_run_args["read_intra_cluster_router_lookahead"] = intra_cluster_router_lookahead - second_run_args["write_intra_cluster_router_lookahead"] = ( - "intra_cluster_router_lookahead2.capnp" - ) + second_run_args[ + "write_intra_cluster_router_lookahead" + ] = "intra_cluster_router_lookahead2.capnp" # run VPR run( From 5a9fa88fd1fe26cd7ee46f96a2cc25616e4ec937 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Mon, 31 Mar 2025 10:59:56 -0400 Subject: [PATCH 06/17] fix formatting issue --- vtr_flow/scripts/python_libs/vtr/vpr/vpr.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vtr_flow/scripts/python_libs/vtr/vpr/vpr.py b/vtr_flow/scripts/python_libs/vtr/vpr/vpr.py index 8fba5e1f4f0..50278757656 100644 --- a/vtr_flow/scripts/python_libs/vtr/vpr/vpr.py +++ b/vtr_flow/scripts/python_libs/vtr/vpr/vpr.py @@ -298,9 +298,9 @@ def run_second_time( if "write_intra_cluster_router_lookahead" in second_run_args: intra_cluster_router_lookahead = second_run_args["write_intra_cluster_router_lookahead"] second_run_args["read_intra_cluster_router_lookahead"] = intra_cluster_router_lookahead - second_run_args[ - "write_intra_cluster_router_lookahead" - ] = "intra_cluster_router_lookahead2.capnp" + second_run_args["write_intra_cluster_router_lookahead"] = ( + "intra_cluster_router_lookahead2.capnp" + ) # run VPR run( From 0ab91a95c859eef8a2612c49a76d26324ab8fdb1 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Mon, 31 Mar 2025 11:23:03 -0400 Subject: [PATCH 07/17] [script] fix when run dir is not found --- vtr_flow/scripts/python_libs/vtr/util.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/vtr_flow/scripts/python_libs/vtr/util.py b/vtr_flow/scripts/python_libs/vtr/util.py index fdca802dab0..aea6d71a028 100644 --- a/vtr_flow/scripts/python_libs/vtr/util.py +++ b/vtr_flow/scripts/python_libs/vtr/util.py @@ -540,12 +540,11 @@ def get_latest_run_dir(base_dir): """ latest_run_dir_name = get_latest_run_dir_name(base_dir) - if latest_run_dir_name is None: + if latest_run_dir_name: + return str(PurePath(base_dir) / latest_run_dir_name) + else: return None - return str(PurePath(base_dir) / latest_run_dir_name) - - def get_existing_run_dir(base_dir: str, run_dir: str) -> str: """ Get an existing run directory (from a previous run). Throw if it doesn't exist @@ -585,7 +584,7 @@ def get_latest_run_dir_name(base_dir): if not run_dir.exists(): # No existing run directories - return None + return "" while run_dir.exists(): run_number += 1 From 223386a0488c790ba9e8ebfcb8045a32c2882e5f Mon Sep 17 00:00:00 2001 From: amin1377 Date: Mon, 31 Mar 2025 11:24:29 -0400 Subject: [PATCH 08/17] make format-py --- vtr_flow/scripts/python_libs/vtr/util.py | 1 + 1 file changed, 1 insertion(+) diff --git a/vtr_flow/scripts/python_libs/vtr/util.py b/vtr_flow/scripts/python_libs/vtr/util.py index aea6d71a028..67969103e61 100644 --- a/vtr_flow/scripts/python_libs/vtr/util.py +++ b/vtr_flow/scripts/python_libs/vtr/util.py @@ -545,6 +545,7 @@ def get_latest_run_dir(base_dir): else: return None + def get_existing_run_dir(base_dir: str, run_dir: str) -> str: """ Get an existing run directory (from a previous run). Throw if it doesn't exist From bbdfbb3180cfaeb742249bfb9680dc1c9734bf8d Mon Sep 17 00:00:00 2001 From: amin1377 Date: Mon, 31 Mar 2025 11:50:19 -0400 Subject: [PATCH 09/17] fix python lint --- vtr_flow/scripts/python_libs/vtr/util.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/vtr_flow/scripts/python_libs/vtr/util.py b/vtr_flow/scripts/python_libs/vtr/util.py index 67969103e61..ff7e016db30 100644 --- a/vtr_flow/scripts/python_libs/vtr/util.py +++ b/vtr_flow/scripts/python_libs/vtr/util.py @@ -22,9 +22,17 @@ from vtr import paths -# The run directory name passed by set_global_run_dir is the run directory name to parse. If it is None, -# the latest run directory will be parsed. -global_run_dir_name = None +class RunDir: + """ + A class for representing a run directory. + """ + # The run directory name passed by set_global_run_dir + # is the run directory name to parse. + # If it is None, the latest run directory will be parsed. + g_run_dir_name = None + + + class RawDefaultHelpFormatter( @@ -230,12 +238,11 @@ def run_system_command( # pylint: enable=too-many-arguments, too-many-instance-attributes, too-few-public-methods, too-many-locals -def set_global_run_dir(run_dir_name): +def set_global_run_dir(current_run_dir_name): """ Set the global run directory name. """ - global global_run_dir_name - global_run_dir_name = run_dir_name + RunDir.g_run_dir_name = current_run_dir_name def check_cmd(command): @@ -576,9 +583,8 @@ def get_latest_run_dir_name(base_dir): """ Returns the highest run number of all run directories with in base_dir """ - global global_run_dir_name - if global_run_dir_name is not None: - return global_run_dir_name + if RunDir.g_run_dir_name is not None: + return RunDir.g_run_dir_name else: run_number = 1 run_dir = Path(base_dir) / run_dir_name(run_number) From b5d0d2cf491565fb18380232f18f0b05a9be93a7 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Mon, 31 Mar 2025 12:16:09 -0400 Subject: [PATCH 10/17] fix formatting issues --- vtr_flow/scripts/python_libs/vtr/util.py | 43 ++++++++++++------------ 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/vtr_flow/scripts/python_libs/vtr/util.py b/vtr_flow/scripts/python_libs/vtr/util.py index ff7e016db30..1d5d38ac9f8 100644 --- a/vtr_flow/scripts/python_libs/vtr/util.py +++ b/vtr_flow/scripts/python_libs/vtr/util.py @@ -26,13 +26,11 @@ class RunDir: """ A class for representing a run directory. """ - # The run directory name passed by set_global_run_dir - # is the run directory name to parse. - # If it is None, the latest run directory will be parsed. - g_run_dir_name = None - - + # The run directory name passed by set_global_run_dir + # is the run directory name to parse. + # If it is None, the latest run directory will be parsed. + g_run_dir_name = None class RawDefaultHelpFormatter( @@ -547,10 +545,11 @@ def get_latest_run_dir(base_dir): """ latest_run_dir_name = get_latest_run_dir_name(base_dir) + run_dir = None if latest_run_dir_name: - return str(PurePath(base_dir) / latest_run_dir_name) - else: - return None + run_dir = str(PurePath(base_dir) / latest_run_dir_name) + + return run_dir def get_existing_run_dir(base_dir: str, run_dir: str) -> str: @@ -571,35 +570,35 @@ def get_next_run_number(base_dir): """ latest_run_dir_name = get_latest_run_dir_name(base_dir) match = re.match(r"^run(\d{3})$", latest_run_dir_name) + next_run_number = 1 if match: latest_run_number = int(match.group(1)) next_run_number = latest_run_number + 1 - return next_run_number - else: - return 1 + + return next_run_number def get_latest_run_dir_name(base_dir): """ Returns the highest run number of all run directories with in base_dir """ + latest_run_dir_name = "" if RunDir.g_run_dir_name is not None: - return RunDir.g_run_dir_name + latest_run_dir_name = RunDir.g_run_dir_name else: run_number = 1 run_dir = Path(base_dir) / run_dir_name(run_number) - if not run_dir.exists(): - # No existing run directories - return "" + if run_dir.exists(): + while run_dir.exists(): + run_number += 1 + run_dir = Path(base_dir) / run_dir_name(run_number) - while run_dir.exists(): - run_number += 1 - run_dir = Path(base_dir) / run_dir_name(run_number) + # Currently one-past the last existing run dir, + # to get latest existing, subtract one + latest_run_dir_name = run_dir_name(run_number - 1) - # Currently one-past the last existing run dir, - # to get latest existing, subtract one - return run_dir_name(run_number - 1) + return latest_run_dir_name def run_dir_name(run_num): From 927488c254122b0fe0be2bd094955f264cf9dd03 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Mon, 31 Mar 2025 12:52:34 -0400 Subject: [PATCH 11/17] [script] add class methods --- vtr_flow/scripts/python_libs/vtr/util.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/vtr_flow/scripts/python_libs/vtr/util.py b/vtr_flow/scripts/python_libs/vtr/util.py index 1d5d38ac9f8..84c7f81810d 100644 --- a/vtr_flow/scripts/python_libs/vtr/util.py +++ b/vtr_flow/scripts/python_libs/vtr/util.py @@ -32,6 +32,14 @@ class RunDir: # If it is None, the latest run directory will be parsed. g_run_dir_name = None + @classmethod + def set_run_dir_name(cls, run_dir_name): + cls.g_run_dir_name = run_dir_name + + @classmethod + def get_run_dir_name(cls): + return cls.g_run_dir_name + class RawDefaultHelpFormatter( argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionHelpFormatter @@ -240,7 +248,7 @@ def set_global_run_dir(current_run_dir_name): """ Set the global run directory name. """ - RunDir.g_run_dir_name = current_run_dir_name + RunDir.set_run_dir_name(current_run_dir_name) def check_cmd(command): @@ -583,8 +591,8 @@ def get_latest_run_dir_name(base_dir): Returns the highest run number of all run directories with in base_dir """ latest_run_dir_name = "" - if RunDir.g_run_dir_name is not None: - latest_run_dir_name = RunDir.g_run_dir_name + if RunDir.get_run_dir_name() is not None: + latest_run_dir_name = RunDir.get_run_dir_name() else: run_number = 1 run_dir = Path(base_dir) / run_dir_name(run_number) From d67615f222bc0bf7903acac57060b890f8950a99 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Mon, 31 Mar 2025 13:01:44 -0400 Subject: [PATCH 12/17] fix python lint --- vtr_flow/scripts/python_libs/vtr/util.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/vtr_flow/scripts/python_libs/vtr/util.py b/vtr_flow/scripts/python_libs/vtr/util.py index 84c7f81810d..09a216dcd35 100644 --- a/vtr_flow/scripts/python_libs/vtr/util.py +++ b/vtr_flow/scripts/python_libs/vtr/util.py @@ -33,11 +33,17 @@ class RunDir: g_run_dir_name = None @classmethod - def set_run_dir_name(cls, run_dir_name): - cls.g_run_dir_name = run_dir_name + def set_run_dir_name(cls, current_run_dir_name): + """ + Set the run directory name passed by the user. + """ + cls.g_run_dir_name = current_run_dir_name @classmethod def get_run_dir_name(cls): + """ + Get the run directory name passed by the user. + """ return cls.g_run_dir_name From 31a315e6f6d997dd5d335e32c98ea55efeec2796 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Mon, 31 Mar 2025 13:13:14 -0400 Subject: [PATCH 13/17] fix pylint --- vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py b/vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py index 8720a8481a1..90308efcfd8 100755 --- a/vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py +++ b/vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py @@ -532,11 +532,8 @@ def calc_geomean(args, configs): print("date\trevision", file=out) first = False lines = summary.readlines() - run_dir_name = os.path.basename( - get_latest_run_dir(find_task_dir(configs[0], args.alt_tasks_dir)) - ) print( - run_dir_name, + os.path.basename(get_latest_run_dir(find_task_dir(configs[0], args.alt_tasks_dir))), file=out, end="\t", ) From b1565150e7329eab57cf876cc6223d7c1c3df22e Mon Sep 17 00:00:00 2001 From: amin1377 Date: Wed, 2 Apr 2025 18:39:40 -0400 Subject: [PATCH 14/17] [script] apply comments --- vtr_flow/scripts/python_libs/vtr/__init__.py | 2 +- .../scripts/python_libs/vtr/parse_vtr_task.py | 4 +-- vtr_flow/scripts/python_libs/vtr/util.py | 32 ++++++++----------- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/vtr_flow/scripts/python_libs/vtr/__init__.py b/vtr_flow/scripts/python_libs/vtr/__init__.py index 44dc5cdd99e..b822da03dc0 100644 --- a/vtr_flow/scripts/python_libs/vtr/__init__.py +++ b/vtr_flow/scripts/python_libs/vtr/__init__.py @@ -20,7 +20,7 @@ verify_file, pretty_print_table, find_task_dir, - set_global_run_dir, + RunDir, ) from .log_parse import ( determine_lut_size, diff --git a/vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py b/vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py index 90308efcfd8..5bda2aa8dba 100755 --- a/vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py +++ b/vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py @@ -32,7 +32,7 @@ VtrError, create_jobs, paths, - set_global_run_dir, + RunDir, ) # pylint: enable=wrong-import-position @@ -151,7 +151,7 @@ def vtr_command_main(arg_list, prog=None): # Load the arguments args = vtr_command_argparser(prog).parse_args(arg_list) if args.run is not None: - set_global_run_dir(args.run) + RunDir.set_user_run_dir_name(args.run) try: task_names = args.task diff --git a/vtr_flow/scripts/python_libs/vtr/util.py b/vtr_flow/scripts/python_libs/vtr/util.py index 09a216dcd35..bd0e7f4c54d 100644 --- a/vtr_flow/scripts/python_libs/vtr/util.py +++ b/vtr_flow/scripts/python_libs/vtr/util.py @@ -33,14 +33,14 @@ class RunDir: g_run_dir_name = None @classmethod - def set_run_dir_name(cls, current_run_dir_name): + def set_user_run_dir_name(cls, current_run_dir_name): """ Set the run directory name passed by the user. """ cls.g_run_dir_name = current_run_dir_name @classmethod - def get_run_dir_name(cls): + def get_user_run_dir_name(cls): """ Get the run directory name passed by the user. """ @@ -250,13 +250,6 @@ def run_system_command( # pylint: enable=too-many-arguments, too-many-instance-attributes, too-few-public-methods, too-many-locals -def set_global_run_dir(current_run_dir_name): - """ - Set the global run directory name. - """ - RunDir.set_run_dir_name(current_run_dir_name) - - def check_cmd(command): """ Return True if command can be run, False otherwise. @@ -557,7 +550,7 @@ def get_latest_run_dir(base_dir): """ Returns the run directory with the highest run number in base_dir """ - latest_run_dir_name = get_latest_run_dir_name(base_dir) + latest_run_dir_name = get_active_run_dir_name(base_dir) run_dir = None if latest_run_dir_name: @@ -582,7 +575,7 @@ def get_next_run_number(base_dir): """ Returns the next available (i.e. non-existing) run number in base_dir """ - latest_run_dir_name = get_latest_run_dir_name(base_dir) + latest_run_dir_name = get_active_run_dir_name(base_dir) match = re.match(r"^run(\d{3})$", latest_run_dir_name) next_run_number = 1 if match: @@ -592,13 +585,16 @@ def get_next_run_number(base_dir): return next_run_number -def get_latest_run_dir_name(base_dir): +def get_active_run_dir_name(base_dir): """ - Returns the highest run number of all run directories with in base_dir + Returns the active run directory name. If the user has specified + a run directory name, it will be returned. Otherwise, the + highest run number of all run directories within in base_dir + will be returned. """ - latest_run_dir_name = "" - if RunDir.get_run_dir_name() is not None: - latest_run_dir_name = RunDir.get_run_dir_name() + active_run_dir_name = "" + if RunDir.get_user_run_dir_name() is not None: + active_run_dir_name = RunDir.get_user_run_dir_name() else: run_number = 1 run_dir = Path(base_dir) / run_dir_name(run_number) @@ -610,9 +606,9 @@ def get_latest_run_dir_name(base_dir): # Currently one-past the last existing run dir, # to get latest existing, subtract one - latest_run_dir_name = run_dir_name(run_number - 1) + active_run_dir_name = run_dir_name(run_number - 1) - return latest_run_dir_name + return active_run_dir_name def run_dir_name(run_num): From f2368fe5985ed146cf8636019c1635dbc90d0cd7 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Wed, 2 Apr 2025 18:43:39 -0400 Subject: [PATCH 15/17] [script] rename get_latest_run_dir to get_active_run_dir --- vtr_flow/scripts/python_libs/vtr/__init__.py | 2 +- vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py | 8 ++++---- vtr_flow/scripts/python_libs/vtr/task.py | 7 +++---- vtr_flow/scripts/python_libs/vtr/util.py | 11 ++++++----- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/vtr_flow/scripts/python_libs/vtr/__init__.py b/vtr_flow/scripts/python_libs/vtr/__init__.py index b822da03dc0..9237e03be89 100644 --- a/vtr_flow/scripts/python_libs/vtr/__init__.py +++ b/vtr_flow/scripts/python_libs/vtr/__init__.py @@ -15,7 +15,7 @@ argparse_use_previous, argparse_str2bool, get_existing_run_dir, - get_latest_run_dir, + get_active_run_dir, get_next_run_dir, verify_file, pretty_print_table, diff --git a/vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py b/vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py index 5bda2aa8dba..0eff7bbb75c 100755 --- a/vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py +++ b/vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py @@ -19,7 +19,7 @@ from vtr import ( load_list_file, RawDefaultHelpFormatter, - get_latest_run_dir, + get_active_run_dir, load_task_config, find_task_config_file, load_pass_requirements, @@ -216,7 +216,7 @@ def parse_task(config, config_jobs, flow_metrics_basename=FIRST_PARSE_FILE, alt_ max_arch_len = len("architecture") max_circuit_len = len("circuit") for job in config_jobs: - work_dir = job.work_dir(get_latest_run_dir(find_task_dir(config, alt_tasks_dir))) + work_dir = job.work_dir(get_active_run_dir(find_task_dir(config, alt_tasks_dir))) job.parse_command()[0] = work_dir # job.second_parse_command()[0] = work_dir job.qor_parse_command()[0] = work_dir @@ -533,7 +533,7 @@ def calc_geomean(args, configs): first = False lines = summary.readlines() print( - os.path.basename(get_latest_run_dir(find_task_dir(configs[0], args.alt_tasks_dir))), + os.path.basename(get_active_run_dir(find_task_dir(configs[0], args.alt_tasks_dir))), file=out, end="\t", ) @@ -579,7 +579,7 @@ def find_latest_run_dir(config, alt_tasks_dir=None): """Find the latest run directory for given configuration""" task_dir = find_task_dir(config, alt_tasks_dir) - run_dir = get_latest_run_dir(task_dir) + run_dir = get_active_run_dir(task_dir) if not run_dir: raise InspectError( diff --git a/vtr_flow/scripts/python_libs/vtr/task.py b/vtr_flow/scripts/python_libs/vtr/task.py index be2559446fe..178b0675e7e 100644 --- a/vtr_flow/scripts/python_libs/vtr/task.py +++ b/vtr_flow/scripts/python_libs/vtr/task.py @@ -16,8 +16,7 @@ load_list_file, load_parse_results, get_existing_run_dir, - get_latest_run_dir, - get_next_run_dir, + get_active_run_dir, find_task_dir, load_script_param, paths, @@ -585,10 +584,10 @@ def create_jobs(args, configs, after_run=False) -> List[Job]: work_dir = get_work_dir_addr(arch, circuit, noc_traffic) run_dir = ( - str(Path(get_latest_run_dir(find_task_dir(config, args.alt_tasks_dir))) / work_dir) + str(Path(get_active_run_dir(find_task_dir(config, args.alt_tasks_dir))) / work_dir) if after_run else str( - Path(get_next_run_dir(find_task_dir(config, args.alt_tasks_dir))) / work_dir + Path(get_active_run_dir(find_task_dir(config, args.alt_tasks_dir))) / work_dir ) ) diff --git a/vtr_flow/scripts/python_libs/vtr/util.py b/vtr_flow/scripts/python_libs/vtr/util.py index bd0e7f4c54d..e816e8b881c 100644 --- a/vtr_flow/scripts/python_libs/vtr/util.py +++ b/vtr_flow/scripts/python_libs/vtr/util.py @@ -546,15 +546,16 @@ def find_task_dir(config, alt_tasks_dir=None): return str(task_dir) -def get_latest_run_dir(base_dir): +def get_active_run_dir(base_dir): """ - Returns the run directory with the highest run number in base_dir + Returns full path to the active run directory + locatedin base_dir """ - latest_run_dir_name = get_active_run_dir_name(base_dir) + active_run_dir_name = get_active_run_dir_name(base_dir) run_dir = None - if latest_run_dir_name: - run_dir = str(PurePath(base_dir) / latest_run_dir_name) + if active_run_dir_name: + run_dir = str(PurePath(base_dir) / active_run_dir_name) return run_dir From 880ad268939ba0995865807a6ea0b5e6beaed0c1 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Fri, 4 Apr 2025 09:34:40 -0400 Subject: [PATCH 16/17] [script] afix the bug with get_next_run_dir --- vtr_flow/scripts/python_libs/vtr/task.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vtr_flow/scripts/python_libs/vtr/task.py b/vtr_flow/scripts/python_libs/vtr/task.py index 178b0675e7e..3d063d05202 100644 --- a/vtr_flow/scripts/python_libs/vtr/task.py +++ b/vtr_flow/scripts/python_libs/vtr/task.py @@ -16,6 +16,7 @@ load_list_file, load_parse_results, get_existing_run_dir, + get_next_run_dir, get_active_run_dir, find_task_dir, load_script_param, @@ -587,7 +588,7 @@ def create_jobs(args, configs, after_run=False) -> List[Job]: str(Path(get_active_run_dir(find_task_dir(config, args.alt_tasks_dir))) / work_dir) if after_run else str( - Path(get_active_run_dir(find_task_dir(config, args.alt_tasks_dir))) / work_dir + Path(get_next_run_dir(find_task_dir(config, args.alt_tasks_dir))) / work_dir ) ) From 5049dcf7d0a961a6af31ee496d01806e075ad8ef Mon Sep 17 00:00:00 2001 From: amin1377 Date: Fri, 4 Apr 2025 09:52:30 -0400 Subject: [PATCH 17/17] python lint --- vtr_flow/scripts/python_libs/vtr/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vtr_flow/scripts/python_libs/vtr/util.py b/vtr_flow/scripts/python_libs/vtr/util.py index e816e8b881c..a80521f07e8 100644 --- a/vtr_flow/scripts/python_libs/vtr/util.py +++ b/vtr_flow/scripts/python_libs/vtr/util.py @@ -548,7 +548,7 @@ def find_task_dir(config, alt_tasks_dir=None): def get_active_run_dir(base_dir): """ - Returns full path to the active run directory + Returns full path to the active run directory locatedin base_dir """ active_run_dir_name = get_active_run_dir_name(base_dir)