Skip to content

Commit 5abb720

Browse files
committed
catching errors
1 parent eff3d8d commit 5abb720

File tree

2 files changed

+35
-31
lines changed

2 files changed

+35
-31
lines changed

proj/environment/manager.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,11 @@ def _start_logging(self):
8383
extra={"markup": True},
8484
)
8585

86+
def _log_conf(self):
8687
# log config.py
87-
logging.info("=" * 20)
88-
logging.info("=" * 20)
8988
with open("proj/model/config.py") as f:
9089
conf = f.read()
9190
logging.info(conf)
92-
logging.info("=" * 20)
93-
logging.info("=" * 20)
9491

9592
def _save_results(self):
9693
# save config
@@ -147,6 +144,7 @@ def _upload_to_dropbox(self):
147144
upload_folder(dbx, self.datafolder, dpx_path)
148145

149146
def conclude(self):
147+
self._log_conf()
150148
self._save_results()
151149
self._save_video()
152150

proj/run/runner.py

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -70,40 +70,46 @@ def run_experiment(
7070
task_id = progress.add_task("running", start=True, total=n_steps)
7171

7272
for itern in range(n_steps):
73-
progress.advance(task_id, 1)
73+
try:
74+
progress.advance(task_id, 1)
7475

75-
curr_x = np.array(model.curr_x)
76+
curr_x = np.array(model.curr_x)
7677

77-
# plan
78-
g_xs = environment.plan(curr_x, trajectory, itern)
78+
# plan
79+
g_xs = environment.plan(curr_x, trajectory, itern)
7980

80-
# obtain sol
81-
u = controller.obtain_sol(curr_x, g_xs)
81+
# obtain sol
82+
u = controller.obtain_sol(curr_x, g_xs)
8283

83-
# step
84-
model.step(u)
84+
# step
85+
model.step(u)
8586

86-
# get current cost
87-
environment.curr_cost = controller.calc_step_cost(
88-
np.array(model.curr_x), u, g_xs[0, :]
89-
)
90-
91-
# update world
92-
environment.itern = itern
93-
environment.update_world(g_xs, elapsed=itern * model.dt)
94-
95-
# log status once a second
96-
if itern % int(1 / model.dt) == 0:
97-
log.info(
98-
f"Iteration {itern}/{n_steps}. Current cost: {environment.curr_cost}."
87+
# get current cost
88+
environment.curr_cost = controller.calc_step_cost(
89+
np.array(model.curr_x), u, g_xs[0, :]
9990
)
10091

101-
# Check if we're done
102-
if environment.isdone(model.curr_x, trajectory):
103-
log.info("environment says we're DONE")
104-
break
105-
if environment.stop:
106-
log.info("environment says STOP")
92+
# update world
93+
environment.itern = itern
94+
environment.update_world(g_xs, elapsed=itern * model.dt)
95+
96+
# log status once a second
97+
if itern % int(1 / model.dt) == 0:
98+
log.info(
99+
f"Iteration {itern}/{n_steps}. Current cost: {environment.curr_cost}."
100+
)
101+
102+
# Check if we're done
103+
if environment.isdone(model.curr_x, trajectory):
104+
log.info("environment says we're DONE")
105+
break
106+
if environment.stop:
107+
log.info("environment says STOP")
108+
break
109+
except Exception as e:
110+
logging.error(
111+
f"Failed to take next step in simulation.\n error {e}"
112+
)
107113
break
108114

109115
log.info(f"Terminated after {itern} iterations.")

0 commit comments

Comments
 (0)