Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
black and isort formatting
Browse files Browse the repository at this point in the history
sebidoe committed Jul 1, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 484087b commit 9f0b2c4
Showing 36 changed files with 714 additions and 452 deletions.
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):
1 change: 1 addition & 0 deletions carl/envs/__init__.py
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
found = brax_spec is not None
if found:
from carl.envs.brax import *

pass
else:
warnings.warn(
11 changes: 7 additions & 4 deletions carl/envs/box2d/carl_bipedal_walker.py
Original file line number Diff line number Diff line change
@@ -5,9 +5,9 @@
from gym.envs.box2d import bipedal_walker
from gym.envs.box2d import bipedal_walker as bpw

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,
@@ -88,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,
):
"""
@@ -119,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()
@@ -194,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
19 changes: 11 additions & 8 deletions carl/envs/box2d/carl_lunarlander.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from typing import Any, Dict, List, Optional, Tuple, Union, TypeVar
from typing import Any, Dict, List, Optional, Tuple, TypeVar, Union

from gym import Wrapper

from gym.envs.box2d import lunar_lander
from gym.envs.box2d.lunar_lander import heuristic

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")
@@ -74,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()
@@ -113,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,
):
"""
@@ -178,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:
6 changes: 4 additions & 2 deletions carl/envs/box2d/carl_vehicle_racing.py
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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,
):
"""
37 changes: 19 additions & 18 deletions carl/envs/brax/carl_ant.py
Original file line number Diff line number Diff line change
@@ -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,
@@ -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)
8 changes: 5 additions & 3 deletions carl/envs/brax/carl_fetch.py
Original file line number Diff line number Diff line change
@@ -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,
@@ -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:
8 changes: 5 additions & 3 deletions carl/envs/brax/carl_grasp.py
Original file line number Diff line number Diff line change
@@ -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,
@@ -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:
8 changes: 5 additions & 3 deletions carl/envs/brax/carl_halfcheetah.py
Original file line number Diff line number Diff line change
@@ -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,
@@ -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:
13 changes: 7 additions & 6 deletions carl/envs/brax/carl_humanoid.py
Original file line number Diff line number Diff line change
@@ -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,
@@ -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:
36 changes: 19 additions & 17 deletions carl/envs/brax/carl_ur5e.py
Original file line number Diff line number Diff line change
@@ -6,14 +6,14 @@
import brax
import numpy as np
from brax.envs.ur5e import _SYSTEM_CONFIG, Ur5e
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": 40000,
@@ -42,21 +42,23 @@

class CARLUr5e(CARLEnv):
def __init__(
self,
env: Ur5e = Ur5e(),
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: Ur5e = Ur5e(),
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)
Loading

0 comments on commit 9f0b2c4

Please sign in to comment.