├── .dockerignore
├── .github
└── ISSUE_TEMPLATE
│ └── bug_report.md
├── .gitignore
├── .travis.yml
├── Dockerfile
├── LICENSE.md
├── MANIFEST.in
├── Makefile
├── README.md
├── docs
├── .nojekyll
├── Makefile
├── _static
│ └── .gitkeep
├── _templates
│ └── .gitkeep
├── build
│ ├── doctrees
│ │ ├── environment.pickle
│ │ ├── index.doctree
│ │ ├── internals.doctree
│ │ └── reference.doctree
│ └── html
│ │ ├── .buildinfo
│ │ ├── _modules
│ │ ├── index.html
│ │ └── mujoco_py
│ │ │ ├── builder.html
│ │ │ └── mjviewer.html
│ │ ├── _sources
│ │ ├── index.rst.txt
│ │ ├── internals.rst.txt
│ │ └── reference.rst.txt
│ │ ├── _static
│ │ ├── ajax-loader.gif
│ │ ├── basic.css
│ │ ├── comment-bright.png
│ │ ├── comment-close.png
│ │ ├── comment.png
│ │ ├── css
│ │ │ ├── badge_only.css
│ │ │ └── theme.css
│ │ ├── doctools.js
│ │ ├── down-pressed.png
│ │ ├── down.png
│ │ ├── file.png
│ │ ├── fonts
│ │ │ ├── Inconsolata-Bold.ttf
│ │ │ ├── Inconsolata-Regular.ttf
│ │ │ ├── Lato-Bold.ttf
│ │ │ ├── Lato-Regular.ttf
│ │ │ ├── RobotoSlab-Bold.ttf
│ │ │ ├── RobotoSlab-Regular.ttf
│ │ │ ├── fontawesome-webfont.eot
│ │ │ ├── fontawesome-webfont.svg
│ │ │ ├── fontawesome-webfont.ttf
│ │ │ └── fontawesome-webfont.woff
│ │ ├── jquery-3.1.0.js
│ │ ├── jquery.js
│ │ ├── js
│ │ │ ├── modernizr.min.js
│ │ │ └── theme.js
│ │ ├── minus.png
│ │ ├── plus.png
│ │ ├── pygments.css
│ │ ├── searchtools.js
│ │ ├── underscore-1.3.1.js
│ │ ├── underscore.js
│ │ ├── up-pressed.png
│ │ ├── up.png
│ │ └── websupport.js
│ │ ├── genindex.html
│ │ ├── index.html
│ │ ├── internals.html
│ │ ├── objects.inv
│ │ ├── reference.html
│ │ ├── search.html
│ │ └── searchindex.js
├── conf.py
├── index.html
├── index.rst
├── internals.rst
└── reference.rst
├── examples
├── body_interaction.py
├── disco_fetch.py
├── internal_functions.py
├── markers_demo.py
├── mjvive.py
├── multigpu_rendering.py
├── render_callback.py
├── serialize_model.py
├── setting_state.py
├── substep_callback.py
└── tosser.py
├── mujoco_py
├── __init__.py
├── builder.py
├── cymj.pyx
├── generated
│ ├── README.md
│ ├── __init__.py
│ ├── const.py
│ └── wrappers.pxi
├── gl
│ ├── __init__.py
│ ├── dummyshim.c
│ ├── egl.h
│ ├── eglext.h
│ ├── eglplatform.h
│ ├── eglshim.c
│ ├── glshim.h
│ ├── khrplatform.h
│ └── osmesashim.c
├── mjbatchrenderer.pyx
├── mjpid.pyx
├── mjrendercontext.pyx
├── mjrenderpool.py
├── mjsim.pyx
├── mjsimstate.pyx
├── mjviewer.py
├── modder.py
├── opengl_context.pyx
├── pxd
│ ├── __init__.py
│ ├── mjdata.pxd
│ ├── mjmodel.pxd
│ ├── mjrender.pxd
│ ├── mjui.pxd
│ ├── mjvisualize.pxd
│ └── mujoco.pxd
├── test_imgs
│ ├── test_glfw_context.png
│ ├── test_materials.premod.png
│ ├── test_materials.props.png
│ ├── test_materials.rand_all.png
│ ├── test_multiple_sims.loop0_0.png
│ ├── test_multiple_sims.loop0_1.png
│ ├── test_multiple_sims.loop1_0.png
│ ├── test_multiple_sims.loop1_1.png
│ ├── test_multiple_sims.loop2_0.png
│ ├── test_multiple_sims.loop2_1.png
│ ├── test_render_pool.mp_test_cameras.0.png
│ ├── test_render_pool.mp_test_cameras.1.png
│ ├── test_render_pool.mp_test_rendering.0.png
│ ├── test_render_pool.mp_test_states.1.png
│ ├── test_render_pool.mp_test_states.2.png
│ ├── test_render_pool.mp_test_states.3.png
│ ├── test_render_pool.mp_test_states.4.png
│ ├── test_render_pool.mp_test_states.5.png
│ ├── test_rendering.camera1.narrow.png
│ ├── test_rendering.camera1.png
│ ├── test_rendering.freecam.depth-darwin.png
│ ├── test_rendering.freecam.depth.png
│ ├── test_rendering.freecam.png
│ ├── test_rendering_markers.camera1.png
│ ├── test_resetting.loop0_0.png
│ ├── test_resetting.loop0_1.png
│ ├── test_resetting.loop1_0.png
│ ├── test_resetting.loop1_1.png
│ ├── test_resetting.loop2_0.png
│ ├── test_resetting.loop2_1.png
│ ├── test_textures.premod.png
│ ├── test_textures.rand_all.png
│ ├── test_textures.rand_specific.png
│ ├── test_textures.rand_texrepeat.png
│ ├── test_textures.rgb.png
│ └── test_textures.variety.png
├── tests
│ ├── __init__.py
│ ├── include.xml
│ ├── test.xml
│ ├── test_composite.py
│ ├── test_cymj.py
│ ├── test_examples.py
│ ├── test_gen_wrappers.py
│ ├── test_modder.py
│ ├── test_opengl_context.py
│ ├── test_pid.py
│ ├── test_render_pool.py
│ ├── test_substep.py
│ ├── test_vfs.py
│ ├── test_viewer.py
│ └── utils.py
├── utils.py
└── version.py
├── pyproject.toml
├── requirements.dev.txt
├── requirements.txt
├── scripts
└── gen_wrappers.py
├── setup.py
├── vendor
├── 10_nvidia.json
├── Xdummy
└── Xdummy-entrypoint
└── xmls
├── claw.xml
├── door.xml
├── fetch
├── base_link_collision.stl
├── bellows_link_collision.stl
├── elbow_flex_link_collision.stl
├── estop_link.stl
├── forearm_roll_link_collision.stl
├── gripper_link.stl
├── head_pan_link_collision.stl
├── head_tilt_link_collision.stl
├── l_wheel_link_collision.stl
├── laser_link.stl
├── main.xml
├── r_wheel_link_collision.stl
├── shoulder_lift_link_collision.stl
├── shoulder_pan_link_collision.stl
├── torso_fixed_link.stl
├── torso_lift_link_collision.stl
├── upperarm_roll_link_collision.stl
├── wrist_flex_link_collision.stl
└── wrist_roll_link_collision.stl
├── juggler.xml
├── key.xml
├── shelf.xml
├── slider.xml
└── tosser.xml
/.dockerignore:
--------------------------------------------------------------------------------
1 | generated_cymj*
2 | _pyxbld*
3 | dist
4 | cache
5 | .idea/*
6 | *~
7 | .*~
8 | *#*#
9 | *.o
10 | *.dat
11 | *.prof
12 | *.lprof
13 | *.local
14 | .realsync
15 | .DS_Store
16 | **/*.egg-info
17 | .cache
18 | *.ckpt
19 | *.log
20 | .ipynb_checkpoints
21 | venv/
22 | .vimrc
23 | *.settings
24 | *.svn
25 | .project
26 | .pydevproject
27 | tags
28 | *sublime-project
29 | *sublime-workspace
30 | # Intermediate outputs
31 | __pycache__
32 | **/__pycache__
33 | *.pb.*
34 | *.pyc
35 | *.swp
36 | *.swo
37 | # generated data
38 | *.rdb
39 | *.db
40 | *.avi
41 | # mujoco outputs
42 | MUJOCO_LOG.TXT
43 | model.txt
44 | .window_data
45 | .idea/*.xml
46 | outputfile
47 | tmp*
48 | cymj.c
49 | **/.git
50 | **/*.so
51 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 |
5 | ---
6 |
7 | **Describe the bug**
8 | A clear and concise description of what the bug is.
9 |
10 | **To Reproduce**
11 | Steps to reproduce the behavior.
12 |
13 | **Expected behavior**
14 | A clear and concise description of what you expected to happen.
15 |
16 | **Error Messages**
17 | Including more/longer error messages gives us more information to work with.
18 |
19 | **Desktop (please complete the following information):**
20 | - OS: [e.g. macOS 10.13.6]
21 | - Python Version [e.g. 3.6.6]
22 | - Mujoco Version [e.g. 1.50]
23 | - mujoco-py version [e.g. 1.50.1.59]
24 |
25 | **Environment**
26 | - output of: `echo $LD_LIBRARY_PATH`
27 | - output of: `echo $HOME`
28 | - output of: `echo $USER`
29 |
30 | **Additional context**
31 | Add any other context about the problem here.
32 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | mujoco-py-**
2 | mjkey.txt
3 | mujoco_py/generated/cymj*
4 | _pyxbld*
5 | dist
6 | cache
7 | .idea/*
8 | *~
9 | .*~
10 | *#*#
11 | *.o
12 | *.dat
13 | *.prof
14 | *.lprof
15 | *.local
16 | .realsync
17 | .DS_Store
18 | **/*.egg-info
19 | .cache
20 | *.ckpt
21 | *.log
22 | .ipynb_checkpoints
23 | venv/
24 | .vimrc
25 | *.settings
26 | *.svn
27 | .project
28 | .pydevproject
29 | tags
30 | *sublime-project
31 | *sublime-workspace
32 | # Intermediate outputs
33 | __pycache__
34 | **/__pycache__
35 | *.pb.*
36 | *.pyc
37 | *.swp
38 | *.swo
39 | # generated data
40 | *.rdb
41 | *.db
42 | *.avi
43 | # mujoco outputs
44 | MUJOCO_LOG.TXT
45 | model.txt
46 | .window_data
47 | .idea/*.xml
48 | outputfile
49 | tmp*
50 | cymj.c
51 | **/.git
52 | .eggs/
53 | *.so
54 | .python-version
55 | /build
56 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: generic
2 |
3 | before_install:
4 | - curl $MUJOCO_FOR_LINUX | tar -xz ./mjkey.txt
5 | - docker build -t image-under-test .
6 |
7 | script:
8 | - docker run --rm image-under-test
9 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | # We need the CUDA base dockerfile to enable GPU rendering
2 | # on hosts with GPUs.
3 | # The image below is a pinned version of nvidia/cuda:9.1-cudnn7-devel-ubuntu16.04 (from Jan 2018)
4 | # If updating the base image, be sure to test on GPU since it has broken in the past.
5 | FROM nvidia/cuda@sha256:4df157f2afde1cb6077a191104ab134ed4b2fd62927f27b69d788e8e79a45fa1
6 |
7 | RUN apt-get update -q \
8 | && DEBIAN_FRONTEND=noninteractive apt-get install -y \
9 | curl \
10 | git \
11 | libgl1-mesa-dev \
12 | libgl1-mesa-glx \
13 | libglew-dev \
14 | libosmesa6-dev \
15 | software-properties-common \
16 | net-tools \
17 | unzip \
18 | vim \
19 | virtualenv \
20 | wget \
21 | xpra \
22 | xserver-xorg-dev \
23 | && apt-get clean \
24 | && rm -rf /var/lib/apt/lists/*
25 |
26 | RUN DEBIAN_FRONTEND=noninteractive add-apt-repository --yes ppa:deadsnakes/ppa && apt-get update
27 | RUN DEBIAN_FRONTEND=noninteractive apt-get install --yes python3.6-dev python3.6 python3-pip
28 | RUN virtualenv --python=python3.6 env
29 |
30 | RUN rm /usr/bin/python
31 | RUN ln -s /env/bin/python3.6 /usr/bin/python
32 | RUN ln -s /env/bin/pip3.6 /usr/bin/pip
33 | RUN ln -s /env/bin/pytest /usr/bin/pytest
34 |
35 | RUN curl -o /usr/local/bin/patchelf https://s3-us-west-2.amazonaws.com/openai-sci-artifacts/manual-builds/patchelf_0.9_amd64.elf \
36 | && chmod +x /usr/local/bin/patchelf
37 |
38 | ENV LANG C.UTF-8
39 |
40 | RUN mkdir -p /root/.mujoco \
41 | && wget https://www.roboti.us/download/mujoco200_linux.zip -O mujoco.zip \
42 | && unzip mujoco.zip -d /root/.mujoco \
43 | && mv /root/.mujoco/mujoco200_linux /root/.mujoco/mujoco200 \
44 | && rm mujoco.zip
45 | COPY ./mjkey.txt /root/.mujoco/
46 | ENV LD_LIBRARY_PATH /root/.mujoco/mujoco200/bin:${LD_LIBRARY_PATH}
47 | ENV LD_LIBRARY_PATH /usr/local/nvidia/lib64:${LD_LIBRARY_PATH}
48 |
49 | COPY vendor/Xdummy /usr/local/bin/Xdummy
50 | RUN chmod +x /usr/local/bin/Xdummy
51 |
52 | # Workaround for https://bugs.launchpad.net/ubuntu/+source/nvidia-graphics-drivers-375/+bug/1674677
53 | COPY ./vendor/10_nvidia.json /usr/share/glvnd/egl_vendor.d/10_nvidia.json
54 |
55 | WORKDIR /mujoco_py
56 | # Copy over just requirements.txt at first. That way, the Docker cache doesn't
57 | # expire until we actually change the requirements.
58 | COPY ./requirements.txt /mujoco_py/
59 | COPY ./requirements.dev.txt /mujoco_py/
60 | RUN pip install --no-cache-dir -r requirements.txt
61 | RUN pip install --no-cache-dir -r requirements.dev.txt
62 |
63 | # Delay moving in the entire code until the very end.
64 | ENTRYPOINT ["/mujoco_py/vendor/Xdummy-entrypoint"]
65 | CMD ["pytest"]
66 | COPY . /mujoco_py
67 | RUN python setup.py install
68 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | # mujoco-py
2 |
3 | The MIT License
4 |
5 | Copyright (c) 2017 OpenAI (http://openai.com)
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in
15 | all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | THE SOFTWARE.
24 |
25 | # Mujoco models
26 | This work is derived from [MuJuCo models](http://www.mujoco.org/forum/index.php?resources/) used under the following license:
27 | ```
28 | This file is part of MuJoCo.
29 | Copyright 2009-2015 Roboti LLC.
30 | Mujoco :: Advanced physics simulation engine
31 | Source : www.roboti.us
32 | Version : 1.31
33 | Released : 23Apr16
34 | Author :: Vikash Kumar
35 | Contacts : kumar@roboti.us
36 | ```
37 |
--------------------------------------------------------------------------------
/MANIFEST.in:
--------------------------------------------------------------------------------
1 | include pyproject.toml
2 | include requirements.txt
3 | include requirements.dev.txt
4 | recursive-include mujoco_py *.h *.py *.pyx *.pxd *.pxi *.xml *.c
5 | include mujoco_py/gl/*.c
6 | include setup.py
7 | include mujoco_py/generated/cymj_*_linuxcpuextensionbuilder.so
8 | include mujoco_py/generated/cymj_*_linuxgpuextensionbuilder.so
9 | include xmls/*
10 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | SHELL := /bin/bash
2 | .PHONY: all clean build test mount_shell shell upload check-env
3 |
4 | MUJOCO_LICENSE_PATH ?= ~/.mujoco/mjkey.txt
5 | VERSION := `cd mujoco_py; python -c "from version import get_version;print(get_version())"; cd ..`
6 | PYTHON_VERSION := "36"
7 | DOCKER_NAME := quay.io/openai/mujoco_py:$(USER)_$(VERSION)
8 | DOCKER := $(shell type -p nvidia-docker || echo docker)
9 | UUID := $(shell uuidgen)
10 |
11 | all: test
12 |
13 | clean:
14 | rm -rf mujoco_py.egg-info
15 | rm -rf */__pycache__
16 | rm -rf */*/__pycache__
17 | rm -rf mujoco_py/generated/_pyxbld*
18 | rm -rf mujoco_py/generated/*.so
19 | rm -rf mujoco_py/generated/*.dll
20 | rm -rf mujoco_py/generated_cymj*
21 | rm -rf mujoco_py/cythonlock_*.pyc
22 | rm -rf mujoco_py/cymj.c
23 | rm -rf mujoco_py/__pycache__
24 | rm -rf dist
25 | rm -rf build
26 |
27 | build: check-license
28 | cp $(MUJOCO_LICENSE_PATH) mjkey.txt
29 | docker build -t $(DOCKER_NAME) . || rm mjkey.txt && rm mjkey.txt
30 |
31 | push:
32 | docker push $(DOCKER_NAME)
33 |
34 | pull:
35 | docker pull $(DOCKER_NAME)
36 |
37 | test: build
38 | # run it interactive mode so we can abort with CTRL+C
39 | $(DOCKER) run --rm -i $(DOCKER_NAME) pytest
40 |
41 | test_gpu: build push
42 | $(eval NODE="$(shell cirrascale-cli reserve -g 1080ti -t 10m)")
43 | $(eval GPUS="$(shell echo $(NODE)| grep -oE '[^:]+f' | cut -c1-1 )")
44 | $(eval NODE="$(shell echo $(NODE)| grep -oE '[^=]+:' | sed 's/://')")
45 | ssh -t -o StrictHostKeyChecking=no $(NODE) 'docker pull $(DOCKER_NAME) && export GPUS=$(GPUS) && nvidia-docker run --rm -e GPUS -i $(DOCKER_NAME) pytest -m "not requires_glfw"'
46 |
47 | shell:
48 | $(DOCKER) run --rm -it $(DOCKER_NAME) /bin/bash
49 |
50 | mount:
51 | $(DOCKER) run -e GPUS -it -v `pwd`:/mujoco_py-dev $(DOCKER_NAME) /bin/bash -c "pip uninstall -y mujoco-py; rm -rf /mujoco_py; (cd /mujoco_py-dev; export PYTHONPATH='/mujoco_py-dev'; /bin/bash)"
52 |
53 | cirra:
54 | $(eval NODE="$(shell cirrascale-cli reserve)")
55 | $(eval GPUS="$(shell echo $(NODE)| grep -oE '[^:]+f' | cut -c1-1 )")
56 | $(eval NODE="$(shell echo $(NODE)| grep -oE '[^=]+:' | sed 's/://')")
57 | tmux new-session "while :; do rsync -e 'ssh -o StrictHostKeyChecking=no' --delete -rzai --out-format='%t %f %b' --chmod=Du+rwx --exclude='*extensionbuilder.so' --exclude='dist' --exclude='cymj.c' --exclude='_pyxbld_*' --exclude='__pycache__' --exclude='*.egg-info' --exclude='.cache' --exclude='.git' --exclude='*.pyc' --exclude='*.swp' --exclude='.idea' . $(NODE):~/mujoco_py/ ; sleep 1; done" \; \
58 | split-window "ssh -t -o StrictHostKeyChecking=no $(NODE) 'mkdir -p ~/mujoco_py && cd ~/mujoco_py && export GPUS=$(GPUS) && /bin/bash'; " \; select-layout 9ce0,204x51,0,0[204x4,0,0,32,204x46,0,5,33]
59 |
60 | # Requires to generate all *.so files. Call make generate_mac_so on mac;
61 | # Call make generate_cpu_so on mac or linux.
62 | #
63 | # Call make generate_gpu_so on linux with nvidia-docker. The easiest way is to get to cirrascale, and call: make cirra.
64 | # Then you have to copy back generated cymj_linuxgpuextensionbuilder.so file.
65 | #
66 | # Gather all *.so files.
67 | upload:
68 | # Commented out for now, binary distributions seem not to work very well
69 | # test -f ./mujoco_py/generated/cymj_$(VERSION)_$(PYTHON_VERSION)_linuxcpuextensionbuilder.so || exit -1
70 | # test -f ./mujoco_py/generated/cymj_$(VERSION)_$(PYTHON_VERSION)_linuxgpuextensionbuilder.so || exit -1
71 | rm -rf dist
72 | python setup.py sdist
73 | twine upload dist/*
74 |
75 | generate_gpu_so:
76 | rm -f ./mujoco_py/generated/cymj_*_linuxgpuextensionbuilder.so
77 | nvidia-docker run -it --name $(UUID) $(DOCKER_NAME) bash -c "make clean;python -c 'import mujoco_py'"
78 | nvidia-docker cp $(UUID):/mujoco_py/mujoco_py/generated/cymj_$(VERSION)_$(PYTHON_VERSION)_linuxgpuextensionbuilder.so mujoco_py/generated/
79 |
80 | generate_cpu_so:
81 | rm -f ./mujoco_py/generated/cymj_*_linuxcpuextensionbuilder.so
82 | docker run -it --name $(UUID) $(DOCKER_NAME) bash -c "make clean;python -c 'import mujoco_py'"
83 | docker cp $(UUID):/mujoco_py/mujoco_py/generated/cymj_$(VERSION)_$(PYTHON_VERSION)_linuxcpuextensionbuilder.so mujoco_py/generated/
84 |
85 |
86 | check-license:
87 | ifeq ("","$(wildcard $(MUJOCO_LICENSE_PATH))")
88 | $(error "License key not found at location $(MUJOCO_LICENSE_PATH). Use MUJOCO_LICENSE_PATH to specify its path")
89 | endif
90 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | **Status:** Maintenance (expect bug fixes and minor updates)
2 |
3 | # mujoco-py [](https://openai.github.io/mujoco-py/build/html/index.html) [](https://travis-ci.org/openai/mujoco-py)
4 |
5 | [MuJoCo](http://mujoco.org/) is a physics engine for detailed, efficient rigid body simulations with contacts.
6 | `mujoco-py` allows using MuJoCo from Python 3.
7 |
8 | This library has been updated to be compatible with MuJoCo version 2.0 released on 10/1/2018.
9 |
10 |
11 | ## Synopsis
12 |
13 | ### Requirements
14 |
15 | The following platforms are currently supported:
16 |
17 | - Linux with Python 3.6+. See [the `Dockerfile`](Dockerfile) for the canonical list of system dependencies.
18 | - OS X with Python 3.6+.
19 |
20 | The following platforms are DEPRECATED and unsupported:
21 |
22 | - Windows support has been DEPRECATED and removed in [2.0.2.0](https://github.com/openai/mujoco-py/releases/tag/v2.0.2.0a1). One known good past version is [1.50.1.68](https://github.com/openai/mujoco-py/blob/9ea9bb000d6b8551b99f9aa440862e0c7f7b4191/README.md#requirements).
23 | - Python 2 has been DEPRECATED and removed in [1.50.1.0](https://github.com/openai/mujoco-py/releases/tag/1.50.1.0). Python 2 users can stay on the [`0.5` branch](https://github.com/openai/mujoco-py/tree/0.5). The latest release there is [`0.5.7`](https://github.com/openai/mujoco-py/releases/tag/0.5.7) which can be installed with `pip install mujoco-py==0.5.7`.
24 |
25 | ### Install MuJoCo
26 |
27 | 1. Obtain a 30-day free trial on the [MuJoCo website](https://www.roboti.us/license.html)
28 | or free license if you are a student.
29 | The license key will arrive in an email with your username and password.
30 | 2. Download the MuJoCo version 2.0 binaries for
31 | [Linux](https://www.roboti.us/download/mujoco200_linux.zip) or
32 | [OSX](https://www.roboti.us/download/mujoco200_macos.zip).
33 | 3. Unzip the downloaded `mujoco200` directory into `~/.mujoco/mujoco200`,
34 | and place your license key (the `mjkey.txt` file from your email)
35 | at `~/.mujoco/mjkey.txt`.
36 |
37 | If you want to specify a nonstandard location for the key and package,
38 | use the env variables `MUJOCO_PY_MJKEY_PATH` and `MUJOCO_PY_MUJOCO_PATH`.
39 |
40 | ### Install and use `mujoco-py`
41 | To include `mujoco-py` in your own package, add it to your requirements like so:
42 | ```
43 | mujoco-py<2.1,>=2.0
44 | ```
45 | To play with `mujoco-py` interactively, follow these steps:
46 | ```
47 | $ pip3 install -U 'mujoco-py<2.1,>=2.0'
48 | $ python3
49 | import mujoco_py
50 | import os
51 | mj_path, _ = mujoco_py.utils.discover_mujoco()
52 | xml_path = os.path.join(mj_path, 'model', 'humanoid.xml')
53 | model = mujoco_py.load_model_from_path(xml_path)
54 | sim = mujoco_py.MjSim(model)
55 |
56 | print(sim.data.qpos)
57 | # [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
58 |
59 | sim.step()
60 | print(sim.data.qpos)
61 | # [-2.09531783e-19 2.72130735e-05 6.14480786e-22 -3.45474715e-06
62 | # 7.42993721e-06 -1.40711141e-04 -3.04253586e-04 -2.07559344e-04
63 | # 8.50646247e-05 -3.45474715e-06 7.42993721e-06 -1.40711141e-04
64 | # -3.04253586e-04 -2.07559344e-04 -8.50646247e-05 1.11317030e-04
65 | # -7.03465386e-05 -2.22862221e-05 -1.11317030e-04 7.03465386e-05
66 | # -2.22862221e-05]
67 | ```
68 |
69 | See the [full documentation](https://openai.github.io/mujoco-py/build/html/index.html) for advanced usage.
70 |
71 | ## Troubleshooting
72 |
73 | ### You're on MacOS and you see `clang: error: unsupported option '-fopenmp'`
74 |
75 | If this happend during installation or just running `python -c "import mujoco_py"` then the issue seems to be related to [this](https://github.com/velocyto-team/velocyto.R/issues/2#issuecomment-341165967) and the TL;DR is that for macOS the default compiler Apple clang LLVM does not support openmp. So you can try to install another clang/llvm installation. For example (requires [brew](https://brew.sh/)):
76 |
77 | ```bash
78 | brew install llvm
79 | brew install boost
80 | brew install hdf5
81 |
82 | # Add this to your .bashrc/.zshrc:
83 | export PATH="/usr/local/opt/llvm/bin:$PATH"
84 |
85 | export CC="/usr/local/opt/llvm/bin/clang"
86 | export CXX="/usr/local/opt/llvm/bin/clang++"
87 | export CXX11="/usr/local/opt/llvm/bin/clang++"
88 | export CXX14="/usr/local/opt/llvm/bin/clang++"
89 | export CXX17="/usr/local/opt/llvm/bin/clang++"
90 | export CXX1X="/usr/local/opt/llvm/bin/clang++"
91 |
92 | export LDFLAGS="-L/usr/local/opt/llvm/lib"
93 | export CPPFLAGS="-I/usr/local/opt/llvm/include"
94 | ```
95 |
96 | **Note:** Don't forget to source your `.bashrc/.zshrc` after editing it and try to install `mujoco-py` again:
97 |
98 | ```bash
99 | # Make sure your python environment is activated
100 | pip install -U 'mujoco-py<2.1,>=2.0'
101 | ```
102 |
103 | ### Missing GLFW
104 |
105 | A common error when installing is:
106 |
107 | raise ImportError("Failed to load GLFW3 shared library.")
108 |
109 | Which happens when the `glfw` python package fails to find a GLFW dynamic library.
110 |
111 | MuJoCo ships with its own copy of this library, which can be used during installation.
112 |
113 | Add the path to the mujoco bin directory to your dynamic loader:
114 |
115 | LD_LIBRARY_PATH=$HOME/.mujoco/mujoco200/bin pip install mujoco-py
116 |
117 | This is particularly useful on Ubuntu 14.04, which does not have a GLFW package.
118 |
119 |
120 | ### Ubuntu installtion troubleshooting
121 |
122 | Because `mujoco_py` has compiled native code that needs to be linked to a supplied MuJoCo binary, it's installation
123 | on linux can be more challenging than pure Python source packages.
124 |
125 | To install mujoco-py on Ubuntu, make sure you have the following libraries installed:
126 |
127 | sudo apt install libosmesa6-dev libgl1-mesa-glx libglfw3
128 |
129 | If you installed above libraries and you still see an error that `-lGL` cannot be found, most likely you need
130 | to create the symbolic link directly:
131 |
132 | sudo ln -s /usr/lib/x86_64-linux-gnu/libGL.so.1 /usr/lib/x86_64-linux-gnu/libGL.so
133 |
134 |
135 | ## Usage Examples
136 |
137 | A number of examples demonstrating some advanced features of `mujoco-py` can be found in [`examples/`](/./examples/). These include:
138 | - [`body_interaction.py`](./examples/body_interaction.py): shows interactions between colliding bodies
139 | - [`disco_fetch.py`](./examples/disco_fetch.py): shows how `TextureModder` can be used to randomize object textures
140 | - [`internal_functions.py`](./examples/internal_functions.py): shows how to call raw mujoco functions like `mjv_room2model`
141 | - [`markers_demo.py`](./examples/markers_demo.py): shows how to add visualization-only geoms to the viewer
142 | - [`serialize_model.py`](./examples/serialize_model.py): shows how to save and restore a model
143 | - [`setting_state.py`](./examples/setting_state.py): shows how to reset the simulation to a given state
144 | - [`tosser.py`](./examples/tosser.py): shows a simple actuated object sorting robot application
145 |
146 | See the [full documentation](https://openai.github.io/mujoco-py/build/html/index.html) for advanced usage.
147 |
148 | ## Development
149 |
150 | To run the provided unit and integrations tests:
151 |
152 | ```
153 | make test
154 | ```
155 |
156 | To test GPU-backed rendering, run:
157 |
158 | ```
159 | make test_gpu
160 | ```
161 |
162 | This is somewhat dependent on internal OpenAI infrastructure at the moment, but it should run if you change the `Makefile` parameters for your own setup.
163 |
164 | ## Changelog
165 |
166 | - 03/08/2018: We removed MjSimPool, because most of benefit one can get with multiple processes having single simulation.
167 |
168 | ## Credits
169 |
170 | `mujoco-py` is maintained by the OpenAI Robotics team. Contributors include:
171 |
172 | - Alex Ray
173 | - Bob McGrew
174 | - Jonas Schneider
175 | - Jonathan Ho
176 | - Peter Welinder
177 | - Wojciech Zaremba
178 | - Jerry Tworek
179 |
--------------------------------------------------------------------------------
/docs/.nojekyll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/.nojekyll
--------------------------------------------------------------------------------
/docs/Makefile:
--------------------------------------------------------------------------------
1 | SPHINXOPTS =
2 | SPHINXBUILD = python -msphinx
3 | SPHINXPROJ = mujoco-py
4 | SOURCEDIR = .
5 | BUILDDIR = build
6 |
7 | .PHONY: all clean
8 |
9 | all:
10 | @$(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
11 |
12 | clean:
13 | @$(SPHINXBUILD) -M clean "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14 |
--------------------------------------------------------------------------------
/docs/_static/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/_static/.gitkeep
--------------------------------------------------------------------------------
/docs/_templates/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/_templates/.gitkeep
--------------------------------------------------------------------------------
/docs/build/doctrees/environment.pickle:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/build/doctrees/environment.pickle
--------------------------------------------------------------------------------
/docs/build/doctrees/index.doctree:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/build/doctrees/index.doctree
--------------------------------------------------------------------------------
/docs/build/doctrees/internals.doctree:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/build/doctrees/internals.doctree
--------------------------------------------------------------------------------
/docs/build/doctrees/reference.doctree:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/build/doctrees/reference.doctree
--------------------------------------------------------------------------------
/docs/build/html/.buildinfo:
--------------------------------------------------------------------------------
1 | # Sphinx build info version 1
2 | # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
3 | config: ed7df2c1f6fc81f1edc97343eaa55651
4 | tags: 645f666f9bcd5a90fca523b33c5a78b7
5 |
--------------------------------------------------------------------------------
/docs/build/html/_modules/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Overview: module code — mujoco-py 1.50.1.0 documentation
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
101 |
102 |
103 |
104 |
105 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 | - Docs »
137 |
138 | - Overview: module code
139 |
140 |
141 | -
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
All modules for which code is available
156 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
220 |
221 |
222 |
223 |
--------------------------------------------------------------------------------
/docs/build/html/_sources/index.rst.txt:
--------------------------------------------------------------------------------
1 | =======================
2 | mujoco-py Documentation
3 | =======================
4 |
5 | .. toctree::
6 | reference
7 | internals
8 |
9 | `MuJoCo `_ is a physics engine for detailed, efficient rigid body simulations with contacts. ``mujoco-py`` allows using MuJoCo from Python 3.
10 |
11 | See the `README `_ for installation instructions and example usage.
12 |
13 | ``mujoco-py`` allows access to MuJoCo on a number of different levels of abstraction:
14 |
15 | - Directly from Cython (low-level): `Raw Cython declarations `_ are provided for using the MuJoCo C structs and functions directly in your own Cython code.
16 |
17 | - Using :ref:`pymjdata` (medium-level): These wrappers are lightweight Cython ``cdef`` classes that expose MuJuCo data to Python space. The data in the MuJoCo structs is exposed as NumPy arrays bound to Mujoco-allocated memory, so there is no copying overhead when accessing or modifying MuJoCo state from Python. For more information on how this works internally, see [this document](./doc/cython_wrappers.md).
18 |
19 | - Using :class:`mujoco_py.MjSim` (high-level): :class:`mujoco_py.MjSim` manages a stateful simulation similar to the `MujocoEnv `_ class found in `Gym `_
20 | .
21 |
--------------------------------------------------------------------------------
/docs/build/html/_sources/internals.rst.txt:
--------------------------------------------------------------------------------
1 | Internals
2 | =========
3 |
4 | .. _genwrapper:
5 |
6 | Autogenerated wrappers
7 | ----------------------
8 |
9 | The Cython struct wrappers are generated by ``scripts/gen_wrappers.py``. To illustrate how the wrappers work, let's consider a toy C structure and the corresponding generated Cython cdef class. Here's a stripped down version of ``mjData`` with a scalar member and a pointer (array) member::
10 |
11 | typedef struct _mjData {
12 | int ne;
13 | mjtNum* qpos; // (nq x 1)
14 | } mjData;
15 |
16 | Here's the corresponding generated Cython wrapper code::
17 |
18 | cdef class PyMjData(object):
19 | cdef mjData* ptr
20 | cdef mjModel* _model
21 | cdef np.ndarray _qpos
22 |
23 | cdef void _set(self, mjData* p, mjModel* model):
24 | self.ptr = p
25 | self._model = model
26 | self._qpos = _wrap_mjtNum_1d(p.qpos, model.nq)
27 |
28 | @property
29 | def ne(self): return self.ptr.ne
30 |
31 | @ne.setter
32 | def ne(self, int x): self.ptr.ne = x
33 |
34 | @property
35 | def qpos(self): return self._qpos
36 |
37 | cdef PyMjData WrapMjData(mjData* p, mjModel* model):
38 | cdef PyMjData o = PyMjData()
39 | o._set(p, model)
40 | return o
41 |
42 | ``PyMjData`` is the wrapper class for exposing the underlying Mujoco structure to Python; it doesn't perform any memory mangement. A user writing Cython code can create this wrapper using ``WrapMjData``. A ``mjModel`` pointer must be passed because the shape of a ``mjData`` member, namely ``qpos``, depends on ``model->nq``.
43 |
44 | Each field of ``mjData`` corresponds to some generated piece of code in ``PyMjData`` that depends on the type of that field. For example, ``ne`` is a scalar integer, so it gets exposed as a pair of getter and setter methods in ``PyMjData``. ``qpos`` is an array represented as a pointer to its first element, so it's wrapped with a NumPy array by ``_wrap_mjtNum_1d`` and is exposed with a getter for that NumPy array.
45 |
46 | The function ``_wrap_mjtNum_1d`` creates a Cython memoryview from the data pointer and converts it to a NumPy array pointing to the same memory::
47 |
48 | cdef inline np.ndarray _wrap_mjtNum_1d(mjtNum* a, int shape0):
49 | if shape0 == 0: return None
50 | cdef mjtNum[:] b = a
51 | return np.asarray(b)
52 |
53 | Similar functions for other types are also generated as required.
54 |
55 | Keep in mind that the only reason to use these autogenerated wrappers is to allow Python users of the Cython code to easily access Mujoco data (for instance the ``MjSim`` Cython class, found in ``cymj/cymj.pyx`). If you're writing Cython code and you don't need the user to access Mujoco data from Python, then there is no reason to use these wrappers.
56 |
--------------------------------------------------------------------------------
/docs/build/html/_static/ajax-loader.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/build/html/_static/ajax-loader.gif
--------------------------------------------------------------------------------
/docs/build/html/_static/comment-bright.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/build/html/_static/comment-bright.png
--------------------------------------------------------------------------------
/docs/build/html/_static/comment-close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/build/html/_static/comment-close.png
--------------------------------------------------------------------------------
/docs/build/html/_static/comment.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/build/html/_static/comment.png
--------------------------------------------------------------------------------
/docs/build/html/_static/css/badge_only.css:
--------------------------------------------------------------------------------
1 | .fa:before{-webkit-font-smoothing:antialiased}.clearfix{*zoom:1}.clearfix:before,.clearfix:after{display:table;content:""}.clearfix:after{clear:both}@font-face{font-family:FontAwesome;font-weight:normal;font-style:normal;src:url("../font/fontawesome_webfont.eot");src:url("../font/fontawesome_webfont.eot?#iefix") format("embedded-opentype"),url("../font/fontawesome_webfont.woff") format("woff"),url("../font/fontawesome_webfont.ttf") format("truetype"),url("../font/fontawesome_webfont.svg#FontAwesome") format("svg")}.fa:before{display:inline-block;font-family:FontAwesome;font-style:normal;font-weight:normal;line-height:1;text-decoration:inherit}a .fa{display:inline-block;text-decoration:inherit}li .fa{display:inline-block}li .fa-large:before,li .fa-large:before{width:1.875em}ul.fas{list-style-type:none;margin-left:2em;text-indent:-0.8em}ul.fas li .fa{width:0.8em}ul.fas li .fa-large:before,ul.fas li .fa-large:before{vertical-align:baseline}.fa-book:before{content:""}.icon-book:before{content:""}.fa-caret-down:before{content:""}.icon-caret-down:before{content:""}.fa-caret-up:before{content:""}.icon-caret-up:before{content:""}.fa-caret-left:before{content:""}.icon-caret-left:before{content:""}.fa-caret-right:before{content:""}.icon-caret-right:before{content:""}.rst-versions{position:fixed;bottom:0;left:0;width:300px;color:#fcfcfc;background:#1f1d1d;border-top:solid 10px #343131;font-family:"Lato","proxima-nova","Helvetica Neue",Arial,sans-serif;z-index:400}.rst-versions a{color:#2980B9;text-decoration:none}.rst-versions .rst-badge-small{display:none}.rst-versions .rst-current-version{padding:12px;background-color:#272525;display:block;text-align:right;font-size:90%;cursor:pointer;color:#27AE60;*zoom:1}.rst-versions .rst-current-version:before,.rst-versions .rst-current-version:after{display:table;content:""}.rst-versions .rst-current-version:after{clear:both}.rst-versions .rst-current-version .fa{color:#fcfcfc}.rst-versions .rst-current-version .fa-book{float:left}.rst-versions .rst-current-version .icon-book{float:left}.rst-versions .rst-current-version.rst-out-of-date{background-color:#E74C3C;color:#fff}.rst-versions .rst-current-version.rst-active-old-version{background-color:#F1C40F;color:#000}.rst-versions.shift-up .rst-other-versions{display:block}.rst-versions .rst-other-versions{font-size:90%;padding:12px;color:gray;display:none}.rst-versions .rst-other-versions hr{display:block;height:1px;border:0;margin:20px 0;padding:0;border-top:solid 1px #413d3d}.rst-versions .rst-other-versions dd{display:inline-block;margin:0}.rst-versions .rst-other-versions dd a{display:inline-block;padding:6px;color:#fcfcfc}.rst-versions.rst-badge{width:auto;bottom:20px;right:20px;left:auto;border:none;max-width:300px}.rst-versions.rst-badge .icon-book{float:none}.rst-versions.rst-badge .fa-book{float:none}.rst-versions.rst-badge.shift-up .rst-current-version{text-align:right}.rst-versions.rst-badge.shift-up .rst-current-version .fa-book{float:left}.rst-versions.rst-badge.shift-up .rst-current-version .icon-book{float:left}.rst-versions.rst-badge .rst-current-version{width:auto;height:30px;line-height:30px;padding:0 6px;display:block;text-align:center}@media screen and (max-width: 768px){.rst-versions{width:85%;display:none}.rst-versions.shift{display:block}}
2 | /*# sourceMappingURL=badge_only.css.map */
3 |
--------------------------------------------------------------------------------
/docs/build/html/_static/down-pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/build/html/_static/down-pressed.png
--------------------------------------------------------------------------------
/docs/build/html/_static/down.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/build/html/_static/down.png
--------------------------------------------------------------------------------
/docs/build/html/_static/file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/build/html/_static/file.png
--------------------------------------------------------------------------------
/docs/build/html/_static/fonts/Inconsolata-Bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/build/html/_static/fonts/Inconsolata-Bold.ttf
--------------------------------------------------------------------------------
/docs/build/html/_static/fonts/Inconsolata-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/build/html/_static/fonts/Inconsolata-Regular.ttf
--------------------------------------------------------------------------------
/docs/build/html/_static/fonts/Lato-Bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/build/html/_static/fonts/Lato-Bold.ttf
--------------------------------------------------------------------------------
/docs/build/html/_static/fonts/Lato-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/build/html/_static/fonts/Lato-Regular.ttf
--------------------------------------------------------------------------------
/docs/build/html/_static/fonts/RobotoSlab-Bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/build/html/_static/fonts/RobotoSlab-Bold.ttf
--------------------------------------------------------------------------------
/docs/build/html/_static/fonts/RobotoSlab-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/build/html/_static/fonts/RobotoSlab-Regular.ttf
--------------------------------------------------------------------------------
/docs/build/html/_static/fonts/fontawesome-webfont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/build/html/_static/fonts/fontawesome-webfont.eot
--------------------------------------------------------------------------------
/docs/build/html/_static/fonts/fontawesome-webfont.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/build/html/_static/fonts/fontawesome-webfont.ttf
--------------------------------------------------------------------------------
/docs/build/html/_static/fonts/fontawesome-webfont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/build/html/_static/fonts/fontawesome-webfont.woff
--------------------------------------------------------------------------------
/docs/build/html/_static/js/theme.js:
--------------------------------------------------------------------------------
1 | require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o");
80 |
81 | // Add expand links to all parents of nested ul
82 | $('.wy-menu-vertical ul').not('.simple').siblings('a').each(function () {
83 | var link = $(this);
84 | expand = $('');
85 | expand.on('click', function (ev) {
86 | self.toggleCurrent(link);
87 | ev.stopPropagation();
88 | return false;
89 | });
90 | link.prepend(expand);
91 | });
92 | };
93 |
94 | nav.reset = function () {
95 | // Get anchor from URL and open up nested nav
96 | var anchor = encodeURI(window.location.hash);
97 | if (anchor) {
98 | try {
99 | var link = $('.wy-menu-vertical')
100 | .find('[href="' + anchor + '"]');
101 | // If we didn't find a link, it may be because we clicked on
102 | // something that is not in the sidebar (eg: when using
103 | // sphinxcontrib.httpdomain it generates headerlinks but those
104 | // aren't picked up and placed in the toctree). So let's find
105 | // the closest header in the document and try with that one.
106 | if (link.length === 0) {
107 | var doc_link = $('.document a[href="' + anchor + '"]');
108 | var closest_section = doc_link.closest('div.section');
109 | // Try again with the closest section entry.
110 | link = $('.wy-menu-vertical')
111 | .find('[href="#' + closest_section.attr("id") + '"]');
112 |
113 | }
114 | $('.wy-menu-vertical li.toctree-l1 li.current')
115 | .removeClass('current');
116 | link.closest('li.toctree-l2').addClass('current');
117 | link.closest('li.toctree-l3').addClass('current');
118 | link.closest('li.toctree-l4').addClass('current');
119 | }
120 | catch (err) {
121 | console.log("Error expanding nav for anchor", err);
122 | }
123 | }
124 | };
125 |
126 | nav.onScroll = function () {
127 | this.winScroll = false;
128 | var newWinPosition = this.win.scrollTop(),
129 | winBottom = newWinPosition + this.winHeight,
130 | navPosition = this.navBar.scrollTop(),
131 | newNavPosition = navPosition + (newWinPosition - this.winPosition);
132 | if (newWinPosition < 0 || winBottom > this.docHeight) {
133 | return;
134 | }
135 | this.navBar.scrollTop(newNavPosition);
136 | this.winPosition = newWinPosition;
137 | };
138 |
139 | nav.onResize = function () {
140 | this.winResize = false;
141 | this.winHeight = this.win.height();
142 | this.docHeight = $(document).height();
143 | };
144 |
145 | nav.hashChange = function () {
146 | this.linkScroll = true;
147 | this.win.one('hashchange', function () {
148 | this.linkScroll = false;
149 | });
150 | };
151 |
152 | nav.toggleCurrent = function (elem) {
153 | var parent_li = elem.closest('li');
154 | parent_li.siblings('li.current').removeClass('current');
155 | parent_li.siblings().find('li.current').removeClass('current');
156 | parent_li.find('> ul li.current').removeClass('current');
157 | parent_li.toggleClass('current');
158 | }
159 |
160 | return nav;
161 | };
162 |
163 | module.exports.ThemeNav = ThemeNav();
164 |
165 | if (typeof(window) != 'undefined') {
166 | window.SphinxRtdTheme = { StickyNav: module.exports.ThemeNav };
167 | }
168 |
169 | },{"jquery":"jquery"}]},{},["sphinx-rtd-theme"]);
170 |
--------------------------------------------------------------------------------
/docs/build/html/_static/minus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/build/html/_static/minus.png
--------------------------------------------------------------------------------
/docs/build/html/_static/plus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/build/html/_static/plus.png
--------------------------------------------------------------------------------
/docs/build/html/_static/pygments.css:
--------------------------------------------------------------------------------
1 | .highlight .hll { background-color: #ffffcc }
2 | .highlight { background: #eeffcc; }
3 | .highlight .c { color: #408090; font-style: italic } /* Comment */
4 | .highlight .err { border: 1px solid #FF0000 } /* Error */
5 | .highlight .k { color: #007020; font-weight: bold } /* Keyword */
6 | .highlight .o { color: #666666 } /* Operator */
7 | .highlight .ch { color: #408090; font-style: italic } /* Comment.Hashbang */
8 | .highlight .cm { color: #408090; font-style: italic } /* Comment.Multiline */
9 | .highlight .cp { color: #007020 } /* Comment.Preproc */
10 | .highlight .cpf { color: #408090; font-style: italic } /* Comment.PreprocFile */
11 | .highlight .c1 { color: #408090; font-style: italic } /* Comment.Single */
12 | .highlight .cs { color: #408090; background-color: #fff0f0 } /* Comment.Special */
13 | .highlight .gd { color: #A00000 } /* Generic.Deleted */
14 | .highlight .ge { font-style: italic } /* Generic.Emph */
15 | .highlight .gr { color: #FF0000 } /* Generic.Error */
16 | .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
17 | .highlight .gi { color: #00A000 } /* Generic.Inserted */
18 | .highlight .go { color: #333333 } /* Generic.Output */
19 | .highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */
20 | .highlight .gs { font-weight: bold } /* Generic.Strong */
21 | .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
22 | .highlight .gt { color: #0044DD } /* Generic.Traceback */
23 | .highlight .kc { color: #007020; font-weight: bold } /* Keyword.Constant */
24 | .highlight .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */
25 | .highlight .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */
26 | .highlight .kp { color: #007020 } /* Keyword.Pseudo */
27 | .highlight .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */
28 | .highlight .kt { color: #902000 } /* Keyword.Type */
29 | .highlight .m { color: #208050 } /* Literal.Number */
30 | .highlight .s { color: #4070a0 } /* Literal.String */
31 | .highlight .na { color: #4070a0 } /* Name.Attribute */
32 | .highlight .nb { color: #007020 } /* Name.Builtin */
33 | .highlight .nc { color: #0e84b5; font-weight: bold } /* Name.Class */
34 | .highlight .no { color: #60add5 } /* Name.Constant */
35 | .highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */
36 | .highlight .ni { color: #d55537; font-weight: bold } /* Name.Entity */
37 | .highlight .ne { color: #007020 } /* Name.Exception */
38 | .highlight .nf { color: #06287e } /* Name.Function */
39 | .highlight .nl { color: #002070; font-weight: bold } /* Name.Label */
40 | .highlight .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
41 | .highlight .nt { color: #062873; font-weight: bold } /* Name.Tag */
42 | .highlight .nv { color: #bb60d5 } /* Name.Variable */
43 | .highlight .ow { color: #007020; font-weight: bold } /* Operator.Word */
44 | .highlight .w { color: #bbbbbb } /* Text.Whitespace */
45 | .highlight .mb { color: #208050 } /* Literal.Number.Bin */
46 | .highlight .mf { color: #208050 } /* Literal.Number.Float */
47 | .highlight .mh { color: #208050 } /* Literal.Number.Hex */
48 | .highlight .mi { color: #208050 } /* Literal.Number.Integer */
49 | .highlight .mo { color: #208050 } /* Literal.Number.Oct */
50 | .highlight .sa { color: #4070a0 } /* Literal.String.Affix */
51 | .highlight .sb { color: #4070a0 } /* Literal.String.Backtick */
52 | .highlight .sc { color: #4070a0 } /* Literal.String.Char */
53 | .highlight .dl { color: #4070a0 } /* Literal.String.Delimiter */
54 | .highlight .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */
55 | .highlight .s2 { color: #4070a0 } /* Literal.String.Double */
56 | .highlight .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */
57 | .highlight .sh { color: #4070a0 } /* Literal.String.Heredoc */
58 | .highlight .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */
59 | .highlight .sx { color: #c65d09 } /* Literal.String.Other */
60 | .highlight .sr { color: #235388 } /* Literal.String.Regex */
61 | .highlight .s1 { color: #4070a0 } /* Literal.String.Single */
62 | .highlight .ss { color: #517918 } /* Literal.String.Symbol */
63 | .highlight .bp { color: #007020 } /* Name.Builtin.Pseudo */
64 | .highlight .fm { color: #06287e } /* Name.Function.Magic */
65 | .highlight .vc { color: #bb60d5 } /* Name.Variable.Class */
66 | .highlight .vg { color: #bb60d5 } /* Name.Variable.Global */
67 | .highlight .vi { color: #bb60d5 } /* Name.Variable.Instance */
68 | .highlight .vm { color: #bb60d5 } /* Name.Variable.Magic */
69 | .highlight .il { color: #208050 } /* Literal.Number.Integer.Long */
--------------------------------------------------------------------------------
/docs/build/html/_static/up-pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/build/html/_static/up-pressed.png
--------------------------------------------------------------------------------
/docs/build/html/_static/up.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/build/html/_static/up.png
--------------------------------------------------------------------------------
/docs/build/html/objects.inv:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StanfordVL/mujoco-py/5017c4b78fe7c707627a6792c63651ca66669c3e/docs/build/html/objects.inv
--------------------------------------------------------------------------------
/docs/build/html/search.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Search — mujoco-py 1.50.1.0 documentation
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
101 |
102 |
103 |
104 |
105 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 | - Docs »
137 |
138 | - Search
139 |
140 |
141 | -
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
227 |
228 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
--------------------------------------------------------------------------------
/docs/conf.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | # -*- coding: utf-8 -*-
3 | #
4 | # mujoco-py documentation build configuration file, created by
5 | # sphinx-quickstart on Tue Jun 27 15:21:11 2017.
6 | #
7 | # This file is execfile()d with the current directory set to its
8 | # containing dir.
9 | #
10 | # Note that not all possible configuration values are present in this
11 | # autogenerated file.
12 | #
13 | # All configuration values have a default; values that are commented out
14 | # serve to show the default.
15 |
16 | # If extensions (or modules to document with autodoc) are in another directory,
17 | # add these directories to sys.path here. If the directory is relative to the
18 | # documentation root, use os.path.abspath to make it absolute, like shown here.
19 | #
20 | # import os
21 | # import sys
22 | # sys.path.insert(0, os.path.abspath('.'))
23 |
24 |
25 | # -- General configuration ------------------------------------------------
26 |
27 | # If your documentation needs a minimal Sphinx version, state it here.
28 | #
29 | # needs_sphinx = '1.0'
30 |
31 | # Add any Sphinx extension module names here, as strings. They can be
32 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
33 | # ones.
34 | extensions = ['sphinx.ext.autodoc',
35 | 'sphinx.ext.viewcode',
36 | 'numpydoc']
37 |
38 | # Add any paths that contain templates here, relative to this directory.
39 | templates_path = ['_templates']
40 |
41 | # The suffix(es) of source filenames.
42 | # You can specify multiple suffix as a list of string:
43 | #
44 | # source_suffix = ['.rst', '.md']
45 | source_suffix = '.rst'
46 |
47 | # The master toctree document.
48 | master_doc = 'index'
49 |
50 | # General information about the project.
51 | project = 'mujoco-py'
52 | copyright = '2017, OpenAI'
53 | author = 'OpenAI'
54 |
55 | # The version info for the project you're documenting, acts as replacement for
56 | # |version| and |release|, also used in various other places throughout the
57 | # built documents.
58 | #
59 | # The short X.Y version.
60 | import mujoco_py
61 | version = mujoco_py.__version__
62 | # The full version, including alpha/beta/rc tags.
63 | release = mujoco_py.__version__
64 |
65 | # The language for content autogenerated by Sphinx. Refer to documentation
66 | # for a list of supported languages.
67 | #
68 | # This is also used if you do content translation via gettext catalogs.
69 | # Usually you set "language" from the command line for these cases.
70 | language = None
71 |
72 | # List of patterns, relative to source directory, that match files and
73 | # directories to ignore when looking for source files.
74 | # This patterns also effect to html_static_path and html_extra_path
75 | exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
76 |
77 | # The name of the Pygments (syntax highlighting) style to use.
78 | pygments_style = 'sphinx'
79 |
80 | # If true, `todo` and `todoList` produce output, else they produce nothing.
81 | todo_include_todos = False
82 |
83 |
84 | # -- Options for HTML output ----------------------------------------------
85 |
86 | # The theme to use for HTML and HTML Help pages. See the documentation for
87 | # a list of builtin themes.
88 | #
89 | html_theme = "sphinx_rtd_theme"
90 |
91 | # Theme options are theme-specific and customize the look and feel of a theme
92 | # further. For a list of options available for each theme, see the
93 | # documentation.
94 | #
95 | # html_theme_options = {}
96 |
97 | # Add any paths that contain custom static files (such as style sheets) here,
98 | # relative to this directory. They are copied after the builtin static files,
99 | # so a file named "default.css" will overwrite the builtin "default.css".
100 | html_static_path = ['_static']
101 |
102 |
103 | # -- Options for HTMLHelp output ------------------------------------------
104 |
105 | # Output file base name for HTML help builder.
106 | htmlhelp_basename = 'mujoco-pydoc'
107 |
108 |
109 | # -- Options for LaTeX output ---------------------------------------------
110 |
111 | latex_elements = {
112 | # The paper size ('letterpaper' or 'a4paper').
113 | #
114 | # 'papersize': 'letterpaper',
115 |
116 | # The font size ('10pt', '11pt' or '12pt').
117 | #
118 | # 'pointsize': '10pt',
119 |
120 | # Additional stuff for the LaTeX preamble.
121 | #
122 | # 'preamble': '',
123 |
124 | # Latex figure (float) alignment
125 | #
126 | # 'figure_align': 'htbp',
127 | }
128 |
129 | # Grouping the document tree into LaTeX files. List of tuples
130 | # (source start file, target name, title,
131 | # author, documentclass [howto, manual, or own class]).
132 | latex_documents = [
133 | (master_doc, 'mujoco-py.tex', 'mujoco-py Documentation',
134 | 'OpenAI', 'manual'),
135 | ]
136 |
137 |
138 | # -- Options for manual page output ---------------------------------------
139 |
140 | # One entry per manual page. List of tuples
141 | # (source start file, name, description, authors, manual section).
142 | man_pages = [
143 | (master_doc, 'mujoco-py', 'mujoco-py Documentation',
144 | [author], 1)
145 | ]
146 |
147 |
148 | # -- Options for Texinfo output -------------------------------------------
149 |
150 | # Grouping the document tree into Texinfo files. List of tuples
151 | # (source start file, target name, title, author,
152 | # dir menu entry, description, category)
153 | texinfo_documents = [
154 | (master_doc, 'mujoco-py', 'mujoco-py Documentation',
155 | author, 'mujoco-py', 'One line description of project.',
156 | 'Miscellaneous'),
157 | ]
158 |
--------------------------------------------------------------------------------
/docs/index.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/docs/index.rst:
--------------------------------------------------------------------------------
1 | =======================
2 | mujoco-py Documentation
3 | =======================
4 |
5 | .. toctree::
6 | reference
7 | internals
8 |
9 | `MuJoCo `_ is a physics engine for detailed, efficient rigid body simulations with contacts. ``mujoco-py`` allows using MuJoCo from Python 3.
10 |
11 | See the `README `_ for installation instructions and example usage.
12 |
13 | ``mujoco-py`` allows access to MuJoCo on a number of different levels of abstraction:
14 |
15 | - Directly from Cython (low-level): `Raw Cython declarations `_ are provided for using the MuJoCo C structs and functions directly in your own Cython code.
16 |
17 | - Using :ref:`pymjdata` (medium-level): These wrappers are lightweight Cython ``cdef`` classes that expose MuJuCo data to Python space. The data in the MuJoCo structs is exposed as NumPy arrays bound to Mujoco-allocated memory, so there is no copying overhead when accessing or modifying MuJoCo state from Python. For more information on how this works internally, see [this document](./doc/cython_wrappers.md).
18 |
19 | - Using :class:`mujoco_py.MjSim` (high-level): :class:`mujoco_py.MjSim` manages a stateful simulation similar to the `MujocoEnv `_ class found in `Gym `_
20 | .
21 |
--------------------------------------------------------------------------------
/docs/internals.rst:
--------------------------------------------------------------------------------
1 | Internals
2 | =========
3 |
4 | .. _genwrapper:
5 |
6 | Autogenerated wrappers
7 | ----------------------
8 |
9 | The Cython struct wrappers are generated by ``scripts/gen_wrappers.py``. To illustrate how the wrappers work, let's consider a toy C structure and the corresponding generated Cython cdef class. Here's a stripped down version of ``mjData`` with a scalar member and a pointer (array) member::
10 |
11 | typedef struct _mjData {
12 | int ne;
13 | mjtNum* qpos; // (nq x 1)
14 | } mjData;
15 |
16 | Here's the corresponding generated Cython wrapper code::
17 |
18 | cdef class PyMjData(object):
19 | cdef mjData* ptr
20 | cdef mjModel* _model
21 | cdef np.ndarray _qpos
22 |
23 | cdef void _set(self, mjData* p, mjModel* model):
24 | self.ptr = p
25 | self._model = model
26 | self._qpos = _wrap_mjtNum_1d(p.qpos, model.nq)
27 |
28 | @property
29 | def ne(self): return self.ptr.ne
30 |
31 | @ne.setter
32 | def ne(self, int x): self.ptr.ne = x
33 |
34 | @property
35 | def qpos(self): return self._qpos
36 |
37 | cdef PyMjData WrapMjData(mjData* p, mjModel* model):
38 | cdef PyMjData o = PyMjData()
39 | o._set(p, model)
40 | return o
41 |
42 | ``PyMjData`` is the wrapper class for exposing the underlying Mujoco structure to Python; it doesn't perform any memory mangement. A user writing Cython code can create this wrapper using ``WrapMjData``. A ``mjModel`` pointer must be passed because the shape of a ``mjData`` member, namely ``qpos``, depends on ``model->nq``.
43 |
44 | Each field of ``mjData`` corresponds to some generated piece of code in ``PyMjData`` that depends on the type of that field. For example, ``ne`` is a scalar integer, so it gets exposed as a pair of getter and setter methods in ``PyMjData``. ``qpos`` is an array represented as a pointer to its first element, so it's wrapped with a NumPy array by ``_wrap_mjtNum_1d`` and is exposed with a getter for that NumPy array.
45 |
46 | The function ``_wrap_mjtNum_1d`` creates a Cython memoryview from the data pointer and converts it to a NumPy array pointing to the same memory::
47 |
48 | cdef inline np.ndarray _wrap_mjtNum_1d(mjtNum* a, int shape0):
49 | if shape0 == 0: return None
50 | cdef mjtNum[:] b = a
51 | return np.asarray(b)
52 |
53 | Similar functions for other types are also generated as required.
54 |
55 | Keep in mind that the only reason to use these autogenerated wrappers is to allow Python users of the Cython code to easily access Mujoco data (for instance the ``MjSim`` Cython class, found in ``cymj/cymj.pyx`). If you're writing Cython code and you don't need the user to access Mujoco data from Python, then there is no reason to use these wrappers.
56 |
--------------------------------------------------------------------------------
/examples/body_interaction.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | """
3 | Example of how bodies interact with each other. For a body to be able to
4 | move it needs to have joints. In this example, the "robot" is a red ball
5 | with X and Y slide joints (and a Z slide joint that isn't controlled).
6 | On the floor, there's a cylinder with X and Y slide joints, so it can
7 | be pushed around with the robot. There's also a box without joints. Since
8 | the box doesn't have joints, it's fixed and can't be pushed around.
9 | """
10 | from mujoco_py import load_model_from_xml, MjSim, MjViewer
11 | import math
12 | import os
13 |
14 | MODEL_XML = """
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | """
48 |
49 | model = load_model_from_xml(MODEL_XML)
50 | sim = MjSim(model)
51 | viewer = MjViewer(sim)
52 | t = 0
53 | while True:
54 | sim.data.ctrl[0] = math.cos(t / 10.) * 0.01
55 | sim.data.ctrl[1] = math.sin(t / 10.) * 0.01
56 | t += 1
57 | sim.step()
58 | viewer.render()
59 | if t > 100 and os.getenv('TESTING') is not None:
60 | break
61 |
--------------------------------------------------------------------------------
/examples/disco_fetch.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | """
3 | Displays robot fetch at a disco party.
4 | """
5 | from mujoco_py import load_model_from_path, MjSim, MjViewer
6 | from mujoco_py.modder import TextureModder
7 | import os
8 |
9 | model = load_model_from_path("xmls/fetch/main.xml")
10 | sim = MjSim(model)
11 |
12 | viewer = MjViewer(sim)
13 | modder = TextureModder(sim)
14 |
15 | t = 0
16 |
17 | while True:
18 | for name in sim.model.geom_names:
19 | modder.rand_all(name)
20 |
21 | viewer.render()
22 | t += 1
23 | if t > 100 and os.getenv('TESTING') is not None:
24 | break
25 |
--------------------------------------------------------------------------------
/examples/internal_functions.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | """
3 | Shows how to access internal functions from MuJoCo.
4 | """
5 | from mujoco_py import load_model_from_xml, MjSim, functions
6 | import numpy as np
7 |
8 | MODEL_XML = """
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | """
20 |
21 | model = load_model_from_xml(MODEL_XML)
22 | sim = MjSim(model)
23 |
24 | print("Nicely exposed function:\n")
25 | print(sim.model.get_xml())
26 |
27 | print("\nversus MuJoCo internals:\n\n")
28 |
29 | functions.mj_saveLastXML("/tmp/saved.xml", model, "", 0)
30 | with open("/tmp/saved.xml", "r") as f:
31 | print(f.read())
32 |
33 | sim.render(100, 100)
34 |
35 | modelpos = np.zeros(3)
36 | modelquat = np.zeros(4)
37 | roompos = np.ones(3)
38 | roomquat = np.array([1., 0., 1., 0.])
39 |
40 | functions.mjv_room2model(modelpos, modelquat, roompos,
41 | roomquat, sim.render_contexts[0].scn)
42 |
43 | print("\n\nAnother internal function, mjv_room2model:")
44 | print("modelpos = %s, modelquat = %s" % (str(modelpos), str(modelquat)))
45 |
46 |
47 | res = np.zeros(9)
48 | functions.mju_quat2Mat(res, roomquat)
49 | print("\n\nAnother internal function, mju_quat2Mat:\n%s" % res)
50 |
--------------------------------------------------------------------------------
/examples/markers_demo.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # demonstration of markers (visual-only geoms)
3 |
4 | import math
5 | import time
6 | import os
7 | import numpy as np
8 | from mujoco_py import load_model_from_xml, MjSim, MjViewer
9 |
10 | MODEL_XML = """
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | """
25 |
26 | model = load_model_from_xml(MODEL_XML)
27 | sim = MjSim(model)
28 | viewer = MjViewer(sim)
29 | step = 0
30 | while True:
31 | t = time.time()
32 | x, y = math.cos(t), math.sin(t)
33 | viewer.add_marker(pos=np.array([x, y, 1]),
34 | label=str(t))
35 | viewer.render()
36 |
37 | step += 1
38 | if step > 100 and os.getenv('TESTING') is not None:
39 | break
40 |
--------------------------------------------------------------------------------
/examples/mjvive.py:
--------------------------------------------------------------------------------
1 | '''
2 | EXPERIMENTAL: Displays MuJoCo model in VR.
3 |
4 | Based on http://www.mujoco.org/book/source/mjvive.cpp
5 | No controller integration currently
6 |
7 | This example is a demonstration of a near-direct translation of an existing
8 | MuJoCo example (mjvive.cpp), showing how to use lower-level functionality
9 | in conjunction with Python.
10 |
11 | Known occasional issues with SteamVR (all-black textures seen),
12 | fixed by closing and re-opening.
13 |
14 | Requires HTC Vive, Windows, and OpenVR.
15 |
16 | Install openvr python module with:
17 | pip install openvr
18 | '''
19 |
20 |
21 | import math
22 | import os
23 | import glfw
24 | import openvr
25 | import numpy as np
26 | import OpenGL.GL as gl
27 | from mujoco_py import functions
28 | from mujoco_py.builder import mujoco_path
29 | from mujoco_py.cymj import (MjRenderContext, MjSim, load_model_from_xml,
30 | PyMjrRect, PyMjvCamera)
31 | from mujoco_py.generated.const import (CAT_ALL, FB_OFFSCREEN, FONT_BIG,
32 | GRID_BOTTOMLEFT, STEREO_SIDEBYSIDE)
33 |
34 |
35 | # Normally global variables aren't used like this in python,
36 | # but we want to be as close as possible to the original file.
37 | class HMD(): # anonymous object we can set fields on
38 | pass
39 |
40 |
41 | window = None
42 | sim = None
43 | ctx = None
44 | hmd = HMD()
45 |
46 |
47 | def initMuJoCo(filename, width2, height):
48 | ''' load model, init simulation and rendering '''
49 | global window, sim, ctx
50 | assert glfw.init(), 'Could not initialize GLFW'
51 | glfw.window_hint(glfw.SAMPLES, 0)
52 | glfw.window_hint(glfw.DOUBLEBUFFER, True)
53 | glfw.window_hint(glfw.RESIZABLE, 0)
54 | window = glfw.create_window(width2 // 4, height // 2, "mjvive.py", None, None)
55 | assert window, "Could not create GLFW window"
56 | glfw.make_context_current(window)
57 | glfw.swap_interval(0)
58 | # GLEW init required in C++, not in Python
59 | sim = MjSim(load_model_from_xml(open(filename).read()))
60 | sim.forward()
61 | sim.model.vis.global_.offwidth = width2
62 | sim.model.vis.global_.offheight = height
63 | sim.model.vis.quality.offsamples = 8
64 | ctx = MjRenderContext(sim)
65 | ctx.scn.enabletransform = 1
66 | ctx.scn.translate[1:3] = -0.5
67 | ctx.scn.rotate[0:2] = math.cos(-0.25 * math.pi), math.sin(-0.25 * math.pi)
68 | ctx.scn.scale = 1
69 | ctx.scn.stereo = STEREO_SIDEBYSIDE
70 |
71 |
72 | def v_initPre():
73 | ''' init vr before MuJoCo init '''
74 | global hmd
75 | hmd.system = openvr.init(openvr.VRApplication_Scene)
76 | hmd.roompos = np.zeros(3)
77 | hmd.roommat = np.eye(3)
78 | hmd.eyeoffset = np.zeros((2, 3))
79 | openvr.VRCompositor().setTrackingSpace(openvr.TrackingUniverseStanding)
80 | hmd.width, hmd.height = hmd.system.getRecommendedRenderTargetSize()
81 | for n in range(2):
82 | hmd.eyeoffset[n] = np.array(hmd.system.getEyeToHeadTransform(n).m)[0:3, 3]
83 |
84 |
85 | def v_initPost():
86 | ''' init vr after MuJoCo init '''
87 | global hmd
88 | for n in range(2):
89 | znear, zfar = 0.05, 50.0
90 | left, right, top, bottom = hmd.system.getProjectionRaw(n)
91 | ctx.scn.camera[n].frustum_bottom = -bottom * znear
92 | ctx.scn.camera[n].frustum_top = -top * znear
93 | ctx.scn.camera[n].frustum_center = 0.5 * (left + right) * znear
94 | ctx.scn.camera[n].frustum_near = znear
95 | ctx.scn.camera[n].frustum_far = zfar
96 | gl.glActiveTexture(gl.GL_TEXTURE2)
97 | hmd.idtex = gl.glGenTextures(1)
98 | gl.glBindTexture(gl.GL_TEXTURE_2D, hmd.idtex)
99 | gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
100 | gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST)
101 | gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE)
102 | gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE)
103 | gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA8, 2 * hmd.width, hmd.height, 0, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, None)
104 | hmd.poses = (openvr.TrackedDevicePose_t * openvr.k_unMaxTrackedDeviceCount)()
105 | hmd.boundLeft = openvr.VRTextureBounds_t(0., 0., 0.5, 1.)
106 | hmd.boundRight = openvr.VRTextureBounds_t(0.5, 0., 1., 1.)
107 | hmd.vTex = openvr.Texture_t(hmd.idtex, openvr.TextureType_OpenGL, openvr.ColorSpace_Gamma)
108 |
109 |
110 | def v_update():
111 | ''' update vr poses and controller states '''
112 | global ctx, hmd
113 | openvr.VRCompositor().waitGetPoses(hmd.poses, openvr.k_unMaxTrackedDeviceCount, None, 0)
114 | m = np.array(hmd.poses[openvr.k_unTrackedDeviceIndex_Hmd].mDeviceToAbsoluteTracking.m)
115 | hmd.roompos, hmd.roommat = m[0:3, 3], m[0:3, 0:3]
116 | for n in range(2):
117 | ctx.scn.camera[n].pos[:] = hmd.roompos + np.matmul(hmd.roommat, hmd.eyeoffset[n])
118 | ctx.scn.camera[n].forward[0:3] = -hmd.roommat[:, 2]
119 | ctx.scn.camera[n].up[0:3] = hmd.roommat[:, 1]
120 |
121 |
122 | def v_render():
123 | ''' render to vr and window '''
124 | global hmd, ctx, window
125 | # resolve multi-sample offscreen buffer
126 | gl.glBindFramebuffer(gl.GL_READ_FRAMEBUFFER, ctx.con.offFBO)
127 | gl.glReadBuffer(gl.GL_COLOR_ATTACHMENT0)
128 | gl.glBindFramebuffer(gl.GL_DRAW_FRAMEBUFFER, ctx.con.offFBO_r)
129 | gl.glDrawBuffer(gl.GL_COLOR_ATTACHMENT0)
130 | gl.glBlitFramebuffer(0, 0, 2 * hmd.width, hmd.height,
131 | 0, 0, 2 * hmd.width, hmd.height,
132 | gl.GL_COLOR_BUFFER_BIT, gl.GL_NEAREST)
133 | # blit to window, left only, window is half-size
134 | gl.glBindFramebuffer(gl.GL_READ_FRAMEBUFFER, ctx.con.offFBO_r)
135 | gl.glReadBuffer(gl.GL_COLOR_ATTACHMENT0)
136 | gl.glBindFramebuffer(gl.GL_DRAW_FRAMEBUFFER, 0)
137 | gl.glDrawBuffer(gl.GL_BACK if ctx.con.windowDoublebuffer else gl.GL_FRONT)
138 | gl.glBlitFramebuffer(0, 0, hmd.width, hmd.height,
139 | 0, 0, hmd.width // 2, hmd.height // 2,
140 | gl.GL_COLOR_BUFFER_BIT, gl.GL_NEAREST)
141 | # blit to vr texture
142 | gl.glActiveTexture(gl.GL_TEXTURE2)
143 | gl.glBindFramebuffer(gl.GL_DRAW_FRAMEBUFFER, ctx.con.offFBO_r)
144 | gl.glFramebufferTexture2D(gl.GL_FRAMEBUFFER, gl.GL_COLOR_ATTACHMENT1, gl.GL_TEXTURE_2D, hmd.idtex, 0)
145 | gl.glDrawBuffer(gl.GL_COLOR_ATTACHMENT1)
146 | gl.glBlitFramebuffer(0, 0, 2 * hmd.width, hmd.height,
147 | 0, 0, 2 * hmd.width, hmd.height,
148 | gl.GL_COLOR_BUFFER_BIT, gl.GL_NEAREST)
149 | gl.glFramebufferTexture2D(gl.GL_FRAMEBUFFER, gl.GL_COLOR_ATTACHMENT1, gl.GL_TEXTURE_2D, 0, 0)
150 | gl.glDrawBuffer(gl.GL_COLOR_ATTACHMENT0)
151 | openvr.VRCompositor().submit(openvr.Eye_Left, hmd.vTex, hmd.boundLeft)
152 | openvr.VRCompositor().submit(openvr.Eye_Right, hmd.vTex, hmd.boundRight)
153 | # swap if window is double-buffered, flush just in case
154 | if ctx.con.windowDoublebuffer:
155 | glfw.swap_buffers(window)
156 | gl.glFlush()
157 |
158 |
159 | if __name__ == '__main__':
160 | filename = os.path.join(mujoco_path, 'model', 'humanoid.xml')
161 | v_initPre()
162 | initMuJoCo(filename, hmd.width * 2, hmd.height)
163 | v_initPost()
164 |
165 | FPS = 90.0
166 | lasttm = glfw.get_time()
167 | frametime = sim.data.time
168 | viewFull = PyMjrRect()
169 | viewFull.width, viewFull.height = 2 * hmd.width, hmd.height
170 | nullCam = PyMjvCamera()
171 |
172 | while not glfw.window_should_close(window):
173 | if sim.data.time - frametime > 1 / FPS or sim.data.time < frametime:
174 | functions.mjv_updateScene(sim.model, sim.data, ctx.vopt, ctx.pert, nullCam, CAT_ALL, ctx.scn)
175 | v_update()
176 | functions.mjr_setBuffer(FB_OFFSCREEN, ctx.con)
177 | functions.mjr_render(viewFull, ctx.scn, ctx.con)
178 | FPS = .9 * FPS + .1 / (glfw.get_time() - lasttm)
179 | lasttm = glfw.get_time()
180 | functions.mjr_overlay(FONT_BIG, GRID_BOTTOMLEFT, viewFull, 'FPS %.1f' % FPS, '', ctx.con)
181 | v_render()
182 | frametime = sim.data.time
183 | sim.step()
184 | glfw.poll_events()
185 | # close
186 | openvr.shutdown()
187 | gl.glDeleteTextures(1, hmd.idtex)
188 | del sim
189 | del ctx
190 | glfw.terminate()
191 |
--------------------------------------------------------------------------------
/examples/multigpu_rendering.py:
--------------------------------------------------------------------------------
1 | """
2 | This is an example for rendering on multiple GPUs in parallel,
3 | using the multiprocessing module.
4 | """
5 | from multiprocessing import set_start_method
6 | from time import perf_counter
7 |
8 | from mujoco_py import load_model_from_path, MjRenderPool
9 |
10 |
11 | def main():
12 | # Image size for rendering
13 | IMAGE_WIDTH = 255
14 | IMAGE_HEIGHT = 255
15 | # Number of frames to render per sim
16 | N_FRAMES = 100
17 | # Number of sims to run in parallel (assumes one per GPU),
18 | # so N_SIMS=2 assumes there are 2 GPUs available.
19 | N_SIMS = 2
20 |
21 | pool = MjRenderPool(load_model_from_path("xmls/tosser.xml"), device_ids=N_SIMS)
22 |
23 | print("main(): start benchmarking", flush=True)
24 | start_t = perf_counter()
25 |
26 | for _ in range(N_FRAMES):
27 | pool.render(IMAGE_WIDTH, IMAGE_HEIGHT)
28 |
29 | t = perf_counter() - start_t
30 | print("Completed in %.1fs: %.3fms, %.1f FPS" % (
31 | t, t / (N_FRAMES * N_SIMS) * 1000, (N_FRAMES * N_SIMS) / t),
32 | flush=True)
33 |
34 | print("main(): finished", flush=True)
35 |
36 |
37 | if __name__ == "__main__":
38 | set_start_method('spawn')
39 | main()
40 |
--------------------------------------------------------------------------------
/examples/render_callback.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | """
3 | Shows how to use render callback.
4 | """
5 | from mujoco_py import load_model_from_path, MjSim, MjViewer
6 | from mujoco_py.modder import TextureModder
7 | import os
8 |
9 | modder = None
10 | def render_callback(sim, viewer):
11 | global modder
12 | if modder is None:
13 | modder = TextureModder(sim)
14 | for name in sim.model.geom_names:
15 | modder.rand_all(name)
16 |
17 | model = load_model_from_path("xmls/fetch/main.xml")
18 | sim = MjSim(model, render_callback=render_callback)
19 |
20 | viewer = MjViewer(sim)
21 |
22 | t = 0
23 |
24 | while True:
25 | viewer.render()
26 | t += 1
27 | if t > 100 and os.getenv('TESTING') is not None:
28 | break
--------------------------------------------------------------------------------
/examples/serialize_model.py:
--------------------------------------------------------------------------------
1 | """
2 | # Serialization/Deserialization of Models
3 |
4 | Sometimes its useful to send a mujoco model over the network, or save it
5 | to a file with all assets embedded.
6 | """
7 | import mujoco_py
8 |
9 | # The binary MJB format is preferable, since it includes assets like
10 | # textures and meshes.
11 | model = mujoco_py.load_model_from_path("xmls/claw.xml")
12 | mjb_bytestring = model.get_mjb()
13 | model_from_binary = mujoco_py.load_model_from_mjb(mjb_bytestring)
14 | assert model.nbody == model_from_binary.nbody
15 |
16 | # XML is preferable to MJB when readability and backward compatibility are
17 | # important.
18 | xml_string = model.get_xml()
19 | model_from_xml = mujoco_py.load_model_from_xml(xml_string)
20 | assert model.nbody == model_from_xml.nbody
21 |
--------------------------------------------------------------------------------
/examples/setting_state.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | """
3 | Example for how to modifying the MuJoCo qpos during execution.
4 | """
5 |
6 | import os
7 | from mujoco_py import load_model_from_xml, MjSim, MjViewer
8 |
9 | MODEL_XML = """
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | """
24 |
25 |
26 | def print_box_xpos(sim):
27 | print("box xpos:", sim.data.get_body_xpos("box"))
28 |
29 |
30 | model = load_model_from_xml(MODEL_XML)
31 | sim = MjSim(model)
32 | viewer = MjViewer(sim)
33 |
34 | states = [{'box:x': +0.8, 'box:y': +0.8},
35 | {'box:x': -0.8, 'box:y': +0.8},
36 | {'box:x': -0.8, 'box:y': -0.8},
37 | {'box:x': +0.8, 'box:y': -0.8},
38 | {'box:x': +0.0, 'box:y': +0.0}]
39 |
40 | # MjModel.joint_name2id returns the index of a joint in
41 | # MjData.qpos.
42 | x_joint_i = sim.model.get_joint_qpos_addr("box:x")
43 | y_joint_i = sim.model.get_joint_qpos_addr("box:y")
44 |
45 | print_box_xpos(sim)
46 |
47 | while True:
48 | for state in states:
49 | sim_state = sim.get_state()
50 | sim_state.qpos[x_joint_i] = state["box:x"]
51 | sim_state.qpos[y_joint_i] = state["box:y"]
52 | sim.set_state(sim_state)
53 | sim.forward()
54 | print("updated state to", state)
55 | print_box_xpos(sim)
56 | viewer.render()
57 |
58 | if os.getenv('TESTING') is not None:
59 | break
60 |
--------------------------------------------------------------------------------
/examples/substep_callback.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | """
3 | Example how substep_callback can be used to detect contacts/penetrations that
4 | are not visible in between steps.
5 |
6 | In this example a sphere pushes a cylinder, which then slides away.
7 | The entirety of the contact and separation happens in substeps.
8 |
9 | In between steps there is always zero contacts, so the push is not observed.
10 |
11 | We use a substep_callback to get a sum of the external forces on the cylinder.
12 | """
13 | from mujoco_py import load_model_from_xml, MjSim
14 |
15 | MODEL_XML = """
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | """
33 |
34 | fn = '''
35 | #define SQUARE(a) (a * a)
36 | void fun(const mjModel* m, mjData* d) {
37 | for (int i = d->ne; i < d->nefc; i++) {
38 | pos_sum += SQUARE(d->efc_pos[i]);
39 | }
40 | }
41 | '''
42 |
43 | sim = MjSim(load_model_from_xml(MODEL_XML), nsubsteps=50,
44 | substep_callback=fn, userdata_names=['pos_sum'])
45 | t = 0
46 | while t < 10:
47 | t += 1
48 | sim.data.ctrl[0] = .2
49 | print('t', t)
50 | sim.step()
51 | # verify that there are no contacts visible between steps
52 | assert sim.data.ncon == 0, 'No contacts should be detected here'
53 | # verify that contacts (and penetrations) are visible to substep_callback
54 | if t > 1:
55 | assert sim.data.get_userdata('pos_sum') > 0 # detected collision
56 |
--------------------------------------------------------------------------------
/examples/tosser.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | """
3 | Shows how to toss a capsule to a container.
4 | """
5 | from mujoco_py import load_model_from_path, MjSim, MjViewer
6 | import os
7 |
8 | model = load_model_from_path("xmls/tosser.xml")
9 | sim = MjSim(model)
10 |
11 | viewer = MjViewer(sim)
12 |
13 |
14 | sim_state = sim.get_state()
15 |
16 | while True:
17 | sim.set_state(sim_state)
18 |
19 | for i in range(1000):
20 | if i < 150:
21 | sim.data.ctrl[:] = 0.0
22 | else:
23 | sim.data.ctrl[:] = -1.0
24 | sim.step()
25 | viewer.render()
26 |
27 | if os.getenv('TESTING') is not None:
28 | break
29 |
--------------------------------------------------------------------------------
/mujoco_py/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | import os
3 | from mujoco_py.builder import cymj, ignore_mujoco_warnings, functions, MujocoException
4 | from mujoco_py.generated import const
5 | from mujoco_py.mjrenderpool import MjRenderPool
6 | from mujoco_py.mjviewer import MjViewer, MjViewerBasic
7 | from mujoco_py.version import __version__, get_version
8 | import mujoco_py
9 |
10 | load_model_from_path = cymj.load_model_from_path
11 | load_model_from_xml = cymj.load_model_from_xml
12 | load_model_from_mjb = cymj.load_model_from_mjb
13 | MjSim = cymj.MjSim
14 | MjSimState = cymj.MjSimState
15 | MjRenderContext = cymj.MjRenderContext
16 | MjRenderContextOffscreen = cymj.MjRenderContextOffscreen
17 | MjRenderContextWindow = cymj.MjRenderContextWindow
18 | MjBatchRenderer = cymj.MjBatchRenderer
19 | GlfwContext = cymj.GlfwContext
20 |
21 |
22 | # Public API:
23 | __all__ = ['MjSim', 'MjSimState',
24 | 'MjRenderContextOffscreen', 'MjRenderContextWindow',
25 | 'MjRenderContext', 'MjViewer', 'MjViewerBasic',
26 | 'MujocoException', 'MjRenderPool', 'MjBatchRenderer', 'GlfwContext',
27 | 'load_model_from_path', 'load_model_from_xml',
28 | 'load_model_from_mjb',
29 | 'ignore_mujoco_warnings', 'const', "functions",
30 | "__version__", "get_version"]
31 |
32 |
33 | # Print out a warning if we can't find the key.
34 | # this is nicer than failing activation, which we can not do in python.
35 | # The mujoco library exits the process forcibly, in a way we can't try/catch.
36 | mujoco_py.builder.find_key()
37 | if not os.environ.get('MUJOCO_PY_SKIP_ACTIVATE'):
38 | mujoco_py.builder.activate()
39 |
--------------------------------------------------------------------------------
/mujoco_py/cymj.pyx:
--------------------------------------------------------------------------------
1 | # cython: language_level=3
2 | import copy
3 | import logging
4 | import os
5 | import platform
6 | import tempfile
7 | import sys
8 | from collections import namedtuple
9 | from libc.stdlib cimport malloc, free
10 | from libc.string cimport strncpy
11 | from numbers import Number
12 | from tempfile import TemporaryDirectory
13 |
14 | import numpy as np
15 | from cython cimport view
16 | from cython.parallel import parallel, prange
17 | from mujoco_py.generated import const
18 |
19 | include "generated/wrappers.pxi"
20 | include "opengl_context.pyx"
21 | include "mjsim.pyx"
22 | include "mjsimstate.pyx"
23 | include "mjrendercontext.pyx"
24 | include "mjbatchrenderer.pyx"
25 | include "mjpid.pyx"
26 |
27 | cdef extern from "gl/glshim.h":
28 |
29 | cdef int usingEGL()
30 | cdef int initOpenGL(int device_id)
31 | cdef void closeOpenGL()
32 | cdef int makeOpenGLContextCurrent(int device_id)
33 | cdef int setOpenGLBufferSize(int device_id, int width, int height)
34 |
35 | cdef unsigned int createPBO(int width, int height, int batchSize, int use_short)
36 | cdef void freePBO(unsigned int pixelBuffer)
37 | cdef void copyFBOToPBO(mjrContext* con,
38 | unsigned int pbo_rgb, unsigned int pbo_depth,
39 | mjrRect viewport, int bufferOffset)
40 | cdef void readPBO(unsigned char *buffer_rgb, unsigned short *buffer_depth,
41 | unsigned int pbo_rgb, unsigned int pbo_depth,
42 | int width, int height, int batchSize)
43 |
44 |
45 |
46 | # TODO: make this function or class so these comments turn into doc strings:
47 |
48 | # Python warning callback function, which is set
49 | # MuJoCo has a user-settable callback function for warnings: mju_user_warning()
50 | # We want to supply a python function, and be able to raise exceptions.
51 | # To do this we have to wrap two things:
52 |
53 | # This is the python callback function. We save it in the global() context
54 | # so we can access it from a C wrapper function (c_warning_callback)
55 | cdef object py_warning_callback
56 | cdef object py_error_callback
57 | # This is the saved exception. Because the C callback can not propagate
58 | # exceptions, this must be set to None before calling into MuJoCo, and then
59 | # inspected afterwards.
60 | # These are combined in a simple class which handles both:
61 | # with wrap_mujoco_warning():
62 | # mj_somefunc()
63 | cdef object py_warning_exception = None
64 | cdef object py_error_exception = None
65 |
66 |
67 | cdef void c_warning_callback(const char *msg) with gil:
68 | '''
69 | Wraps the warning callback so we can raise exceptions.
70 | Because callbacks can't propagate exceptions, we set a global that has
71 | to be inspected later.
72 | Use wrap_mujoco_warning() to check for that saved exception and
73 | re-raise it back to the caller.
74 | '''
75 | global py_warning_callback
76 | try:
77 | (