Skip to content

Commit 1390d86

Browse files
fixed bug with retry not being triggerd on CARLA crash
1 parent edeca6c commit 1390d86

1 file changed

Lines changed: 20 additions & 22 deletions

File tree

cawsr.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def run_scenario(
277277
)
278278
result_dict = result_.get()
279279
result_dict["status"] = False
280-
result_dict["driving_score"] = 0.0
280+
result_dict["driving_score"] = None
281281

282282
if algorithm_mode:
283283
algorithm._update_generator(seed) # type: ignore
@@ -337,38 +337,36 @@ def run_scenario(
337337
# stop the MetricsCollector thread
338338
MetricsCollector.reset()
339339

340+
# Safe fallback defined before the try block
341+
result_dict = {"status": False, "driving_score": None}
342+
340343
try:
341-
# analyse the scenario, throws exception if scenario didn't finish
342344
criteria = self._output_criteria(
343-
self.scenario_manager.scenario.get_criteria(), # type: ignore
345+
self.scenario_manager.scenario.get_criteria(),
344346
f"{self.results_manager.last_scenario}/{scenario_name}.json",
345347
)
346348
logger.info("Calculating driving score...")
347-
348349
driving_score = self._calculate_driving_score(criteria)
349-
350350
result_dict = result_.get()
351351
result_dict["driving_score"] = driving_score
352352
result_dict["status"] = result
353353
logger.info("Processed driving score...")
354+
if algorithm_mode:
355+
algorithm._update_generator(seed) # type: ignore
354356

357+
try:
358+
definition = algorithm._scenario_callback( # type: ignore
359+
current_definiton, result_dict["driving_score"]
360+
)
361+
result_dict["definition"] = definition
362+
except Exception:
363+
logger.error(
364+
"Something went wrong while processing algorithm callback; is CARLA alive?"
365+
)
355366
except Exception:
356367
logger.info("Something went wrong, retrying scenario...")
357-
358-
# read the scenario definition
359-
if algorithm_mode:
360-
algorithm._update_generator(seed) # type: ignore
361-
362-
try:
363-
definition = algorithm._scenario_callback( # type: ignore
364-
current_definiton, result_dict["driving_score"]
365-
)
366-
result_dict["definition"] = definition
367-
result_.put(result_dict)
368-
except Exception:
369-
logger.error(
370-
"Something went wrong while processing algorithm callback; is CARLA alive?"
371-
)
368+
finally:
369+
result_.put(result_dict)
372370

373371
def _tick_carla(self) -> None:
374372
"""Advances CARLA 1 tick into the future"""
@@ -581,8 +579,8 @@ def _cawsr_process(
581579

582580
# if the process exits (CARLA crash for example), these are none
583581
# fetch execution status of the scenario (failure or success)
584-
status = result.get(["status"], None)
585-
driving_score = result.get(["driving_score"], None)
582+
status = result.get("status", None)
583+
driving_score = result.get("driving_score", None)
586584

587585
logger.info(f"Scenario iteration {run} achieved a score of {driving_score}")
588586
logger.info(

0 commit comments

Comments
 (0)