Skip to content

Commit 7d3861d

Browse files
committed
Improved bounds check to deal with non-numericals, other improvements
1 parent 5798286 commit 7d3861d

File tree

4 files changed

+8
-16
lines changed

4 files changed

+8
-16
lines changed

kernel_tuner/strategies/common.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,11 @@ def get_bounds(self):
242242
"""Create a bounds array from the tunable parameters."""
243243
bounds = []
244244
for values in self.encoded_params_values if self.encode_non_numeric else self.searchspace.params_values:
245-
bounds.append((min(values), max(values)))
245+
try:
246+
bounds.append((min(values), max(values)))
247+
except TypeError:
248+
# if values are not numeric, use the first and last value as bounds
249+
bounds.append((values[0], values[-1]))
246250
return bounds
247251

248252
def encoded_to_params(self, config):

kernel_tuner/strategies/diff_evo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def tune(searchspace: Searchspace, runner, tuning_options):
4545

4646
try:
4747
differential_evolution(searchspace, cost_func, bounds, popsize, maxiter, F, CR, method, constraint_aware, tuning_options.verbose)
48-
except util.StopCriterionReached as e:
48+
except StopCriterionReached as e:
4949
if tuning_options.verbose:
5050
print(e)
5151

kernel_tuner/strategies/pso.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,11 @@ def tune(searchspace: Searchspace, runner, tuning_options):
2323
# scale variables in x because PSO works with velocities to visit different configurations
2424
cost_func = CostFunc(searchspace, tuning_options, runner, scaling=True)
2525

26-
<<<<<<< HEAD
2726
# using this instead of get_bounds because scaling is used
28-
bounds, _, eps = cost_func.get_bounds_x0_eps()
27+
bounds, x0, eps = cost_func.get_bounds_x0_eps()
2928

3029
num_particles, maxiter, w, c1, c2, constraint_aware = common.get_options(tuning_options.strategy_options, _options)
3130
num_particles = min(round(searchspace.size / 2), num_particles)
32-
=======
33-
#using this instead of get_bounds because scaling is used
34-
bounds, x0, eps = cost_func.get_bounds_x0_eps()
35-
36-
num_particles, maxiter, w, c1, c2 = common.get_options(tuning_options.strategy_options, _options)
37-
>>>>>>> origin/custom_diff_evo
3831

3932
best_score_global = sys.float_info.max
4033
best_position_global = []

kernel_tuner/strategies/simulated_annealing.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,8 @@ def tune(searchspace: Searchspace, runner, tuning_options):
3535
max_fevals = min(searchspace.size, max_fevals)
3636

3737
# get random starting point and evaluate cost
38-
<<<<<<< HEAD
39-
pos = generate_starting_point(searchspace, constraint_aware)
40-
old_cost = cost_func(pos, check_restrictions=not constraint_aware)
41-
=======
4238
pos = cost_func.get_start_pos()
43-
old_cost = cost_func(pos, check_restrictions=False)
44-
>>>>>>> origin/custom_diff_evo
39+
old_cost = cost_func(pos, check_restrictions=not constraint_aware)
4540

4641
# main optimization loop
4742
stuck = 0

0 commit comments

Comments
 (0)