Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix history vehicles key error + not recreate SMARTS instance #439

Merged
merged 7 commits into from
Jan 19, 2021
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
16 changes: 9 additions & 7 deletions examples/history_vehicles_replacement_for_imitation_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ def act(self, obs):

def main(scenarios, headless, seed):
scenarios_iterator = Scenario.scenario_variations(scenarios, [])
smarts = SMARTS(
agent_interfaces={},
traffic_sim=SumoTrafficSimulation(headless=True, auto_start=True),
envision=Envision(),
)

for _ in scenarios:
scenario = next(scenarios_iterator)
agent_missions = scenario.discover_missions_of_traffic_histories()
Expand All @@ -33,14 +39,10 @@ def main(scenarios, headless, seed):
),
agent_builder=KeepLaneAgent,
)

agent = agent_spec.build_agent()

smarts = SMARTS(
agent_interfaces={agent_id: agent_spec.interface},
traffic_sim=SumoTrafficSimulation(headless=True, auto_start=True),
envision=Envision(),
)
smarts.switch_ego_agent({agent_id: agent_spec.interface})

observations = smarts.reset(scenario)

dones = {agent_id: False}
Expand All @@ -52,7 +54,7 @@ def main(scenarios, headless, seed):
{agent_id: agent_action}
)

smarts.destroy()
smarts.destroy()


if __name__ == "__main__":
Expand Down
3 changes: 3 additions & 0 deletions smarts/core/agent_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ def send_observations_to_social_agents(self, observations):
obs = observations[agent_id]
self._remote_social_agents_action[agent_id] = remote_agent.act(obs)

def switch_initial_agent(self, agent_interface):
self._initial_interfaces = agent_interface

def setup_agents(self, sim):
self.init_ego_agents(sim)
self.setup_social_agents(sim)
Expand Down
2 changes: 1 addition & 1 deletion smarts/core/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def observe(sim, agent_id, sensor_state, vehicle):
and sensor_state.steps_completed == 1
and agent_id in sim.agent_manager.ego_agent_ids
):
logger.warning(f"{agent_id} is done on the first step")
logger.warning(f"Agent Id: {agent_id} is done on the first step")

return (
Observation(
Expand Down
4 changes: 4 additions & 0 deletions smarts/core/smarts.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,10 @@ def setup(self, scenario: Scenario):
def add_provider(self, provider):
self._providers.append(provider)

def switch_ego_agent(self, agent_interface):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe replace switch with a more accurate verb?

self._agent_manager.switch_initial_agent(agent_interface)
self._is_setup = False

def _setup_road_network(self):
glb_path = self.scenario.map_glb_filepath
if self._road_network_np:
Expand Down
4 changes: 4 additions & 0 deletions smarts/core/trap_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ def largest_vehicle_plane_dimension(vehicle):
),
)
for v_id in sorted_vehicle_ids:
# Skip the capturing process if history traffic is used
if sim.scenario.traffic_history:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One assumption here is when doing imitation learning, there will be no SUMO traffic, therefore we wanted to disable the trapping.

break

vehicle = vehicles[v_id]
point = Point(vehicle.position)

Expand Down