google-deepmind / mujoco

Multi-Joint dynamics with Contact. A general purpose physics simulator.
https://mujoco.org
Apache License 2.0
8.08k stars 809 forks source link

Large Scene support + DoF locking #7

Open yuvaltassa opened 3 years ago

yuvaltassa commented 3 years ago

Currently there is no mechanism in MuJoCo for locking (a.k.a, sleeping, freezing) degrees-of-freedom. This is important for e.g. simulating large scenes.

This could be implemented either at the level of joints, or at the level of subtrees (children of the world body).

venkataarikatlaagility commented 1 year ago

@yuvaltassa are there any updates on this feature? If not, do you have any suggestions on the best way to go about it?

yuvaltassa commented 1 year ago

Yes and no.

Very generally, MuJoCo was designed to simulate medium sized scenes, so handling of large scenes can be improved in many ways, and large scenes are indeed one of our top priorities. We've already made changes and have several more coming soon that will reduce and eventually eliminate quadratic memory allocation in mjData (MuJoCo uses sparse math, but in some important places assumes for convenience that dense memory is available). This will enable the most basic of all large-scene features: fit the scene in memory 🤠

Following this, a very low hanging fruit which we intend to work on soon is MuJoCo's inefficient broadphase collision detection, which prunes far too few narrowphase calls. This leads to a large unnecessary slowdown, yet is not hard to improve.

Only after these steps are complete does it make sense to move towards the two features required for actual large scenes: dof freezing and parallel handling of contact islands (cliques of contacts and dofs). There are many decisions to make here and different possible approaches, and these will take time to figure out.

In terms of timeline, I can say that the features described in the first two paragraphs are planned for 2023. It is fair to hope that the detailed design of the dof freezing and contact islands will also happen, but it's hard to imagine the implementation being completed this year.

I hope this makes sense.

venkataarikatlaagility commented 1 year ago

It's good to hear that this is part of your plans. Looking forward to the improvements.

peterdavidfagan commented 10 months ago

+1 on this feature, it would be nice to have the option to lock and unlock joints for tuning actuators.

gedalia commented 6 months ago

+1 as well, we're looking at supporting larger worlds and wondering what the best options are, being able to pause physics on idle areas of the scene till they are disturbed would go along way to helping our performance goals.

yuvaltassa commented 6 months ago

There are two potential variants of dof sleeping:

  1. Sleep ("lock") individual joints.
  2. Sleep entire world sub-trees (a free body, a whole robot, etc).

Could people comment on whether 2 would be good enough for their purposes or if they really need 1?

gedalia commented 6 months ago

I think 2 would work for us. I guess it depends on how flexible it is. But at the very least it would allow us to build a sim where we had a decent number of objects where we aren't always interacting with everything.

peterdavidfagan commented 6 months ago

For my use case, functionality 1. was what I was looking for. With this being said I have subsequently changed strategy a bit, for the most part I have been able to work by building controllers that use the motor actuator model and this seems to work well for what I needed. As a result, I don't personally have an immediate need for 1. but it would be nice to have this flexibility nonetheless.

I also think 2. would be super useful, I haven't progressed to overly complex scenes yet but I can imagine this will be something I may also encounter in future.

No immediate need for either feature right now on my side but I would prefer option 1. due to its generality.