Skip to content

Commit 62d98df

Browse files
committed
Various improvements to the handling of budget and return values in pyatf strategies
1 parent c2c9458 commit 62d98df

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

kernel_tuner/strategies/pyatf_strategies.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def tune(searchspace: Searchspace, runner, tuning_options):
1515
from pyatf.search_techniques.search_technique import SearchTechnique
1616

1717
# setup the Kernel Tuner functionalities
18-
cost_func = CostFunc(searchspace, tuning_options, runner, scaling=True, snap=True)
18+
cost_func = CostFunc(searchspace, tuning_options, runner, scaling=True, snap=True, return_invalid=True)
1919
# using this instead of get_bounds because scaling is used
2020
bounds, _, eps = cost_func.get_bounds_x0_eps()
2121

@@ -39,10 +39,11 @@ def tune(searchspace: Searchspace, runner, tuning_options):
3939
get_next_coordinates_or_indices = search_technique.get_next_coordinates
4040
coordinates_or_indices = set() # Set[Union[Coordinates, Index]]
4141
costs = {} # Dict[Union[Coordinates, Index], Cost]
42+
eval_count = 0
4243

4344
try:
4445
# optimization loop (KT-compatible re-implementation of `make_step` from TuningRun)
45-
while True:
46+
while eval_count < searchspace.size:
4647

4748
# get new coordinates
4849
if not coordinates_or_indices:
@@ -62,13 +63,14 @@ def tune(searchspace: Searchspace, runner, tuning_options):
6263
coords_or_index = tuple(b[0]+c*(b[1]-b[0]) for c, b in zip(coords_or_index, bounds) if c is not None)
6364

6465
# evaluate the configuration
65-
opt_result = cost_func(coords_or_index)
66+
opt_result = cost_func(coords_or_index)
6667

6768
# adjust opt_result to expected PyATF output in cost and valid
6869
if not isinstance(opt_result, (int, float)):
6970
valid = False
7071
else:
7172
cost = opt_result
73+
eval_count += 1
7274

7375
# record the evaluation
7476
costs[coords_or_index] = cost

0 commit comments

Comments
 (0)