Skip to content

Commit

Permalink
Merge branch 'main' of github.com:automl/ConfigSpace
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiebergman committed Jul 18, 2024
2 parents 0527d3b + 6247934 commit b7e62e3
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/ConfigSpace/_condition_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ def add(self, hp: Hyperparameter) -> None:
existing = self.nodes.get(hp.name, None)
if existing is not None:
raise HyperparameterAlreadyExistsError(
f"Hyperparameter {existing.name} already exists in space."
f"Hyperparameter '{existing.name}' already exists in space."
f"\nExisting: {existing.hp}"
f"\nNew one: {hp}",
)
Expand Down
7 changes: 4 additions & 3 deletions src/ConfigSpace/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from ConfigSpace.exceptions import IllegalValueError
from ConfigSpace.hyperparameters import FloatHyperparameter
from ConfigSpace.hyperparameters.hp_components import ROUND_PLACES
from ConfigSpace.types import NotSet, f64

if TYPE_CHECKING:
Expand Down Expand Up @@ -115,9 +116,9 @@ def __init__(
if not hp.legal_value(value):
raise IllegalValueError(hp, value)

# Truncate the float to be of constant length for a python version
# Truncate the float to be of constant lengt
if isinstance(hp, FloatHyperparameter):
value = float(np.round(value, 16)) # type: ignore
value = float(np.round(value, ROUND_PLACES)) # type: ignore

self._values[key] = value
self._vector[i] = hp.to_vector(value) # type: ignore
Expand Down Expand Up @@ -226,7 +227,7 @@ def __getitem__(self, key: str) -> Any:

# Truncate float to be of constant length for a python version
if isinstance(hyperparameter, FloatHyperparameter):
value = float(np.round(value, 16)) # type: ignore
value = float(np.round(value, ROUND_PLACES)) # type: ignore

if self._values is None:
self._values = {}
Expand Down
8 changes: 4 additions & 4 deletions src/ConfigSpace/hyperparameters/beta_float.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ def __init__(
" 1 so that the probability density is finite.",
)

self.alpha = float(alpha)
self.beta = float(beta)
self.lower = float(lower)
self.upper = float(upper)
self.alpha = float(np.round(alpha, ROUND_PLACES))
self.beta = float(np.round(beta, ROUND_PLACES))
self.lower = float(np.round(lower, ROUND_PLACES))
self.upper = float(np.round(upper, ROUND_PLACES))
self.log = bool(log)

try:
Expand Down
7 changes: 5 additions & 2 deletions src/ConfigSpace/hyperparameters/hp_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
RandomState = np.random.RandomState

CONSTANT_VECTOR_VALUE = i64(0)
ROUND_PLACES = 9
ATOL = 1e-9

# NOTE: Beyond this point, tests start to fail on equality checks
# due to transforms. This seems to be a relatively stable point
ROUND_PLACES = 13
ATOL = 1e-13

T_contra = TypeVar("T_contra", contravariant=True)

Expand Down
8 changes: 4 additions & 4 deletions src/ConfigSpace/hyperparameters/normal_float.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ def __init__(
f"mu={mu} must be positive for log-scale.",
)

self.lower = float(lower)
self.upper = float(upper)
self.mu = float(mu)
self.sigma = float(sigma)
self.lower = float(np.round(lower, ROUND_PLACES))
self.upper = float(np.round(upper, ROUND_PLACES))
self.mu = float(np.round(mu, ROUND_PLACES))
self.sigma = float(np.round(sigma, ROUND_PLACES))
self.log = bool(log)

try:
Expand Down
4 changes: 2 additions & 2 deletions src/ConfigSpace/hyperparameters/uniform_float.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def __init__(
Field for holding meta data provided by the user. Not used by
ConfigSpace.
"""
self.lower = float(lower)
self.upper = float(upper)
self.lower = float(np.round(lower, ROUND_PLACES))
self.upper = float(np.round(upper, ROUND_PLACES))
self.log = log

try:
Expand Down
4 changes: 2 additions & 2 deletions test/read_and_write/test_pcs_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_read_configuration_space_easy():
expected.write("float_a [-1.23, 6.45] [2.61] # bla\n")
expected.write("e_float_a [.5E-2, 4.5e+06] [2250000.0025]\n")
expected.write("int_a [-1, 6] [2]i\n")
expected.write("log_a [4e-1, 6.45] [1.6062378404]l\n")
expected.write("log_a [4e-1, 6.45] [1.6062378404209]l\n")
expected.write("int_log_a [1, 6] [2]il\n")
expected.write('cat_a {a,"b",c,d} [a]\n')
expected.write(r'@.:;/\?!$%&_-<>*+1234567890 {"const"} ["const"]\n')
Expand Down Expand Up @@ -254,7 +254,7 @@ def test_read_new_configuration_space_easy():
expected.write("float_a real [-1.23, 6.45] [2.61] # bla\n")
expected.write("e_float_a real [.5E-2, 4.5e+06] [2250000.0025]\n")
expected.write("int_a integer [-1, 6] [2]\n")
expected.write("log_a real [4e-1, 6.45] [1.6062378404]log\n")
expected.write("log_a real [4e-1, 6.45] [1.6062378404209] log\n")
expected.write("int_log_a integer [1, 6] [2]log\n")
expected.write('cat_a categorical {a,"b",c,d} [a]\n')
expected.write(r'@.:;/\?!$%&_-<>*+1234567890 categorical {"const"} ["const"]\n')
Expand Down
5 changes: 3 additions & 2 deletions test/test_configuration_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -1123,10 +1123,11 @@ def test_uniformfloat_transform():
value_b = b.sample_value(seed=rs)
values_dict = {"a": value_a, "b": value_b}
config = Configuration(cs, values=values_dict)
string = json.dumps(dict(config))
values = dict(config)
string = json.dumps(values)
saved_value = json.loads(string)
saved_value = byteify(saved_value)
assert values_dict == saved_value
assert values == saved_value


def test_setitem():
Expand Down

0 comments on commit b7e62e3

Please sign in to comment.