23
23
from mlos_core .optimizers .bayesian_optimizers import BaseBayesianOptimizer , SmacOptimizer
24
24
from mlos_core .spaces .adapters import SpaceAdapterType
25
25
26
- from mlos_core .tests import get_all_concrete_subclasses
26
+ from mlos_core .tests import get_all_concrete_subclasses , SEED
27
27
28
28
29
29
_LOG = logging .getLogger (__name__ )
@@ -76,7 +76,7 @@ def objective(x: pd.Series) -> npt.ArrayLike: # pylint: disable=invalid-name
76
76
ret : npt .ArrayLike = (6 * x - 2 )** 2 * np .sin (12 * x - 4 )
77
77
return ret
78
78
# Emukit doesn't allow specifying a random state, so we set the global seed.
79
- np .random .seed (42 )
79
+ np .random .seed (SEED )
80
80
optimizer = optimizer_class (parameter_space = configuration_space , ** kwargs )
81
81
82
82
with pytest .raises (ValueError , match = "No observations" ):
@@ -320,7 +320,7 @@ def objective(point: pd.DataFrame) -> pd.Series:
320
320
ret : pd .Series = point ["x" ] + point ["y" ]
321
321
return ret
322
322
323
- input_space = CS .ConfigurationSpace (seed = 2169 )
323
+ input_space = CS .ConfigurationSpace (seed = SEED )
324
324
# add a mix of numeric datatypes
325
325
input_space .add_hyperparameter (CS .UniformIntegerHyperparameter (name = 'x' , lower = 0 , upper = 5 ))
326
326
input_space .add_hyperparameter (CS .UniformFloatHyperparameter (name = 'y' , lower = 0.0 , upper = 5.0 ))
@@ -347,14 +347,13 @@ def objective(point: pd.DataFrame) -> pd.Series:
347
347
suggestion = optimizer .suggest ()
348
348
assert isinstance (suggestion , pd .DataFrame )
349
349
assert (suggestion .columns == ['x' , 'y' ]).all ()
350
- # Build suggestion mapping to cooperate with Configuration, note that
351
- # doing a .iloc[0].to_dict() will cause pandas convert all numeric types
352
- # to float64
353
- tmp_suggest = {'x' : suggestion ['x' ].values [0 ], 'y' : suggestion ['y' ].values [0 ]}
354
- # check that suggestion is in the space
355
- configuration = CS .Configuration (optimizer .parameter_space , tmp_suggest )
350
+ # Check suggestion values are the expected dtype
351
+ assert isinstance (suggestion ['x' ].iloc [0 ], np .integer )
352
+ assert isinstance (suggestion ['y' ].iloc [0 ], np .floating )
353
+ # Check that suggestion is in the space
354
+ test_configuration = CS .Configuration (optimizer .parameter_space , suggestion .astype ('O' ).iloc [0 ].to_dict ())
356
355
# Raises an error if outside of configuration space
357
- configuration .is_valid_configuration ()
356
+ test_configuration .is_valid_configuration ()
358
357
observation = objective (suggestion )
359
358
assert isinstance (observation , pd .Series )
360
359
optimizer .register (suggestion , observation )
0 commit comments