mujoco icon indicating copy to clipboard operation
mujoco copied to clipboard

[MJX] visualize parallel environments in one viewer

Open panwliu opened this issue 1 year ago • 9 comments

First of all, thanks for the great work! MJX could make a great impact in the robotics community.

I'm doing massive parallel simulation using MJX. During the development phase, I'd like to visualize the parallel environments. For example, I spawned 4096 humanoids, and I'd like to visualize them all in a viewer as the image (a screenshot of Isaac Gym). I saw that mjx/mujoco/mjx/viewer.py is used to visualize one environment. How to visualize the parallel environments in one viewer?

Thanks Screenshot from 2024-01-21 14-57-55

panwliu avatar Jan 21 '24 23:01 panwliu

Yes, I am also very curious to know if there's a way to do it @yuvaltassa.

rs545837 avatar Jan 22 '24 18:01 rs545837

Hi folks,

For the MJX part, you can simulate N environments and write them back to MjData via get_data which accepts a batched mjx.Data.

Now for visualizing N environments, the simplest way I can think of is to create an MjModel/MjData with N characters (procedurally generate the XML or use something like dm_env composer), and then feed the qpos from the above step back into your MjData. Others should comment on this replication bit though. I know that there has been some active discussion on better ways to repeat bodies.

btaba avatar Jan 26 '24 22:01 btaba

Hi @btaba , thanks for the response.

Since mujoco doesn't allow repeated bodies in the XML, it actually makes procedurally generating N characters not trivial. Also needs careful handling in feeding the batched mjx.Data to the right bodies.

Another possible way would be a "batched" version of mjModel. Would you think this as an option?

panwliu avatar Jan 31 '24 17:01 panwliu

I think what you want is visual only, no? Like, your humanoids don't need to touch each other at all, right?

This is something that @vikashplus (and, as it turns out, #1395) have asked for.

What you actually want, IIUC, is something like mjv_updateScene, except you want "mjv_addToScene", i.e. some way to add together the geoms from multiple mjData instances into one visual scene. Correct?

yuvaltassa avatar Feb 05 '24 13:02 yuvaltassa

+1 mjv_addToScene will be amazing. I have been trying to unsuccessfully hack this in multiple ways.

vikashplus avatar Feb 05 '24 15:02 vikashplus

some way to add together the geoms from multiple mjData instances into one visual scene

@yuvaltassa, exactly!

panwliu avatar Feb 06 '24 01:02 panwliu

Okay, this is MUCH easier than your initial proposal. I'll try to do something like this in the next few days, will update here.

yuvaltassa avatar Feb 06 '24 05:02 yuvaltassa

@yuvaltassa was wondering if there was any update on this feature. I think it would be really great to have, and not only good to get a nice overview for how the robots are behaving, but also nice for making videos for research papers etc.

AlexS28 avatar Feb 25 '24 04:02 AlexS28

@yuvaltassa Any update on this? Would definitely be huge if this is somehow possible!

alexhansson avatar Mar 25 '24 21:03 alexhansson