def reconfigure( self, config: habitat.Config, capture_video: Optional[bool] = None, seed: Optional[int] = None, min_duration: Optional[int] = None, max_duration: Optional[int] = None, ) -> None: if capture_video is not None: self._capture_video = capture_video if seed is not None: # This is needed for reproducible episode shuffling random.seed(seed) np.random.seed(seed) with capture_output('habitat_sim'): self.habitat_env.reconfigure(config) # Habitat's reconfigure doesn't update the task config, so we do that manually: self.habitat_env._task = make_task( config.TASK.TYPE, config=config.TASK, sim=self.habitat_env._sim, dataset=self.habitat_env._dataset, ) if seed is not None: self.seed(seed) if min_duration is not None: self._min_duration = min_duration if max_duration is not None: self._max_duration = max_duration
def __init__(self, config: Config, dataset: Optional[Dataset] = None) -> None: assert config.is_frozen(), ("Freeze the config before creating the " "environment, use config.freeze()") self._config = config self._dataset = dataset self._current_episode_index = None if self._dataset is None and config.DATASET.TYPE: self._dataset = make_dataset(id_dataset=config.DATASET.TYPE, config=config.DATASET) self._episodes = self._dataset.episodes if self._dataset else [] self._sim = make_sim(id_sim=self._config.SIMULATOR.TYPE, config=self._config.SIMULATOR) self._task = make_task( self._config.TASK.TYPE, task_config=self._config.TASK, sim=self._sim, dataset=dataset, ) self.observation_space = SpaceDict({ **self._sim.sensor_suite.observation_spaces.spaces, **self._task.sensor_suite.observation_spaces.spaces, }) self.action_space = self._sim.action_space self._max_episode_seconds = ( self._config.ENVIRONMENT.MAX_EPISODE_SECONDS) self._max_episode_steps = self._config.ENVIRONMENT.MAX_EPISODE_STEPS self._elapsed_steps = 0 self._episode_start_time: Optional[float] = None self._episode_over = False
def __init__(self, config: Config, dataset: Optional[Dataset] = None) -> None: """Constructor :param config: config for the environment. Should contain id for simulator and ``task_name`` which are passed into ``make_sim`` and ``make_task``. :param dataset: reference to dataset for task instance level information. Can be defined as :py:`None` in which case ``_episodes`` should be populated from outside. """ assert config.is_frozen(), ("Freeze the config before creating the " "environment, use config.freeze().") self._config = config self._dataset = dataset self._current_episode_index = None if self._dataset is None and config.DATASET.TYPE: self._dataset = make_dataset(id_dataset=config.DATASET.TYPE, config=config.DATASET) self._episodes = self._dataset.episodes if self._dataset else [] self._current_episode = None iter_option_dict = { k.lower(): v for k, v in config.ENVIRONMENT.ITERATOR_OPTIONS.items() } self._episode_iterator = self._dataset.get_episode_iterator( **iter_option_dict) # load the first scene if dataset is present if self._dataset: assert (len(self._dataset.episodes) > 0), "dataset should have non-empty episodes list" self._config.defrost() self._config.SIMULATOR.SCENE = self._dataset.episodes[0].scene_id self._config.freeze() self._sim = make_sim(id_sim=self._config.SIMULATOR.TYPE, config=self._config.SIMULATOR) self._task = make_task( self._config.TASK.TYPE, config=self._config.TASK, sim=self._sim, dataset=self._dataset, ) self.observation_space = SpaceDict({ **self._sim.sensor_suite.observation_spaces.spaces, **self._task.sensor_suite.observation_spaces.spaces, }) self.action_space = self._task.action_space self._max_episode_seconds = ( self._config.ENVIRONMENT.MAX_EPISODE_SECONDS) self._max_episode_steps = self._config.ENVIRONMENT.MAX_EPISODE_STEPS self._elapsed_steps = 0 self._episode_start_time: Optional[float] = None self._episode_over = False
def __init__(self, config: Config, dataset: Optional[Dataset] = None) -> None: assert config.is_frozen(), ("Freeze the config before creating the " "environment, use config.freeze().") self._config = config self._dataset = dataset self._current_episode_index = None if self._dataset is None and config.DATASET.TYPE: self._dataset = make_dataset(id_dataset=config.DATASET.TYPE, config=config.DATASET) self._episodes = self._dataset.episodes if self._dataset else [] self._current_episode = None iter_option_dict = { k.lower(): v for k, v in config.ENVIRONMENT.ITERATOR_OPTIONS.items() } self._episode_iterator = self._dataset.get_episode_iterator( **iter_option_dict) # load the first scene if dataset is present if self._dataset: assert (len(self._dataset.episodes) > 0), "dataset should have non-empty episodes list" self._config.defrost() self._config.SIMULATOR.SCENE = self._dataset.episodes[0].scene_id self._config.freeze() self._sim = make_sim(id_sim=self._config.SIMULATOR.TYPE, config=self._config.SIMULATOR) self._task = make_task( self._config.TASK.TYPE, task_config=self._config.TASK, sim=self._sim, dataset=self._dataset, ) self.observation_space = SpaceDict({ **self._sim.sensor_suite.observation_spaces.spaces, **self._task.sensor_suite.observation_spaces.spaces, }) self.action_space = self._sim.action_space self._max_episode_seconds = ( self._config.ENVIRONMENT.MAX_EPISODE_SECONDS) self._max_episode_steps = self._config.ENVIRONMENT.MAX_EPISODE_STEPS self._elapsed_steps = 0 self._episode_start_time: Optional[float] = None self._episode_over = False
def __init__(self, config: Config, dataset: Optional[Dataset] = None) -> None: """Constructor. Mimics the :ref:`Env` constructor. Args: :param config: config for the environment. Should contain id for simulator and ``task_name`` for each task, which are passed into ``make_sim`` and ``make_task``. :param dataset: reference to dataset used for first task instance level information. Can be defined as :py:`None` in which case dataset will be built using ``make_dataset`` and ``config``. """ # let superclass instantiate current task by merging first task in TASKS to TASK if len(config.MULTI_TASK.TASKS): logger.info( "Overwriting config.TASK ({}) with first entry in config.MULTI_TASK.TASKS ({})." .format(config.TASK.TYPE, config.MULTI_TASK.TASKS[0].TYPE)) config.defrost() config.TASK.merge_from_other_cfg(config.MULTI_TASK.TASKS[0]) config.freeze() # TASKS[0] dataset has higher priority over default one (if specified), instatiate it before if dataset is None and config.MULTI_TASK.TASKS[0].DATASET.TYPE: dataset = make_dataset( id_dataset=config.MULTI_TASK.TASKS[0].DATASET.TYPE, config=config.MULTI_TASK.TASKS[0].DATASET, ) # initialize first task leveraging Env super().__init__(config, dataset=dataset) # instatiate other tasks self._tasks = [self._task] self._curr_task_idx = 0 # keep each tasks episode iterator to avoid re-creation self._episode_iterators = [self._episode_iterator] for task in config.MULTI_TASK.TASKS[1:]: self._tasks.append( make_task( task.TYPE, config=task, sim=self._sim, # each task gets its dataset dataset=make_dataset( # TODO: lazy make_dataset support id_dataset=task.DATASET.TYPE, config=task.DATASET), )) # get task episode iterator iter_option_dict = { k.lower(): v for k, v in task.EPISODE_ITERATOR_OPTIONS.items() } iter_option_dict["seed"] = self._config.SEED task_ep_iterator: EpisodeIterator = self._tasks[ -1]._dataset.get_episode_iterator(**iter_option_dict) self._episode_iterators.append(task_ep_iterator) # episode counter self._eps_counter = -1 self._cumulative_steps_counter = 0 # when and how to change task is defined here self._task_sampling_behavior = ( config.MULTI_TASK.TASK_ITERATOR.TASK_SAMPLING) self._change_task_behavior = ( config.MULTI_TASK.TASK_ITERATOR.TASK_CHANGE_TIMESTEP) # custom task label can be specified self._curr_task_label = self._task._config.get("TASK_LABEL", self._curr_task_idx) # add task_idx to observation space self.observation_space = spaces.Dict({ **self._sim.sensor_suite.observation_spaces.spaces, **self._task.sensor_suite.observation_spaces.spaces, "task_idx": spaces.Discrete(len(self._tasks)), })
def __init__(self, config: Config) -> None: """Constructor :param config: config for the environment. Should contain id for simulator and ``task_name`` which are passed into ``make_sim`` and ``make_task``. :param dataset: reference to dataset for task instance level information. Can be defined as :py:`None` in which case ``_episodes`` should be populated from outside. """ assert config.is_frozen(), ("Freeze the config before creating the " "environment, use config.freeze().") self._config = config self._current_episode_index = None self._current_episode = None iter_option_dict = { k.lower(): v for k, v in config.ENVIRONMENT.ITERATOR_OPTIONS.items() } self._scenes = config.DATASET.CONTENT_SCENES self._swap_building_every = config.ENVIRONMENT.ITERATOR_OPTIONS.MAX_SCENE_REPEAT_EPISODES print('[HabitatEnv] Total {} scenes : '.format(len(self._scenes)), self._scenes) print('[HabitatEnv] swap building every', self._swap_building_every) self._current_scene_episode_idx = 0 self._current_scene_idx = 0 self._config.defrost() if 'mp3d' in config.DATASET.DATA_PATH: self._config.SIMULATOR.SCENE = os.path.join( config.DATASET.SCENES_DIR, 'mp3d/{}/{}.glb'.format(self._scenes[0], self._scenes[0])) else: self._config.SIMULATOR.SCENE = os.path.join( config.DATASET.SCENES_DIR, 'gibson_habitat/{}.glb'.format(self._scenes[0])) if not os.path.exists(self._config.SIMULATOR.SCENE): self._config.SIMULATOR.SCENE = os.path.join( self._config.DATASET.SCENES_DIR, 'gibson_more/{}.glb'.format(self._scenes[0])) self._config.freeze() self._sim = make_sim(id_sim=self._config.SIMULATOR.TYPE, config=self._config.SIMULATOR) self._task = make_task(self._config.TASK.TYPE, config=self._config.TASK, sim=self._sim) self.observation_space = SpaceDict({ **self._sim.sensor_suite.observation_spaces.spaces, **self._task.sensor_suite.observation_spaces.spaces, }) self.action_space = self._task.action_space self._max_episode_seconds = ( self._config.ENVIRONMENT.MAX_EPISODE_SECONDS) self._max_episode_steps = self._config.ENVIRONMENT.MAX_EPISODE_STEPS self._elapsed_steps = 0 self._episode_start_time: Optional[float] = None self._episode_over = False #TODO listup demonstration data self._episode_dataset = {}