Skip to content

Commit

Permalink
Make dm_control an extra dependency
Browse files Browse the repository at this point in the history
Because dm_control needs to be installed from vcs or tarball, garage
cannot be directly installed in pipenv (see [this
issue](pypa/pipenv#3396)).

I've copied the example that used our dm_control wrapper, modified
the original example to use gym, and modified the copy to clarify the
extra dependency.

I've also modified the `garage.env.dm_control` module to report a
helpful error message if dm_control isn't found.

`pip install garage[all]` will still install dm_control.
  • Loading branch information
krzentner committed Aug 1, 2019
1 parent f4a6271 commit d0a2877
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
23 changes: 23 additions & 0 deletions examples/step_dm_control_env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python3
"""Example of how to load, step, and visualize an environment.
This example requires that garage[dm_control] be installed.
"""
from garage.envs.dm_control import DmControlEnv

# Construct the environment
env = DmControlEnv.from_suite('walker', 'run')

# Reset the environment and launch the viewer
env.reset()
env.render()

# Step randomly until interrupted
try:
print('Press Ctrl-C to stop...')
while True:
env.step(env.action_space.sample())
env.render()
except KeyboardInterrupt:
print('Exiting...')
env.close()
4 changes: 2 additions & 2 deletions examples/step_env.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python3
"""Example of how to load, step, and visualize an environment."""
from garage.envs.dm_control import DmControlEnv
import gym

# Construct the environment
env = DmControlEnv.from_suite('walker', 'run')
env = gym.make('MountainCar-v0')

# Reset the environment and launch the viewer
env.reset()
Expand Down
14 changes: 9 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
'click',
'cloudpickle',
'cma==1.1.06',
# dm_control throws an error during install about not being able to
# find a build dependency (absl-py). Later pip executes the `install`
# command again and the install succeeds because absl-py has been
# installed. This is stupid, but harmless.
'dm_control @ https://api.github.com/repos/deepmind/dm_control/tarball/7a36377879c57777e5d5b4da5aae2cd2a29b607a', # noqa: E501
'dowel==0.0.2',
'gym[all]==0.12.4',
'joblib<0.13,>=0.12',
Expand All @@ -48,6 +43,15 @@

# Dependencies for optional features
extras = {}

extras['dm_control'] = [
# dm_control throws an error during install about not being able to
# find a build dependency (absl-py). Later pip executes the `install`
# command again and the install succeeds because absl-py has been
# installed. This is stupid, but harmless.
'dm_control @ https://api.github.com/repos/deepmind/dm_control/tarball/7a36377879c57777e5d5b4da5aae2cd2a29b607a', # noqa: E501
]

extras['all'] = list(set(sum(extras.values(), [])))

# Intel dependencies not included in all
Expand Down
6 changes: 6 additions & 0 deletions src/garage/envs/dm_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
See https://github.com/deepmind/dm_control
"""
try:
import dm_control # noqa: F401
except ImportError:
raise ImportError("To use garage's dm_control wrappers, please install "
'garage[dm_control].')

from garage.envs.dm_control.dm_control_viewer import DmControlViewer
from garage.envs.dm_control.dm_control_env import DmControlEnv # noqa: I100

Expand Down

0 comments on commit d0a2877

Please sign in to comment.