Skip to content

Commit c4f7f32

Browse files
committed
Merge branch 'master' into parallel_runner
2 parents 5cb0243 + 57d853a commit c4f7f32

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

doc/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ tornado==6.5.1 ; python_version >= "3.9" and python_version < "3.15"
8282
traitlets==5.14.3 ; python_version >= "3.9" and python_version < "3.15"
8383
typing-extensions==4.12.2 ; python_version >= "3.9" and python_version < "3.15"
8484
tzdata==2025.1 ; python_version >= "3.9" and python_version < "3.15"
85-
urllib3==2.3.0 ; python_version >= "3.9" and python_version < "3.15"
85+
urllib3==2.5.0 ; python_version >= "3.9" and python_version < "3.15"
8686
wcwidth==0.2.13 ; python_version >= "3.9" and python_version < "3.15"
8787
webencodings==0.5.1 ; python_version >= "3.9" and python_version < "3.15"
8888
xmltodict==0.14.2 ; python_version >= "3.9" and python_version < "3.15"

kernel_tuner/strategies/common.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from time import perf_counter
44

55
import numpy as np
6+
import numbers
67

78
from kernel_tuner import util
89
from kernel_tuner.searchspace import Searchspace
@@ -109,8 +110,15 @@ def __call__(self, x, check_restrictions=True):
109110
self.runner.last_strategy_start_time = perf_counter()
110111

111112
# get numerical return value, taking optimization direction into account
112-
return_value = result[self.tuning_options.objective] or sys.float_info.max
113-
return_value = return_value if not self.tuning_options.objective_higher_is_better else -return_value
113+
return_value = result[self.tuning_options.objective]
114+
115+
if isinstance(return_value, numbers.Number):
116+
if self.tuning_options.objective_higher_is_better:
117+
# flip the sign if higher means better
118+
return_value = -return_value
119+
else:
120+
# this is not a valid configuration, just return max
121+
return_value = sys.float_info.max
114122

115123
return return_value
116124

kernel_tuner/strategies/firefly_algorithm.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def __init__(self, bounds):
9494
"""Create Firefly at random position within bounds."""
9595
super().__init__(bounds)
9696
self.bounds = bounds
97-
self.intensity = 1 / self.score
97+
self.intensity = -self.score
9898

9999
def distance_to(self, other):
100100
"""Return Euclidian distance between self and other Firefly."""
@@ -103,10 +103,7 @@ def distance_to(self, other):
103103
def compute_intensity(self, fun):
104104
"""Evaluate cost function and compute intensity at this position."""
105105
self.evaluate(fun)
106-
if self.score == sys.float_info.max:
107-
self.intensity = -sys.float_info.max
108-
else:
109-
self.intensity = 1 / self.score
106+
self.intensity = -self.score
110107

111108
def move_towards(self, other, beta, alpha):
112109
"""Move firefly towards another given beta and alpha values."""

kernel_tuner/strategies/simulated_annealing.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,24 @@ def tune(searchspace: Searchspace, runner, tuning_options):
8787

8888
def acceptance_prob(old_cost, new_cost, T, tuning_options):
8989
"""Annealing equation, with modifications to work towards a lower value."""
90-
error_val = sys.float_info.max if not tuning_options.objective_higher_is_better else -sys.float_info.max
90+
error_val = sys.float_info.max
91+
res = 0.0
9192
# if start pos is not valid, always move
9293
if old_cost == error_val:
93-
return 1.0
94+
res = 1.0
9495
# if we have found a valid ps before, never move to nonvalid pos
95-
if new_cost == error_val:
96-
return 0.0
96+
elif new_cost == error_val:
97+
res = 0.0
9798
# always move if new cost is better
98-
if new_cost < old_cost:
99-
return 1.0
99+
elif new_cost < old_cost:
100+
res = 1.0
100101
# maybe move if old cost is better than new cost depending on T and random value
101-
if tuning_options.objective_higher_is_better:
102-
return np.exp(((new_cost-old_cost)/new_cost)/T)
103-
return np.exp(((old_cost-new_cost)/old_cost)/T)
102+
else:
103+
if tuning_options.objective_higher_is_better:
104+
res = np.exp(((new_cost-old_cost)/new_cost)/T)
105+
else:
106+
res = np.exp(((old_cost-new_cost)/old_cost)/T)
107+
return res
104108

105109

106110
def neighbor(pos, searchspace: Searchspace):

0 commit comments

Comments
 (0)