Skip to content

Commit 3707750

Browse files
benjamcCarolin Benjaminsamskssebidoe
authored
Version 0.2.0 (#63)
* Update twine check * Fix return type * Annotate inits * Annotate args * carl/context mypy fixed * Fix mypy * Handle return types of gym.Env in reset * Fix mypy for carl_env.py * Correct reset function * Fix mypy * Fix mypy brax * Fix mypy brax * Moved demo to examples * Update reset signature * Remove rendering of score label In the current gym version, there is no score label. * Fix mypy box2d * Move CARLVehicleRacing example * Update carracing example * Fix mypy box2d * Fix mypy * Fix mypy * Update reset function * mypy dmc fish * mypy dmc quadruped * mypy dmc context utils * wrapper fix * Fix mypy mario * mypy dmc walker * mypy dmc loader * Fix mypy mario * mypy dmc * Add changelog.md * Add S.D. to authors * Update version * mario everything except from env done * mario_env done * Update setup.py Remove setup.cfg and fill init with more info. * Update gym version * Remove RNA * mypy corrected for everything except carl_rna * gitignore * Fix mypy * Change type of contexts to Contexts * Change type of default_context to Context * black, isort and flake8 * Update try_dm_control.py * Update try_dm_control.py * Fix pre-commit * Update changelog.md * Update changelog.md * Update changelog.md * Fix tests * Fix dist check * Fix mypy * Format isort * Remove setup packages for experiments No experiments in this branch * Remove requirements for rna * Update requirements * Remove RNA * Fix tests.yaml * Remove operating system warning * Add test for dmc loader * Move to examples * Add requirement * Remove requirement * Update tests.yaml * Fix whitespace in tests.yaml Co-authored-by: Carolin Benjamins <benjamins@tnt.uni-hannover.de> Co-authored-by: amsks <adityak735@gmail.com> Co-authored-by: Sebastian Döhler <sebastiandoehler@hotmail.de> Co-authored-by: sebidoe <45859263+sebidoe@users.noreply.github.com>
1 parent 43cf6fd commit 3707750

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1019
-991
lines changed

.github/workflows/dist.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,18 @@ jobs:
3838
- name: Twine check
3939
run: |
4040
pip install twine
41-
last_dist=$(ls -t dist/CARL-*.tar.gz | head -n 1)
41+
last_dist=$(ls -t dist/carl-*.tar.gz | head -n 1)
4242
twine_output=`twine check "$last_dist"`
43-
if [[ "$twine_output" != "Checking $last_dist: PASSED" ]]; then echo $twine_output && exit 1;fi
43+
if [[ "$twine_output" != "Checking $last_dist: PASSED" ]]
44+
then
45+
echo $twine_output
46+
else
47+
pip install $last_dist
48+
fi
4449
4550
- name: Install dist
4651
run: |
47-
last_dist=$(ls -t dist/CARL-*.tar.gz | head -n 1)
52+
last_dist=$(ls -t dist/carl-*.tar.gz | head -n 1)
4853
pip install $last_dist
4954
5055
- name: PEP 561 Compliance

.github/workflows/tests.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,21 @@ jobs:
8585
# Miniconda is available in $CONDA env var
8686
$CONDA/bin/conda create -n testenv --yes pip wheel gxx_linux-64 gcc_linux-64 python=${{ matrix.python-version }}
8787
$CONDA/envs/testenv/bin/python3 -m pip install --upgrade pip
88-
$CONDA/envs/testenv/bin/pip3 install -e .[dev]
88+
$CONDA/envs/testenv/bin/pip3 install -e .[dev,dm_control]
8989
9090
- name: Source install
9191
if: matrix.kind == 'source'
9292
run: |
9393
python -m pip install --upgrade pip
94-
pip install -e .[dev]
94+
pip install -e .[dev,dm_control]
9595
9696
- name: Dist install
9797
if: matrix.kind == 'dist'
9898
run: |
9999
python -m pip install --upgrade pip
100100
python setup.py sdist
101-
last_dist=$(ls -t dist/CARL-*.tar.gz | head -n 1)
102-
pip install $last_dist[dev]
101+
last_dist=$(ls -t dist/carl-*.tar.gz | head -n 1)
102+
pip install $last_dist[dev,dm_control]
103103
104104
- name: Tests
105105
timeout-minutes: 60

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ carl/runscripts/generated
1313
docs/html
1414
docs/apidoc
1515
CARL.egg-info
16+
carl.egg-info
1617
.mypy_cache
1718
.pytest_cache
1819
.coverage

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ repos:
1717
args: [--check]
1818

1919
- repo: https://github.com/ambv/black
20-
rev: 21.12b0
20+
rev: 22.6.0
2121
hooks:
2222
- id: black
2323
name: black formatter carl

README.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ Benchmarks include:
2121
- [Super Mario (TOAD-GAN)](https://github.com/Mawiszus/TOAD-GAN), a procedurally generated jump'n'run game with control
2222
over level similarity
2323

24-
- [RNADesign](https://github.com/automl/learna/), an environment for RNA design given structure
25-
constraints with structures from different datasets to choose from
26-
2724
- [dm_control](https://github.com/deepmind/dm_control), environments based on the MuJoCo physics engine. The environments are extended with different context features.
2825

2926
![Screenshot of each environment included in CARL.](./docs/source/figures/envs_overview.png)
@@ -44,7 +41,7 @@ pip install .
4441

4542
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:
4643
```bash
47-
pip install -e .[box2d, brax, rna, mario, dm_control]
44+
pip install -e .[box2d, brax, mario, dm_control]
4845
```
4946

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

63-
If you want to use the RNA design environment, you also need to download the RNA data
64-
in addition to installing the dependencies. Please follow the instructions in carl/envs/rna.
65-
6660
## CARL's Contextual Extension
6761
CARL contextually extends the environment by making the context visible and configurable.
6862
During training we therefore can encounter different contexts and train for generalization.
@@ -95,8 +89,6 @@ Benchmarking Track)](https://arxiv.org/pdf/2106.13281.pdf)
9589
[TOAD-GAN: Coherent Style Level Generation from a Single Example,
9690
Awiszus et al., AIIDE 2020](https://arxiv.org/pdf/2008.01531.pdf)
9791

98-
[Learning to Design RNA, Runge et al., ICRL 2019](https://arxiv.org/pdf/1812.11951.pdf)
99-
10092
[dm_control: Software and Tasks for Continuous Control](https://arxiv.org/pdf/2006.12983.pdf)
10193

10294
## License

carl/__init__.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
__copyright__ = "Copyright 2021, AutoML.org Freiburg-Hannover"
21
__license__ = "Apache-2.0 License"
3-
__version__ = "0.1"
4-
__author__ = "Carolin Benjamins, Theresa Eimer, Frederik Schubert, André Biedenkapp, Aditya Mohan"
2+
__version__ = "0.2.0"
3+
__author__ = "Carolin Benjamins, Theresa Eimer, Frederik Schubert, André Biedenkapp, Aditya Mohan, Sebastian Döhler"
4+
5+
6+
import datetime
7+
8+
name = "CARL"
9+
package_name = "carl"
10+
author = __author__
11+
12+
author_email = "benjamins@tnt.uni-hannover.de"
13+
description = "CARL- Contextually Adaptive Reinforcement Learning"
14+
url = "https://www.automl.org/"
15+
project_urls = {
16+
"Documentation": "https://carl.readthedocs.io/en/latest/",
17+
"Source Code": "https://github.com/https://github.com/automl/CARL",
18+
}
19+
copyright = f"""
20+
Copyright {datetime.date.today().strftime('%Y')}, AutoML.org Freiburg-Hannover
21+
"""
22+
version = __version__

carl/context/augmentation.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from typing import List, Union
1+
from typing import Any, List, Union
22

33
import numpy as np
44

55

66
def add_gaussian_noise(
77
default_value: Union[float, List[float]],
8-
percentage_std: float = 0.01,
8+
percentage_std: Union[float, Any] = 0.01,
99
random_generator: np.random.Generator = None,
10-
) -> Union[float, List[float]]:
10+
) -> Union[float, Any]:
1111
"""
1212
Add gaussian noise to default value.
1313
@@ -45,7 +45,6 @@ def add_gaussian_noise(
4545

4646
seed = 123456
4747
rng = np.random.default_rng(seed=seed)
48-
default_value = 10
4948
default_value = list(np.arange(0, 4))
5049
percentage_std = 0.01
5150
n_samples = 1000

carl/context/sampling.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from scipy.stats import norm
66

77
from carl import envs
8+
from carl.utils.types import Context, Contexts
89

910

1011
def get_default_context_and_bounds(
@@ -145,9 +146,9 @@ def sample_contexts(
145146
sample_dists[context_feature_name] = (random_variable, context_feature_type)
146147

147148
# Sample contexts
148-
contexts = {}
149+
contexts: Contexts = {}
149150
for i in range(0, num_contexts):
150-
c = {}
151+
c: Context = {}
151152
# k = name of context feature
152153
for k in env_defaults.keys():
153154
if k in sample_dists.keys():
@@ -157,7 +158,7 @@ def sample_contexts(
157158
lower_bound, upper_bound = env_bounds[k][0], env_bounds[k][1]
158159
if context_feature_type == list:
159160
length = np.random.randint(
160-
5e5
161+
500000
161162
) # TODO should we allow lists to be this long? or should we parametrize this?
162163
arg_class = sample_dists[k][1][1]
163164
context_list = random_variable.rvs(size=length)

carl/context/selection.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from abc import abstractmethod
2-
from typing import Any, Callable, Dict, List, Optional, Tuple
2+
from typing import Any, Callable, List, Optional, Tuple
33

44
import numpy as np
55

6-
from carl.utils.types import Context
6+
from carl.utils.types import Context, Contexts
77

88

99
class AbstractSelector(object):
@@ -15,13 +15,13 @@ class AbstractSelector(object):
1515
1616
Parameters
1717
----------
18-
contexts: Dict[Any, Context]
18+
contexts: Contexts
1919
Context set. A `Context` is a Dict[str, Any].
2020
2121
2222
Attributes
2323
----------
24-
contexts : Dict[Any, Context]
24+
contexts : Contexts
2525
Context set.
2626
context_ids : List[int]
2727
Integer index for contexts.
@@ -34,8 +34,8 @@ class AbstractSelector(object):
3434
3535
"""
3636

37-
def __init__(self, contexts: Dict[Any, Context]):
38-
self.contexts: Dict[Any, Context] = contexts
37+
def __init__(self, contexts: Contexts):
38+
self.contexts: Contexts = contexts
3939
self.context_ids: List[int] = list(np.arange(len(contexts)))
4040
self.contexts_keys: List[Any] = list(contexts.keys())
4141
self.n_calls: int = 0
@@ -79,7 +79,7 @@ class RandomSelector(AbstractSelector):
7979
Random Context Selector.
8080
"""
8181

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

96-
def _select(self):
96+
def _select(self) -> Tuple[Context, int]:
9797
if self.context_id is None:
9898
self.context_id = -1
9999
self.context_id = (self.context_id + 1) % len(self.contexts)
@@ -110,7 +110,7 @@ class CustomSelector(AbstractSelector):
110110
111111
Parameters
112112
----------
113-
contexts: Dict[Any, Context]
113+
contexts: Contexts
114114
Set of contexts.
115115
selector_function: callable
116116
Function receiving a pointer to the selector implementing selection logic.
@@ -133,13 +133,13 @@ class CustomSelector(AbstractSelector):
133133

134134
def __init__(
135135
self,
136-
contexts: Dict[Any, Context],
136+
contexts: Contexts,
137137
selector_function: Callable[[AbstractSelector], Tuple[Context, int]],
138138
):
139139
super().__init__(contexts=contexts)
140140
self.selector_function = selector_function
141141

142-
def _select(self):
143-
context, context_id = self.selector_function(inst=self)
142+
def _select(self) -> Tuple[Context, int]:
143+
context, context_id = self.selector_function(self)
144144
self.context_id = context_id
145145
return context, context_id

carl/context/utils.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from typing import Dict, List, Tuple
1+
from typing import Any, Dict, List, Tuple, Type
22

33
import numpy as np
44

55

66
def get_context_bounds(
7-
context_keys: List[str], context_bounds: Dict[str, Tuple[float, float, float]]
7+
context_keys: List[str], context_bounds: Dict[str, Tuple[float, float, Type[Any]]]
88
) -> Tuple[np.ndarray, np.ndarray]:
99
"""
1010
Get context bounds for specific features.
@@ -15,7 +15,7 @@ def get_context_bounds(
1515
----------
1616
context_keys: List[str]
1717
Names of context features.
18-
context_bounds: Dict[str, Tuple[float, float, float]]
18+
context_bounds: Dict[str, Tuple[float, float, type]]
1919
Dictionary containing lower and upper bound as a tuple, e.g., "context_feature_name": (-np.inf, np.inf)).
2020
2121
Returns
@@ -28,7 +28,7 @@ def get_context_bounds(
2828
upper_bounds = np.empty(shape=len(context_keys))
2929

3030
for i, context_key in enumerate(context_keys):
31-
l, u, _ = context_bounds[context_key]
31+
l, u, dtype = context_bounds[context_key]
3232
lower_bounds[i] = l
3333
upper_bounds[i] = u
3434

@@ -51,16 +51,16 @@ def get_context_bounds(
5151
}
5252

5353
CONTEXT_BOUNDS = {
54-
"min_position": (-np.inf, np.inf),
55-
"max_position": (-np.inf, np.inf),
56-
"max_speed": (0, np.inf),
57-
"goal_position": (-np.inf, np.inf),
58-
"goal_velocity": (-np.inf, np.inf),
59-
"force": (-np.inf, np.inf),
60-
"gravity": (0, np.inf),
61-
"min_position_start": (-np.inf, np.inf),
62-
"max_position_start": (-np.inf, np.inf),
63-
"min_velocity_start": (-np.inf, np.inf),
64-
"max_velocity_start": (-np.inf, np.inf),
54+
"min_position": (-np.inf, np.inf, float),
55+
"max_position": (-np.inf, np.inf, float),
56+
"max_speed": (0, np.inf, float),
57+
"goal_position": (-np.inf, np.inf, float),
58+
"goal_velocity": (-np.inf, np.inf, float),
59+
"force": (-np.inf, np.inf, float),
60+
"gravity": (0, np.inf, float),
61+
"min_position_start": (-np.inf, np.inf, float),
62+
"max_position_start": (-np.inf, np.inf, float),
63+
"min_velocity_start": (-np.inf, np.inf, float),
64+
"max_velocity_start": (-np.inf, np.inf, float),
6565
}
6666
lower, upper = get_context_bounds(list(DEFAULT_CONTEXT.keys()), CONTEXT_BOUNDS)

0 commit comments

Comments
 (0)