Creative-Chan

MuJoCo와 mujoco-py 설치 본문

Machine Learning/Reinforcement Learning

MuJoCo와 mujoco-py 설치

Creative.Chan 2022. 4. 13. 13:13

목차

    1. MuJoCo란?

    https://mujoco.org/

     

    MuJoCo — Advanced Physics Simulation

    Dear MuJoCo users, We are excited to announce that DeepMind has acquired MuJoCo and is making it freely available to everyone via our Download page. The DeepMind Robotics Simulation team is working hard to prepare the codebase for full open sourcing in 202

    mujoco.org

    MuJoCo(Multi-Joint dynamics with Contact)는 Advanced Physics Simulator, 즉 물리엔진이다.

    물리적인 현상들을 빠르고 자연스럽게 구현할 수 있어 로봇이나 애니메이션, 기계학습 등 다양한 목적으로 사용될 수 있고, 강화학습에 자주 사용되는 시뮬레이터이다.

    Roboti LLC에서 초기에 개발되었던 MuJoCo는 2021년 10월 Deepmind에 인수되어 오픈소스 프로젝트를 표방하며 무료로 풀리게 되었다.

    아래는 Deepmind에서 MuJoCo 사용자들에게 보내는 글이다.

    Dear MuJoCo users, We are excited to announce that DeepMind has acquired MuJoCo and is making it freely available to everyone via our Download page. The DeepMind Robotics Simulation team is working hard to prepare the codebase for full open sourcing in 2022, and we look forward to developing it further together with the community. When we open source MuJoCo, its GitHub repository will become its new home. We encourage everyone to follow the project there, and to submit any questions, bugs, feature requests, etc. using the Issues section of that repository. Until then, mujoco.org will remain the home for MuJoCo.

    이전에는 학생에게 제공되는 1년짜리 라이센스로 사용했었는데 세상이 바뀌어가고 있는 것을 느낀다.

    MuJoCo는 C언어로 되어있어 연구자들이 사용하기에 편리하다.

    그러나 머신러닝 연구자들에게는 Python이 익숙하고 사용하기 때문에 mujoco-py라는 Python Wrapper를 통해 Python으로 사용할 수 있다.

    2022년 4월 13일 기준, MuJoCo 2.1.4가 Release 되었지만, MuJoCo 2.1.0을 기준으로 설치하는 법을 정리하고자 한다.

    설치환경: Ubuntu 18.04

    2. MuJoCo 2.1.0 설치

    (옛날에는 MuJoCo와 mujoco-py의설치가 매우 복잡했던 것으로 기억하는데 단순해졌다.)

    https://github.com/deepmind/mujoco/releases

     

    Releases · deepmind/mujoco

    Multi-Joint dynamics with Contact. A general purpose physics simulator. - deepmind/mujoco

    github.com

    1. 위의 Releases 페이지에 들어가 2.1.0버전(mujoco210-linux-x86_64.tar.gz)을 다운로드 받는다.
    2. 다운로드 받은 파일의 압축을 해제한다.
    tar -zxvf mujoco210-linux-x86_64.tar.gz
    

    3. 압축 해제한 바이너리 폴더를 Home 경로의 .mujoco 숨김 폴더로 옮긴다.

    mkdir ~/.mujoco
    cp -r mujoco210 ~/.mujoco/
    

    4. 시뮬레이션이 실행이 되는지 확인한다.

    cd ~/.mujoco/mujoco210/bin
    ./simulate ../model/humanoid.xml
    

    다음과 같이 시뮬레이션이 실행된다면 성공한 것이다. 설치는 매우 간단하다.

    3. mujoco-py 설치

    https://github.com/openai/mujoco-py

     

    GitHub - openai/mujoco-py: MuJoCo is a physics engine for detailed, efficient rigid body simulations with contacts. mujoco-py al

    MuJoCo is a physics engine for detailed, efficient rigid body simulations with contacts. mujoco-py allows using MuJoCo from Python 3. - GitHub - openai/mujoco-py: MuJoCo is a physics engine for det...

    github.com

    mujoco-py는 open-ai에서 관리하고 있다.

    본인은 Conda 환경 안에서 mujoco-py를 설치할 것이다.

    conda activate <ENV_NAME>
    pip3 install -U 'mujoco-py<2.2,>=2.1'
    

    이 역시 매우 간단하며, Python을 실행하여 다음과 같은 샘플 코드를 실행했을 때 결과를 얻을 수 있다면 성공한 것이다.

    import mujoco_py
    import os
    mj_path = mujoco_py.utils.discover_mujoco()
    xml_path = os.path.join(mj_path, 'model', 'humanoid.xml')
    model = mujoco_py.load_model_from_path(xml_path)
    sim = mujoco_py.MjSim(model)
    
    print(sim.data.qpos)
    # [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
    
    sim.step()
    print(sim.data.qpos)
    # [-2.09531783e-19  2.72130735e-05  6.14480786e-22 -3.45474715e-06
    #   7.42993721e-06 -1.40711141e-04 -3.04253586e-04 -2.07559344e-04
    #   8.50646247e-05 -3.45474715e-06  7.42993721e-06 -1.40711141e-04
    #  -3.04253586e-04 -2.07559344e-04 -8.50646247e-05  1.11317030e-04
    #  -7.03465386e-05 -2.22862221e-05 -1.11317030e-04  7.03465386e-05
    #  -2.22862221e-05]
    
    Comments