diff --git a/kernel_tuner/strategies/dual_annealing.py b/kernel_tuner/strategies/dual_annealing.py index 598151ea..93c7a746 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() diff --git a/kernel_tuner/strategies/simulated_annealing.py b/kernel_tuner/strategies/simulated_annealing.py index 962a1e34..ffd8f3bd 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)