@@ -181,90 +181,110 @@ def main(device: str = "cpu", n_worlds_exp: int = 6):
181181 # Reopen the file in append mode for each result
182182
183183 n_steps = 1000
184+ skip_sim , skip_gym = False , False
184185 # Test with increasing number of parallel environments (worlds)
185186 for n_worlds in [10 ** i for i in range (n_worlds_exp + 1 )]:
186- print (f"\n Testing with { n_worlds } parallel environments:" )
187- sim_config .n_worlds = n_worlds
188-
189- # Test with a single step first to see if we should continue
190- sim_config .freq = 500 # Test sim at 500 hz
191- test_times = profile_step (sim_config , 1 , device )
192-
193- single_step_time = test_times [0 ]
194- # If single step takes too long, skip this and remaining tests
195- if single_step_time > max_seconds_per_run / n_steps : # threshold for the tests
196- print (
197- f" Skipping benchmark for { n_worlds } and higher - single step took "
198- f"{ single_step_time * 1000 :.2f} s (> 1m)"
199- )
200- break
201-
202- # Configure simulator
203- print (f" Running simulator benchmark ({ n_worlds } worlds)..." )
204- # Run simulator benchmark using existing function
205- times_sim = profile_step (sim_config , n_steps , device )
206-
207- # Calculate metrics for CSV
208- total_time = sum (times_sim )
209- avg_step_time = np .mean (times_sim )
210- n_frames = n_steps * n_worlds
211- fps = n_frames / total_time
212- real_time_factor = (n_steps / sim_config .freq ) * n_worlds / total_time
213-
214- # Save simulator results
215- # Reopen CSV writer in append mode
216- with open (csv_file , "a" , newline = "" ) as f :
217- csv_writer = csv .writer (f )
218- csv_writer .writerow (
219- [
220- "simulator" ,
221- 1 , # n_drones
222- n_worlds ,
223- n_steps ,
224- total_time ,
225- avg_step_time ,
226- fps ,
227- real_time_factor ,
228- sim_config .device ,
229- ]
230- )
231- f .flush ()
232-
233- print (f" Running gym environment benchmark ({ n_worlds } worlds)..." )
234- # Run gym environment benchmark using existing function
235- sim_config .freq = 50 # Test gym at 50 hz
236- try :
237- times_gym = profile_gym_env_step (sim_config , n_steps , device )
238- except ValueError as e :
239- if "RESOURCE_EXHAUSTED" in str (e ):
240- print (f" Skipping benchmark for { n_worlds } - resource exhausted" )
241- continue # Only continue, we might still be able to benchmark sim
242- raise e
243-
244- # Calculate metrics for CSV
245- total_time = sum (times_gym )
246- avg_step_time = np .mean (times_gym )
247- n_frames = n_steps * n_worlds
248- fps = n_frames / total_time
249- real_time_factor = (n_steps / sim_config .freq ) * sim_config .n_worlds / total_time
250-
251- # Save gym environment results
252- with open (csv_file , "a" , newline = "" ) as f :
253- csv_writer = csv .writer (f )
254- csv_writer .writerow (
255- [
256- "gym_env" ,
257- sim_config .n_drones ,
258- sim_config .n_worlds ,
259- n_steps ,
260- total_time ,
261- avg_step_time ,
262- fps ,
263- real_time_factor ,
264- sim_config .device ,
265- ]
266- )
267- f .flush ()
187+ if not skip_sim :
188+ print (f"\n Testing with { n_worlds } parallel environments:" )
189+ sim_config .n_worlds = n_worlds
190+
191+ # Test with a single step first to see if we should continue
192+ sim_config .freq = 500 # Test sim at 500 hz
193+ single_step_time = profile_step (sim_config , 2 , device )[1 ]
194+
195+ # If single step takes too long, skip this and remaining tests
196+ if single_step_time > max_seconds_per_run / n_steps : # threshold for the tests
197+ print (
198+ f" Skipping benchmark for { n_worlds } and higher - single step took "
199+ f"{ single_step_time * n_steps :.2f} s (> 1m)"
200+ )
201+ skip_sim = True
202+
203+ if not skip_sim :
204+ # Configure simulator
205+ print (f" Running simulator benchmark ({ n_worlds } worlds)..." )
206+ # Run simulator benchmark using existing function
207+ times_sim = profile_step (sim_config , n_steps , device )
208+
209+ # Calculate metrics for CSV
210+ total_time = sum (times_sim )
211+ avg_step_time = np .mean (times_sim )
212+ n_frames = n_steps * n_worlds
213+ fps = n_frames / total_time
214+ real_time_factor = (n_steps / sim_config .freq ) * n_worlds / total_time
215+
216+ # Save simulator results
217+ # Reopen CSV writer in append mode
218+ with open (csv_file , "a" , newline = "" ) as f :
219+ csv_writer = csv .writer (f )
220+ csv_writer .writerow (
221+ [
222+ "simulator" ,
223+ 1 , # n_drones
224+ n_worlds ,
225+ n_steps ,
226+ total_time ,
227+ avg_step_time ,
228+ fps ,
229+ real_time_factor ,
230+ sim_config .device ,
231+ ]
232+ )
233+ f .flush ()
234+
235+ if not skip_gym :
236+ print (f" Running gym environment benchmark ({ n_worlds } worlds)..." )
237+ # Run gym environment benchmark using existing function
238+ sim_config .freq = 50 # Test gym at 50 hz
239+ try :
240+ single_step_time = profile_gym_env_step (sim_config , 2 , device )[1 ]
241+ # If single step takes too long, skip this test only
242+ if single_step_time > max_seconds_per_run / n_steps : # threshold for the tests
243+ print (
244+ f" Skipping benchmark for { n_worlds } - single step took "
245+ f"{ single_step_time * n_steps :.2f} s (> 1m)"
246+ )
247+ skip_gym = True
248+ except ValueError as e :
249+ if "RESOURCE_EXHAUSTED" in str (e ):
250+ print (f" Skipping benchmark for { n_worlds } - resource exhausted" )
251+ skip_gym = True
252+ else :
253+ raise e
254+
255+ if not skip_gym :
256+ try :
257+ times_gym = profile_gym_env_step (sim_config , n_steps , device )
258+ except ValueError as e :
259+ if "RESOURCE_EXHAUSTED" in str (e ):
260+ print (f" Skipping benchmark for { n_worlds } - resource exhausted" )
261+ continue # Only continue, we might still be able to benchmark sim
262+ raise e
263+
264+ # Calculate metrics for CSV
265+ total_time = sum (times_gym )
266+ avg_step_time = np .mean (times_gym )
267+ n_frames = n_steps * n_worlds
268+ fps = n_frames / total_time
269+ real_time_factor = (n_steps / sim_config .freq ) * sim_config .n_worlds / total_time
270+
271+ # Save gym environment results
272+ with open (csv_file , "a" , newline = "" ) as f :
273+ csv_writer = csv .writer (f )
274+ csv_writer .writerow (
275+ [
276+ "gym_env" ,
277+ sim_config .n_drones ,
278+ sim_config .n_worlds ,
279+ n_steps ,
280+ total_time ,
281+ avg_step_time ,
282+ fps ,
283+ real_time_factor ,
284+ sim_config .device ,
285+ ]
286+ )
287+ f .flush ()
268288
269289 print (f"\n Benchmark results saved to { csv_file } " )
270290
0 commit comments