Skip to content

Commit bbfef12

Browse files
committed
feat: Add port config.
1 parent e49b730 commit bbfef12

File tree

6 files changed

+42
-17
lines changed

6 files changed

+42
-17
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
openai_config.json
33

44
environment/frontend_server/storage/*
5-
environment/frontend_server/temp_storage/*
5+
environment/frontend_server/temp_storage*/*
66
reverie/backend_server/cost-logs/*
77

88
# Logs folder

environment/frontend_server/translator/views.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
from django.contrib.staticfiles.templatetags.staticfiles import static
1818
from .models import *
1919

20+
fs_temp_storage = "temp_storage"
21+
2022
def landing(request):
2123
context = {}
2224
template = "landing/landing.html"
@@ -103,8 +105,8 @@ def UIST_Demo(request):
103105

104106

105107
def home(request):
106-
f_curr_sim_code = "temp_storage/curr_sim_code.json"
107-
f_curr_step = "temp_storage/curr_step.json"
108+
f_curr_sim_code = f"{fs_temp_storage}/curr_sim_code.json"
109+
f_curr_step = f"{fs_temp_storage}/curr_step.json"
108110

109111
if not check_if_file_exists(f_curr_step):
110112
context = {}
@@ -308,7 +310,7 @@ def path_tester_update(request):
308310
data = json.loads(request.body)
309311
camera = data["camera"]
310312

311-
with open(f"temp_storage/path_tester_env.json", "w") as outfile:
313+
with open(f"{fs_temp_storage}/path_tester_env.json", "w") as outfile:
312314
outfile.write(json.dumps(camera, indent=2))
313315

314316
return HttpResponse("received")

reverie/backend_server/automatic_execution.py

+16-7
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,21 @@ def parse_args() -> Tuple[str, str, int, bool]:
5555
default="/usr/bin/google-chrome %s",
5656
help='Browser path, default is /usr/bin/google-chrome %s'
5757
)
58+
parser.add_argument(
59+
'--port',
60+
type=str,
61+
default="8000",
62+
help='Port number for the frontend server'
63+
)
5864
origin = parser.parse_args().origin
5965
target = parser.parse_args().target
6066
steps = parser.parse_args().steps
6167
ui = parser.parse_args().ui
6268
ui = True if ui.lower() == "true" else False
6369
browser_path = parser.parse_args().browser_path
70+
port = parser.parse_args().port
6471

65-
return origin, target, steps, ui, browser_path
72+
return origin, target, steps, ui, browser_path, port
6673

6774

6875
def get_starting_step(exp_name: str) -> int:
@@ -81,13 +88,15 @@ def get_starting_step(exp_name: str) -> int:
8188
return current_step
8289

8390

84-
def start_web_tab(ui: bool, browser_path: str) -> None:
91+
def start_web_tab(ui: bool, browser_path: str, port: str) -> None:
8592
"""Open a new tab in the browser with the simulator home page
8693
8794
Args:
8895
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.
8998
"""
90-
url = "http://localhost:8000/simulator_home"
99+
url = f"http://localhost:{port}/simulator_home"
91100
print("(Auto-Exec): Opening the simulator home page", flush=True)
92101
time.sleep(5)
93102
try:
@@ -137,7 +146,7 @@ def save_checkpoint(rs, idx: int, th: Process) -> Tuple[str, int, int]:
137146
checkpoint_freq = 2 # 1 step = 10 sec
138147
log_path = "cost-logs"
139148
idx = 0
140-
origin, target, tot_steps, ui, browser_path = parse_args()
149+
origin, target, tot_steps, ui, browser_path, port = parse_args()
141150
current_step = get_starting_step(origin)
142151
exp_name = target
143152
start_time = datetime.now()
@@ -149,15 +158,15 @@ def save_checkpoint(rs, idx: int, th: Process) -> Tuple[str, int, int]:
149158
print(f"(Auto-Exec): Target: {target}", flush=True)
150159
print(f"(Auto-Exec): Total steps: {tot_steps}", flush=True)
151160
print(f"(Auto-Exec): Checkpoint Freq: {checkpoint_freq}", flush=True)
152-
161+
153162
while current_step < tot_steps:
154163
try:
155164
steps_to_run = curr_checkpoint - current_step
156165
target = f"{exp_name}-s-{idx}-{current_step}-{curr_checkpoint}"
157166
print(f"(Auto-Exec): STAGE {idx}", flush=True)
158167
print(f"(Auto-Exec): Running experiment '{exp_name}' from step '{current_step}' to '{curr_checkpoint}'", flush=True)
159168
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))
161170
th.start()
162171
rs.open_server(input_command=f"run {steps_to_run}")
163172
except KeyboardInterrupt:
@@ -178,7 +187,7 @@ def save_checkpoint(rs, idx: int, th: Process) -> Tuple[str, int, int]:
178187
finally:
179188
time.sleep(10) # Wait for the server to finish and then kill the process
180189
if th.is_alive():
181-
th.terminate()
190+
th.kill()
182191

183192
print(f"(Auto-Exec): EXPERIMENT FINISHED: {exp_name}")
184193
OpenAICostLoggerViz.print_experiment_cost(experiment=exp_name, path=log_path)

reverie/backend_server/reverie.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ class ReverieServer:
5656
def __init__(self,
5757
fork_sim_code,
5858
sim_code):
59+
60+
print ("(reverie): Temp storage: ", fs_temp_storage)
61+
5962
# FORKING FROM A PRIOR SIMULATION:
6063
# <fork_sim_code> indicates the simulation we are forking from.
6164
# Interestingly, all simulations must be forked from some initial
@@ -650,9 +653,6 @@ def open_server(self, input_command: str = None) -> None:
650653
origin = parser.parse_args().origin
651654
target = parser.parse_args().target
652655

653-
print(f"Origin: {origin}")
654-
print(f"Target: {target}")
655-
656656
rs = ReverieServer(origin, target)
657657
rs.open_server()
658658

run_backend_automatic.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ CONDA_ENV="simulacra"
66
LOGS_PATH="../../logs"
77

88
FILE_NAME="Bash-Script"
9-
echo "(${FILE_NAME}): Running backend server at: http://127.0.0.1:8000/simulator_home"
109
cd ${BACKEND_SCRIPT_PATH}
1110
source /home/${USER}/anaconda3/bin/activate ${CONDA_ENV}
1211

@@ -38,6 +37,12 @@ while [[ $# -gt 0 ]]; do
3837
shift
3938
shift
4039
;;
40+
--port|-p)
41+
ARGS="${ARGS} --port ${2}"
42+
echo "(${FILE_NAME}): Running backend server at: http://127.0.0.1:${2}/simulator_home"
43+
shift
44+
shift
45+
;;
4146
*)
4247
echo "Unknown argument: $1"
4348
exit 1

run_frontend.sh

+11-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@ FRONTEND_SCRIPT_PATH="environment/frontend_server"
44
FRONTEND_SCRIPT_FILE="manage.py"
55
CONDA_ENV="simulacra"
66

7-
echo "Running frontend server"
7+
FILE_NAME="Bash-Script-Frontend"
8+
echo "(${FILE_NAME}): Running frontend server"
89
cd ${FRONTEND_SCRIPT_PATH}
910
source /home/${USER}/anaconda3/bin/activate ${CONDA_ENV}
1011

11-
python ${FRONTEND_SCRIPT_FILE} runserver
12+
PORT=8000
13+
if [ -z "$1" ]
14+
then
15+
echo "(${FILE_NAME}): No port provided. Using default port: ${PORT}"
16+
else
17+
PORT=$1
18+
fi
19+
20+
python ${FRONTEND_SCRIPT_FILE} runserver ${PORT}

0 commit comments

Comments
 (0)