From 34aa6ce014dd7daede14af981b075b9099f0908d Mon Sep 17 00:00:00 2001 From: Ben van Werkhoven Date: Tue, 10 Mar 2026 09:37:15 +0100 Subject: [PATCH 1/2] prevent floating point overflow in dual annealing strategy --- kernel_tuner/strategies/dual_annealing.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel_tuner/strategies/dual_annealing.py b/kernel_tuner/strategies/dual_annealing.py index 598151ea5..93c7a7464 100644 --- a/kernel_tuner/strategies/dual_annealing.py +++ b/kernel_tuner/strategies/dual_annealing.py @@ -1,5 +1,6 @@ """The strategy that uses the dual annealing optimization method.""" import scipy.optimize +import numpy as np from kernel_tuner.util import StopCriterionReached from kernel_tuner.searchspace import Searchspace @@ -16,7 +17,7 @@ def tune(searchspace: Searchspace, runner, tuning_options): method, max_fevals = common.get_options(tuning_options.strategy_options, _options) #scale variables in x to make 'eps' relevant for multiple variables - cost_func = CostFunc(searchspace, tuning_options, runner, scaling=True) + cost_func = CostFunc(searchspace, tuning_options, runner, scaling=True, invalid_value=np.inf) bounds, x0, _ = cost_func.get_bounds_x0_eps() From 76bc5494ad628692cdbfff0515fa6d0c7334b561 Mon Sep 17 00:00:00 2001 From: Ben van Werkhoven Date: Tue, 10 Mar 2026 10:04:21 +0100 Subject: [PATCH 2/2] avoid division by zero in simulated annealing --- kernel_tuner/strategies/simulated_annealing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel_tuner/strategies/simulated_annealing.py b/kernel_tuner/strategies/simulated_annealing.py index 962a1e34c..ffd8f3bd8 100644 --- a/kernel_tuner/strategies/simulated_annealing.py +++ b/kernel_tuner/strategies/simulated_annealing.py @@ -96,7 +96,7 @@ def acceptance_prob(old_cost, new_cost, T): # if start pos is not valid, always move if isinstance(old_cost, ErrorConfig): res = 1.0 - # if we have found a valid ps before, never move to nonvalid pos + # if we have found a valid pos before, never move to nonvalid pos elif isinstance(new_cost, ErrorConfig): res = 0.0 # always move if new cost is better @@ -108,7 +108,7 @@ def acceptance_prob(old_cost, new_cost, T): abs_diff = old_cost - new_cost # relative to abs(old_cost), as the cost might be negative - rel_diff = abs_diff / np.abs(old_cost) + rel_diff = abs_diff / (np.abs(old_cost) if old_cost != 0.0 else 1e-20) # exponential decay res = np.exp(rel_diff / T)