Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate dmcontrol updated #55

Merged
merged 39 commits into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
383e271
Add dm_control to requirements
May 25, 2022
05f5058
Add/transform dm_control/Mujoco into CARLEnv
May 25, 2022
594eff6
adapt observations and render rgb
sebidoe Jun 7, 2022
1efa11e
change dmc load, simplify wrapper
sebidoe Jun 7, 2022
dcbdecc
dmc initializations
sebidoe Jun 8, 2022
4c486dc
refactor, load context into dmc cartpole
sebidoe Jun 8, 2022
268843d
remove print
sebidoe Jun 9, 2022
3a9ce8e
update cartpole context
sebidoe Jun 9, 2022
cf756bd
general dmc env
sebidoe Jun 10, 2022
b06ded7
add walker
sebidoe Jun 13, 2022
bf21bb6
fix load dmc
sebidoe Jun 13, 2022
f3aac23
update walker context
sebidoe Jun 13, 2022
d71b2d1
camera id in render
sebidoe Jun 13, 2022
cf977e4
dmc test function
sebidoe Jun 13, 2022
c74aece
add more context tasks to walker
sebidoe Jun 13, 2022
1d130d7
add quadruped
sebidoe Jun 13, 2022
3ff0cec
add dmc fish
sebidoe Jun 13, 2022
ea53c3c
walker context defaults, adapt context utils
sebidoe Jun 20, 2022
af96a0b
update adapt context function
sebidoe Jun 20, 2022
f711123
quadruped adapt context utils
sebidoe Jun 20, 2022
f18c799
update dmc context parameters
sebidoe Jun 20, 2022
12f6ea6
rename utils->loader
sebidoe Jun 21, 2022
f148fb9
add masking to dmc envs
sebidoe Jun 21, 2022
0073f29
remove cartpole env
sebidoe Jun 21, 2022
af93320
formatting
sebidoe Jun 21, 2022
d236bd0
dmc env less duplicate code
sebidoe Jun 22, 2022
f1c2ddd
Rename/move file
Jun 24, 2022
433fa0e
Fix tests
Jun 24, 2022
84de6bd
Merge remote-tracking branch 'origin/main' into integrate_dmcontrol
Jun 27, 2022
8b951a5
Change default tasks
Jun 27, 2022
5d9f994
Adjust episode lengths to 1000
Jun 27, 2022
037b2e9
add docstring
sebidoe Jul 1, 2022
2d23f17
update readme
sebidoe Jul 1, 2022
f5c6557
flake8 formatting
sebidoe Jul 1, 2022
47254f5
dmc dict observation space
sebidoe Jul 1, 2022
ebe8ea3
import list
sebidoe Jul 1, 2022
4e6833c
Merge branch 'main' into integrate_dmcontrol
sebidoe Jul 1, 2022
484087b
formatting
sebidoe Jul 1, 2022
9f0b2c4
black and isort formatting
sebidoe Jul 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Benchmarks include:
- [RNADesign](https://github.com/automl/learna/), an environment for RNA design given structure
constraints with structures from different datasets to choose from

- [dm_control](https://github.com/deepmind/dm_control), environments based on the MuJoCo physics engine. The environments are extended with different context features.

![Screenshot of each environment included in CARL.](./docs/source/figures/envs_overview.png)

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

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:
```bash
pip install -e .[box2d, brax, rna, mario]
pip install -e .[box2d, brax, rna, mario, dm_control]
```

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

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

[dm_control: Software and Tasks for Continuous Control](https://arxiv.org/pdf/2006.12983.pdf)

## License
CARL falls under the Apache License 2.0 (see file 'LICENSE') as is permitted by all
work that we use. This includes CARLMario, which is not based on the Nintendo Game, but on
Expand Down
4 changes: 1 addition & 3 deletions carl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
__copyright__ = "Copyright 2021, AutoML.org Freiburg-Hannover"
__license__ = "Apache-2.0 License"
__version__ = "0.1"
__author__ = (
"Carolin Benjamins, Theresa Eimer, Frederik Schubert, André Biedenkapp, Aditya Mohan"
)
__author__ = "Carolin Benjamins, Theresa Eimer, Frederik Schubert, André Biedenkapp, Aditya Mohan"
4 changes: 3 additions & 1 deletion carl/context/selection.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from abc import abstractmethod
from typing import Any, Callable, Dict, List, Optional, Tuple

import numpy as np

from carl.utils.types import Context
from typing import Dict, Any, Optional, Tuple, List, Callable


class AbstractSelector(object):
Expand Down
1 change: 1 addition & 0 deletions carl/envs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
found = brax_spec is not None
if found:
from carl.envs.brax import *

pass
else:
warnings.warn(
Expand Down
16 changes: 8 additions & 8 deletions carl/envs/box2d/carl_bipedal_walker.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
from typing import Any, Dict, List, Optional, Tuple, Union
from typing import Any, Dict, List, Optional, Union

import Box2D
import numpy as np
from Box2D.b2 import edgeShape, fixtureDef, polygonShape
from gym import spaces
from gym.envs.box2d import bipedal_walker
from gym.envs.box2d import bipedal_walker as bpw
from gym.utils import EzPickle

from carl.context.selection import AbstractSelector
from carl.envs.carl_env import CARLEnv
from carl.utils.trial_logger import TrialLogger
from carl.context.selection import AbstractSelector

DEFAULT_CONTEXT = {
"FPS": 50,
Expand Down Expand Up @@ -91,7 +88,9 @@ def __init__(
state_context_features: Optional[List[str]] = None,
context_mask: Optional[List[str]] = None,
dict_observation_space: bool = False,
context_selector: Optional[Union[AbstractSelector, type(AbstractSelector)]] = None,
context_selector: Optional[
Union[AbstractSelector, type(AbstractSelector)]
] = None,
context_selector_kwargs: Optional[Dict] = None,
):
"""
Expand Down Expand Up @@ -122,7 +121,6 @@ def __init__(
context_selector=context_selector,
context_selector_kwargs=context_selector_kwargs,
context_mask=context_mask,

)
self.whitelist_gaussian_noise = list(
DEFAULT_CONTEXT.keys()
Expand Down Expand Up @@ -197,7 +195,9 @@ def _update_context(self):
self.env.world.gravity = gravity


def demo_heuristic(env: Union[CARLBipedalWalkerEnv, bipedal_walker.BipedalWalker]) -> None:
def demo_heuristic(
env: Union[CARLBipedalWalkerEnv, bipedal_walker.BipedalWalker]
) -> None:
env.reset()
steps = 0
total_reward = 0
Expand Down
23 changes: 11 additions & 12 deletions carl/envs/box2d/carl_lunarlander.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
from typing import Any, Dict, List, Optional, Tuple, Union, TypeVar
from typing import Any, Dict, List, Optional, Tuple, TypeVar, Union

import Box2D
import numpy as np
from gym import spaces
from gym import Wrapper

from gym.envs.box2d import lunar_lander
from gym.envs.box2d.lunar_lander import heuristic
from gym.utils import EzPickle, seeding

from carl.context.selection import AbstractSelector
from carl.envs.carl_env import CARLEnv
from carl.utils.trial_logger import TrialLogger
from carl.context.selection import AbstractSelector

ObsType = TypeVar("ObsType")
ActType = TypeVar("ActType")
Expand Down Expand Up @@ -78,9 +73,9 @@

class LunarLanderEnv(Wrapper):
def __init__(
self,
env: Optional[lunar_lander.LunarLander] = None,
high_gameover_penalty: bool = False,
self,
env: Optional[lunar_lander.LunarLander] = None,
high_gameover_penalty: bool = False,
):
if env is None:
env = lunar_lander.LunarLander()
Expand Down Expand Up @@ -117,7 +112,9 @@ def __init__(
max_episode_length: int = 1000,
high_gameover_penalty: bool = False,
dict_observation_space: bool = False,
context_selector: Optional[Union[AbstractSelector, type(AbstractSelector)]] = None,
context_selector: Optional[
Union[AbstractSelector, type(AbstractSelector)]
] = None,
context_selector_kwargs: Optional[Dict] = None,
):
"""
Expand Down Expand Up @@ -182,7 +179,9 @@ def _update_context(self) -> None:


def demo_heuristic_lander(
env: Union[CARLLunarLanderEnv, lunar_lander.LunarLander, lunar_lander.LunarLanderContinuous],
env: Union[
CARLLunarLanderEnv, lunar_lander.LunarLander, lunar_lander.LunarLanderContinuous
],
seed: Optional[int] = None,
render: bool = False,
) -> float:
Expand Down
6 changes: 4 additions & 2 deletions carl/envs/box2d/carl_vehicle_racing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from gym.envs.box2d.car_dynamics import Car
from pyglet import gl

from carl.context.selection import AbstractSelector
from carl.envs.box2d.parking_garage.bus import AWDBus # as Car
from carl.envs.box2d.parking_garage.bus import AWDBusLargeTrailer # as Car
from carl.envs.box2d.parking_garage.bus import AWDBusSmallTrailer # as Car
Expand Down Expand Up @@ -37,7 +38,6 @@
from carl.envs.box2d.parking_garage.trike import TukTukSmallTrailer # as Car
from carl.envs.carl_env import CARLEnv
from carl.utils.trial_logger import TrialLogger
from carl.context.selection import AbstractSelector

PARKING_GARAGE_DICT = {
# Racing car
Expand Down Expand Up @@ -196,7 +196,9 @@ def __init__(
state_context_features: Optional[List[str]] = None,
context_mask: Optional[List[str]] = None,
dict_observation_space: bool = False,
context_selector: Optional[Union[AbstractSelector, type(AbstractSelector)]] = None,
context_selector: Optional[
Union[AbstractSelector, type(AbstractSelector)]
] = None,
context_selector_kwargs: Optional[Dict] = None,
):
"""
Expand Down
37 changes: 19 additions & 18 deletions carl/envs/brax/carl_ant.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import brax
import numpy as np
from brax.envs.ant import _SYSTEM_CONFIG, Ant
from brax.envs.wrappers import GymWrapper, VectorWrapper, VectorGymWrapper
from brax.envs.wrappers import GymWrapper, VectorGymWrapper, VectorWrapper
from google.protobuf import json_format, text_format
from google.protobuf.json_format import MessageToDict
from numpyencoder import NumpyEncoder

from carl.context.selection import AbstractSelector
from carl.envs.carl_env import CARLEnv
from carl.utils.trial_logger import TrialLogger
from carl.context.selection import AbstractSelector

DEFAULT_CONTEXT = {
"joint_stiffness": 5000,
Expand All @@ -38,22 +38,23 @@

class CARLAnt(CARLEnv):
def __init__(
self,
env: Ant = Ant(),
n_envs: int = 1,
contexts: Dict[str, Dict] = {},
hide_context=False,
add_gaussian_noise_to_context: bool = False,
gaussian_noise_std_percentage: float = 0.01,
logger: Optional[TrialLogger] = None,
scale_context_features: str = "no",
default_context: Optional[Dict] = DEFAULT_CONTEXT,
state_context_features: Optional[List[str]] = None,
context_mask: Optional[List[str]] = None,
dict_observation_space: bool = False,
context_selector: Optional[Union[AbstractSelector, type(AbstractSelector)]] = None,
context_selector_kwargs: Optional[Dict] = None,

self,
env: Ant = Ant(),
n_envs: int = 1,
contexts: Dict[str, Dict] = {},
hide_context=False,
add_gaussian_noise_to_context: bool = False,
gaussian_noise_std_percentage: float = 0.01,
logger: Optional[TrialLogger] = None,
scale_context_features: str = "no",
default_context: Optional[Dict] = DEFAULT_CONTEXT,
state_context_features: Optional[List[str]] = None,
context_mask: Optional[List[str]] = None,
dict_observation_space: bool = False,
context_selector: Optional[
Union[AbstractSelector, type(AbstractSelector)]
] = None,
context_selector_kwargs: Optional[Dict] = None,
):
if n_envs == 1:
env = GymWrapper(env)
Expand Down
8 changes: 5 additions & 3 deletions carl/envs/brax/carl_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import brax
import numpy as np
from brax.envs.fetch import _SYSTEM_CONFIG, Fetch
from brax.envs.wrappers import GymWrapper, VectorWrapper, VectorGymWrapper
from brax.envs.wrappers import GymWrapper, VectorGymWrapper, VectorWrapper
from google.protobuf import json_format, text_format
from google.protobuf.json_format import MessageToDict
from numpyencoder import NumpyEncoder

from carl.context.selection import AbstractSelector
from carl.envs.carl_env import CARLEnv
from carl.utils.trial_logger import TrialLogger
from carl.context.selection import AbstractSelector

DEFAULT_CONTEXT = {
"joint_stiffness": 5000,
Expand Down Expand Up @@ -55,7 +55,9 @@ def __init__(
state_context_features: Optional[List[str]] = None,
context_mask: Optional[List[str]] = None,
dict_observation_space: bool = False,
context_selector: Optional[Union[AbstractSelector, type(AbstractSelector)]] = None,
context_selector: Optional[
Union[AbstractSelector, type(AbstractSelector)]
] = None,
context_selector_kwargs: Optional[Dict] = None,
):
if n_envs == 1:
Expand Down
8 changes: 5 additions & 3 deletions carl/envs/brax/carl_grasp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import brax
import numpy as np
from brax.envs.grasp import _SYSTEM_CONFIG, Grasp
from brax.envs.wrappers import GymWrapper, VectorWrapper, VectorGymWrapper
from brax.envs.wrappers import GymWrapper, VectorGymWrapper, VectorWrapper
from google.protobuf import json_format, text_format
from google.protobuf.json_format import MessageToDict
from numpyencoder import NumpyEncoder

from carl.context.selection import AbstractSelector
from carl.envs.carl_env import CARLEnv
from carl.utils.trial_logger import TrialLogger
from carl.context.selection import AbstractSelector

DEFAULT_CONTEXT = {
"joint_stiffness": 5000,
Expand Down Expand Up @@ -55,7 +55,9 @@ def __init__(
state_context_features: Optional[List[str]] = None,
context_mask: Optional[List[str]] = None,
dict_observation_space: bool = False,
context_selector: Optional[Union[AbstractSelector, type(AbstractSelector)]] = None,
context_selector: Optional[
Union[AbstractSelector, type(AbstractSelector)]
] = None,
context_selector_kwargs: Optional[Dict] = None,
):
if n_envs == 1:
Expand Down
8 changes: 5 additions & 3 deletions carl/envs/brax/carl_halfcheetah.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import brax
import numpy as np
from brax.envs.halfcheetah import _SYSTEM_CONFIG, Halfcheetah
from brax.envs.wrappers import GymWrapper, VectorWrapper, VectorGymWrapper
from brax.envs.wrappers import GymWrapper, VectorGymWrapper, VectorWrapper
from google.protobuf import json_format, text_format
from google.protobuf.json_format import MessageToDict
from numpyencoder import NumpyEncoder

from carl.context.selection import AbstractSelector
from carl.envs.carl_env import CARLEnv
from carl.utils.trial_logger import TrialLogger
from carl.context.selection import AbstractSelector

DEFAULT_CONTEXT = {
"joint_stiffness": 15000.0,
Expand Down Expand Up @@ -49,7 +49,9 @@ def __init__(
state_context_features: Optional[List[str]] = None,
context_mask: Optional[List[str]] = None,
dict_observation_space: bool = False,
context_selector: Optional[Union[AbstractSelector, type(AbstractSelector)]] = None,
context_selector: Optional[
Union[AbstractSelector, type(AbstractSelector)]
] = None,
context_selector_kwargs: Optional[Dict] = None,
):
if n_envs == 1:
Expand Down
13 changes: 7 additions & 6 deletions carl/envs/brax/carl_humanoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
import copy
import json

import numpy as np
import brax
import numpy as np
from brax import jumpy as jp
from brax.envs.wrappers import GymWrapper, VectorWrapper, VectorGymWrapper
from brax.envs.humanoid import Humanoid, _SYSTEM_CONFIG
from brax.envs.humanoid import _SYSTEM_CONFIG, Humanoid
from brax.envs.wrappers import GymWrapper, VectorGymWrapper, VectorWrapper
from brax.physics import bodies

from google.protobuf import json_format, text_format
from google.protobuf.json_format import MessageToDict
from numpyencoder import NumpyEncoder

from carl.context.selection import AbstractSelector
from carl.envs.carl_env import CARLEnv
from carl.utils.trial_logger import TrialLogger
from carl.context.selection import AbstractSelector

DEFAULT_CONTEXT = {
"gravity": -9.8,
Expand Down Expand Up @@ -50,7 +49,9 @@ def __init__(
state_context_features: Optional[List[str]] = None,
context_mask: Optional[List[str]] = None,
dict_observation_space: bool = False,
context_selector: Optional[Union[AbstractSelector, type(AbstractSelector)]] = None,
context_selector: Optional[
Union[AbstractSelector, type(AbstractSelector)]
] = None,
context_selector_kwargs: Optional[Dict] = None,
):
if n_envs == 1:
Expand Down
Loading