Skip to content

Actor vehicle name same as configuration. #1957

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

Merged
merged 7 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Copy and pasting the git commit messages is __NOT__ enough.
- The trap manager, `TrapManager`, is now a subclass of `ActorCaptureManager`.
- Considering lane-change time ranges between 3s and 6s, assuming a speed of 13.89m/s, the via sensor lane acquisition range was increased from 40m to 80m, for better driving ability.
- Modified naming of benchmark used in NeurIPS 2022 from driving-smarts-competition-env to driving-smarts-v2022.
- Social agent actor vehicles are now exactly named the same as the `name` of the actor.
### Deprecated
### Fixed
- Fixed an issue where Argoverse scenarios with a `Mission` would not run properly.
Expand Down
26 changes: 14 additions & 12 deletions scenarios/sumo/intersections/6lane/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
from smarts.sstudio import gen_scenario
from smarts.sstudio.types import Mission, Route, Scenario, SocialAgentActor

actors = [
SocialAgentActor(
name=f"non-interactive-agent-{speed}-v0",
agent_locator="zoo.policies:non-interactive-agent-v0",
policy_kwargs={"speed": speed},
)
for speed in [10, 30, 80]
]

def actor_gen(id_):
return [
SocialAgentActor(
name=f"{id_}-non-interactive-agent-{speed}-v0",
agent_locator="zoo.policies:non-interactive-agent-v0",
policy_kwargs={"speed": speed},
)
for speed in [10, 30, 80]
]


def to_mission(start_edge, end_edge):
Expand All @@ -22,10 +24,10 @@ def to_mission(start_edge, end_edge):
gen_scenario(
Scenario(
social_agent_missions={
"group-1": (actors, [to_mission("edge-north-NS", "edge-south-NS")]),
"group-2": (actors, [to_mission("edge-west-WE", "edge-east-WE")]),
"group-3": (actors, [to_mission("edge-east-EW", "edge-west-EW")]),
"group-4": (actors, [to_mission("edge-south-SN", "edge-north-SN")]),
"group-1": (actor_gen(1), [to_mission("edge-north-NS", "edge-south-NS")]),
"group-2": (actor_gen(2), [to_mission("edge-west-WE", "edge-east-WE")]),
"group-3": (actor_gen(3), [to_mission("edge-east-EW", "edge-west-EW")]),
"group-4": (actor_gen(4), [to_mission("edge-south-SN", "edge-north-SN")]),
}
),
output_dir=Path(__file__).parent,
Expand Down
44 changes: 17 additions & 27 deletions scenarios/sumo/tests/multi_agents_loop/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,30 @@
]
)

laner_agent = t.SocialAgentActor(
name="keep-lane-agent",
agent_locator="zoo.policies:keep-lane-agent-v0",
)

buddha_agent = t.SocialAgentActor(
name="buddha-agent",
agent_locator="scenarios.sumo.tests.multi_agents_loop.agent_prefabs:buddha-agent-v0",
)
def make_laner(id_):
return t.SocialAgentActor(
name=f"keep-lane-agent_{id_}",
agent_locator="zoo.policies:keep-lane-agent-v0",
)


def make_buddha(id_):
return t.SocialAgentActor(
name=f"buddha-actor_{id_}",
agent_locator="scenarios.sumo.tests.multi_agents_loop.agent_prefabs:buddha-agent-v0",
)


gen_scenario(
t.Scenario(
traffic={"basic": traffic},
social_agent_missions={
"group_1": (
[laner_agent, buddha_agent],
[t.Mission(route=t.RandomRoute())],
),
"group_2": (
[laner_agent, buddha_agent],
[t.Mission(route=t.RandomRoute())],
),
"group_3": (
[laner_agent, buddha_agent],
[t.Mission(route=t.RandomRoute())],
),
"group_4": (
[laner_agent, buddha_agent],
[t.Mission(route=t.RandomRoute())],
),
"group_5": (
[laner_agent, buddha_agent],
f"group_{i}": (
[make_laner(i), make_buddha(i)],
[t.Mission(route=t.RandomRoute())],
),
)
for i in range(1, 6)
},
),
output_dir=Path(__file__).parent,
Expand Down
15 changes: 11 additions & 4 deletions smarts/core/agent_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(self, sim, interfaces, zoo_addrs=None):

# TODO: This field is only for social agents, but is being used as if it were
# for any agent. Revisit the accessors.
self._social_agent_data_models = {}
self._social_agent_data_models: Dict[str, SocialAgent] = {}

# We send observations and receive actions for all values in this dictionary
self._remote_social_agents = {}
Expand Down Expand Up @@ -486,7 +486,7 @@ def _start_keep_alive_boid_agents(self):
actor = bubble.actor
social_agent_data_model = SocialAgent(
id=SocialAgentId.new(actor.name),
name=actor.name,
actor_name=actor.name,
is_boid=True,
is_boid_keep_alive=True,
agent_locator=actor.agent_locator,
Expand Down Expand Up @@ -531,7 +531,12 @@ def add_and_emit_social_agent(
return True

def _add_agent(
self, agent_id, agent_interface, agent_model, boid=False, trainable=True
self,
agent_id,
agent_interface,
agent_model: SocialAgent,
boid=False,
trainable=True,
):
# TODO: Disentangle what is entangled below into:
# 1. AgentState initialization,
Expand Down Expand Up @@ -570,7 +575,9 @@ def _add_agent(
scenario.surface_patches,
agent_model.initial_speed,
boid=boid,
vehicle_id=agent_model.actor_name,
)

role = ActorRole.EgoAgent if trainable else ActorRole.SocialAgent
for provider in sim.providers:
if agent_interface.action not in provider.actions:
Expand Down Expand Up @@ -660,7 +667,7 @@ def agent_name(self, agent_id: str) -> str:
if agent_id not in self._social_agent_data_models:
return ""

return self._social_agent_data_models[agent_id].name
return self._social_agent_data_models[agent_id].actor_name

def is_boid_agent(self, agent_id: str) -> bool:
"""Check if an agent is a boid agent"""
Expand Down
5 changes: 3 additions & 2 deletions smarts/core/bubble_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,9 +729,10 @@ def _prepare_sensors_for_agent_control(
def _start_social_agent(
self, sim, agent_id, social_agent, social_agent_actor, bubble
):
id_ = SocialAgentId.new(social_agent_actor.name)
social_agent_data_model = SocialAgent(
id=SocialAgentId.new(social_agent_actor.name),
name=social_agent_actor.name,
id=id_,
actor_name=id_,
is_boid=bubble.is_boid,
is_boid_keep_alive=bubble.keep_alive,
agent_locator=social_agent_actor.agent_locator,
Expand Down
2 changes: 1 addition & 1 deletion smarts/core/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SocialAgent:
"""A serializable representation of a social agent."""

id: str
name: str
actor_name: str
is_boid: bool
is_boid_keep_alive: bool
agent_locator: str
Expand Down
2 changes: 1 addition & 1 deletion smarts/core/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def setdefault(l: list, index: int, default):
(
SocialAgent(
id=SocialAgentId.new(actor.name, group=namespace),
name=actor.name,
actor_name=actor.name,
is_boid=False,
is_boid_keep_alive=False,
agent_locator=actor.agent_locator,
Expand Down
42 changes: 28 additions & 14 deletions smarts/core/tests/test_smarts_frame_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@
@pytest.fixture
def scenarios():
with temp_scenario(name="6lane", map="maps/6lane.net.xml") as scenario_root:
actors = [
t.SocialAgentActor(
name=f"non-interactive-agent-{speed}-v0",
agent_locator="zoo.policies:non-interactive-agent-v0",
policy_kwargs={"speed": speed},
)
for speed in [10, 30, 80]
]

def actor_gen(id_):
return [
t.SocialAgentActor(
name=f"non-interactive-agent-{speed}-v0_{id_}",
agent_locator="zoo.policies:non-interactive-agent-v0",
policy_kwargs={"speed": speed},
)
for speed in [10, 30, 80]
]

def to_mission(start_edge, end_edge):
route = t.Route(begin=(start_edge, 1, 0), end=(end_edge, 1, "max"))
Expand All @@ -58,12 +60,24 @@ def fifth_mission(start_edge, end_edge):
gen_scenario(
t.Scenario(
social_agent_missions={
"group-1": (actors, [to_mission("edge-north-NS", "edge-south-NS")]),
"group-2": (actors, [to_mission("edge-west-WE", "edge-east-WE")]),
"group-3": (actors, [to_mission("edge-east-EW", "edge-west-EW")]),
"group-4": (actors, [to_mission("edge-south-SN", "edge-north-SN")]),
"group-1": (
actor_gen(1),
[to_mission("edge-north-NS", "edge-south-NS")],
),
"group-2": (
actor_gen(2),
[to_mission("edge-west-WE", "edge-east-WE")],
),
"group-3": (
actor_gen(3),
[to_mission("edge-east-EW", "edge-west-EW")],
),
"group-4": (
actor_gen(4),
[to_mission("edge-south-SN", "edge-north-SN")],
),
"group-5": (
actors,
actor_gen(5),
[fifth_mission("edge-south-SN", "edge-east-WE")],
),
},
Expand Down Expand Up @@ -92,7 +106,7 @@ def smarts():
agents = {AGENT_1: laner}
smarts = SMARTS(
agents,
traffic_sims=[SumoTrafficSimulation(headless=True)],
traffic_sims=[SumoTrafficSimulation(headless=False)],
envision=None,
)

Expand Down
4 changes: 3 additions & 1 deletion smarts/core/vehicle_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,11 +653,13 @@ def build_agent_vehicle(
surface_patches,
initial_speed=None,
boid=False,
*,
vehicle_id=None,
):
"""Build an entirely new vehicle for an agent."""
vehicle = Vehicle.build_agent_vehicle(
sim=sim,
vehicle_id=agent_id,
vehicle_id=vehicle_id or agent_id,
agent_interface=agent_interface,
plan=plan,
vehicle_filepath=filepath,
Expand Down
18 changes: 10 additions & 8 deletions smarts/diagnostic/10_agents_to_n_roads/10_roads/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,22 @@
from smarts.sstudio import gen_scenario
from smarts.sstudio.types import Mission, RandomRoute, Route, Scenario, SocialAgentActor

actors = [
SocialAgentActor(
name=f"non-interactive-agent-50-v0",
agent_locator="zoo.policies:non-interactive-agent-v0",
policy_kwargs={"speed": 50},
)
]

def gen_actors(id_):
return [
SocialAgentActor(
name=f"non-interactive-agent-50-v0_{id_}",
agent_locator="zoo.policies:non-interactive-agent-v0",
policy_kwargs={"speed": 50},
)
]


def to_missions(agent_num):
missions = {}
for i in range(0, agent_num):
missions[f"group-{i}"] = tuple(
(actors, [Mission(route=RandomRoute())]),
(gen_actors(i), [Mission(route=RandomRoute())]),
)
return missions

Expand Down
18 changes: 10 additions & 8 deletions smarts/diagnostic/10_agents_to_n_roads/1_roads/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,22 @@
from smarts.sstudio import gen_scenario
from smarts.sstudio.types import Mission, RandomRoute, Route, Scenario, SocialAgentActor

actors = [
SocialAgentActor(
name=f"non-interactive-agent-50-v0",
agent_locator="zoo.policies:non-interactive-agent-v0",
policy_kwargs={"speed": 50},
)
]

def gen_actors(id_):
return [
SocialAgentActor(
name=f"non-interactive-agent-50-v0_{id_}",
agent_locator="zoo.policies:non-interactive-agent-v0",
policy_kwargs={"speed": 50},
)
]


def to_missions(agent_num):
missions = {}
for i in range(0, agent_num):
missions[f"group-{i}"] = tuple(
(actors, [Mission(route=RandomRoute())]),
(gen_actors(i), [Mission(route=RandomRoute())]),
)
return missions

Expand Down
18 changes: 10 additions & 8 deletions smarts/diagnostic/10_agents_to_n_roads/20_roads/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,22 @@
from smarts.sstudio import gen_scenario
from smarts.sstudio.types import Mission, RandomRoute, Route, Scenario, SocialAgentActor

actors = [
SocialAgentActor(
name=f"non-interactive-agent-50-v0",
agent_locator="zoo.policies:non-interactive-agent-v0",
policy_kwargs={"speed": 50},
)
]

def gen_actors(id_):
return [
SocialAgentActor(
name=f"non-interactive-agent-50-v0_{id_}",
agent_locator="zoo.policies:non-interactive-agent-v0",
policy_kwargs={"speed": 50},
)
]


def to_missions(agent_num):
missions = {}
for i in range(0, agent_num):
missions[f"group-{i}"] = tuple(
(actors, [Mission(route=RandomRoute())]),
(gen_actors(i), [Mission(route=RandomRoute())]),
)
return missions

Expand Down
18 changes: 10 additions & 8 deletions smarts/diagnostic/10_agents_to_n_roads/50_roads/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,22 @@
from smarts.sstudio import gen_scenario
from smarts.sstudio.types import Mission, RandomRoute, Route, Scenario, SocialAgentActor

actors = [
SocialAgentActor(
name=f"non-interactive-agent-50-v0",
agent_locator="zoo.policies:non-interactive-agent-v0",
policy_kwargs={"speed": 50},
)
]

def gen_actors(id_):
return [
SocialAgentActor(
name=f"non-interactive-agent-50-v0_{id_}",
agent_locator="zoo.policies:non-interactive-agent-v0",
policy_kwargs={"speed": 50},
)
]


def to_missions(agent_num):
missions = {}
for i in range(0, agent_num):
missions[f"group-{i}"] = tuple(
(actors, [Mission(route=RandomRoute())]),
(gen_actors(i), [Mission(route=RandomRoute())]),
)
return missions

Expand Down
Loading