Common debugging strategies for legacy mujoco and realted projects (Diffuser, Decision Diffuser, etc)

Recently, I was trying to reproduce the result and get a feeling about how those diffusion-based reinforcement learning algorithm actually works. It has been a long time I haven’t running RL stuff, and surprisingly found that it is a bit difficult to get it correct at the first time. In this post, I summarized the getting start guide of mujoco-py, debugging tips, and list the errors I have encountered before.

Before using mujoco-py

Mujoco was originally from Roboti and bought by DeepMind. Originally, OpenAI maintains mujoco-py package until version 2.1.2.14. After that, mujoco-py was deprecated and DeepMind manages another package called mujoco. Both packages are available on PyPI.

mujoco-py was deprecated around 2021, so a lot of works built before 2022 or 2022 are still using the old mujoco-py package.

Mujoco main program

Notably, mujoco-py does not contain the main simulation program. Therefore, we need to install the main program before installing mujoco-py to avoid issues. Here is some handy code snippets to install the main program:

sudo apt install zip -y

cd ~
wget https://www.roboti.us/download/mujoco200_linux.zip
wget https://www.roboti.us/file/mjkey.txt
unzip mujoco200_linux.zip

mkdir ~/.mujoco
mv mjkey.txt ~/.mujoco/mjkey.txt
mv mujoco200_linux ~/.mujoco/mujoco200

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/.mujoco/mujoco200/bin

Mujoco OpenGL dependencies

Moreover, mujoco depends on OpenGL. Therefore, some libraries are required: (Reference)

sudo apt install libosmesa6-dev libgl1-mesa-glx libglfw3

If you don’t have sudo privilege, you may consider using: (Reference).

conda install -c conda-forge mesalib glew glfw
export LD_LIBRARY_PATH=$CONDA_PREFIX/lib:$LD_LIBRARY_PATH

Debugging tips

Common Issues

Lack of MESA: fatal error: GL/osmesa.h: No such file or directory

Error Message:

/lib/python3.8/site-packages/mujoco_py/gl/osmesashim.c:1:10: fatal
error: GL/osmesa.h: No such file or directory
1 | #include <GL/osmesa.h>

Solution:

Lack of libGL.so

Error messsage:

cannot find -lGL: No such file or directory

Solution:

Cython issue: Cannot assign type 'void (const char ) except * nogil' to 'void ()(const char *) noexcept nogil'.

Error message:


Error compiling Cython file:
------------------------------------------------------------
...
    See c_warning_callback, which is the C wrapper to the user defined function
    '''
    global py_warning_callback
    global mju_user_warning
    py_warning_callback = warn
    mju_user_warning = c_warning_callback
                       ^
------------------------------------------------------------

/workspace/miniconda3/envs/diffuser/lib/python3.8/site-packages/mujoco_py/cymj.pyx:92:23: Cannot assign type 'void (const char *) except * nogil' to 'void (*)(const char *) noexcept nogil'. Exception values are incompatible. Suggest adding 'noexcept' to the type of 'c_warning_callback'.

Error compiling Cython file:
------------------------------------------------------------
...
    See c_warning_callback, which is the C wrapper to the user defined function
    '''
    global py_error_callback
    global mju_user_error
    py_error_callback = err_callback
    mju_user_error = c_error_callback
                     ^
-----------------------

Solution:

Legacy gym: Unknown distribution option: 'tests_require’

Error message:

Preparing metadata (setup. py) ... error error: subprocess-exited-with-error
x python setup.py egg_info did not run successfully.
exit code: 1
13 lines of outputi
warnings.warn(msg)
[end of output]
/workspace/miniconda3/envs/diffuser/lib/python3.8/site-packages/setuptools/_distutils/dist.py:261: UserWarning: Unknown distribution option: 'tests_require'
error in gym setup command: 'extras_require' must be a dictionary whose values are strings or lists of strings containing valid project/version requirement specifiers.
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
See above for output.

Also,

has invalid metadata: Expected end or semicolon (after version specifier) opencv-python>=3. 
Please use pip<24.1 if you need to use this version

Solution:

Mesa target issue

Error message:

ImportError: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /tmp2/yqkqknct/miniconda3/envs/diffuser/bin/../lib/libOSMesa.so.8)

Solution: