Simulation multiple robot in one scene

Discussion in 'Simulation' started by ViktorM, Jun 11, 2018.

  1. Hi,

    In the doc's CPU or GPU section you've mentioned that only when simulating more than 1000 robots a benefit running simulation on a GPU could be seen. My question is, how a lot of robots can be loaded and simulated in parallel on a CPU? Say I'd like to simulate and run in parallel 100 Cassies robots to perform a RL training. What is the simplest way to load and simulate such a number of robots? In OpenAI self-play environments the loaded and simulated only 2 humanoids and they were hard-coded in the xml file. It's not a very scalable way of loading multiple robots, are there any other ways?
  2. Emo Todorov

    Emo Todorov Administrator Staff Member

    Do you want the robots to interact with each other, or are the simulations independent?

    If they are independent, load the model once and create multiple copies of mjData -- one for each thread. The number of threads should equal the number of logical cores for optimal performance. Then run the simulations in parallel with parallel for (in OpenMP) or your own threads if you prefer. Do not create 1000 threads! That works well on GPUs but not on CPUs.

    If they are supposed to interact, you have to create a model with lots of robots in it. The XML format allows include statements, so you can make a model file that includes the robot model many times. But you have to make sure the robot model does not have named elements, or else the names will be repeated which is a compile error.

    Ideally there would be a model-building API, and indeed there is one internally, but it uses C++ which cannot be exported in a compiler-independent library. There is a plan to write a C wrapper around it for a future release (but not immediately).