Skip to content

Commit b30eeb5

Browse files
committed
Apply formatter
1 parent 5bb1769 commit b30eeb5

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

smac/initial_design/random_design.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from smac.initial_design.abstract_initial_design import AbstractInitialDesign
66
from smac.utils.configspace import create_uniform_configspace_copy
7+
78
__copyright__ = "Copyright 2025, Leibniz University Hanover, Institute of AI"
89
__license__ = "3-clause BSD"
910

smac/utils/configspace.py

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
__license__ = "3-clause BSD"
3131

3232

33-
get_one_exchange_neighbourhood = partial(get_one_exchange_neighbourhood, stdev=0.05, num_neighbors=8)
33+
get_one_exchange_neighbourhood = partial(
34+
get_one_exchange_neighbourhood, stdev=0.05, num_neighbors=8
35+
)
3436

3537

3638
def convert_configurations_to_array(configs: list[Configuration]) -> np.ndarray:
@@ -106,22 +108,30 @@ def get_types(
106108
bounds[i] = (0, 1.0)
107109
elif isinstance(param, NormalFloatHyperparameter):
108110
if can_be_inactive:
109-
raise ValueError("Inactive parameters not supported for Beta and Normal Hyperparameters")
111+
raise ValueError(
112+
"Inactive parameters not supported for Beta and Normal Hyperparameters"
113+
)
110114

111115
bounds[i] = (param.lower_vectorized, param.upper_vectorized)
112116
elif isinstance(param, NormalIntegerHyperparameter):
113117
if can_be_inactive:
114-
raise ValueError("Inactive parameters not supported for Beta and Normal Hyperparameters")
118+
raise ValueError(
119+
"Inactive parameters not supported for Beta and Normal Hyperparameters"
120+
)
115121

116122
bounds[i] = (param.lower_vectorized, param.upper_vectorized)
117123
elif isinstance(param, BetaFloatHyperparameter):
118124
if can_be_inactive:
119-
raise ValueError("Inactive parameters not supported for Beta and Normal Hyperparameters")
125+
raise ValueError(
126+
"Inactive parameters not supported for Beta and Normal Hyperparameters"
127+
)
120128

121129
bounds[i] = (param.lower_vectorized, param.upper_vectorized)
122130
elif isinstance(param, BetaIntegerHyperparameter):
123131
if can_be_inactive:
124-
raise ValueError("Inactive parameters not supported for Beta and Normal Hyperparameters")
132+
raise ValueError(
133+
"Inactive parameters not supported for Beta and Normal Hyperparameters"
134+
)
125135

126136
bounds[i] = (param.lower_vectorized, param.upper_vectorized)
127137
elif not isinstance(
@@ -146,7 +156,9 @@ def get_types(
146156
return types, bounds
147157

148158

149-
def get_conditional_hyperparameters(X: np.ndarray, Y: np.ndarray | None = None) -> np.ndarray:
159+
def get_conditional_hyperparameters(
160+
X: np.ndarray, Y: np.ndarray | None = None
161+
) -> np.ndarray:
150162
"""Returns conditional hyperparameters if values with -1 or smaller are observed. X is used
151163
if Y is not specified.
152164
"""
@@ -183,7 +195,9 @@ def print_config_changes(
183195
for k in sorted(all_keys):
184196
inc_k = incumbent.get(k, "-inactive-")
185197
cha_k = challenger.get(k, "-inactive-")
186-
lines.append(f"--- {k}: {inc_k} -> {cha_k}" + " (unchanged)" if inc_k == cha_k else "")
198+
lines.append(
199+
f"--- {k}: {inc_k} -> {cha_k}" + " (unchanged)" if inc_k == cha_k else ""
200+
)
187201

188202
msg = "\n".join(lines)
189203
logger.debug(msg)
@@ -212,7 +226,9 @@ def transform_continuous_designs(
212226
if isinstance(param, NumericalHyperparameter):
213227
if isinstance(param, IntegerHyperparameter):
214228
design[:, idx] = param.to_vector(param.to_value(design[:, idx]))
215-
elif isinstance(param, NumericalHyperparameter) and not isinstance(param, IntegerHyperparameter):
229+
elif isinstance(param, NumericalHyperparameter) and not isinstance(
230+
param, IntegerHyperparameter
231+
):
216232
continue
217233
elif isinstance(param, Constant):
218234
design_ = np.zeros(np.array(design.shape) + np.array((0, 1)))
@@ -228,7 +244,9 @@ def transform_continuous_designs(
228244
v_design[v_design == 1] = 1 - 10**-10
229245
design[:, idx] = np.array(v_design * len(param.sequence), dtype=int)
230246
else:
231-
raise ValueError("Hyperparameter not supported when transforming a continuous design.")
247+
raise ValueError(
248+
"Hyperparameter not supported when transforming a continuous design."
249+
)
232250

233251
configs = []
234252
for vector in design:
@@ -244,14 +262,17 @@ def transform_continuous_designs(
244262

245263
return configs
246264

247-
def create_uniform_configspace_copy(configspace:ConfigurationSpace) -> ConfigurationSpace:
265+
266+
def create_uniform_configspace_copy(
267+
configspace: ConfigurationSpace,
268+
) -> ConfigurationSpace:
248269
"""Creates a copy of the given configuration space with uniform transformed hyperparameters.
249-
270+
250271
Parameters
251272
----------
252273
configspace : ConfigurationSpace
253274
The configuration space to be transformed.
254-
275+
255276
Returns
256277
-------
257278
ConfigurationSpace
@@ -260,7 +281,9 @@ def create_uniform_configspace_copy(configspace:ConfigurationSpace) -> Configura
260281
configspace_name = configspace.name
261282
configspace_meta = configspace.meta
262283
random_state = configspace.random.get_state()
263-
new_configuration_space = ConfigurationSpace(name = configspace_name, meta = configspace_meta)
284+
new_configuration_space = ConfigurationSpace(
285+
name=configspace_name, meta=configspace_meta
286+
)
264287
new_configuration_space.random.set_state(random_state)
265288

266289
for hyperparameter in configspace.values():

0 commit comments

Comments
 (0)