Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting an existing gazebo environment into vectorized environment #831

Open
utsavpatel22 opened this issue Apr 27, 2020 · 7 comments
Open
Labels
custom gym env Issue related to Custom Gym Env question Further information is requested

Comments

@utsavpatel22
Copy link

I am trying to train a mobile robot using stable baselines. I have created a custom environment so stable baselines can be used to train the robot. Now the issues is if I just use a single agent then the training process takes a lot of time. I am trying to vectorize the environment but I could not find any detailed documentation on that. I cannot launch multiple gazebo instances as each takes a lot of computational resources. I want to launch multiple robots in a single gazebo environment and train them parallelly. Does anyone have any experience with this?

@Miffyli Miffyli added custom gym env Issue related to Custom Gym Env question Further information is requested labels Apr 27, 2020
@Miffyli
Copy link
Collaborator

Miffyli commented Apr 27, 2020

The built-in VecEnvs only support launching multiple instances of the same environment. You have to modify the Gazebo environment to include multiple robots to gather data, and then implement a VecEnv wrapper that correctly handles this data (pretends to be multiple environments, but in reality just passes on the data from a single environment with multiple agents).

Unity ML Agents repository could give some tips on how to do the former, as they "parallelize" learning in Unity environment in a similar fashion.

@utsavpatel22
Copy link
Author

Thank you so much for your quick response. I will look into that.

@ChengYen-Tang
Copy link

Is this what you want?

# multiprocess environment
n_cpu = 4
env = SubprocVecEnv([lambda: gym.make('CartPole-v1') for i in range(n_cpu)])

@utsavpatel22
Copy link
Author

No @ChengYen-Tang , I have a Gazebo environment, and I have step, get_obs, reset etc. functions defined for a single agent in the environment. I tried training a single agent with PPO, but the training process is too slow, I need to run multiple agents to speed up the training. Now I cannot launch multiple Gazebo instances as Gazebo needs a good amount of memory, so I want to launch multiple robot instances in a single Gazebo environment. I am not exactly sure how I can do that. Do I need to define the methods of VecEnv class? If yes it would be great if you can point me to some example code if someone has tried to do the same. I am going through Unity ML Agents but still it is not clear. Thanks for looking into the issue.

@diegoferigo
Copy link

Take in consideration that, depending of the robot you're using, the simulation in Gazebo could become a bottleneck. In other words, when multiple robots are part of the simulation, the RTF of Gazebo could drop significantly since after all the gzserver is a single-process application. Simple robots are could be handled easily, instead robot with complex collisions primitives could become very expensive to compute.

@utsavpatel22
Copy link
Author

Thank you @diegoferigo I will consider that.

@MonGreL94
Copy link

@utsavpatel22 Hey there, have you managed to define this kind of vectorized environment with multiple robots in a single gazebo environment? If yes, how does it work? Can you share some code, or tips please? I am trying to do the same thing.
Thanks a lot in advance 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
custom gym env Issue related to Custom Gym Env question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants