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

Add tests for SMAC #206

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 10 additions & 1 deletion package/samplers/smac_sampler/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from collections.abc import Sequence
from pathlib import Path
import warnings

from ConfigSpace import Categorical
from ConfigSpace import Configuration
Expand Down Expand Up @@ -226,6 +227,11 @@ def _get_init_design(
raise NotImplementedError(f"Unknown Initial Design Type: {init_design_type}")
return init_design

def reseed_rng(self) -> None:
Copy link
Member Author

Choose a reason for hiding this comment

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

reseed_rng is currently not implemented. This will cause unexpected behavior when n_jobs > 1.

warnings.warn(
"SMACSampler does not support reseeding the random number generator. Please instantiate a new SMACSampler with a different random seed instead."
)

def sample_relative(
self, study: Study, trial: FrozenTrial, search_space: dict[str, BaseDistribution]
) -> dict[str, float]:
Expand All @@ -237,6 +243,9 @@ def sample_relative(
study._storage.set_trial_system_attr(trial._trial_id, _SMAC_SEED_KEY, trial_info.seed)
params = {}
for name, hp_value in cfg.items():
# SMAC uses np.int64 for integer parameters
if isinstance(hp_value, np.int64):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if isinstance(hp_value, np.int64):
if isinstance(hp_value, np.integer):

hp_value = hp_value.item() # Convert to Python int.
Copy link
Member Author

@y0z y0z Dec 12, 2024

Choose a reason for hiding this comment

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

SMAC returns np.int64 by default, and it fails some tests. This change fixes them.

if name in self._hp_scale_value:
hp_value = self._integer_to_step_hp(
integer_value=hp_value, scale_info=self._hp_scale_value[name]
Expand Down Expand Up @@ -344,5 +353,5 @@ def _convert_to_config_space_design_space(
else:
raise NotImplementedError(f"Unknown Hyperparameter Type: {type(distribution)}")
if hp is not None:
config_space.add_hyperparameter(hp)
config_space.add(hp)
Copy link
Member Author

Choose a reason for hiding this comment

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

config_space.add_hyperparameter is deprecated and it is recommended to use add.

return config_space, scale_values
Loading
Loading