habitat-lab icon indicating copy to clipboard operation
habitat-lab copied to clipboard

A tutorial of using VectorEnv for multiple processes, e.g. the shortest path following example?

Open eric-xw opened this issue 6 years ago • 3 comments

Hi,

Can you provide an example of using VectorEnv for shortest path following? similar to this one (https://github.com/facebookresearch/habitat-api/blob/master/examples/shortest_path_follower_example.py) but with multiple processes.

Thanks, Xin

eric-xw avatar Apr 16 '19 22:04 eric-xw

We don't have such tutorial yet.

mathfac avatar Jun 14 '19 08:06 mathfac

Hi! Is this still of any interests?

gianscarpe avatar Jun 30 '21 13:06 gianscarpe

Hi @eric-xw @gianscarpe

If you are still interested in using the VectorEnv for shortest path following, this should be pretty easy to implement.

You may define a thin wrapper around of the Env class (let's say, SPFEnv) that should have attributes env (Env instance) and spf (ShortestPathFollower instance). SPFEnv will translate SPFEnv.step(any_action) to Env.step(spf.get_next_action()).

from habitat.tasks.nav.shortest_path_follower import ShortestPathFollower

class SPFEnv(Env):
    def __init__(self, config, goal_radius):
        super().__init__(config)
        self.shortest_path_follower = ShortestPathFollower(
            sim=self.sim,
            goal_radius=goal_radius,
            return_one_hot=False
        )

    def step(self, action):
        best_action = self.shortest_path_follower.get_next_action(
            self.current_episode.goals[0].position
        )
        return super().step(best_action)

Then using VectorEnv you could create as many instances of SPFEnv as you need. For more details on how to use VectorEnv you may check PPOTrainer implementation.

rpartsey avatar Aug 31 '22 08:08 rpartsey

Closing due to inactivity. Feel free to re-open the issue, if you still have questions.

rpartsey avatar Jan 26 '23 12:01 rpartsey