def test_python_model(self): param_server = ParameterServer( filename="modules/runtime/tests/data/deterministic_scenario.json") scenario_generation = DeterministicScenarioGeneration(num_scenarios=3, random_seed=0, params=param_server) viewer = MPViewer(params=param_server, follow_agent_id=False, use_world_bounds=True) env = Runtime(0.2, viewer, scenario_generation, render=True) single_track_model = SingleTrackModel(param_server) behavior_model = DynamicBehaviorModel(single_track_model, param_server) env.reset() env._world.get_agent(0).behavior_model = behavior_model env._world.get_agent(0).behavior_model.clone() env.reset() env._world.get_agent(0).behavior_model = behavior_model env._world.get_agent(0).behavior_model.set_last_action(np.array([1., 2.])) print(env._world.get_agent(0).behavior_model.get_last_action()) env._world.step(0.2) print(env._world.get_agent(0).behavior_model.get_last_action())
def test_bark_agent_in_runtime(self): # check whether the bark agent really does work params = ParameterServer( filename="configurations/sac_highway/config.json") configuration = SACHighwayConfiguration(params) scenario_generator = configuration._scenario_generator viewer = MPViewer(params=params, x_range=[-50, 50], y_range=[-50, 50], follow_agent_id=100, screen_dims=[500, 500], use_world_bounds=False) env = Runtime(0.2, viewer, scenario_generator, render=True) env.reset() dynamic_model = env._world.agents[ env._scenario._eval_agent_ids[0]].dynamic_model bark_agent = BARKMLBehaviorModel(configuration, dynamic_model, env._scenario._eval_agent_ids) bark_agent.set_last_action(np.array([1., 0.])) env._world.get_agent( env._scenario._eval_agent_ids[0]).behavior_model = bark_agent for _ in range(0, 35): env.step()
def test_runtime(self): """Asserts the runtime to make sure the basic functionality is given by the current state of BARK. """ param_server = ParameterServer( filename="tests/data/deterministic_scenario_test.json") scenario_generation = DeterministicScenarioGeneration(num_scenarios=3, random_seed=0, params=param_server) param_server["Visualization"]["Agents"]["DrawRoute", "Draw the local map of each agent", True] viewer = MPViewer(params=param_server, use_world_bounds=True) env = Runtime(0.2, viewer, scenario_generation, render=True) env.reset() agent_ids = [] agent_states = [] centers_of_driving_corridor= [] for key, agent in env._world.agents.items(): agent_ids.append(agent.id) agent_states.append(agent.state) for i in range(0, 5): print("Scenario {}:".format( str(env._scenario_generator._current_scenario_idx))) # assert scenario ids self.assertEqual(env._scenario_generator._current_scenario_idx, (i % 3) + 1) for _ in range(0, 35): # assert ids states_before = [] for i, (key, agent) in enumerate(env._world.agents.items()): self.assertEqual(key, agent.id) self.assertEqual(agent_ids[i], agent.id) states_before.append(agent.state) # TODO(@hart): why does this not work print(key, agent.goal_definition.goal_shape) env.step() # assert state has been changed by the step() function for i, (key, agent) in enumerate(env._world.agents.items()): np.testing.assert_equal(np.any(np.not_equal(states_before[i], agent.state)), True) # check whether the reset works env.reset() for i, (key, agent) in enumerate(env._world.agents.items()): self.assertEqual(key, agent.id) self.assertEqual(agent_ids[i], agent.id) np.testing.assert_array_equal(agent_states[i], agent.state)
def test_visualization(self): param_server = ParameterServer( filename="modules/runtime/tests/data/deterministic_scenario.json") scenario_generation = DeterministicScenarioGeneration( num_scenarios=3, random_seed=0, params=param_server) viewer = MPViewer(params=param_server, follow_agent_id=False, use_world_bounds=True) env = Runtime(0.2, viewer, scenario_generation, render=True) env.reset() for _ in range(0, 5): print("Scenario {}:".format( str(env._scenario_generator._current_scenario_idx))) for _ in range(0, 5): env.step() env.reset()
def test_python_model(self): param_server = ParameterServer( filename="modules/runtime/tests/data/deterministic_scenario.json") scenario_generation = DeterministicScenarioGeneration(num_scenarios=3, random_seed=0, params=param_server) viewer = MPViewer(params=param_server, follow_agent_id=False, use_world_bounds=True) env = Runtime(0.2, viewer, scenario_generation, render=True) behavior_model = DummyBehaviorModel(param_server) env.reset() env._world.get_agent(0).behavior_model = behavior_model env._world.get_agent(0).behavior_model.clone() np.testing.assert_array_equal( env._world.get_agent(0).behavior_model.plan(0.2, env._world)[1], np.array([0.2, 5111.626, 5106.8305 + 0.2, 1.5, 10])) env.reset() env._world.get_agent(0).behavior_model = behavior_model env._world.step(0.2) np.testing.assert_array_equal( env._world.get_agent(0).state, np.array([0.2, 5111.626, 5106.8305 + 0.2, 1.5, 10], dtype=np.float32)) env._world.step(0.2) np.testing.assert_array_equal( env._world.get_agent(0).state, np.array([0.4, 5111.626, 5106.8305 + 0.4, 1.5, 10], dtype=np.float32)) env._world.step(0.2) np.testing.assert_array_equal( env._world.get_agent(0).state, np.array([0.6, 5111.626, 5106.8305 + 0.6, 1.5, 10], dtype=np.float32)) print("History:", env._world.get_agent(0).history) # environment loop env.reset() for i in range(0, 7): env.step()
scenario_generation = params["Scenario"]["Generation"][ "ConfigurableScenarioGeneration"] map_filename = scenario_generation["MapFilename"] scenario_generation["MapFilename"] = base_dir + "/" + map_filename params["BaseDir"] = base_dir # actual model ml_config = HighwayConfiguration(params) ml_behavior = BARKMLBehaviorModel(configuration=ml_config) scenario_generator = ml_config._scenario_generator viewer = MPViewer(params=params, use_world_bounds=True) env = Runtime(0.2, viewer, scenario_generator, render=True) env.reset() env._world.agents[ env._scenario._eval_agent_ids[0]].behavior_model = ml_behavior print(ml_behavior) for _ in range(0, 50): env.step() # to find database files os.chdir("../benchmark_database/") dbs = DatabaseSerializer(test_scenarios=4, test_world_steps=5, num_serialize_scenarios=10) dbs.process("database") local_release_filename = dbs.release(version="test") db = BenchmarkDatabase(database_root=local_release_filename)