google-deepmind / mujoco_mpc

Real-time behaviour synthesis with MuJoCo, using Predictive Control
https://github.com/deepmind/mujoco_mpc
Apache License 2.0
1.06k stars 157 forks source link

Different behavior between python API and GUI #347

Closed adawne closed 3 weeks ago

adawne commented 3 weeks ago

Hi! Thank you for this work! I was able to achieve the task I wanted using the GUI. However, I noticed that when I tried using the Python API with the exact same setup, I ended up with a different trajectory. I need to use the Python API because I have to integrate it with another part that is already implemented in MuJoCo using Python.

Could this difference in behavior be related to this issue? https://github.com/google-deepmind/mujoco_mpc/issues/322#issuecomment-2111497018. Do you have any tips on how I can achieve the same behavior in Python as I do in the GUI? Also, the MPC parameters defined in the MJCF file should be automatically applied when I run the model in Python, correct?

thowell commented 3 weeks ago

The C++ GUI interface is asynchronous. The number of planning iterations per simulation step is hardware dependent. In contrast, the Python API is synchronous and the number of planning iterations per simulation step is fixed.

Increasing the number of planning iterations per simulation step should be beneficial. For example, in this cartpole demo increase num_steps.

The C++ interface and Python API use the same parameters and settings defined in the task xml file.