Skip to content

Commit

Permalink
Add make command for running test on GPU host (openai#91)
Browse files Browse the repository at this point in the history
Makes it easy to run tests on a GPU host. Also cleaned up the various test marks.
  • Loading branch information
welinder committed Aug 17, 2017
1 parent 7e6d1e1 commit 22415da
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 28 deletions.
3 changes: 1 addition & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ install:
- conda create -q -n test-environment python=3.5 numpy scipy
- activate test-environment
- SET PATH=%userprofile%\.mujoco\mjpro150\bin;%PATH%;
- SET RENDERING_OFF=1
- cd C:\projects\mujoco-py
- pip install -r requirements.txt
- pip install -r requirements.dev.txt

build: off

test_script:
- pytest -s --verbose --durations=10 --instafail
- pytest -s --verbose --durations=10 --instafail -m "not requires_rendering"


1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ outputfile
tmp*
cymj.c
**/.git
**/*.so
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ test: build
# run it interactive mode so we can abort with CTRL+C
$(DOCKER) run --rm -i $(DOCKER_NAME) pytest

test_gpu: build push
$(eval NODE="$(shell cirrascale-cli reserve -g 1080ti -t 10m)")
$(eval GPUS="$(shell echo $(NODE)| grep -oE '[^:]+f' | cut -c1-1 )")
$(eval NODE="$(shell echo $(NODE)| grep -oE '[^=]+:' | sed 's/://')")
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"'

shell:
$(DOCKER) run --rm -it $(DOCKER_NAME) /bin/bash

Expand All @@ -48,7 +54,6 @@ cirra:
tmux new-session "while :; do rsync -e 'ssh -o StrictHostKeyChecking=no' --delete -rzai --out-format='%t %f %b' --chmod=Du+rwx --exclude='dist' --exclude='cymj.c' --exclude='_pyxbld_*' --exclude='*extensionbuilder.so' --exclude='__pycache__' --exclude='*.egg-info' --exclude='.cache' --exclude='.git' --exclude='*.pyc' --exclude='*.swp' --exclude='.idea' . $(NODE):~/mujoco_py/ ; sleep 1; done" \; \
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]


upload:
rm -rf dist
python setup.py sdist
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ To run the provided unit and integrations tests:
make test
```

To test GPU-backed rendering, run:

```
make test_gpu
```

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.

## Credits

`mujoco-py` is maintained by the OpenAI Robotics team. Contributors include:
Expand Down
18 changes: 10 additions & 8 deletions mujoco_py/tests/test_cymj.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ignore_mujoco_warnings,
load_model_from_mjb)
from mujoco_py import const, cymj
from mujoco_py.tests.utils import compare_imgs, requires_rendering
from mujoco_py.tests.utils import compare_imgs
import scipy.misc
from threading import Thread, Event
from multiprocessing import get_context
Expand Down Expand Up @@ -54,7 +54,7 @@ def test_mj_sim_basics():
sim.forward()


@requires_rendering
@pytest.mark.requires_rendering
def test_arrays_of_objs():
model = load_model_from_xml(BASIC_MODEL_XML)
sim = MjSim(model)
Expand Down Expand Up @@ -554,7 +554,7 @@ def test_xvelr(): # xvelr = rotational velocity in world frame
np.testing.assert_allclose(body2_xvelr, sim.data.body_xvelr[2])


@requires_rendering
@pytest.mark.requires_rendering
def test_rendering():
model = load_model_from_xml(BASIC_MODEL_XML)
sim = MjSim(model)
Expand Down Expand Up @@ -587,7 +587,7 @@ def test_rendering():
compare_imgs(img, 'test_rendering_markers.camera1.png')


@requires_rendering
@pytest.mark.requires_rendering
def test_rendering_failing():
model = load_model_from_xml(BASIC_MODEL_XML)
sim = MjSim(model)
Expand All @@ -607,7 +607,7 @@ def test_rendering_failing():
pass


@requires_rendering
@pytest.mark.requires_rendering
def test_viewercontext():
model = load_model_from_xml(BASIC_MODEL_XML)
sim = MjSim(model)
Expand All @@ -621,7 +621,7 @@ def test_viewercontext():
label="mark")


@requires_rendering
@pytest.mark.requires_rendering
def test_many_sims_rendering():
model = load_model_from_xml(BASIC_MODEL_XML)
sims = [MjSim(model) for _ in range(5)]
Expand Down Expand Up @@ -649,7 +649,9 @@ def test_sensors():
sim.data.get_sensor("touchsensor")


@pytest.mark.skipif("Darwin" not in sys.platform, reason="Only Darwin code is thread safe.")
@pytest.mark.requires_rendering
@pytest.mark.skipif("Darwin" not in sys.platform,
reason="Only Darwin code is thread safe.")
def test_concurrent_rendering():
'''Best-effort testing that concurrent multi-threaded rendering works.
The test has no guarantees around being deterministic, but if it fails
Expand Down Expand Up @@ -683,7 +685,7 @@ def func(sim, event):
thread.join()
assert err is None, "Exception: %s" % (str(err))

@requires_rendering
@pytest.mark.requires_rendering
def test_high_res():
model = load_model_from_xml(BASIC_MODEL_XML)
sim = MjSim(model)
Expand Down
5 changes: 3 additions & 2 deletions mujoco_py/tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import os.path
import mujoco_py
import sys
from mujoco_py.tests.utils import requires_rendering
import pytest
mujoco_py_root = os.path.dirname(os.path.dirname(mujoco_py.__file__))


@requires_rendering
@pytest.mark.requires_rendering
@pytest.mark.requires_glfw
def test_examples():
scripts = glob.glob("%s/examples/*.py" % mujoco_py_root)
env = os.environ.update({'TESTING': 'true'})
Expand Down
11 changes: 6 additions & 5 deletions mujoco_py/tests/test_modder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from mujoco_py import MjSim, load_model_from_xml
from mujoco_py.modder import MaterialModder, TextureModder
from mujoco_py.tests.utils import compare_imgs, requires_rendering
from mujoco_py.tests.utils import compare_imgs
import numpy as np

BASIC_MODEL_XML = """
Expand Down Expand Up @@ -31,7 +32,7 @@
</mujoco>
"""

@requires_rendering
@pytest.mark.requires_rendering
def test_textures():
model = load_model_from_xml(BASIC_MODEL_XML)
sim = MjSim(model)
Expand Down Expand Up @@ -85,7 +86,7 @@ def test_textures():
compare_imgs(sim.render(201, 205, camera_name="topcam"),
'test_textures.rand_texrepeat.png')

@requires_rendering
@pytest.mark.requires_rendering
def test_materials():
model = load_model_from_xml(BASIC_MODEL_XML)
sim = MjSim(model)
Expand All @@ -107,7 +108,7 @@ def test_materials():
compare_imgs(sim.render(201, 205, camera_name="topcam"),
'test_materials.rand_all.png')

@requires_rendering
@pytest.mark.requires_rendering
def test_multiple_sims():
# Ensure that creating new simulators still produces good renderings.
xml = """
Expand Down Expand Up @@ -138,7 +139,7 @@ def test_multiple_sims():
'test_multiple_sims.loop%d_%d.png' % (i, j))


@requires_rendering
@pytest.mark.requires_rendering
def test_resetting():
# Ensure that resetting environment and creating new simulators
# still produces good renderings.
Expand Down
6 changes: 3 additions & 3 deletions mujoco_py/tests/test_render_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from mujoco_py import MjSim, MjRenderPool, load_model_from_xml
from mujoco_py.modder import TextureModder
from mujoco_py.tests.utils import compare_imgs, requires_rendering
from mujoco_py.tests.utils import compare_imgs

BASIC_MODEL_XML = """
<mujoco>
Expand Down Expand Up @@ -42,7 +42,7 @@
"""


@requires_rendering
@pytest.mark.requires_rendering
def test_spawn():
# pytest and nose both use 'fork' by default, so we
# expect a runtime error
Expand All @@ -51,7 +51,7 @@ def test_spawn():
MjRenderPool(model, n_workers=3)


@requires_rendering
@pytest.mark.requires_rendering
def test_multiprocessing():
# pytest doesn't work well with multiprocessing, so just
# run the multiprocessing tests manually by running this
Expand Down
5 changes: 3 additions & 2 deletions mujoco_py/tests/test_viewer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import pytest
from mujoco_py import load_model_from_path, MjSim
from mujoco_py.mjviewer import MjViewer
from mujoco_py.tests.utils import requires_rendering


@requires_rendering
@pytest.mark.requires_rendering
@pytest.mark.requires_glfw
def test_viewer():
model = load_model_from_path("mujoco_py/tests/test.xml")
sim = MjSim(model)
Expand Down
5 changes: 0 additions & 5 deletions mujoco_py/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,3 @@ def compare_imgs(img, truth_filename, do_assert=True):
if do_assert:
assert diff <= 1
return diff


# Skips test when RENDERING_OFF.
requires_rendering = pytest.mark.skipif(os.environ.get("RENDERING_OFF", False),
reason="Skip test when system doesn't support rendering")

0 comments on commit 22415da

Please sign in to comment.