From ac4693d34ff1d4bbe76010ebc7d75049584abbfd Mon Sep 17 00:00:00 2001 From: Marie Burer Date: Tue, 26 Aug 2025 13:39:53 -0500 Subject: [PATCH 1/5] Added the ability for the GA algorithm to take alternate configurations on the command line --- carla_sim/GA.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/carla_sim/GA.py b/carla_sim/GA.py index 2392b09..94e42f9 100644 --- a/carla_sim/GA.py +++ b/carla_sim/GA.py @@ -13,6 +13,7 @@ from collections import namedtuple import yaml from datetime import datetime +import argparse def get_similarity_between_npc_behaviors(b1, b2): n = min(len(b1), len(b2)) @@ -219,7 +220,14 @@ def genetic_fuzzer(spawn_config, weather_params, return best_ind, best_fit if __name__ == '__main__': - ga_cfg = tools.load_ga_config('./parameters/ga.yaml') + parser = argparse.ArgumentParser(prog = 'GA.py', description='AV-Fuzzer Genetic Algorithm') + parser.add_argument('-g', '--genetics', default='parameters/GA.yaml', type=str, metavar='path/to/genetics.yaml') + parser.add_argument('-w', '--weather', default='parameters/weather.yaml', type=str, metavar='path/to/weather.yaml') + parser.add_argument('-s', '--spawn', default='parameters/spawn.yaml', type=str, metavar='path/to/spawn.yaml') + + args = parser.parse_args() + + ga_cfg = tools.load_ga_config(args.genetics) POP_SIZE = ga_cfg['pop_size'] MAX_GENS = ga_cfg['max_gens'] @@ -227,8 +235,8 @@ def genetic_fuzzer(spawn_config, weather_params, MUTATION_RATE = ga_cfg['mutation_rate'] TOURNAMENT_K = ga_cfg['tournament_k'] - weather_config = tools.load_weather_yaml('./parameters/weather.yaml') - spawn_config = tools.load_spawn_yaml('./parameters/spawn.yaml') + weather_config = tools.load_weather_yaml(args.weather) + spawn_config = tools.load_spawn_yaml(args.spawn) best_ind, best_fit = genetic_fuzzer( From 89c6809235d3121db821b2f579187e84a6d2977c Mon Sep 17 00:00:00 2001 From: Marie Burer Date: Mon, 1 Sep 2025 14:40:21 -0500 Subject: [PATCH 2/5] added the ability to alter the map via test scenario files --- carla_sim/simulation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/carla_sim/simulation.py b/carla_sim/simulation.py index c73b803..9b9e445 100644 --- a/carla_sim/simulation.py +++ b/carla_sim/simulation.py @@ -27,7 +27,7 @@ def run_simulation(spawn_config, weather_params, client = carla.Client("localhost", 2000) client.set_timeout(10.0) - client.load_world('Town03') + client.load_world(spawn_config['map']) world = client.get_world() tools.set_weather(world, weather_params) From 660e8337c28ce64527fba9310ba8b4da60a71b69 Mon Sep 17 00:00:00 2001 From: Marie Burer Date: Tue, 2 Sep 2025 11:49:30 -0500 Subject: [PATCH 3/5] alterened spawn.yaml to be compliant --- carla_sim/parameters/spawn.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/carla_sim/parameters/spawn.yaml b/carla_sim/parameters/spawn.yaml index e83aa6a..c87b0b9 100644 --- a/carla_sim/parameters/spawn.yaml +++ b/carla_sim/parameters/spawn.yaml @@ -1,3 +1,6 @@ +map: + "Town03" + ev: start: [30.874001, 7.542412, 0.3] end: [205.874001, 8.542412, 0.3] From 1f8e5a2d9ce6cfb51868a96de8902982dd031c91 Mon Sep 17 00:00:00 2001 From: Marie Burer Date: Tue, 2 Sep 2025 12:11:12 -0500 Subject: [PATCH 4/5] changed how maps are chosen to command-line rather than spawn yaml --- carla_sim/GA.py | 10 +++++++--- carla_sim/parameters/spawn.yaml | 8 +++++--- carla_sim/simulation.py | 7 ++++--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/carla_sim/GA.py b/carla_sim/GA.py index 94e42f9..0519315 100644 --- a/carla_sim/GA.py +++ b/carla_sim/GA.py @@ -98,7 +98,7 @@ def mutate(ind, spawn_config, mutation_rate=0.02): lst[i] = tools.generate_npc_behaviors(cfg,1,extra_steer_perturb=True)[0] return (b1, b2) -def genetic_fuzzer(spawn_config, weather_params, +def genetic_fuzzer(map, spawn_config, weather_params, pop_size=10, max_gens=5, crossover_rate=0.2, mutation_rate=0.3, @@ -139,8 +139,8 @@ def genetic_fuzzer(spawn_config, weather_params, for ind in population: fit,res = simulation.evaluate_individual( - spawn_config, weather_params, ind, - tick_interval=tick_interval, + map, spawn_config, weather_params, + ind, tick_interval=tick_interval, max_frames=max_frames ) raw_fitness.append(fit) @@ -224,9 +224,12 @@ def genetic_fuzzer(spawn_config, weather_params, parser.add_argument('-g', '--genetics', default='parameters/GA.yaml', type=str, metavar='path/to/genetics.yaml') parser.add_argument('-w', '--weather', default='parameters/weather.yaml', type=str, metavar='path/to/weather.yaml') parser.add_argument('-s', '--spawn', default='parameters/spawn.yaml', type=str, metavar='path/to/spawn.yaml') + parser.add_argument('-m', '--map', default="Town03", type=str, metavar='map') args = parser.parse_args() + map = args.map + ga_cfg = tools.load_ga_config(args.genetics) POP_SIZE = ga_cfg['pop_size'] @@ -240,6 +243,7 @@ def genetic_fuzzer(spawn_config, weather_params, best_ind, best_fit = genetic_fuzzer( + map, spawn_config, weather_config, pop_size = POP_SIZE, diff --git a/carla_sim/parameters/spawn.yaml b/carla_sim/parameters/spawn.yaml index c87b0b9..1157338 100644 --- a/carla_sim/parameters/spawn.yaml +++ b/carla_sim/parameters/spawn.yaml @@ -1,9 +1,7 @@ -map: - "Town03" - ev: start: [30.874001, 7.542412, 0.3] end: [205.874001, 8.542412, 0.3] + rotation: [0.0, 0.0, 0.0] npc1: start: [40.874001, 3.542412, 0.3] @@ -11,6 +9,7 @@ npc1: brake_chance: 0.3 brake_range: [0.0, 0.5] steer_range: [0.0, 0.02] + rotation: [0.0, 0.0, 0.0] npc2: start: [70.874001, 7.542412, 0.3] @@ -18,11 +17,14 @@ npc2: brake_chance: 0.3 brake_range: [0.0, 0.4] steer_range: [0.0, 0.02] + rotation: [0.0, 0.0, 0.0] pedestrian1: start: [65.874001, 3.542412, 0.3] end: [80.874001, 3.542412, 0.5] + rotation: [0.0, 0.0, 0.0] pedestrian2: start: [55.874001, 3.542412, 0.3] end: [90.874001, 3.542412, 0.5] + rotation: [0.0, 0.0, 0.0] diff --git a/carla_sim/simulation.py b/carla_sim/simulation.py index 9b9e445..ff916fe 100644 --- a/carla_sim/simulation.py +++ b/carla_sim/simulation.py @@ -19,7 +19,7 @@ 'hitTime' # Frame index when collision happened ]) -def run_simulation(spawn_config, weather_params, +def run_simulation(map, spawn_config, weather_params, npc1_behaviors, npc2_behaviors, tick_interval=0.05, max_frames=500): @@ -27,7 +27,7 @@ def run_simulation(spawn_config, weather_params, client = carla.Client("localhost", 2000) client.set_timeout(10.0) - client.load_world(spawn_config['map']) + client.load_world(map) world = client.get_world() tools.set_weather(world, weather_params) @@ -154,7 +154,7 @@ def on_collision(event): -def evaluate_individual(spawn_config, weather_params, individual, +def evaluate_individual(map, spawn_config, weather_params, individual, tick_interval=0.05, max_frames=500): npc1_behaviors, npc2_behaviors = individual @@ -163,6 +163,7 @@ def evaluate_individual(spawn_config, weather_params, individual, result = run_simulation( + map, spawn_config, weather_params, npc1_behaviors, From f247d93bb89e44f872e9b82754140269f1cde3af Mon Sep 17 00:00:00 2001 From: Marie Burer Date: Tue, 2 Sep 2025 17:48:53 -0500 Subject: [PATCH 5/5] Revert "changed how maps are chosen to command-line rather than spawn yaml" This reverts commit 1f8e5a2d9ce6cfb51868a96de8902982dd031c91. --- carla_sim/GA.py | 10 +++------- carla_sim/parameters/spawn.yaml | 8 +++----- carla_sim/simulation.py | 7 +++---- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/carla_sim/GA.py b/carla_sim/GA.py index 0519315..94e42f9 100644 --- a/carla_sim/GA.py +++ b/carla_sim/GA.py @@ -98,7 +98,7 @@ def mutate(ind, spawn_config, mutation_rate=0.02): lst[i] = tools.generate_npc_behaviors(cfg,1,extra_steer_perturb=True)[0] return (b1, b2) -def genetic_fuzzer(map, spawn_config, weather_params, +def genetic_fuzzer(spawn_config, weather_params, pop_size=10, max_gens=5, crossover_rate=0.2, mutation_rate=0.3, @@ -139,8 +139,8 @@ def genetic_fuzzer(map, spawn_config, weather_params, for ind in population: fit,res = simulation.evaluate_individual( - map, spawn_config, weather_params, - ind, tick_interval=tick_interval, + spawn_config, weather_params, ind, + tick_interval=tick_interval, max_frames=max_frames ) raw_fitness.append(fit) @@ -224,12 +224,9 @@ def genetic_fuzzer(map, spawn_config, weather_params, parser.add_argument('-g', '--genetics', default='parameters/GA.yaml', type=str, metavar='path/to/genetics.yaml') parser.add_argument('-w', '--weather', default='parameters/weather.yaml', type=str, metavar='path/to/weather.yaml') parser.add_argument('-s', '--spawn', default='parameters/spawn.yaml', type=str, metavar='path/to/spawn.yaml') - parser.add_argument('-m', '--map', default="Town03", type=str, metavar='map') args = parser.parse_args() - map = args.map - ga_cfg = tools.load_ga_config(args.genetics) POP_SIZE = ga_cfg['pop_size'] @@ -243,7 +240,6 @@ def genetic_fuzzer(map, spawn_config, weather_params, best_ind, best_fit = genetic_fuzzer( - map, spawn_config, weather_config, pop_size = POP_SIZE, diff --git a/carla_sim/parameters/spawn.yaml b/carla_sim/parameters/spawn.yaml index 1157338..c87b0b9 100644 --- a/carla_sim/parameters/spawn.yaml +++ b/carla_sim/parameters/spawn.yaml @@ -1,7 +1,9 @@ +map: + "Town03" + ev: start: [30.874001, 7.542412, 0.3] end: [205.874001, 8.542412, 0.3] - rotation: [0.0, 0.0, 0.0] npc1: start: [40.874001, 3.542412, 0.3] @@ -9,7 +11,6 @@ npc1: brake_chance: 0.3 brake_range: [0.0, 0.5] steer_range: [0.0, 0.02] - rotation: [0.0, 0.0, 0.0] npc2: start: [70.874001, 7.542412, 0.3] @@ -17,14 +18,11 @@ npc2: brake_chance: 0.3 brake_range: [0.0, 0.4] steer_range: [0.0, 0.02] - rotation: [0.0, 0.0, 0.0] pedestrian1: start: [65.874001, 3.542412, 0.3] end: [80.874001, 3.542412, 0.5] - rotation: [0.0, 0.0, 0.0] pedestrian2: start: [55.874001, 3.542412, 0.3] end: [90.874001, 3.542412, 0.5] - rotation: [0.0, 0.0, 0.0] diff --git a/carla_sim/simulation.py b/carla_sim/simulation.py index ff916fe..9b9e445 100644 --- a/carla_sim/simulation.py +++ b/carla_sim/simulation.py @@ -19,7 +19,7 @@ 'hitTime' # Frame index when collision happened ]) -def run_simulation(map, spawn_config, weather_params, +def run_simulation(spawn_config, weather_params, npc1_behaviors, npc2_behaviors, tick_interval=0.05, max_frames=500): @@ -27,7 +27,7 @@ def run_simulation(map, spawn_config, weather_params, client = carla.Client("localhost", 2000) client.set_timeout(10.0) - client.load_world(map) + client.load_world(spawn_config['map']) world = client.get_world() tools.set_weather(world, weather_params) @@ -154,7 +154,7 @@ def on_collision(event): -def evaluate_individual(map, spawn_config, weather_params, individual, +def evaluate_individual(spawn_config, weather_params, individual, tick_interval=0.05, max_frames=500): npc1_behaviors, npc2_behaviors = individual @@ -163,7 +163,6 @@ def evaluate_individual(map, spawn_config, weather_params, individual, result = run_simulation( - map, spawn_config, weather_params, npc1_behaviors,