Skip to content

Commit 43cf6fd

Browse files
sebidoeCarolin Benjamins
andauthored
Integrate dmcontrol updated (#55)
* Add dm_control to requirements * Add/transform dm_control/Mujoco into CARLEnv We could also use the Mujoco envs from gym, but they don't have every env and this way we have more options to modify the envs (it is at least more obvious). There are still some open todos. * adapt observations and render rgb * change dmc load, simplify wrapper * dmc initializations * refactor, load context into dmc cartpole * remove print * update cartpole context * general dmc env * add walker * fix load dmc * update walker context * camera id in render * dmc test function * add more context tasks to walker * add quadruped * add dmc fish * walker context defaults, adapt context utils * update adapt context function * quadruped adapt context utils * update dmc context parameters * rename utils->loader * add masking to dmc envs * remove cartpole env * formatting * dmc env less duplicate code * Rename/move file * Fix tests * Change default tasks * Adjust episode lengths to 1000 According to dm control settings. * add docstring * update readme * flake8 formatting * dmc dict observation space * import list * formatting * black and isort formatting Co-authored-by: Carolin Benjamins <benjamins@tnt.uni-hannover.de>
1 parent eada47e commit 43cf6fd

40 files changed

+853
-556
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Benchmarks include:
2424
- [RNADesign](https://github.com/automl/learna/), an environment for RNA design given structure
2525
constraints with structures from different datasets to choose from
2626

27+
- [dm_control](https://github.com/deepmind/dm_control), environments based on the MuJoCo physics engine. The environments are extended with different context features.
28+
2729
![Screenshot of each environment included in CARL.](./docs/source/figures/envs_overview.png)
2830

2931
For more information, check out our [documentation](https://carl.readthedocs.io/en/latest/)!
@@ -42,7 +44,7 @@ pip install .
4244

4345
This will only install the basic classic control environments, which should run on most operating systems. For the full set of environments, use the install options:
4446
```bash
45-
pip install -e .[box2d, brax, rna, mario]
47+
pip install -e .[box2d, brax, rna, mario, dm_control]
4648
```
4749

4850
These may not be compatible with Windows systems. Box2D environment may need to be installed via conda on MacOS systems:
@@ -95,6 +97,8 @@ Awiszus et al., AIIDE 2020](https://arxiv.org/pdf/2008.01531.pdf)
9597

9698
[Learning to Design RNA, Runge et al., ICRL 2019](https://arxiv.org/pdf/1812.11951.pdf)
9799

100+
[dm_control: Software and Tasks for Continuous Control](https://arxiv.org/pdf/2006.12983.pdf)
101+
98102
## License
99103
CARL falls under the Apache License 2.0 (see file 'LICENSE') as is permitted by all
100104
work that we use. This includes CARLMario, which is not based on the Nintendo Game, but on

carl/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
__copyright__ = "Copyright 2021, AutoML.org Freiburg-Hannover"
22
__license__ = "Apache-2.0 License"
33
__version__ = "0.1"
4-
__author__ = (
5-
"Carolin Benjamins, Theresa Eimer, Frederik Schubert, André Biedenkapp, Aditya Mohan"
6-
)
4+
__author__ = "Carolin Benjamins, Theresa Eimer, Frederik Schubert, André Biedenkapp, Aditya Mohan"

carl/context/selection.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from abc import abstractmethod
2+
from typing import Any, Callable, Dict, List, Optional, Tuple
3+
24
import numpy as np
5+
36
from carl.utils.types import Context
4-
from typing import Dict, Any, Optional, Tuple, List, Callable
57

68

79
class AbstractSelector(object):

carl/envs/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
found = brax_spec is not None
2121
if found:
2222
from carl.envs.brax import *
23+
2324
pass
2425
else:
2526
warnings.warn(

carl/envs/box2d/carl_bipedal_walker.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
from typing import Any, Dict, List, Optional, Tuple, Union
1+
from typing import Any, Dict, List, Optional, Union
22

3-
import Box2D
43
import numpy as np
54
from Box2D.b2 import edgeShape, fixtureDef, polygonShape
6-
from gym import spaces
75
from gym.envs.box2d import bipedal_walker
86
from gym.envs.box2d import bipedal_walker as bpw
9-
from gym.utils import EzPickle
107

8+
from carl.context.selection import AbstractSelector
119
from carl.envs.carl_env import CARLEnv
1210
from carl.utils.trial_logger import TrialLogger
13-
from carl.context.selection import AbstractSelector
1411

1512
DEFAULT_CONTEXT = {
1613
"FPS": 50,
@@ -91,7 +88,9 @@ def __init__(
9188
state_context_features: Optional[List[str]] = None,
9289
context_mask: Optional[List[str]] = None,
9390
dict_observation_space: bool = False,
94-
context_selector: Optional[Union[AbstractSelector, type(AbstractSelector)]] = None,
91+
context_selector: Optional[
92+
Union[AbstractSelector, type(AbstractSelector)]
93+
] = None,
9594
context_selector_kwargs: Optional[Dict] = None,
9695
):
9796
"""
@@ -122,7 +121,6 @@ def __init__(
122121
context_selector=context_selector,
123122
context_selector_kwargs=context_selector_kwargs,
124123
context_mask=context_mask,
125-
126124
)
127125
self.whitelist_gaussian_noise = list(
128126
DEFAULT_CONTEXT.keys()
@@ -197,7 +195,9 @@ def _update_context(self):
197195
self.env.world.gravity = gravity
198196

199197

200-
def demo_heuristic(env: Union[CARLBipedalWalkerEnv, bipedal_walker.BipedalWalker]) -> None:
198+
def demo_heuristic(
199+
env: Union[CARLBipedalWalkerEnv, bipedal_walker.BipedalWalker]
200+
) -> None:
201201
env.reset()
202202
steps = 0
203203
total_reward = 0

carl/envs/box2d/carl_lunarlander.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
from typing import Any, Dict, List, Optional, Tuple, Union, TypeVar
1+
from typing import Any, Dict, List, Optional, Tuple, TypeVar, Union
22

3-
import Box2D
4-
import numpy as np
5-
from gym import spaces
63
from gym import Wrapper
7-
84
from gym.envs.box2d import lunar_lander
95
from gym.envs.box2d.lunar_lander import heuristic
10-
from gym.utils import EzPickle, seeding
116

7+
from carl.context.selection import AbstractSelector
128
from carl.envs.carl_env import CARLEnv
139
from carl.utils.trial_logger import TrialLogger
14-
from carl.context.selection import AbstractSelector
1510

1611
ObsType = TypeVar("ObsType")
1712
ActType = TypeVar("ActType")
@@ -78,9 +73,9 @@
7873

7974
class LunarLanderEnv(Wrapper):
8075
def __init__(
81-
self,
82-
env: Optional[lunar_lander.LunarLander] = None,
83-
high_gameover_penalty: bool = False,
76+
self,
77+
env: Optional[lunar_lander.LunarLander] = None,
78+
high_gameover_penalty: bool = False,
8479
):
8580
if env is None:
8681
env = lunar_lander.LunarLander()
@@ -117,7 +112,9 @@ def __init__(
117112
max_episode_length: int = 1000,
118113
high_gameover_penalty: bool = False,
119114
dict_observation_space: bool = False,
120-
context_selector: Optional[Union[AbstractSelector, type(AbstractSelector)]] = None,
115+
context_selector: Optional[
116+
Union[AbstractSelector, type(AbstractSelector)]
117+
] = None,
121118
context_selector_kwargs: Optional[Dict] = None,
122119
):
123120
"""
@@ -182,7 +179,9 @@ def _update_context(self) -> None:
182179

183180

184181
def demo_heuristic_lander(
185-
env: Union[CARLLunarLanderEnv, lunar_lander.LunarLander, lunar_lander.LunarLanderContinuous],
182+
env: Union[
183+
CARLLunarLanderEnv, lunar_lander.LunarLander, lunar_lander.LunarLanderContinuous
184+
],
186185
seed: Optional[int] = None,
187186
render: bool = False,
188187
) -> float:

carl/envs/box2d/carl_vehicle_racing.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from gym.envs.box2d.car_dynamics import Car
77
from pyglet import gl
88

9+
from carl.context.selection import AbstractSelector
910
from carl.envs.box2d.parking_garage.bus import AWDBus # as Car
1011
from carl.envs.box2d.parking_garage.bus import AWDBusLargeTrailer # as Car
1112
from carl.envs.box2d.parking_garage.bus import AWDBusSmallTrailer # as Car
@@ -37,7 +38,6 @@
3738
from carl.envs.box2d.parking_garage.trike import TukTukSmallTrailer # as Car
3839
from carl.envs.carl_env import CARLEnv
3940
from carl.utils.trial_logger import TrialLogger
40-
from carl.context.selection import AbstractSelector
4141

4242
PARKING_GARAGE_DICT = {
4343
# Racing car
@@ -196,7 +196,9 @@ def __init__(
196196
state_context_features: Optional[List[str]] = None,
197197
context_mask: Optional[List[str]] = None,
198198
dict_observation_space: bool = False,
199-
context_selector: Optional[Union[AbstractSelector, type(AbstractSelector)]] = None,
199+
context_selector: Optional[
200+
Union[AbstractSelector, type(AbstractSelector)]
201+
] = None,
200202
context_selector_kwargs: Optional[Dict] = None,
201203
):
202204
"""

carl/envs/brax/carl_ant.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
import brax
77
import numpy as np
88
from brax.envs.ant import _SYSTEM_CONFIG, Ant
9-
from brax.envs.wrappers import GymWrapper, VectorWrapper, VectorGymWrapper
9+
from brax.envs.wrappers import GymWrapper, VectorGymWrapper, VectorWrapper
1010
from google.protobuf import json_format, text_format
1111
from google.protobuf.json_format import MessageToDict
1212
from numpyencoder import NumpyEncoder
1313

14+
from carl.context.selection import AbstractSelector
1415
from carl.envs.carl_env import CARLEnv
1516
from carl.utils.trial_logger import TrialLogger
16-
from carl.context.selection import AbstractSelector
1717

1818
DEFAULT_CONTEXT = {
1919
"joint_stiffness": 5000,
@@ -38,22 +38,23 @@
3838

3939
class CARLAnt(CARLEnv):
4040
def __init__(
41-
self,
42-
env: Ant = Ant(),
43-
n_envs: int = 1,
44-
contexts: Dict[str, Dict] = {},
45-
hide_context=False,
46-
add_gaussian_noise_to_context: bool = False,
47-
gaussian_noise_std_percentage: float = 0.01,
48-
logger: Optional[TrialLogger] = None,
49-
scale_context_features: str = "no",
50-
default_context: Optional[Dict] = DEFAULT_CONTEXT,
51-
state_context_features: Optional[List[str]] = None,
52-
context_mask: Optional[List[str]] = None,
53-
dict_observation_space: bool = False,
54-
context_selector: Optional[Union[AbstractSelector, type(AbstractSelector)]] = None,
55-
context_selector_kwargs: Optional[Dict] = None,
56-
41+
self,
42+
env: Ant = Ant(),
43+
n_envs: int = 1,
44+
contexts: Dict[str, Dict] = {},
45+
hide_context=False,
46+
add_gaussian_noise_to_context: bool = False,
47+
gaussian_noise_std_percentage: float = 0.01,
48+
logger: Optional[TrialLogger] = None,
49+
scale_context_features: str = "no",
50+
default_context: Optional[Dict] = DEFAULT_CONTEXT,
51+
state_context_features: Optional[List[str]] = None,
52+
context_mask: Optional[List[str]] = None,
53+
dict_observation_space: bool = False,
54+
context_selector: Optional[
55+
Union[AbstractSelector, type(AbstractSelector)]
56+
] = None,
57+
context_selector_kwargs: Optional[Dict] = None,
5758
):
5859
if n_envs == 1:
5960
env = GymWrapper(env)

carl/envs/brax/carl_fetch.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
import brax
77
import numpy as np
88
from brax.envs.fetch import _SYSTEM_CONFIG, Fetch
9-
from brax.envs.wrappers import GymWrapper, VectorWrapper, VectorGymWrapper
9+
from brax.envs.wrappers import GymWrapper, VectorGymWrapper, VectorWrapper
1010
from google.protobuf import json_format, text_format
1111
from google.protobuf.json_format import MessageToDict
1212
from numpyencoder import NumpyEncoder
1313

14+
from carl.context.selection import AbstractSelector
1415
from carl.envs.carl_env import CARLEnv
1516
from carl.utils.trial_logger import TrialLogger
16-
from carl.context.selection import AbstractSelector
1717

1818
DEFAULT_CONTEXT = {
1919
"joint_stiffness": 5000,
@@ -55,7 +55,9 @@ def __init__(
5555
state_context_features: Optional[List[str]] = None,
5656
context_mask: Optional[List[str]] = None,
5757
dict_observation_space: bool = False,
58-
context_selector: Optional[Union[AbstractSelector, type(AbstractSelector)]] = None,
58+
context_selector: Optional[
59+
Union[AbstractSelector, type(AbstractSelector)]
60+
] = None,
5961
context_selector_kwargs: Optional[Dict] = None,
6062
):
6163
if n_envs == 1:

carl/envs/brax/carl_grasp.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
import brax
77
import numpy as np
88
from brax.envs.grasp import _SYSTEM_CONFIG, Grasp
9-
from brax.envs.wrappers import GymWrapper, VectorWrapper, VectorGymWrapper
9+
from brax.envs.wrappers import GymWrapper, VectorGymWrapper, VectorWrapper
1010
from google.protobuf import json_format, text_format
1111
from google.protobuf.json_format import MessageToDict
1212
from numpyencoder import NumpyEncoder
1313

14+
from carl.context.selection import AbstractSelector
1415
from carl.envs.carl_env import CARLEnv
1516
from carl.utils.trial_logger import TrialLogger
16-
from carl.context.selection import AbstractSelector
1717

1818
DEFAULT_CONTEXT = {
1919
"joint_stiffness": 5000,
@@ -55,7 +55,9 @@ def __init__(
5555
state_context_features: Optional[List[str]] = None,
5656
context_mask: Optional[List[str]] = None,
5757
dict_observation_space: bool = False,
58-
context_selector: Optional[Union[AbstractSelector, type(AbstractSelector)]] = None,
58+
context_selector: Optional[
59+
Union[AbstractSelector, type(AbstractSelector)]
60+
] = None,
5961
context_selector_kwargs: Optional[Dict] = None,
6062
):
6163
if n_envs == 1:

0 commit comments

Comments
 (0)