Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions aw_scenario_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ def run(self) -> None:
f"Scenario iteration {iteration} achieved a score of {driving_score}"
)

# clean up - delete XML files
self.results_manager.cleanup_xml()

# read the scenario definition
if not self.DEV_MODE:
self.json_definition = self.algorithm._scenario_callback(
Expand Down
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ scenario_runner:
initialisation_budget: 200 # ticks
algorithm:
iterations: 10
path: algorithms/test_alg
path: algorithms/hill_climb
args: # will be passed into the algorithm class as a dict
lanelet_path: /autoware_scenario_runner/algorithms/resources/Town01.osm
radius: 10
27 changes: 19 additions & 8 deletions srunner/tools/results_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, output_dir: str = "results") -> None:
self.results_path = ""
self._scenario_decoder = XMLToFiles()

def _create_run_folder(self, base_path: str = ""):
def _create_run_folder(self, scenario: str, base_path: str = ""):
"""Creates a experiment folder under base_path. The naming convention is as follows
```
run-{yy-mm-dd-h-m-s}
Expand All @@ -33,15 +33,15 @@ def _create_run_folder(self, base_path: str = ""):
base_path = self.output_dir

now = datetime.datetime.now()
full_path = os.path.join(base_path, f"run-{now.strftime('%Y-%m-%d-%H-%M-%S')}") # type: ignore
full_path = os.path.join(
base_path, f"{scenario}-{now.strftime('%Y-%m-%d-%H-%M-%S')}"
) # type: ignore

os.makedirs(full_path, exist_ok=True) # exist_ok=True, no need to error handle
self.results_path = full_path
return full_path

def _create_scenario_folder(
self, scenario: str, iteration: str, results_folder: str
):
def _create_scenario_folder(self, iteration: str, results_folder: str):
"""Creates a folder to hold the results of a individual scenario execution.
The naming convention is as follows
```
Expand All @@ -57,7 +57,7 @@ def _create_scenario_folder(
_type_: _description_
"""

full_path = os.path.join(results_folder, f"{scenario}-{iteration}")
full_path = os.path.join(results_folder, f"{iteration}")

os.makedirs(full_path, exist_ok=True) # exist_ok=True, no need to error handle
self.last_scenario = full_path
Expand All @@ -75,9 +75,9 @@ def parse_json(
"""

if not self.results_path:
self._create_run_folder()
self._create_run_folder(scenario)

self._create_scenario_folder(scenario, iteration, self.results_path)
self._create_scenario_folder(iteration, self.results_path)

# save the definition as a new file
if save_def and isinstance(json_, dict):
Expand All @@ -87,3 +87,14 @@ def parse_json(
json.dump(json_, f)

self._scenario_decoder.parse_scenario(json_, self.last_scenario)

def cleanup_xml(self) -> None:
"""Cleanup the .xml files left over by the scenario execution."""

full_paths = [
f"{self.last_scenario}/route.xml",
f"{self.last_scenario}/scenario.xml",
]

for path in full_paths:
os.remove(path)