@@ -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