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

Version 0.2.0 #63

Merged
merged 77 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
26a4007
Update twine check
Jul 6, 2022
070cbb4
Fix return type
Jul 6, 2022
06f6ea2
Annotate inits
Jul 6, 2022
da41eea
Annotate args
Jul 6, 2022
7e30680
carl/context mypy fixed
amsks Jul 6, 2022
68b6a99
Fix mypy
Jul 6, 2022
9e4408c
Handle return types of gym.Env in reset
Jul 6, 2022
67f7534
Fix mypy for carl_env.py
Jul 6, 2022
7c64edd
Merge remote-tracking branch 'origin/Codestyle' into Codestyle
Jul 6, 2022
dc6d75b
Correct reset function
Jul 6, 2022
7c763f8
Fix mypy
Jul 6, 2022
b64b817
Fix mypy brax
Jul 6, 2022
95e0234
Fix mypy brax
Jul 6, 2022
9dcabad
Moved demo to examples
Jul 6, 2022
5f2a34f
Update reset signature
Jul 6, 2022
c150ed2
Remove rendering of score label
Jul 6, 2022
87ef74c
Fix mypy box2d
Jul 6, 2022
101bf55
Move CARLVehicleRacing example
Jul 6, 2022
9897314
Update carracing example
Jul 6, 2022
cfd5df2
Fix mypy box2d
Jul 6, 2022
7cb58c3
Fix mypy
Jul 6, 2022
1e3b78c
Fix mypy
Jul 6, 2022
bc45f54
Update reset function
Jul 6, 2022
76aa19b
mypy dmc fish
sebidoe Jul 6, 2022
8614644
mypy dmc quadruped
sebidoe Jul 6, 2022
c32bf20
mypy dmc context utils
sebidoe Jul 6, 2022
66660da
wrapper fix
sebidoe Jul 6, 2022
7ffd1af
Fix mypy mario
Jul 6, 2022
581f33d
Merge remote-tracking branch 'origin/Codestyle' into Codestyle
Jul 6, 2022
e715ad7
mypy dmc walker
sebidoe Jul 6, 2022
3ab433d
Merge branch 'Codestyle' of github.com:automl/CARL into Codestyle
sebidoe Jul 6, 2022
99a5355
mypy dmc loader
sebidoe Jul 6, 2022
7a6d54b
Fix mypy mario
Jul 6, 2022
a7dc611
Merge remote-tracking branch 'origin/Codestyle' into Codestyle
Jul 6, 2022
bc5c834
mypy dmc
sebidoe Jul 6, 2022
2c7f018
Merge branch 'Codestyle' of github.com:automl/CARL into Codestyle
sebidoe Jul 6, 2022
1780f5d
Add changelog.md
Jul 6, 2022
db95fa7
Add S.D. to authors
Jul 6, 2022
e239d32
Update version
Jul 6, 2022
119a589
mario everything except from env done
amsks Jul 6, 2022
c7fdc2a
Merge remote-tracking branch 'origin/Codestyle' into Codestyle
amsks Jul 6, 2022
352ba37
mario_env done
amsks Jul 6, 2022
ad5f9a4
Update setup.py
Jul 6, 2022
7b57015
Update gym version
Jul 6, 2022
8d17051
Remove RNA
Jul 6, 2022
b0e044c
mypy corrected for everything except carl_rna
amsks Jul 6, 2022
032dbc9
Merge pull request #61 from automl/remove_rna_env
sebidoe Jul 6, 2022
f613d9b
gitignore
sebidoe Jul 6, 2022
e042843
Merge branch 'version_0.2.0' of github.com:automl/CARL into version_0…
sebidoe Jul 6, 2022
9080c28
Fix mypy
Jul 6, 2022
6c9411b
Change type of contexts to Contexts
Jul 6, 2022
4d759d3
Change type of default_context to Context
Jul 6, 2022
0bc456f
black, isort and flake8
sebidoe Jul 6, 2022
b86be63
Update try_dm_control.py
sebidoe Jul 6, 2022
deb6731
Update try_dm_control.py
sebidoe Jul 6, 2022
c3ae919
Merge pull request #62 from automl/Codestyle
sebidoe Jul 6, 2022
abe7f4e
Fix pre-commit
Jul 7, 2022
90cb915
Update changelog.md
Jul 7, 2022
e2bc9ea
Update changelog.md
Jul 7, 2022
4f69458
Merge remote-tracking branch 'origin/version_0.2.0' into version_0.2.0
Jul 7, 2022
344b5cc
Update changelog.md
Jul 7, 2022
0786b38
Fix tests
Jul 8, 2022
f464d38
Fix dist check
Jul 8, 2022
8343d80
Fix mypy
Jul 8, 2022
44e2a1b
Format isort
Jul 8, 2022
6540ede
Remove setup packages for experiments
Jul 8, 2022
5b6618b
Remove requirements for rna
Jul 8, 2022
aca24aa
Update requirements
Jul 8, 2022
e556b78
Remove RNA
Jul 8, 2022
0d137d6
Fix tests.yaml
Jul 8, 2022
f16dc89
Remove operating system warning
Jul 8, 2022
468764b
Add test for dmc loader
Jul 8, 2022
39996d0
Move to examples
Jul 8, 2022
9c4ed0f
Add requirement
Jul 12, 2022
a533fd4
Remove requirement
Jul 12, 2022
ce969ff
Update tests.yaml
Jul 12, 2022
1a231f3
Fix whitespace in tests.yaml
Jul 12, 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
11 changes: 8 additions & 3 deletions .github/workflows/dist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,18 @@ jobs:
- name: Twine check
run: |
pip install twine
last_dist=$(ls -t dist/CARL-*.tar.gz | head -n 1)
last_dist=$(ls -t dist/carl-*.tar.gz | head -n 1)
twine_output=`twine check "$last_dist"`
if [[ "$twine_output" != "Checking $last_dist: PASSED" ]]; then echo $twine_output && exit 1;fi
if [[ "$twine_output" != "Checking $last_dist: PASSED" ]]
then
echo $twine_output
else
pip install $last_dist
fi

- name: Install dist
run: |
last_dist=$(ls -t dist/CARL-*.tar.gz | head -n 1)
last_dist=$(ls -t dist/carl-*.tar.gz | head -n 1)
pip install $last_dist

- name: PEP 561 Compliance
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,21 @@ jobs:
# Miniconda is available in $CONDA env var
$CONDA/bin/conda create -n testenv --yes pip wheel gxx_linux-64 gcc_linux-64 python=${{ matrix.python-version }}
$CONDA/envs/testenv/bin/python3 -m pip install --upgrade pip
$CONDA/envs/testenv/bin/pip3 install -e .[dev]
$CONDA/envs/testenv/bin/pip3 install -e .[dev,dm_control]

- name: Source install
if: matrix.kind == 'source'
run: |
python -m pip install --upgrade pip
pip install -e .[dev]
pip install -e .[dev,dm_control]

- name: Dist install
if: matrix.kind == 'dist'
run: |
python -m pip install --upgrade pip
python setup.py sdist
last_dist=$(ls -t dist/CARL-*.tar.gz | head -n 1)
pip install $last_dist[dev]
last_dist=$(ls -t dist/carl-*.tar.gz | head -n 1)
pip install $last_dist[dev,dm_control]

- name: Tests
timeout-minutes: 60
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ carl/runscripts/generated
docs/html
docs/apidoc
CARL.egg-info
carl.egg-info
.mypy_cache
.pytest_cache
.coverage
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repos:
args: [--check]

- repo: https://github.com/ambv/black
rev: 21.12b0
rev: 22.6.0
hooks:
- id: black
name: black formatter carl
Expand Down
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ Benchmarks include:
- [Super Mario (TOAD-GAN)](https://github.com/Mawiszus/TOAD-GAN), a procedurally generated jump'n'run game with control
over level similarity

- [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)
Expand All @@ -44,7 +41,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, dm_control]
pip install -e .[box2d, brax, mario, dm_control]
```

These may not be compatible with Windows systems. Box2D environment may need to be installed via conda on MacOS systems:
Expand All @@ -60,9 +57,6 @@ To install the additional requirements for ToadGAN:
javac carl/envs/mario/Mario-AI-Framework/**/*.java
```

If you want to use the RNA design environment, you also need to download the RNA data
in addition to installing the dependencies. Please follow the instructions in carl/envs/rna.

## CARL's Contextual Extension
CARL contextually extends the environment by making the context visible and configurable.
During training we therefore can encounter different contexts and train for generalization.
Expand Down Expand Up @@ -95,8 +89,6 @@ Benchmarking Track)](https://arxiv.org/pdf/2106.13281.pdf)
[TOAD-GAN: Coherent Style Level Generation from a Single Example,
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
Expand Down
24 changes: 21 additions & 3 deletions carl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
__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"
__version__ = "0.2.0"
__author__ = "Carolin Benjamins, Theresa Eimer, Frederik Schubert, André Biedenkapp, Aditya Mohan, Sebastian Döhler"


import datetime

name = "CARL"
package_name = "carl"
author = __author__

author_email = "benjamins@tnt.uni-hannover.de"
description = "CARL- Contextually Adaptive Reinforcement Learning"
url = "https://www.automl.org/"
project_urls = {
"Documentation": "https://carl.readthedocs.io/en/latest/",
"Source Code": "https://github.com/https://github.com/automl/CARL",
}
copyright = f"""
Copyright {datetime.date.today().strftime('%Y')}, AutoML.org Freiburg-Hannover
"""
version = __version__
7 changes: 3 additions & 4 deletions carl/context/augmentation.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from typing import List, Union
from typing import Any, List, Union

import numpy as np


def add_gaussian_noise(
default_value: Union[float, List[float]],
percentage_std: float = 0.01,
percentage_std: Union[float, Any] = 0.01,
random_generator: np.random.Generator = None,
) -> Union[float, List[float]]:
) -> Union[float, Any]:
"""
Add gaussian noise to default value.

Expand Down Expand Up @@ -45,7 +45,6 @@ def add_gaussian_noise(

seed = 123456
rng = np.random.default_rng(seed=seed)
default_value = 10
default_value = list(np.arange(0, 4))
percentage_std = 0.01
n_samples = 1000
Expand Down
7 changes: 4 additions & 3 deletions carl/context/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from scipy.stats import norm

from carl import envs
from carl.utils.types import Context, Contexts


def get_default_context_and_bounds(
Expand Down Expand Up @@ -145,9 +146,9 @@ def sample_contexts(
sample_dists[context_feature_name] = (random_variable, context_feature_type)

# Sample contexts
contexts = {}
contexts: Contexts = {}
for i in range(0, num_contexts):
c = {}
c: Context = {}
# k = name of context feature
for k in env_defaults.keys():
if k in sample_dists.keys():
Expand All @@ -157,7 +158,7 @@ def sample_contexts(
lower_bound, upper_bound = env_bounds[k][0], env_bounds[k][1]
if context_feature_type == list:
length = np.random.randint(
5e5
500000
) # TODO should we allow lists to be this long? or should we parametrize this?
arg_class = sample_dists[k][1][1]
context_list = random_variable.rvs(size=length)
Expand Down
24 changes: 12 additions & 12 deletions carl/context/selection.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from abc import abstractmethod
from typing import Any, Callable, Dict, List, Optional, Tuple
from typing import Any, Callable, List, Optional, Tuple

import numpy as np

from carl.utils.types import Context
from carl.utils.types import Context, Contexts


class AbstractSelector(object):
Expand All @@ -15,13 +15,13 @@ class AbstractSelector(object):

Parameters
----------
contexts: Dict[Any, Context]
contexts: Contexts
Context set. A `Context` is a Dict[str, Any].


Attributes
----------
contexts : Dict[Any, Context]
contexts : Contexts
Context set.
context_ids : List[int]
Integer index for contexts.
Expand All @@ -34,8 +34,8 @@ class AbstractSelector(object):

"""

def __init__(self, contexts: Dict[Any, Context]):
self.contexts: Dict[Any, Context] = contexts
def __init__(self, contexts: Contexts):
self.contexts: Contexts = contexts
self.context_ids: List[int] = list(np.arange(len(contexts)))
self.contexts_keys: List[Any] = list(contexts.keys())
self.n_calls: int = 0
Expand Down Expand Up @@ -79,7 +79,7 @@ class RandomSelector(AbstractSelector):
Random Context Selector.
"""

def _select(self):
def _select(self) -> Tuple[Context, int]:
# TODO seed?
context_id = np.random.choice(self.context_ids)
context = self.contexts[self.contexts_keys[context_id]]
Expand All @@ -93,7 +93,7 @@ class RoundRobinSelector(AbstractSelector):
Iterate through all contexts and then start at the first again.
"""

def _select(self):
def _select(self) -> Tuple[Context, int]:
if self.context_id is None:
self.context_id = -1
self.context_id = (self.context_id + 1) % len(self.contexts)
Expand All @@ -110,7 +110,7 @@ class CustomSelector(AbstractSelector):

Parameters
----------
contexts: Dict[Any, Context]
contexts: Contexts
Set of contexts.
selector_function: callable
Function receiving a pointer to the selector implementing selection logic.
Expand All @@ -133,13 +133,13 @@ class CustomSelector(AbstractSelector):

def __init__(
self,
contexts: Dict[Any, Context],
contexts: Contexts,
selector_function: Callable[[AbstractSelector], Tuple[Context, int]],
):
super().__init__(contexts=contexts)
self.selector_function = selector_function

def _select(self):
context, context_id = self.selector_function(inst=self)
def _select(self) -> Tuple[Context, int]:
context, context_id = self.selector_function(self)
self.context_id = context_id
return context, context_id
30 changes: 15 additions & 15 deletions carl/context/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import Dict, List, Tuple
from typing import Any, Dict, List, Tuple, Type

import numpy as np


def get_context_bounds(
context_keys: List[str], context_bounds: Dict[str, Tuple[float, float, float]]
context_keys: List[str], context_bounds: Dict[str, Tuple[float, float, Type[Any]]]
) -> Tuple[np.ndarray, np.ndarray]:
"""
Get context bounds for specific features.
Expand All @@ -15,7 +15,7 @@ def get_context_bounds(
----------
context_keys: List[str]
Names of context features.
context_bounds: Dict[str, Tuple[float, float, float]]
context_bounds: Dict[str, Tuple[float, float, type]]
Dictionary containing lower and upper bound as a tuple, e.g., "context_feature_name": (-np.inf, np.inf)).

Returns
Expand All @@ -28,7 +28,7 @@ def get_context_bounds(
upper_bounds = np.empty(shape=len(context_keys))

for i, context_key in enumerate(context_keys):
l, u, _ = context_bounds[context_key]
l, u, dtype = context_bounds[context_key]
lower_bounds[i] = l
upper_bounds[i] = u

Expand All @@ -51,16 +51,16 @@ def get_context_bounds(
}

CONTEXT_BOUNDS = {
"min_position": (-np.inf, np.inf),
"max_position": (-np.inf, np.inf),
"max_speed": (0, np.inf),
"goal_position": (-np.inf, np.inf),
"goal_velocity": (-np.inf, np.inf),
"force": (-np.inf, np.inf),
"gravity": (0, np.inf),
"min_position_start": (-np.inf, np.inf),
"max_position_start": (-np.inf, np.inf),
"min_velocity_start": (-np.inf, np.inf),
"max_velocity_start": (-np.inf, np.inf),
"min_position": (-np.inf, np.inf, float),
"max_position": (-np.inf, np.inf, float),
"max_speed": (0, np.inf, float),
"goal_position": (-np.inf, np.inf, float),
"goal_velocity": (-np.inf, np.inf, float),
"force": (-np.inf, np.inf, float),
"gravity": (0, np.inf, float),
"min_position_start": (-np.inf, np.inf, float),
"max_position_start": (-np.inf, np.inf, float),
"min_velocity_start": (-np.inf, np.inf, float),
"max_velocity_start": (-np.inf, np.inf, float),
}
lower, upper = get_context_bounds(list(DEFAULT_CONTEXT.keys()), CONTEXT_BOUNDS)
17 changes: 4 additions & 13 deletions carl/envs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# flake8: noqa: F401
# Modular imports
import importlib
import importlib.util as iutil
import warnings

# Classic control is in gym and thus necessary for the base version to run
from carl.envs.classic_control import *

# Environment loading
box2d_spec = importlib.util.find_spec("Box2D")
box2d_spec = iutil.find_spec("Box2D")
found = box2d_spec is not None
if found:
from carl.envs.box2d import *
Expand All @@ -16,7 +16,7 @@
"Module 'Box2D' not found. If you want to use these environments, please follow the installation guide."
)

brax_spec = importlib.util.find_spec("brax")
brax_spec = iutil.find_spec("brax")
found = brax_spec is not None
if found:
from carl.envs.brax import *
Expand All @@ -34,16 +34,7 @@
"Module 'Mario' not found. Please follow installation guide for ToadGAN environment."
)

RNA_spec = importlib.util.find_spec("viennarna")
found = RNA_spec is not None
if found:
from carl.envs.rna import *
else:
warnings.warn(
"Module 'RNA' not found. Please follow installation guide for RNA environment."
)

dm_control_spec = importlib.util.find_spec("dm_control")
dm_control_spec = iutil.find_spec("dm_control")
found = dm_control_spec is not None
if found:
from carl.envs.dmc import *
Expand Down
Loading