Skip to content

Commit d980119

Browse files
Mujoco v2.0 (#368)
* Add build directory to the git ignore file. * Updating mujoco-py for mujoco 2.0 * Removing commented out test. * Remove windows support. * Alpha version prerelease.
1 parent 399a22b commit d980119

24 files changed

+1778
-421
lines changed

.appveyor.yml

-38
This file was deleted.

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ cymj.c
5353
*.c
5454
*.so
5555
.python-version
56+
/build

Dockerfile

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ RUN curl -o /usr/local/bin/patchelf https://s3-us-west-2.amazonaws.com/openai-sc
3838
ENV LANG C.UTF-8
3939

4040
RUN mkdir -p /root/.mujoco \
41-
&& wget https://www.roboti.us/download/mjpro150_linux.zip -O mujoco.zip \
41+
&& wget https://www.roboti.us/download/mujoco200_linux.zip -O mujoco.zip \
4242
&& unzip mujoco.zip -d /root/.mujoco \
43+
&& mv /root/.mujoco/mujoco200_linux /root/.mujoco/mujoco200 \
4344
&& rm mujoco.zip
4445
COPY ./mjkey.txt /root/.mujoco/
45-
ENV LD_LIBRARY_PATH /root/.mujoco/mjpro150/bin:${LD_LIBRARY_PATH}
46+
ENV LD_LIBRARY_PATH /root/.mujoco/mujoco200/bin:${LD_LIBRARY_PATH}
4647
ENV LD_LIBRARY_PATH /usr/local/nvidia/lib64:${LD_LIBRARY_PATH}
4748

4849
COPY vendor/Xdummy /usr/local/bin/Xdummy

Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ cirra:
6565
#
6666
# Gather all *.so files.
6767
upload:
68-
test -f ./mujoco_py/generated/cymj_$(VERSION)_$(PYTHON_VERSION)_linuxcpuextensionbuilder.so || exit -1
69-
test -f ./mujoco_py/generated/cymj_$(VERSION)_$(PYTHON_VERSION)_linuxgpuextensionbuilder.so || exit -1
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
7071
rm -rf dist
7172
python setup.py sdist
7273
twine upload dist/*

README.md

+15-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
# mujoco-py [![Documentation](https://img.shields.io/badge/docs-latest-brightgreen.svg?style=flat)](https://openai.github.io/mujoco-py/build/html/index.html) [![Build Status](https://travis-ci.org/openai/mujoco-py.svg?branch=master)](https://travis-ci.org/openai/mujoco-py)
44

5-
[MuJoCo](http://mujoco.org/) is a physics engine for detailed, efficient rigid body simulations with contacts. `mujoco-py` allows using MuJoCo from Python 3.
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+
610

711
## Synopsis
812

@@ -15,33 +19,32 @@ The following platforms are currently supported:
1519

1620
The following platforms are DEPRECATED and unsupported:
1721

18-
- Windows support is DEPRECATED and will be removed soon. One known good past version is [1.50.1.68](https://github.com/openai/mujoco-py/blob/9ea9bb000d6b8551b99f9aa440862e0c7f7b4191/README.md#requirements).
22+
- Windows support has been DEPRECATED and removed in [2.0.2.0]. One known good past version is [1.50.1.68](https://github.com/openai/mujoco-py/blob/9ea9bb000d6b8551b99f9aa440862e0c7f7b4191/README.md#requirements).
1923
- 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`.
2024

2125
### Install MuJoCo
2226

2327
1. Obtain a 30-day free trial on the [MuJoCo website](https://www.roboti.us/license.html)
2428
or free license if you are a student.
2529
The license key will arrive in an email with your username and password.
26-
2. Download the MuJoCo version 1.50 binaries for
27-
[Linux](https://www.roboti.us/download/mjpro150_linux.zip),
28-
[OSX](https://www.roboti.us/download/mjpro150_osx.zip), or
29-
[Windows](https://www.roboti.us/download/mjpro150_win64.zip).
30-
3. Unzip the downloaded `mjpro150` directory into `~/.mujoco/mjpro150`,
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`,
3134
and place your license key (the `mjkey.txt` file from your email)
3235
at `~/.mujoco/mjkey.txt`.
3336

3437
If you want to specify a nonstandard location for the key and package,
35-
use the env variables `MUJOCO_PY_MJKEY_PATH` and `MUJOCO_PY_MJPRO_PATH`.
38+
use the env variables `MUJOCO_PY_MJKEY_PATH` and `MUJOCO_PY_MUJOCO_PATH`.
3639

3740
### Install and use `mujoco-py`
3841
To include `mujoco-py` in your own package, add it to your requirements like so:
3942
```
40-
mujoco-py<1.50.2,>=1.50.1
43+
mujoco-py<2.1,>=2.0
4144
```
4245
To play with `mujoco-py` interactively, follow these steps:
4346
```
44-
$ pip3 install -U 'mujoco-py<1.50.2,>=1.50.1'
47+
$ pip3 install -U 'mujoco-py<2.1,>=2.0'
4548
$ python3
4649
import mujoco_py
4750
import os
@@ -77,7 +80,7 @@ MuJoCo ships with its own copy of this library, which can be used during install
7780

7881
Add the path to the mujoco bin directory to your dynamic loader:
7982

80-
LD_LIBRARY_PATH=$HOME/.mujoco/mjpro150/bin pip install mujoco-py
83+
LD_LIBRARY_PATH=$HOME/.mujoco/mujoco200/bin pip install mujoco-py
8184

8285
This is particularly useful on Ubuntu 14.04, which does not have a GLFW package.
8386

@@ -124,3 +127,4 @@ This is somewhat dependent on internal OpenAI infrastructure at the moment, but
124127
- Jonathan Ho
125128
- Peter Welinder
126129
- Wojciech Zaremba
130+
- Jerry Tworek

examples/mjvive.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import numpy as np
2626
import OpenGL.GL as gl
2727
from mujoco_py import functions
28-
from mujoco_py.builder import mjpro_path
28+
from mujoco_py.builder import mujoco_path
2929
from mujoco_py.cymj import (MjRenderContext, MjSim, load_model_from_xml,
3030
PyMjrRect, PyMjvCamera)
3131
from mujoco_py.generated.const import (CAT_ALL, FB_OFFSCREEN, FONT_BIG,
@@ -37,6 +37,7 @@
3737
class HMD(): # anonymous object we can set fields on
3838
pass
3939

40+
4041
window = None
4142
sim = None
4243
ctx = None
@@ -156,7 +157,7 @@ def v_render():
156157

157158

158159
if __name__ == '__main__':
159-
filename = os.path.join(mjpro_path, 'model', 'humanoid.xml')
160+
filename = os.path.join(mujoco_path, 'model', 'humanoid.xml')
160161
v_initPre()
161162
initMuJoCo(filename, hmd.width * 2, hmd.height)
162163
v_initPost()

mujoco_py/builder.py

+33-33
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def get_nvidia_lib_dir():
4141
return paths[-1]
4242

4343

44-
def load_cython_ext(mjpro_path):
44+
def load_cython_ext(mujoco_path):
4545
"""
4646
Loads the cymj Cython extension. This is safe to be called from
4747
multiple processes running on the same machine.
@@ -62,7 +62,7 @@ def load_cython_ext(mjpro_path):
6262
The easy solution is to `import mujoco_py` _before_ `import glfw`.
6363
''')
6464

65-
lib_path = os.path.join(mjpro_path, "bin")
65+
lib_path = os.path.join(mujoco_path, "bin")
6666
if sys.platform == 'darwin':
6767
Builder = MacExtensionBuilder
6868
elif sys.platform == 'linux':
@@ -81,7 +81,7 @@ def load_cython_ext(mjpro_path):
8181
else:
8282
raise RuntimeError("Unsupported platform %s" % sys.platform)
8383

84-
builder = Builder(mjpro_path)
84+
builder = Builder(mujoco_path)
8585
cext_so_path = builder.get_so_file_path()
8686

8787
lockpath = os.path.join(os.path.dirname(cext_so_path), 'mujocopy-buildlock')
@@ -153,7 +153,7 @@ def fix_shared_library(so_file, name, library_path):
153153
subprocess.check_call(['patchelf', '--add-needed', library_path, so_file])
154154

155155

156-
def manually_link_libraries(mjpro_path, raw_cext_dll_path):
156+
def manually_link_libraries(mujoco_path, raw_cext_dll_path):
157157
''' Used to fix mujoco library linking on Mac '''
158158
root, ext = os.path.splitext(raw_cext_dll_path)
159159
final_cext_dll_path = root + '_final' + ext
@@ -167,12 +167,12 @@ def manually_link_libraries(mjpro_path, raw_cext_dll_path):
167167
tmp_final_cext_dll_path = final_cext_dll_path + '~'
168168
shutil.copyfile(raw_cext_dll_path, tmp_final_cext_dll_path)
169169

170-
mj_bin_path = join(mjpro_path, 'bin')
170+
mj_bin_path = join(mujoco_path, 'bin')
171171

172172
# Fix the rpath of the generated library -- i lost the Stackoverflow
173173
# reference here
174-
from_mujoco_path = '@executable_path/libmujoco150.dylib'
175-
to_mujoco_path = '%s/libmujoco150.dylib' % mj_bin_path
174+
from_mujoco_path = '@executable_path/libmujoco200.dylib'
175+
to_mujoco_path = '%s/libmujoco200.dylib' % mj_bin_path
176176
subprocess.check_call(['install_name_tool',
177177
'-change',
178178
from_mujoco_path,
@@ -195,20 +195,20 @@ class MujocoExtensionBuilder():
195195

196196
CYMJ_DIR_PATH = abspath(dirname(__file__))
197197

198-
def __init__(self, mjpro_path):
199-
self.mjpro_path = mjpro_path
198+
def __init__(self, mujoco_path):
199+
self.mujoco_path = mujoco_path
200200
python_version = str(sys.version_info.major) + str(sys.version_info.minor)
201201
self.version = '%s_%s_%s' % (get_version(), python_version, self.build_base())
202202
self.extension = Extension(
203203
'mujoco_py.cymj',
204204
sources=[join(self.CYMJ_DIR_PATH, "cymj.pyx")],
205205
include_dirs=[
206206
self.CYMJ_DIR_PATH,
207-
join(mjpro_path, 'include'),
207+
join(mujoco_path, 'include'),
208208
np.get_include(),
209209
],
210-
libraries=['mujoco150'],
211-
library_dirs=[join(mjpro_path, 'bin')],
210+
libraries=['mujoco200'],
211+
library_dirs=[join(mujoco_path, 'bin')],
212212
extra_compile_args=[
213213
'-fopenmp', # needed for OpenMP
214214
'-w', # suppress numpy compilation warnings
@@ -252,58 +252,58 @@ def get_so_file_path(self):
252252

253253
class WindowsExtensionBuilder(MujocoExtensionBuilder):
254254

255-
def __init__(self, mjpro_path):
256-
super().__init__(mjpro_path)
257-
os.environ["PATH"] += ";" + join(mjpro_path, "bin")
255+
def __init__(self, mujoco_path):
256+
super().__init__(mujoco_path)
257+
os.environ["PATH"] += ";" + join(mujoco_path, "bin")
258258
self.extension.sources.append(self.CYMJ_DIR_PATH + "/gl/dummyshim.c")
259259

260260

261261
class LinuxCPUExtensionBuilder(MujocoExtensionBuilder):
262262

263-
def __init__(self, mjpro_path):
264-
super().__init__(mjpro_path)
263+
def __init__(self, mujoco_path):
264+
super().__init__(mujoco_path)
265265

266266
self.extension.sources.append(
267267
join(self.CYMJ_DIR_PATH, "gl", "osmesashim.c"))
268268
self.extension.libraries.extend(['glewosmesa', 'OSMesa', 'GL'])
269-
self.extension.runtime_library_dirs = [join(mjpro_path, 'bin')]
269+
self.extension.runtime_library_dirs = [join(mujoco_path, 'bin')]
270270

271271
def _build_impl(self):
272272
so_file_path = super()._build_impl()
273273
# Removes absolute paths to libraries. Allows for dynamic loading.
274-
fix_shared_library(so_file_path, 'libmujoco150.so', 'libmujoco150.so')
274+
fix_shared_library(so_file_path, 'libmujoco200.so', 'libmujoco200.so')
275275
fix_shared_library(so_file_path, 'libglewosmesa.so', 'libglewosmesa.so')
276276
return so_file_path
277277

278278

279279
class LinuxGPUExtensionBuilder(MujocoExtensionBuilder):
280280

281-
def __init__(self, mjpro_path):
282-
super().__init__(mjpro_path)
281+
def __init__(self, mujoco_path):
282+
super().__init__(mujoco_path)
283283

284284
self.extension.sources.append(self.CYMJ_DIR_PATH + "/gl/eglshim.c")
285285
self.extension.include_dirs.append(self.CYMJ_DIR_PATH + '/vendor/egl')
286286
self.extension.libraries.extend(['glewegl'])
287-
self.extension.runtime_library_dirs = [join(mjpro_path, 'bin')]
287+
self.extension.runtime_library_dirs = [join(mujoco_path, 'bin')]
288288

289289
def _build_impl(self):
290290
so_file_path = super()._build_impl()
291291
fix_shared_library(so_file_path, 'libOpenGL.so', 'libOpenGL.so.0')
292292
fix_shared_library(so_file_path, 'libEGL.so', 'libEGL.so.1')
293-
fix_shared_library(so_file_path, 'libmujoco150.so', 'libmujoco150.so')
293+
fix_shared_library(so_file_path, 'libmujoco200.so', 'libmujoco200.so')
294294
fix_shared_library(so_file_path, 'libglewegl.so', 'libglewegl.so')
295295
return so_file_path
296296

297297

298298
class MacExtensionBuilder(MujocoExtensionBuilder):
299299

300-
def __init__(self, mjpro_path):
301-
super().__init__(mjpro_path)
300+
def __init__(self, mujoco_path):
301+
super().__init__(mujoco_path)
302302

303303
self.extension.sources.append(self.CYMJ_DIR_PATH + "/gl/dummyshim.c")
304304
self.extension.libraries.extend(['glfw.3'])
305305
self.extension.define_macros = [('ONMAC', None)]
306-
self.extension.runtime_library_dirs = [join(mjpro_path, 'bin')]
306+
self.extension.runtime_library_dirs = [join(mujoco_path, 'bin')]
307307

308308
def _build_impl(self):
309309
if not os.environ.get('CC'):
@@ -327,7 +327,7 @@ def _build_impl(self):
327327
del os.environ['CC']
328328
else: # User-directed c compiler
329329
so_file_path = super()._build_impl()
330-
return manually_link_libraries(self.mjpro_path, so_file_path)
330+
return manually_link_libraries(self.mujoco_path, so_file_path)
331331

332332

333333
class MujocoException(Exception):
@@ -467,9 +467,9 @@ def build_callback_fn(function_string, userdata_names=[]):
467467
source_string += '\nuintptr_t __fun = (uintptr_t) fun;'
468468
# Link against mujoco so we can call mujoco functions from within callback
469469
ffibuilder.set_source(name, source_string,
470-
include_dirs=[join(mjpro_path, 'include')],
471-
library_dirs=[join(mjpro_path, 'bin')],
472-
libraries=['mujoco150'])
470+
include_dirs=[join(mujoco_path, 'include')],
471+
library_dirs=[join(mujoco_path, 'bin')],
472+
libraries=['mujoco200'])
473473
# Catch compilation exceptions so we can cleanup partial files in that case
474474
try:
475475
library_path = ffibuilder.compile(verbose=True)
@@ -478,7 +478,7 @@ def build_callback_fn(function_string, userdata_names=[]):
478478
raise e
479479
# On Mac the MuJoCo library is linked strangely, so we have to fix it here
480480
if sys.platform == 'darwin':
481-
fixed_library_path = manually_link_libraries(mjpro_path, library_path)
481+
fixed_library_path = manually_link_libraries(mujoco_path, library_path)
482482
move(fixed_library_path, library_path) # Overwrite with fixed library
483483
module = load_dynamic_ext(name, library_path)
484484
# Now that the module is loaded into memory, we can actually delete it
@@ -499,8 +499,8 @@ def activate():
499499
functions.mj_activate(key_path)
500500

501501

502-
mjpro_path, key_path = discover_mujoco()
503-
cymj = load_cython_ext(mjpro_path)
502+
mujoco_path, key_path = discover_mujoco()
503+
cymj = load_cython_ext(mujoco_path)
504504

505505

506506
# Trick to expose all mj* functions from mujoco in mujoco_py.*

0 commit comments

Comments
 (0)