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

Add tests for SMAC #206

wants to merge 2 commits into from

Conversation

y0z
Copy link
Member

@y0z y0z commented Dec 10, 2024

Contributor Agreements

Please read the contributor agreements and if you agree, please click the checkbox below.

  • I agree to the contributor agreements.

Motivation

Add tests for SMAC to ensure its quality.

Description of the changes

  • Add tests for SMAC based on the features currently supported.

Notes

Below is a summary of the features missing from SMACSampler that I noticed while introducing the tests (and I skipped the tests for such features at the moment).

  • Support of reseed_rng (importance: relatively high)
  • Support of the following types of search space (importance: low)
    • conditional search space
    • dynamic distributions (i.e., changing its lower/upper bound during optimization)
    • search space with a single value (i.e., low == high holds)
  • Handling of the NaN objective value (importance: low)

@@ -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.

@@ -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):
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.

@@ -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.

@nabenabe0928
Copy link
Contributor

@dengdifan
Hey, are there any ways to update the seed of SMAC after we start optimization?
We need it to increase the randomness of sampler when SMAC is used in multi-threading.

@HideakiImamura
Copy link
Member

@nabenabe0928 Could you review this PR?

Copy link
Contributor

@nabenabe0928 nabenabe0928 left a comment

Choose a reason for hiding this comment

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

Thank you for the PR, I left a comment below!

Why are they not tested?

  • test_sample_relative_categorical
  • test_sample_single_distribution
  • test_single_parameter_objective
  • test_combination_of_different_distributions_objective

Could you add comment lines for the omits?

  • test_reproducible_in_other_process
  • test_reproducible
  • test_sampler_reseed_rng

Can we maybe raise an error or warn in this scenario instead of skipping them?

  • test_nan_objective_value
  • test_dynamic_range_objective
  • test_conditional_parameter_objective

@@ -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):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants