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

Rework Envs #89

Merged
merged 474 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
474 commits
Select commit Hold shift + click to select a range
c5a160a
Fix pre-commit
Jul 12, 2022
8dde8c6
Add finger dmc (#67)
benjamc Sep 13, 2022
3397f14
Fix format, fix tests (#73)
benjamc Nov 3, 2022
901d55e
added rna files
amsks Dec 6, 2022
ea135aa
RNA design environmentclear
amsks Dec 20, 2022
3cfba72
added obs_low and obs_high to class arguments
amsks Dec 20, 2022
997b14a
started editing rna_env
amsks Dec 20, 2022
ff92e5f
mypy the main files
amsks Feb 16, 2023
3846844
fixed docstrings
amsks Feb 16, 2023
42ec7cb
Update changelog.md
benjamc Feb 17, 2023
5e16a7c
Update figures
Feb 22, 2023
7e8e03a
removed carl_rna issues
amsks Feb 22, 2023
3d79a0e
pre-commit issues fixed
amsks Feb 22, 2023
d8bb5fe
Update to gymnasium (#82)
Arman717 Apr 19, 2023
b0ea04c
Remove RNA
Jul 6, 2022
49485b8
Fix return type
Jul 6, 2022
7d22cc4
Annotate inits
Jul 6, 2022
d880656
Annotate args
Jul 6, 2022
1a596e7
Fix mypy
Jul 6, 2022
b40627d
Fix mypy
Jul 6, 2022
b581cb1
black, isort and flake8
sebidoe Jul 6, 2022
db3f8cd
Version 0.2.0 (#63)
benjamc Jul 12, 2022
77fdf59
Update changelog.md
Jul 12, 2022
4a1c83e
added rna files
amsks Dec 6, 2022
0e93236
RNA design environmentclear
amsks Dec 20, 2022
9a495c7
started editing rna_env
amsks Dec 20, 2022
ac2d61a
mypy the main files
amsks Feb 16, 2023
97c7ae8
removed carl_rna issues
amsks Feb 22, 2023
1755b2a
pre-commit issues fixed
amsks Feb 22, 2023
af2c052
Update to gymnasium (#82)
Arman717 Apr 19, 2023
884437b
Update changelog.md
benjamc Apr 19, 2023
2e9b416
formatting update
TheEimer Jun 9, 2023
0ea79bc
more merging
TheEimer Jul 20, 2023
d7fdbe0
added new brax envs
amsks Jul 14, 2023
222567e
Changed citation in README
amsks Jul 14, 2023
9ddc226
updated gitignore
amsks Jul 14, 2023
8ff30b0
added dmc updates
amsks Jul 14, 2023
22e749c
Update dependencies
benjamc Jul 17, 2023
c311939
New carl env
Jun 12, 2023
07de8ec
Format
Jun 12, 2023
d694ce6
Current
benjamc Jul 7, 2023
63622e7
Convert carracing (rendering broken)
benjamc Jul 10, 2023
98788ed
Update Brax Envs
benjamc Jul 12, 2023
c842f79
Dmc new format
TheEimer Jul 11, 2023
baa5b34
Mario changes *untested bc not mac compatible*
TheEimer Jul 11, 2023
9c348cc
Add Brax prefix to class names
benjamc Jul 12, 2023
74807df
removed context mask from dmc
TheEimer Jul 13, 2023
b8cf568
import updates for mario + rna
TheEimer Jul 13, 2023
fe76e58
remove mario for now
TheEimer Jul 13, 2023
ed0cf69
Fix brax context space
benjamc Jul 13, 2023
ada08c5
Prettify spec checking
benjamc Jul 13, 2023
414a6d5
Make format
benjamc Jul 13, 2023
b311d7e
specify mario install issues
TheEimer Jul 13, 2023
c97b321
Fix tests
benjamc Jul 13, 2023
da6dc5d
Update setup.py
Jul 6, 2022
9973f6b
mario everything except from env done
amsks Jul 6, 2022
4e75b26
black, isort and flake8
sebidoe Jul 6, 2022
3c205b1
RNA design environmentclear
amsks Dec 20, 2022
f8018f1
merge with dev
TheEimer Jul 17, 2023
d984f0a
test passing after merge
TheEimer Jul 20, 2023
74664e0
Update setup.py
Jul 6, 2022
d36966b
Update gym version
Jul 6, 2022
27205da
Remove RNA
Jul 6, 2022
2627738
Fix mypy
Jul 6, 2022
746dce0
Fix mypy brax
Jul 6, 2022
57c92a3
Fix mypy
Jul 6, 2022
b03316b
Fix mypy
Jul 6, 2022
83b486d
Fix mypy mario
Jul 6, 2022
ad84def
mario everything except from env done
amsks Jul 6, 2022
c810d62
Fix mypy mario
Jul 6, 2022
f3d5509
mario_env done
amsks Jul 6, 2022
1b70d94
mypy corrected for everything except carl_rna
amsks Jul 6, 2022
42fa7e3
Change type of contexts to Contexts
Jul 6, 2022
d826917
black, isort and flake8
sebidoe Jul 6, 2022
6be9ee2
Fix pre-commit
Jul 7, 2022
8393aa2
Fix dist check
Jul 8, 2022
d8ba4a6
Remove setup packages for experiments
Jul 8, 2022
d76ea10
Remove requirements for rna
Jul 8, 2022
8d61252
Update requirements
Jul 8, 2022
b3a78f4
Add requirement
Jul 12, 2022
f4d5677
Remove requirement
Jul 12, 2022
3c6bcf7
Add sphinx theme to dev dependencies
TheEimer Feb 15, 2023
4f8dc79
Fix docs installation
TheEimer Feb 15, 2023
f60a46e
Fix file structure for doc build attempt
TheEimer Feb 16, 2023
791c108
makefile resolve
TheEimer Feb 17, 2023
f6a063f
move docs from smac to automl theme
TheEimer Feb 17, 2023
217f87c
add docs make all for global makefile
TheEimer Feb 17, 2023
e97c204
removed duplicated api file
TheEimer Feb 17, 2023
81b22a6
Update dist names
Jul 12, 2022
f072206
Fix pre-commit
Jul 12, 2022
4dda189
Update changelog.md
Jul 12, 2022
063d2e5
Remove entry points
Jul 12, 2022
5133d65
Fix gym version
benjamc Jul 21, 2022
3a8819f
Fix gym version
benjamc Jul 21, 2022
1d2773e
Add finger dmc (#67)
benjamc Sep 13, 2022
e21c69b
Fix format, fix tests (#73)
benjamc Nov 3, 2022
342e3d3
added rna files
amsks Dec 6, 2022
46818d3
updated the download eterna file
amsks Dec 12, 2022
501ad08
RNA design environmentclear
amsks Dec 20, 2022
f0c808d
mypy the main files
amsks Feb 16, 2023
75b284a
fixed docstrings
amsks Feb 16, 2023
23f1bee
Add files via upload
benjamc Feb 22, 2023
b13cda8
Update figures
Feb 22, 2023
df3e1de
removed carl_rna issues
amsks Feb 22, 2023
584e64b
pre-commit issues fixed
amsks Feb 22, 2023
5f3ce89
Fix ranges for brax package
Apr 4, 2023
844a57d
Update to gymnasium (#82)
Arman717 Apr 19, 2023
398e8c4
Add changelog.md
Jul 6, 2022
9e73524
Update setup.py
Jul 6, 2022
3e92ec0
Update gym version
Jul 6, 2022
2e9bf0d
Remove RNA
Jul 6, 2022
f48566e
Fix return type
Jul 6, 2022
9b469f6
Annotate inits
Jul 6, 2022
8029925
Annotate args
Jul 6, 2022
1ff5ebf
Fix mypy brax
Jul 6, 2022
cd6db2f
Fix mypy
Jul 6, 2022
af51c50
Fix mypy
Jul 6, 2022
7761d99
Fix mypy mario
Jul 6, 2022
ed7222a
mario everything except from env done
amsks Jul 6, 2022
c79b4b7
Fix mypy mario
Jul 6, 2022
4d962d9
mario_env done
amsks Jul 6, 2022
4f01b0a
mypy corrected for everything except carl_rna
amsks Jul 6, 2022
c9eda26
black, isort and flake8
sebidoe Jul 6, 2022
5cae041
Update changelog.md
Jul 7, 2022
eb88bef
Update changelog.md
Jul 7, 2022
dafa103
Update changelog.md
Jul 7, 2022
ea3a826
Fix dist check
Jul 8, 2022
c6c5a72
Update requirements
Jul 8, 2022
f31ba52
Fix tests.yaml
Jul 8, 2022
499cf96
Update tests.yaml
Jul 12, 2022
d811978
makefile resolve
TheEimer Feb 17, 2023
c3cc364
remove wayward merge string
TheEimer Jun 9, 2023
80a1071
Version 0.2.0 (#63)
benjamc Jul 12, 2022
854a5a2
Update dist names
Jul 12, 2022
fc2329b
Fix pre-commit
Jul 12, 2022
61fa410
Update changelog.md
Jul 12, 2022
5a3dc3d
added sh and util files for data
amsks Dec 6, 2022
a4c6290
added rna files
amsks Dec 6, 2022
30b58cd
updated the download eterna file
amsks Dec 12, 2022
1c68931
udpated parse_dor_brackets
amsks Dec 12, 2022
c30d6ec
RNA design environmentclear
amsks Dec 20, 2022
713c4c8
started editing rna_env
amsks Dec 20, 2022
7aa30c8
mypy the main files
amsks Feb 16, 2023
12a960c
Update changelog.md
benjamc Feb 17, 2023
210c81e
doc update
TheEimer Feb 17, 2023
79957d2
Add files via upload
benjamc Feb 22, 2023
1211d9f
Update figures
Feb 22, 2023
2bf8644
removed carl_rna issues
amsks Feb 22, 2023
66f685a
pre-commit issues fixed
amsks Feb 22, 2023
b40454c
Update to gymnasium (#82)
Arman717 Apr 19, 2023
86a2760
Update changelog.md
benjamc Apr 19, 2023
b12a5dc
formatting update
TheEimer Jun 9, 2023
670da1c
fixing dist + import
TheEimer Jun 9, 2023
e2ef9f7
fix package name
TheEimer Jun 9, 2023
3b7bd4e
precommit
TheEimer Jun 9, 2023
d3fe8a8
added dmc updates
amsks Jul 14, 2023
d368d96
Update dependencies
benjamc Jul 17, 2023
7ddc152
small fixes, added defaults to sampled contexts
becktepe Aug 3, 2023
6bf4585
removed debug statement
becktepe Aug 3, 2023
8c15e89
Remove RNA
Jul 6, 2022
54edc83
Fix mypy brax
Jul 6, 2022
e7d7ecc
Fix mypy
Jul 6, 2022
f4c459a
Fix mypy mario
Jul 6, 2022
e110d13
mario everything except from env done
amsks Jul 6, 2022
c46d8c9
Fix mypy mario
Jul 6, 2022
2085421
mario_env done
amsks Jul 6, 2022
83c5739
mypy corrected for everything except carl_rna
amsks Jul 6, 2022
a58ee4a
black, isort and flake8
sebidoe Jul 6, 2022
218ff93
Fix pre-commit
Jul 7, 2022
259a692
Format isort
Jul 8, 2022
de4940c
Add requirement
Jul 12, 2022
381f909
Remove requirement
Jul 12, 2022
ceaf27b
Add sphinx theme to dev dependencies
TheEimer Feb 15, 2023
a2de58b
Fix docs installation
TheEimer Feb 15, 2023
a1d7387
Fix file structure for doc build attempt
TheEimer Feb 16, 2023
e1de2a9
makefile resolve
TheEimer Feb 17, 2023
43d676e
move docs from smac to automl theme
TheEimer Feb 17, 2023
eda334c
add docs make all for global makefile
TheEimer Feb 17, 2023
2f08c38
removed duplicated api file
TheEimer Feb 17, 2023
d054646
Update dist names
Jul 12, 2022
0bb4c27
Fix pre-commit
Jul 12, 2022
f51e534
Fix format, fix tests (#73)
benjamc Nov 3, 2022
aa6addd
added rna files
amsks Dec 6, 2022
02bb64f
updated the download eterna file
amsks Dec 12, 2022
d4aa531
updated the download eterna file
amsks Dec 12, 2022
5956751
udpated parse_dor_brackets
amsks Dec 12, 2022
adc6d66
RNA design environmentclear
amsks Dec 20, 2022
f22f1b4
started editing rna_env
amsks Dec 20, 2022
8d0f9d5
mypy the main files
amsks Feb 16, 2023
3f8a03b
fixed docstrings
amsks Feb 16, 2023
e47b488
Add files via upload
benjamc Feb 22, 2023
bbf9c08
Update figures
Feb 22, 2023
9cc6793
removed carl_rna issues
amsks Feb 22, 2023
9fafdc1
pre-commit issues fixed
amsks Feb 22, 2023
ff5837c
Update to gymnasium (#82)
Arman717 Apr 19, 2023
1f3d9d0
Add changelog.md
Jul 6, 2022
ab82ed6
Update setup.py
Jul 6, 2022
5a9f3bb
Remove RNA
Jul 6, 2022
fc7fb66
Fix return type
Jul 6, 2022
9b40fdf
Annotate inits
Jul 6, 2022
7245ee4
Annotate args
Jul 6, 2022
760320a
Fix mypy brax
Jul 6, 2022
42fa115
Fix mypy
Jul 6, 2022
3d46108
Fix mypy mario
Jul 6, 2022
83d5ba2
mario everything except from env done
amsks Jul 6, 2022
9120043
Fix mypy mario
Jul 6, 2022
bcb5760
mario_env done
amsks Jul 6, 2022
637fc81
mypy corrected for everything except carl_rna
amsks Jul 6, 2022
2d6928b
black, isort and flake8
sebidoe Jul 6, 2022
6a04106
Update changelog.md
Jul 7, 2022
761c906
Update changelog.md
Jul 7, 2022
73793fd
Update changelog.md
Jul 7, 2022
623d96f
Fix dist check
Jul 8, 2022
fd94638
Update requirements
Jul 8, 2022
2b8a9af
Fix tests.yaml
Jul 8, 2022
da87e5d
Update tests.yaml
Jul 12, 2022
111fd42
makefile resolve
TheEimer Feb 17, 2023
689bd58
remove wayward merge string
TheEimer Jun 9, 2023
e145935
Version 0.2.0 (#63)
benjamc Jul 12, 2022
6cf422c
Update dist names
Jul 12, 2022
7bcc725
Fix pre-commit
Jul 12, 2022
778eb1e
Update changelog.md
Jul 12, 2022
24fb09d
added sh and util files for data
amsks Dec 6, 2022
f29d970
added rna files
amsks Dec 6, 2022
64f8bfe
updated the download eterna file
amsks Dec 12, 2022
d921c30
udpated parse_dor_brackets
amsks Dec 12, 2022
97c98a2
RNA design environmentclear
amsks Dec 20, 2022
f8e93c8
started editing rna_env
amsks Dec 20, 2022
191220a
mypy the main files
amsks Feb 16, 2023
cd575ae
Update changelog.md
benjamc Feb 17, 2023
7155511
Add files via upload
benjamc Feb 22, 2023
debf4b6
Update figures
Feb 22, 2023
9542451
removed carl_rna issues
amsks Feb 22, 2023
3c3254d
pre-commit issues fixed
amsks Feb 22, 2023
4630bf8
Update to gymnasium (#82)
Arman717 Apr 19, 2023
4d625b2
Update changelog.md
benjamc Apr 19, 2023
b601600
formatting update
TheEimer Jun 9, 2023
dfeb161
Fix tests
TheEimer Jun 9, 2023
2b6d127
fixing dist + import
TheEimer Jun 9, 2023
2434163
fix package name
TheEimer Jun 9, 2023
38bd9ad
precommit
TheEimer Jun 9, 2023
310642c
Merge branch 'development' into feature/envrework
benjamc Aug 8, 2023
252494d
Those files sneaked in
benjamc Aug 8, 2023
b579db8
Revert test carl env
benjamc Aug 8, 2023
839f31a
pre-cpmmit
TheEimer Aug 8, 2023
aa4f7e2
dependency + import issues for test
TheEimer Aug 8, 2023
1342095
omegaconf dependency
TheEimer Aug 8, 2023
bdd5793
key error in test
TheEimer Aug 8, 2023
d09e41b
Fix test
benjamc Aug 8, 2023
43b7cff
Merge branch 'feature/envrework' of github.com:automl/CARL into featu…
benjamc Aug 8, 2023
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
230 changes: 230 additions & 0 deletions carl/context/context_space.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
from __future__ import annotations

from typing import Any, List, Union

import gymnasium.spaces as spaces
import numpy as np
from ConfigSpace.configuration_space import Configuration, ConfigurationSpace
from ConfigSpace.hyperparameters import (
Hyperparameter,
NormalFloatHyperparameter,
NumericalHyperparameter,
UniformFloatHyperparameter,
)
from omegaconf import DictConfig
from search_space_encoding import search_space_to_config_space
from typing_extensions import TypeAlias

ContextFeature: TypeAlias = Hyperparameter


class ContextSpace(ConfigurationSpace):
"""
Baseclass for contexts of environments implemented in CARL. DO NOT USE DIRECTLY. USE SUBCLASSES!
"""

def __init__(
self,
context_space: Union[List[Hyperparameter], str, DictConfig, ConfigurationSpace]
| None = None,
context_features: List[str] | None = None,
name: str = "context_space",
seed: int = None,
):
super().__init__(name=name, seed=seed)

if isinstance(context_space, list):
self.add_hyperparameters(context_space)
else:
cs = search_space_to_config_space(context_space)
self.add_hyperparameters(cs.get_hyperparameters())

self._context_features: list[str] = context_features if context_features else []

def to_gym_space(
self, context_features: List[str] = None, as_dict: bool = False
) -> spaces.Space:
if context_features is None:
context_features = [hp.name for hp in self.get_hyperparameters()]

if as_dict:
context_space = {}

for context_feature in context_features:
hp = self.get_hyperparameter(context_feature)
if isinstance(hp, NumericalHyperparameter):
context_space[hp.name] = spaces.Box(low=hp.lower, high=hp.upper)
else:
raise ValueError(
f"Context features must be of type NumericalHyperparameter."
f"Got {type(hp)}."
)
return spaces.Dict(context_space)
else:
low = np.array(
[self.get_hyperparameter(cf).lower for cf in context_features]
)
high = np.array(
[self.get_hyperparameter(cf).upper for cf in context_features]
)

return spaces.Box(low=low, high=high, dtype=np.float32)

benjamc marked this conversation as resolved.
Show resolved Hide resolved
@property
def context_features(self) -> List[str]:
"""
Context features that are sampled.

Returns
-------
List[str]
Context features.
"""
return self._context_features

def sample_configuration(
self, size: int = 1
) -> Union[Configuration, List[Configuration]]:
"""
Samples values for all active context features. For all other values default is used.

Parameters
----------
size : int = 1
Number of contexts to sample.

Returns
-------
Union[Configuration, List[Configuration]]
Sampled contexts.
"""

def insert_defaults(cfg: Configuration) -> Configuration:
values = cfg.get_dictionary()
for feature in values.keys():
if feature not in self._context_features:
values[feature] = self.get_hyperparameter(feature).default_value

return Configuration(self, values=values)

configurations = super().sample_configuration(size=size)

if size == 1:
configurations = insert_defaults(configurations)
else:
for i, configuration in enumerate(configurations):
configurations[i] = insert_defaults(configuration)

return configurations


class CartPoleContextSpace(ContextSpace):
"""
Context space for CARLCartPoleEnv.

Parameters
----------
context_features : List[str]
Context features to vary, i.e. sample.

seed : int = None
Seed for PRNG.
"""

def __init__(
self,
context_space: Union[List[Hyperparameter], str, DictConfig, ConfigurationSpace]
| None = None,
context_features: List[str] | None = None,
seed: int = None,
):
if context_space is None:
context_space = CartPoleContextSpace.get_default()
super().__init__(
context_space, context_features, name=self.__class__.__name__, seed=seed
)

@staticmethod
def get_default() -> list[ContextFeature]:
"""Get context features with default values

Returns
-------
list[ContextFeature]
List of context features
"""
return [
UniformFloatHyperparameter(
"gravity", lower=0.1, upper=np.inf, default_value=9.8
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ask Eddie about np.inf as bounds in uniform

),
UniformFloatHyperparameter(
"masscart", lower=0.1, upper=10, default_value=1.0
),
UniformFloatHyperparameter(
"masspole", lower=0.01, upper=1, default_value=0.1
),
UniformFloatHyperparameter(
"pole_length", lower=0.05, upper=5, default_value=0.5
),
UniformFloatHyperparameter(
"force_magnifier", lower=1, upper=100, default_value=10.0
),
UniformFloatHyperparameter(
"update_interval", lower=0.002, upper=0.2, default_value=0.02
),
UniformFloatHyperparameter(
"initial_state_lower", lower=-10, upper=10, default_value=-0.1
),
UniformFloatHyperparameter(
"initial_state_upper", lower=-10, upper=10, default_value=0.1
), # TODO: We can't have inf. How to handle/annotate when transforming to obs space?
]

def verify(self, configspace: ConfigurationSpace) -> bool:
# TODO Check whether HPs in of configspace in self.hyperparameters included
...


class ContextSampler(ConfigurationSpace):
def __init__(
self,
context_distributions: Union[
List[Hyperparameter], str, DictConfig, ConfigurationSpace
],
seed: int,
):
self.context_distributions = context_distributions
# TODO: pass seed
...

def add_defaults(context_space: ContextSpace):
"""Add defaults from env context space

Parameters
----------
context_space : ContextSpace
_description_
"""
...

def sample_contexts(self, n_contexts: int) -> dict[int, dict[str, Any]]:
contexts = self.sample_configuration(size=n_contexts)
contexts = {i: C for i, C in enumerate(contexts)}
return contexts


if __name__ == "__main__":
print("hello world")
context_space = CartPoleContextSpace()
print(context_space)
context = context_space.sample_configuration()
print(context)

context_sampler = ContextSampler(
[
NormalFloatHyperparameter("gravity", mu=9.8, sigma=1),
],
seed=0,
)

contexts = context_sampler.sample_contexts(n_contexts=10)
142 changes: 142 additions & 0 deletions carl/context/search_space_encoding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
from __future__ import annotations

from typing import Any, Union

import json

from ConfigSpace import ConfigurationSpace # type: ignore[import]
from ConfigSpace.read_and_write import json as csjson # type: ignore[import]
from omegaconf import DictConfig, ListConfig


class JSONCfgEncoder(json.JSONEncoder):
"""Encode DictConfigs.

Convert DictConfigs to normal dicts.
"""

def default(self, obj: Union[DictConfig, ListConfig, Any]) -> Any:
"""Modify default of JSON encoder

Parameters
----------
obj : DictConfig | ListConfig | Any
Object to encode

Returns
-------
Any
Encoded object
"""
if isinstance(obj, DictConfig):
return dict(obj)
elif isinstance(obj, ListConfig):
parsed_list = []
for o in obj:
if type(o) == DictConfig:
o = dict(o)
elif type(o) == ListConfig:
o = list(o)
parsed_list.append(o)

return parsed_list # [dict(o) for o in obj]
return json.JSONEncoder.default(self, obj)


def search_space_to_config_space(
search_space: Union[str, DictConfig, ConfigurationSpace], seed: int = None
) -> ConfigurationSpace:
"""
Convert hydra search space to SMAC's configuration space.

See the [ConfigSpace docs](https://automl.github.io/ConfigSpace/master/API-Doc.html#) for information of how
to define a configuration (search) space.

In a yaml (hydra) config file, the smac.search space must take the form of:

search_space:
hyperparameters:
hyperparameter_name_0:
key1: value1
...
hyperparameter_name_1:
key1: value1
key2: value2
...


Parameters
----------
search_space : Union[str, DictConfig, ConfigurationSpace]
The search space, either a DictConfig from a hydra yaml config file, or a path to a json configuration space
file in the format required of ConfigSpace.
If it already is a ConfigurationSpace, just optionally seed it.
seed : Optional[int]
Optional seed to seed configuration space.


Example of a json-serialized ConfigurationSpace file.
{
"hyperparameters": [
{
"name": "x0",
"type": "uniform_float",
"log": false,
"lower": -512.0,
"upper": 512.0,
"default": -3.0
},
{
"name": "x1",
"type": "uniform_float",
"log": false,
"lower": -512.0,
"upper": 512.0,
"default": -4.0
}
],
"conditions": [],
"forbiddens": [],
"python_module_version": "0.4.17",
"json_format_version": 0.2
}


Returns
-------
ConfigurationSpace
"""
if type(search_space) == str:
with open(search_space, "r") as f:
jason_string = f.read()
cs = csjson.read(jason_string)
elif type(search_space) == DictConfig:
# reorder hyperparameters as List[Dict]
hyperparameters = []
for name, cfg in search_space.hyperparameters.items():
cfg["name"] = name
if "default" not in cfg:
cfg["default"] = None
if "log" not in cfg:
cfg["log"] = False
hyperparameters.append(cfg)
search_space.hyperparameters = hyperparameters

if "conditions" not in search_space:
search_space["conditions"] = []

if "forbiddens" not in search_space:
search_space["forbiddens"] = []

jason_string = json.dumps(search_space, cls=JSONCfgEncoder)
cs = csjson.read(jason_string)
elif type(search_space) == ConfigurationSpace:
cs = search_space
else:
raise ValueError(
f"search_space must be of type str or DictConfig. Got {type(search_space)}."
)

if seed is not None:
cs.seed(seed=seed)
return cs
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def read_file(filepath: str) -> str:
"PyYAML>=5.4.1",
"tabulate>=0.8.9",
"bs4>=0.0.1",
"ConfigSpace",
"omegaconf"
],
extras_require=extras_require,
test_suite="pytest",
Expand Down