@@ -55,14 +55,21 @@ def parse_args() -> Tuple[str, str, int, bool]:
55
55
default = "/usr/bin/google-chrome %s" ,
56
56
help = 'Browser path, default is /usr/bin/google-chrome %s'
57
57
)
58
+ parser .add_argument (
59
+ '--port' ,
60
+ type = str ,
61
+ default = "8000" ,
62
+ help = 'Port number for the frontend server'
63
+ )
58
64
origin = parser .parse_args ().origin
59
65
target = parser .parse_args ().target
60
66
steps = parser .parse_args ().steps
61
67
ui = parser .parse_args ().ui
62
68
ui = True if ui .lower () == "true" else False
63
69
browser_path = parser .parse_args ().browser_path
70
+ port = parser .parse_args ().port
64
71
65
- return origin , target , steps , ui , browser_path
72
+ return origin , target , steps , ui , browser_path , port
66
73
67
74
68
75
def get_starting_step (exp_name : str ) -> int :
@@ -81,13 +88,15 @@ def get_starting_step(exp_name: str) -> int:
81
88
return current_step
82
89
83
90
84
- def start_web_tab (ui : bool , browser_path : str ) -> None :
91
+ def start_web_tab (ui : bool , browser_path : str , port : str ) -> None :
85
92
"""Open a new tab in the browser with the simulator home page
86
93
87
94
Args:
88
95
ui (bool): Open the simulator UI.
96
+ browser_path (str): The path of the browser.
97
+ port (str): The port number of the frontend server.
89
98
"""
90
- url = "http://localhost:8000 /simulator_home"
99
+ url = f "http://localhost:{ port } /simulator_home"
91
100
print ("(Auto-Exec): Opening the simulator home page" , flush = True )
92
101
time .sleep (5 )
93
102
try :
@@ -137,7 +146,7 @@ def save_checkpoint(rs, idx: int, th: Process) -> Tuple[str, int, int]:
137
146
checkpoint_freq = 2 # 1 step = 10 sec
138
147
log_path = "cost-logs"
139
148
idx = 0
140
- origin , target , tot_steps , ui , browser_path = parse_args ()
149
+ origin , target , tot_steps , ui , browser_path , port = parse_args ()
141
150
current_step = get_starting_step (origin )
142
151
exp_name = target
143
152
start_time = datetime .now ()
@@ -149,15 +158,15 @@ def save_checkpoint(rs, idx: int, th: Process) -> Tuple[str, int, int]:
149
158
print (f"(Auto-Exec): Target: { target } " , flush = True )
150
159
print (f"(Auto-Exec): Total steps: { tot_steps } " , flush = True )
151
160
print (f"(Auto-Exec): Checkpoint Freq: { checkpoint_freq } " , flush = True )
152
-
161
+
153
162
while current_step < tot_steps :
154
163
try :
155
164
steps_to_run = curr_checkpoint - current_step
156
165
target = f"{ exp_name } -s-{ idx } -{ current_step } -{ curr_checkpoint } "
157
166
print (f"(Auto-Exec): STAGE { idx } " , flush = True )
158
167
print (f"(Auto-Exec): Running experiment '{ exp_name } ' from step '{ current_step } ' to '{ curr_checkpoint } '" , flush = True )
159
168
rs = reverie .ReverieServer (origin , target )
160
- th = Process (target = start_web_tab , args = (ui , browser_path ))
169
+ th = Process (target = start_web_tab , args = (ui , browser_path , port ))
161
170
th .start ()
162
171
rs .open_server (input_command = f"run { steps_to_run } " )
163
172
except KeyboardInterrupt :
@@ -178,7 +187,7 @@ def save_checkpoint(rs, idx: int, th: Process) -> Tuple[str, int, int]:
178
187
finally :
179
188
time .sleep (10 ) # Wait for the server to finish and then kill the process
180
189
if th .is_alive ():
181
- th .terminate ()
190
+ th .kill ()
182
191
183
192
print (f"(Auto-Exec): EXPERIMENT FINISHED: { exp_name } " )
184
193
OpenAICostLoggerViz .print_experiment_cost (experiment = exp_name , path = log_path )
0 commit comments