Skip to content

Commit e8cdcfe

Browse files
committed
revert list comprehension into for loop for better readability
Signed-off-by: Jack Luar <[email protected]>
1 parent ab31e29 commit e8cdcfe

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

tools/AutoTuner/test/resume_check.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
from contextlib import contextmanager
4343

4444
cur_dir = os.path.dirname(os.path.abspath(__file__))
45+
DEFAULT_MODIFIED_TIME = 0
4546

4647

4748
@contextmanager
@@ -90,13 +91,13 @@ def setUp(self):
9091
for c in options
9192
]
9293

93-
def get_trial_times(self, iteration: int = 0) -> int:
94+
def get_last_modified_time(self, iteration: int = 0) -> int:
9495
"""
9596
Returns the nth iteration time of a trial.
9697
9798
:param iteration: The iteration to check.
9899
:return: The latest modified UNIX time of the nth iteration.
99-
If no folders are found, returns a default value of 9e99.
100+
If no folders are found, returns a default value.
100101
"""
101102
if iteration < 0 or iteration >= self.iterations:
102103
raise ValueError("Iteration must be between 0 and (iterations - 1)")
@@ -105,8 +106,15 @@ def get_trial_times(self, iteration: int = 0) -> int:
105106
cur_dir,
106107
f"../../../flow/logs/{self.platform}/{self.design}/{self.experiment_name}-tune",
107108
)
108-
folders = glob.glob(os.path.join(experiment_dir, f"variant-*-or-{iteration}"))
109-
return max((os.path.getmtime(folder) for folder in folders), default=9e99)
109+
iteration_folders = glob.glob(
110+
os.path.join(experiment_dir, f"variant-*-or-{iteration}")
111+
)
112+
latest_modified_time = DEFAULT_MODIFIED_TIME
113+
for folder in iteration_folders:
114+
modified_time = os.path.getmtime(folder)
115+
if modified_time > latest_modified_time:
116+
latest_modified_time = modified_time
117+
return latest_modified_time
110118

111119
def test_tune_resume(self):
112120
# Goal is to first run the first config (without resume) and then run the second config (with resume)
@@ -119,7 +127,7 @@ def test_tune_resume(self):
119127
time.sleep(30)
120128
# Check if first config is complete
121129
while True:
122-
cur_modified_time = self.get_trial_times()
130+
cur_modified_time = self.get_last_modified_time()
123131
print(f"Current modified time: {cur_modified_time}")
124132
print(f"Latest modified time: {latest_modified_time}")
125133
if abs(cur_modified_time - latest_modified_time) < 1e-3:

0 commit comments

Comments
 (0)