Skip to content

Commit f0afa0b

Browse files
force error on unsupported options
1 parent 768d189 commit f0afa0b

File tree

5 files changed

+14
-4
lines changed

5 files changed

+14
-4
lines changed

kernel_tuner/strategies/brute_force.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
def tune(searchspace: Searchspace, runner, tuning_options):
88

9+
# Force error on unsupported options
10+
common.get_options(tuning_options.strategy_options or [], _options, unsupported=["max_fevals", "time_limit", "x0", "searchspace_construction_options"])
11+
912
# call the runner
1013
return runner.run(searchspace.sorted_list(), tuning_options)
1114

kernel_tuner/strategies/common.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ def make_strategy_options_doc(strategy_options):
4343
return doc
4444

4545

46-
def get_options(strategy_options, options):
46+
def get_options(strategy_options, options, unsupported=None):
4747
"""Get the strategy-specific options or their defaults from user-supplied strategy_options."""
4848
accepted = list(options.keys()) + ["max_fevals", "time_limit", "x0", "searchspace_construction_options"]
49+
if unsupported:
50+
for key in unsupported:
51+
accepted.remove(key)
4952
for key in strategy_options:
5053
if key not in accepted:
5154
raise ValueError(f"Unrecognized option {key} in strategy_options (allowed: {accepted})")

kernel_tuner/strategies/random_sample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
def tune(searchspace: Searchspace, runner, tuning_options):
1313
# get the samples
14-
fraction = common.get_options(tuning_options.strategy_options, _options)[0]
14+
fraction = common.get_options(tuning_options.strategy_options, _options, unsupported=["x0"])[0]
1515
assert 0 <= fraction <= 1.0
1616
num_samples = int(np.ceil(searchspace.size * fraction))
1717

test/strategies/test_strategies.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ def test_strategies(vector_add, strategy):
4444
filter_options = {opt:val for opt, val in options.items() if opt in kernel_tuner.interface.strategy_map[strategy]._options}
4545
else:
4646
filter_options = options
47-
filter_options["max_fevals"] = 10
47+
48+
if strategy != "brute_force":
49+
filter_options["max_fevals"] = 10
4850

4951
results, _ = kernel_tuner.tune_kernel(*vector_add, strategy=strategy, strategy_options=filter_options,
5052
verbose=False, cache=cache_filename, simulation_mode=True)

test/test_time_budgets.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ def test_some_time_budget(env):
6969
@skip_if_no_gcc
7070
def test_full_time_budget(env):
7171
"""Ensure that given ample time budget, the entire space is explored."""
72-
res, _ = tune_kernel(*env, strategy="brute_force", strategy_options={"time_limit": 10.0})
7372

7473
# Ensure that the entire space is explored.
7574
tune_params = env[-1]
7675
size_all = len(list(product(*tune_params.values())))
76+
77+
res, _ = tune_kernel(*env, strategy="random_sample", strategy_options={"fraction": 1.0, "time_limit": 10.0})
78+
7779
assert len(res) == size_all

0 commit comments

Comments
 (0)