def create_scenario(): with temp_scenario(name="cycles", map="maps/6lane.net.xml") as scenario_root: 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] ] for name, (edge_start, edge_end) in [ ("group-1", ("edge-north-NS", "edge-south-NS")), ("group-2", ("edge-west-WE", "edge-east-WE")), ("group-3", ("edge-east-EW", "edge-west-EW")), ("group-4", ("edge-south-SN", "edge-north-SN")), ]: route = Route(begin=("edge-north-NS", 1, 0), end=("edge-south-NS", 1, "max")) missions = [Mission(route=route)] * 2 gen_social_agent_missions( scenario_root, social_agent_actor=actors, name=name, missions=missions, ) yield scenario_root
def scenario_root(scenario_parent_path): # TODO: We may want to consider referencing to concrete scenarios in our tests # rather than generating them. The benefit of generting however is that # we can change the test criteria and scenario code in unison. scenario = Path(scenario_parent_path) / "cycles" scenario.mkdir() shutil.copyfile( Path(__file__).parent / "maps/6lane.net.xml", scenario / "map.net.xml") generate_glb_from_sumo_network(str(scenario / "map.net.xml"), str(scenario / "map.glb")) 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] ] for name, (edge_start, edge_end) in [ ("group-1", ("edge-north-NS", "edge-south-NS")), ("group-2", ("edge-west-WE", "edge-east-WE")), ("group-3", ("edge-east-EW", "edge-west-EW")), ("group-4", ("edge-south-SN", "edge-north-SN")), ]: route = Route(begin=("edge-north-NS", 1, 0), end=("edge-south-NS", 1, "max")) missions = [Mission(route=route)] * 2 # double up gen_social_agent_missions( scenario, social_agent_actor=actors, name=name, missions=missions, ) gen_missions( scenario, missions=[ Mission( Route(begin=("edge-west-WE", 0, 0), end=("edge-east-WE", 0, "max"))) ], ) return scenario
def scenario_root(): # TODO: We may want to consider referencing to concrete scenarios in our tests # rather than generating them. The benefit of generting however is that # we can change the test criteria and scenario code in unison. with temp_scenario(name="cycles", map="maps/6lane.net.xml") as scenario_root: 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] ] for name, (edge_start, edge_end) in [ ("group-1", ("edge-north-NS", "edge-south-NS")), ("group-2", ("edge-west-WE", "edge-east-WE")), ("group-3", ("edge-east-EW", "edge-west-EW")), ("group-4", ("edge-south-SN", "edge-north-SN")), ]: route = Route(begin=("edge-north-NS", 1, 0), end=("edge-south-NS", 1, "max")) missions = [Mission(route=route)] * 2 # double up gen_social_agent_missions( scenario_root, social_agent_actor=actors, name=name, missions=missions, ) gen_missions( scenario_root, missions=[ Mission( Route(begin=("edge-west-WE", 0, 0), end=("edge-east-WE", 0, "max"))) ], ) yield scenario_root
import os import pickle from smarts.sstudio import gen_social_agent_missions from smarts.sstudio import types as t scenario = os.path.dirname(os.path.realpath(__file__)) with open(os.environ["SOCIAL_AGENT_PATH"], "rb") as f: social_agent = pickle.load(f) gen_social_agent_missions( scenario, social_agent_actor=social_agent, name=f"s-agent-{social_agent.name}", missions=[ t.Mission(t.Route(begin=("E3n-3", 2, 200), end=("E3-35", 1, 60))), ], ) """ from pathlib import Path from smarts.sstudio import gen_missions from smarts.sstudio.types import ( Route, Mission, ) scenario = str(Path(__file__).parent)
import os import pickle from smarts.sstudio import gen_social_agent_missions from smarts.sstudio import types as t scenario = os.path.dirname(os.path.realpath(__file__)) with open(os.environ["SOCIAL_AGENT_PATH"], "rb") as f: social_agent = pickle.load(f) gen_social_agent_missions( scenario, social_agent_actor=social_agent, name=f"s-agent-{social_agent.name}", missions=[ t.Mission(t.Route(begin=("E35-3", 2, 50), end=("E3-3l", 2, "max"))), ], )
social_agent3 = SocialAgentActor( name="zoo-car3", agent_locator="agent_prefabs:zoo-agent2-v0", ) # here define social agent type and numbers social_agents = [social_agent2, social_agent3, social_agent1] # generate social agent missisons and store social agents' information under social_agents/ for scenario, starting_edge in zip(scenario_paths, starting_edges): for i, social_agent in enumerate(social_agents): gen_social_agent_missions( scenario, social_agent_actor=social_agent, name=f"s-agent-{social_agent.name}", missions=[ # edge_id, lane_index, offset EndlessMission(begin=(starting_edge, i + 1, 0),), # Mission(Route(begin=("edge-east", 1, 0), end=("edge-east", 1, -5))), ], overwrite=True, ) print("generate social agent missions finished") ######################################### # generate agent missions ######################################### # generate agent Missions so agents will born in the same position after env reset() # Otherwise, no defined agent mission will lead to agent born in different place after env reset()
laner_agent = SocialAgentActor( name="laner-agent", agent_locator= "scenarios.intersections.2lane_circle.agent_prefabs:laner-agent-v0", ) buddha_agent = SocialAgentActor( name="buddha-agent", agent_locator= "scenarios.intersections.2lane_circle.agent_prefabs:buddha-agent-v0", ) gen_social_agent_missions( scenario, social_agent_actor=laner_agent, name=f"s-agent-{laner_agent.name}", missions=[ Mission(Route(begin=("edge-east-EW", 0, 5), end=("edge-west-EW", 0, 5))) ], ) gen_social_agent_missions( scenario, social_agent_actor=buddha_agent, name=f"s-agent-{buddha_agent.name}", missions=[ Mission(Route(begin=("edge-west-WE", 0, 5), end=("edge-east-WE", 0, 5))) ], )
# "this.resolved.module:attribute" # In your own project you would place the prefabs script where python can reach it social_agent1 = SocialAgentActor( name="zoo-car1", agent_locator="scenarios.zoo_intersection.agent_prefabs:zoo-agent2-v0", initial_speed=20, ) social_agent2 = SocialAgentActor( name="zoo-car2", agent_locator="scenarios.zoo_intersection.agent_prefabs:zoo-agent2-v0", initial_speed=20, ) gen_social_agent_missions( scenario, social_agent_actor=social_agent2, name=f"s-agent-{social_agent2.name}", missions=[Mission(RandomRoute())], ) gen_social_agent_missions( scenario, social_agent_actor=social_agent1, name=f"s-agent-{social_agent1.name}", missions=[ EndlessMission(begin=("edge-south-SN", 0, 30)), Mission( Route(begin=("edge-west-WE", 0, 10), end=("edge-east-WE", 0, 10))), ], ) # Agent Missions