Simulating systems with a large number of constraints

Discussion in 'Simulation' started by Marc Tuscher, Oct 10, 2016.

  1. Dear Forum,

    my MJCF-model contains a large number of equality/connect entities leading to many contraints which have to be solved at runtime. Generally MuJoCo is capable of simulating this model though it might not be the most efficient solution. I've experienced great improvements by setting option/solver to PCGsparse. I'm doing a gait optimization using bayesian optimization. Now my questions:

    1. Is there a set of values of parameters (option/timestep, option/iterations etc.) being useful for the application of optimization?

    2. Is there a way of measuring constraint violations?

    Sorry for the long post und thank you very much for this great support.
    I really appreciate it!!

    Best,
    Marc
     
  2. Emo Todorov

    Emo Todorov Administrator Staff Member

    Yes, you need one of the sparse solvers for large systems. The default PGS is a dense solver which scales as O(n^3) where n is the number of active scalar constraints. The elliptic solver is also dense. PCGsparse, CG and CGelliptic are sparse solvers, and scale roughly as O(n), even though the constants are larger. The sparse solvers are not fully tuned yet, and in fact I just developed a new sparse solver which may replace the existing ones in a future release. But they are already usable.

    The timestep should be adjusted to the largest value that produces stable simulations (or maybe slightly smaller, to be conservative). Note that if you are doing optimization, the optimizer will automatically look for loopholes in the physics and try to exploit them. So you may need a smaller timestep in that context compared to regular simulation.

    The iterations parameter is the maximum number of iterations. There is also tolerance which causes early termination. So you can have a large number of iterations for the occasional timestep where the problem is hard, and the rest of the time terminate early because the tolerance threshold will be reached. Larger tolerance causes earlier termination. The default of 1e-6 is rather conservative. You can probably set it to 1e-3 and still obtain reasonable simulations, but you should experiment with it for the specific system.

    As for constraint violations, assuming you mean physical constraints as opposed to poor solver convergence, they are recorded in mjData.efc_pos. Unfortunately the reference documentation is still missing, and it is not easy to interpret this array. Briefly, each scalar constraint has an efc_type and efc_id telling you what constraint this is, and the corresponding efc_pos tells you the size of the violation. The total number of scalar constraints (different for each timestep) is mjData.nefc.

    If you are looking specifically for contact penetration, there is redundant information in the list of contacts in mjData.contact. Each contact has a "dist" field containing the contact distance, negative being penetration.