Skip to content

Commit e36c1b7

Browse files
committed
[vtr][script] add run dir to parse script
1 parent 16b900f commit e36c1b7

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

vtr_flow/scripts/python_libs/vtr/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
verify_file,
2222
pretty_print_table,
2323
find_task_dir,
24+
set_global_run_dir_number
2425
)
2526
from .log_parse import (
2627
determine_lut_size,

vtr_flow/scripts/python_libs/vtr/parse_vtr_task.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
VtrError,
3333
create_jobs,
3434
paths,
35+
set_global_run_dir_number,
3536
)
3637

3738
# pylint: enable=wrong-import-position
@@ -130,7 +131,7 @@ def vtr_command_argparser(prog=None):
130131
help="QoR geomeans are not computed by default",
131132
)
132133

133-
parser.add_argument("-run", default=None, type=str, help="")
134+
parser.add_argument("-run", default=None, type=int, help="Run number to parse. If not provided, the latest run will be parsed.")
134135

135136
parser.add_argument("-revision", default="", help="Revision number")
136137

@@ -144,6 +145,8 @@ def vtr_command_main(arg_list, prog=None):
144145
"""
145146
# Load the arguments
146147
args = vtr_command_argparser(prog).parse_args(arg_list)
148+
if args.run is not None:
149+
set_global_run_dir_number(args.run)
147150
try:
148151
task_names = args.task
149152

vtr_flow/scripts/python_libs/vtr/util.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
from vtr import paths
2323

2424

25+
# The run number passed by get_latest_run_number is the latest run number for the task if this number is None. Otherwise
26+
# it is the run number to parse.
27+
global_run_dir_number = None
28+
2529
class RawDefaultHelpFormatter(
2630
argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionHelpFormatter
2731
):
@@ -224,6 +228,13 @@ def run_system_command(
224228

225229
# pylint: enable=too-many-arguments, too-many-instance-attributes, too-few-public-methods, too-many-locals
226230

231+
def set_global_run_dir_number(run_dir_number):
232+
"""
233+
Set the global run directory number.
234+
"""
235+
global global_run_dir_number
236+
global_run_dir_number = run_dir_number
237+
227238

228239
def check_cmd(command):
229240
"""
@@ -563,20 +574,26 @@ def get_latest_run_number(base_dir):
563574
"""
564575
Returns the highest run number of all run directories with in base_dir
565576
"""
566-
run_number = 1
567-
run_dir = Path(base_dir) / run_dir_name(run_number)
577+
global global_run_dir_number
578+
run_number = None
579+
if global_run_dir_number is None:
580+
run_number = 1
581+
run_dir = Path(base_dir) / run_dir_name(run_number)
568582

569-
if not run_dir.exists():
570-
# No existing run directories
571-
return None
583+
if not run_dir.exists():
584+
# No existing run directories
585+
return None
572586

573-
while run_dir.exists():
574-
run_number += 1
575-
run_dir = Path(base_dir) / run_dir_name(run_number)
587+
while run_dir.exists():
588+
run_number += 1
589+
run_dir = Path(base_dir) / run_dir_name(run_number)
576590

577-
# Currently one-past the last existing run dir,
578-
# to get latest existing, subtract one
579-
return run_number - 1
591+
# Currently one-past the last existing run dir,
592+
# to get latest existing, subtract one
593+
run_number = run_number - 1
594+
else:
595+
run_number = global_run_dir_number
596+
return run_number
580597

581598

582599
def run_dir_name(run_num):

0 commit comments

Comments
 (0)