Skip to content

Commit e4af9f7

Browse files
committed
Added explicit restrictions definition to hyperparameter tuning
1 parent f6811ab commit e4af9f7

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

kernel_tuner/backends/hypertuner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def __init__(self, iterations, compiler_options=None):
7878
"repeats": 25,
7979
"samples": self.iterations,
8080
"minimum_fraction_of_budget_valid": 0.1,
81-
"minimum_number_of_valid_search_iterations": 10,
81+
"minimum_number_of_valid_search_iterations": 5,
8282
},
8383
"statistics_settings": {
8484
"cutoff_percentile": 0.95,

kernel_tuner/hyper.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def randpath():
1717
path = randpath()
1818
return path
1919

20-
def tune_hyper_params(target_strategy: str, hyper_params: dict, *args, **kwargs):
20+
def tune_hyper_params(target_strategy: str, hyper_params: dict, restrictions: list, *args, **kwargs):
2121
"""Tune hyperparameters for a given strategy and kernel.
2222
2323
This function is to be called just like tune_kernel, except that you specify a strategy
@@ -80,7 +80,7 @@ def put_if_not_present(target_dict, key, value):
8080
name = f"hyperparamtuning_{target_strategy.lower()}"
8181

8282
# execute the hyperparameter tuning
83-
result, env = kernel_tuner.tune_kernel(name, None, [], arguments, hyper_params, *args, lang='Hypertuner',
83+
result, env = kernel_tuner.tune_kernel(name, None, [], arguments, hyper_params, restrictions=restrictions, *args, lang='Hypertuner',
8484
objective='score', objective_higher_is_better=True, iterations=iterations, **kwargs)
8585

8686
# remove the temporary cachefile and return only unique results in order
@@ -99,6 +99,7 @@ def put_if_not_present(target_dict, key, value):
9999
strategy_to_tune = args.strategy_to_tune
100100

101101
# select the hyperparameter parameters for the selected optimization algorithm
102+
restrictions = []
102103
if strategy_to_tune.lower() == "pso":
103104
hyperparams = {
104105
'popsize': [10, 20, 30],
@@ -169,6 +170,6 @@ def put_if_not_present(target_dict, key, value):
169170
raise ValueError(f"Invalid argument {strategy_to_tune=}")
170171

171172
# run the hyperparameter tuning
172-
result, env = tune_hyper_params(strategy_to_tune.lower(), hyperparams)
173+
result, env = tune_hyper_params(strategy_to_tune.lower(), hyperparams, restrictions=restrictions)
173174
print(result)
174175
print(env['best_config'])

0 commit comments

Comments
 (0)