Skip to content

No access to road_waypoints observation in v2.0.1 #2175

@reinlepropo

Description

@reinlepropo

High Level Description

It seems that with the 2.0.1 of SMARTS does not provide road_waypoints Observations.

I have tried to set road_waypoints option to True in the Agent Interface but it did not work.

Version

2.0.1 of SMARTS

Steps to reproduce the bug

"""This is an example to show how SMARTS multi-agent works. This example uses the same kind of
agent multiple times. But different agents with different action and observation shapes can be mixed
in."""
import random
import sys
from pathlib import Path
from typing import Final
 
import gymnasium as gym
 
SMARTS_REPO_PATH = Path(__file__).parents[1].absolute()
sys.path.insert(0, str(SMARTS_REPO_PATH))
from examples.tools.argument_parser import minimal_argument_parser
from smarts.core.agent import Agent
from smarts.core.agent_interface import AgentInterface, AgentType
from smarts.core.utils.episodes import episodes
from smarts.sstudio.scenario_construction import build_scenarios
from smarts.core.controllers import ActionSpaceType
 
N_AGENTS = 2
AGENT_IDS: Final[list] = ["Agent %i" % i for i in range(N_AGENTS)]
 
 
class RandomLanerAgent(Agent):
    def __init__(self, action_space) -> None:
        self._action_space = action_space
 
    def act(self, obs, **kwargs):
        return self._action_space.sample()
 
 
class KeepLaneAgent(Agent):
    def __init__(self, action_space) -> None:
        self._action_space = action_space
 
    def act(self, obs, **kwargs):
        return self._action_space.sample()
 
 
def main(scenarios, headless, num_episodes, max_episode_steps=None):
    # This interface must match the action returned by the agent
    agent_interfaces = {
        agent_id: AgentInterface(
        max_episode_steps=max_episode_steps,
        road_waypoints=True,
        waypoint_paths=True,
        action=ActionSpaceType.Lane
    )
        for agent_id in AGENT_IDS
    }
 
    env = gym.make(
        "smarts.env:hiway-v1",
        scenarios=scenarios,
        agent_interfaces=agent_interfaces,
        headless=headless,
    )
 
    for episode in episodes(n=num_episodes):
        agents = {
            agent_id: RandomLanerAgent(env.action_space[agent_id])
            for agent_id in agent_interfaces.keys()
        }
        observations, _ = env.reset()
        episode.record_scenario(env.unwrapped.scenario_log)
 
        terminateds = {"__all__": False}
        while not terminateds["__all__"]:
            actions = {
                agent_id: agent.act(observations) for agent_id, agent in agents.items()
            }
            observations, rewards, terminateds, truncateds, infos = env.step(actions)
 
        print("------------- Available Observations-------------")
        agent_id = list(observations.keys())
        print(list(observations[agent_id[0]].keys()))
        print("--------------------------------------------------")
    env.close()
 
 
if __name__ == "__main__":
    parser = minimal_argument_parser(Path(__file__).stem)
    args = parser.parse_args()
 
    if not args.scenarios:
        args.scenarios = [
            str(SMARTS_REPO_PATH / "scenarios" / "sumo" / "loop"),
        ]
 
    build_scenarios(scenarios=args.scenarios)
 
    main(
        scenarios=args.scenarios,
        headless=args.headless,
        num_episodes=1,
        max_episode_steps=99,
    )

System info

No response

Error logs and screenshots

Console Output of print:

------------- Available Observations-------------
['active', 'steps_completed', 'distance_travelled', 'ego_vehicle_state', 'events', 'waypoint_paths']
--------------------------------------------------

Impact (If known)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions