def __init__( self, scenarios: Sequence[str], agent_specs, shuffle_scenarios=True, headless=False, visdom=False, timestep_sec=0.1, seed=42, num_external_sumo_clients=0, sumo_headless=True, sumo_port=None, sumo_auto_start=True, endless_traffic=True, envision_endpoint=None, envision_record_data_replay_path=None, zoo_workers=None, auth_key=None, ): self._log = logging.getLogger(self.__class__.__name__) smarts.core.seed(seed) self._agent_specs = agent_specs self._dones_registered = 0 self._scenarios_iterator = Scenario.scenario_variations( scenarios, list(agent_specs.keys()), shuffle_scenarios, ) agent_interfaces = { agent_id: agent.interface for agent_id, agent in agent_specs.items() } envision_client = None if not headless: envision_client = Envision( endpoint=envision_endpoint, output_dir=envision_record_data_replay_path ) visdom_client = None if visdom: visdom_client = VisdomClient() self._smarts = SMARTS( agent_interfaces=agent_interfaces, traffic_sim=SumoTrafficSimulation( headless=sumo_headless, time_resolution=timestep_sec, num_external_sumo_clients=num_external_sumo_clients, sumo_port=sumo_port, auto_start=sumo_auto_start, endless_traffic=endless_traffic, ), envision=envision_client, visdom=visdom_client, timestep_sec=timestep_sec, zoo_workers=zoo_workers, auth_key=auth_key, )
def __init__(self, scenarios: Sequence[str], agent_specs: Dict, shuffle_scenarios=True, headless=False, visdom=False, timestep_sec=0.1, seed=42, num_external_sumo_clients=0, sumo_headless=True, sumo_port=None, sumo_auto_start=True, endless_traffic=True, envision_endpoint=None, envision_record_data_replay_path=None, zoo_addrs=None): self._metircs = Metric(1) self.has_connection = False self._log = logging.getLogger(self.__class__.__name__) smarts.core.seed(seed) # Set seed for np and random module. self._agent_specs = agent_specs self._dones_registered = 0 # Setup ego. self._ego = agent_specs[EGO_ID].build_agent() # Setup sceanrios for benchmark. self._scenarios_iterator = Scenario.scenario_variations( scenarios, list(agent_specs.keys()), shuffle_scenarios, ) # Setup envision and visdom. envision_client = None if not headless: envision_client = Envision( endpoint=envision_endpoint, output_dir=envision_record_data_replay_path) visdom_client = None if visdom: visdom_client = VisdomClient() # Setup SMARTS agent_interfaces = { agent_id: agent.interface for agent_id, agent in agent_specs.items() } self._smarts = SMARTS( agent_interfaces=agent_interfaces, traffic_sim=SumoTrafficSimulation( headless=sumo_headless, time_resolution=timestep_sec, num_external_sumo_clients=num_external_sumo_clients, sumo_port=sumo_port, auto_start=sumo_auto_start, endless_traffic=endless_traffic, ), envision=envision_client, visdom=visdom_client, timestep_sec=timestep_sec, zoo_addrs=zoo_addrs)
def __init__( self, scenarios: Sequence[str], agent_specs: Dict[str, AgentSpec], sim_name: Optional[str] = None, shuffle_scenarios: bool = True, headless: bool = True, visdom: bool = False, fixed_timestep_sec: Optional[float] = None, seed: int = 42, num_external_sumo_clients: int = 0, sumo_headless: bool = True, sumo_port: Optional[str] = None, sumo_auto_start: bool = True, endless_traffic: bool = True, envision_endpoint: Optional[str] = None, envision_record_data_replay_path: Optional[str] = None, zoo_addrs: Optional[str] = None, timestep_sec: Optional[ float ] = None, # for backwards compatibility (deprecated) ): """ Args: scenarios (Sequence[str]): A list of scenario directories that will be simulated. agent_specs (Dict[str, AgentSpec]): Specification of the agents that will run in the environment. sim_name (Optional[str], optional): Simulation name. Defaults to None. shuffle_scenarios (bool, optional): If true, order of scenarios will be randomized, else it will be maintained. Defaults to True. headless (bool, optional): If True, disables visualization in Envision. Defaults to False. visdom (bool, optional): If True, enables visualization of observed RGB images in Visdom. Defaults to False. fixed_timestep_sec (Optional[float], optional): Step duration for all components of the simulation. May be None if time deltas are externally-driven. Defaults to None. seed (int, optional): Random number generator seed. Defaults to 42. num_external_sumo_clients (int, optional): Number of SUMO clients beyond SMARTS. Defaults to 0. sumo_headless (bool, optional): If True, disables visualization in SUMO GUI. Defaults to True. sumo_port (Optional[str], optional): SUMO port. Defaults to None. sumo_auto_start (bool, optional): Automatic starting of SUMO. Defaults to True. endless_traffic (bool, optional): SUMO's endless traffic setting. Defaults to True. envision_endpoint (Optional[str], optional): Envision's uri. Defaults to None. envision_record_data_replay_path (Optional[str], optional): Envision's data replay output directory. Defaults to None. zoo_addrs (Optional[str], optional): List of (ip, port) tuples of zoo server, used to instantiate remote social agents. Defaults to None. timestep_sec (Optional[float], optional): [description]. Defaults to None. """ self._log = logging.getLogger(self.__class__.__name__) self.seed(seed) if timestep_sec and not fixed_timestep_sec: warnings.warn( "timestep_sec has been deprecated in favor of fixed_timestep_sec. Please update your code.", category=DeprecationWarning, ) if not fixed_timestep_sec: fixed_timestep_sec = timestep_sec or 0.1 self._agent_specs = agent_specs self._dones_registered = 0 self._scenarios_iterator = Scenario.scenario_variations( scenarios, list(agent_specs.keys()), shuffle_scenarios, ) agent_interfaces = { agent_id: agent.interface for agent_id, agent in agent_specs.items() } envision_client = None if not headless or envision_record_data_replay_path: envision_client = Envision( endpoint=envision_endpoint, sim_name=sim_name, output_dir=envision_record_data_replay_path, headless=headless, ) visdom_client = None if visdom: visdom_client = VisdomClient() all_sumo = Scenario.supports_traffic_simulation(scenarios) traffic_sim = None if not all_sumo: # We currently only support the Native SUMO Traffic Provider and Social Agents for SUMO maps if zoo_addrs: warnings.warn("`zoo_addrs` can only be used with SUMO scenarios") zoo_addrs = None warnings.warn( "We currently only support the Native SUMO Traffic Provider and Social Agents for SUMO maps." "All scenarios passed need to be of SUMO, to enable SUMO Traffic Simulation and Social Agents." ) pass else: from smarts.core.sumo_traffic_simulation import SumoTrafficSimulation traffic_sim = SumoTrafficSimulation( headless=sumo_headless, time_resolution=fixed_timestep_sec, num_external_sumo_clients=num_external_sumo_clients, sumo_port=sumo_port, auto_start=sumo_auto_start, endless_traffic=endless_traffic, ) zoo_addrs = zoo_addrs self._smarts = SMARTS( agent_interfaces=agent_interfaces, traffic_sim=traffic_sim, envision=envision_client, visdom=visdom_client, fixed_timestep_sec=fixed_timestep_sec, zoo_addrs=zoo_addrs, )
def __init__( self, scenarios: Sequence[str], agent_specs: Dict[str, AgentSpec], sim_name=None, shuffle_scenarios=True, headless=False, visdom=False, fixed_timestep_sec=None, seed=42, num_external_sumo_clients=0, sumo_headless=True, sumo_port=None, sumo_auto_start=True, endless_traffic=True, envision_endpoint=None, envision_record_data_replay_path=None, zoo_addrs=None, timestep_sec=None, # for backwards compatibility (deprecated) ): self._log = logging.getLogger(self.__class__.__name__) self.seed(seed) if timestep_sec and not fixed_timestep_sec: warnings.warn( "timestep_sec has been deprecated in favor of fixed_timestep_sec. Please update your code.", category=DeprecationWarning, ) if not fixed_timestep_sec: fixed_timestep_sec = timestep_sec or 0.1 self._agent_specs = agent_specs self._dones_registered = 0 self._scenarios_iterator = Scenario.scenario_variations( scenarios, list(agent_specs.keys()), shuffle_scenarios, ) agent_interfaces = { agent_id: agent.interface for agent_id, agent in agent_specs.items() } envision_client = None if not headless or envision_record_data_replay_path: envision_client = Envision( endpoint=envision_endpoint, sim_name=sim_name, output_dir=envision_record_data_replay_path, headless=headless, ) visdom_client = None if visdom: visdom_client = VisdomClient() all_sumo = Scenario.supports_traffic_simulation(scenarios) traffic_sim = None if not all_sumo: # We currently only support the Native SUMO Traffic Provider and Social Agents for SUMO maps if zoo_addrs: warnings.warn( "`zoo_addrs` can only be used with SUMO scenarios") zoo_addrs = None warnings.warn( "We currently only support the Native SUMO Traffic Provider and Social Agents for SUMO maps." "All scenarios passed need to be of SUMO, to enable SUMO Traffic Simulation and Social Agents." ) pass else: from smarts.core.sumo_traffic_simulation import SumoTrafficSimulation traffic_sim = SumoTrafficSimulation( headless=sumo_headless, time_resolution=fixed_timestep_sec, num_external_sumo_clients=num_external_sumo_clients, sumo_port=sumo_port, auto_start=sumo_auto_start, endless_traffic=endless_traffic, ) zoo_addrs = zoo_addrs self._smarts = SMARTS( agent_interfaces=agent_interfaces, traffic_sim=traffic_sim, envision=envision_client, visdom=visdom_client, fixed_timestep_sec=fixed_timestep_sec, zoo_addrs=zoo_addrs, )
def __init__(self, all_args): self.all_args = all_args self._dones_registered = 0 self.neighbor_num = all_args.neighbor_num self.rews_mode = all_args.rews_mode self.n_agents = all_args.num_agents self.use_proximity = all_args.use_proximity self.use_discrete = all_args.use_discrete # default True self.use_centralized_V = all_args.use_centralized_V self.scenarios = [(all_args.scenario_path + all_args.scenario_name)] self.agent_ids = ["Agent %i" % i for i in range(self.n_agents)] self.obs_space_dict = self.get_obs_space_dict() self.obs_dim = self.get_obs_dim() # ! TODO: self.share_obs_dim = self.get_state_dim( ) if self.use_centralized_V else self.get_obs_dim() self.observation_space = [ gym.spaces.Box(low=-1e10, high=1e10, shape=(self.obs_dim, )) ] * self.n_agents self.share_observation_space = [ gym.spaces.Box(low=-1e10, high=1e10, shape=(self.share_obs_dim, )) ] * self.n_agents if self.use_discrete: self.act_dim = 4 self.action_space = [gym.spaces.Discrete(self.act_dim) ] * self.n_agents self.agent_type = AgentType.Vulner_with_proximity if self.use_proximity else AgentType.Vulner else: # TODO Add continous action space self.agent_type = AgentType.VulnerCon_with_proximity if self.use_proximity else AgentType.VulnerCon raise NotImplementedError self._agent_specs = { agent_id: AgentSpec( interface=AgentInterface.from_type( self.agent_type, max_episode_steps=all_args.horizon), observation_adapter=self.get_obs_adapter(), reward_adapter=self.get_rew_adapter(self.rews_mode, self.neighbor_num), action_adapter=self.get_act_adapter(), ) for agent_id in self.agent_ids } self._scenarios_iterator = Scenario.scenario_variations( self.scenarios, list(self._agent_specs.keys()), all_args.shuffle_scenarios, ) self.agent_interfaces = { agent_id: agent.interface for agent_id, agent in self._agent_specs.items() } self.envision_client = None if not all_args.headless: self.envision_client = Envision( endpoint=all_args.envision_endpoint, output_dir=all_args.envision_record_data_replay_path) self.visdom_client = None if all_args.visdom: self.visdom_client = VisdomClient() self._smarts = SMARTS( agent_interfaces=self.agent_interfaces, traffic_sim=SumoTrafficSimulation( headless=all_args.sumo_headless, time_resolution=all_args.timestep_sec, num_external_sumo_clients=all_args.num_external_sumo_clients, sumo_port=all_args.sumo_port, auto_start=all_args.sumo_auto_start, endless_traffic=all_args.endless_traffic, ), envision=self.envision_client, visdom=self.visdom_client, timestep_sec=all_args.timestep_sec, zoo_workers=all_args.zoo_workers, auth_key=all_args.auth_key, )