From dbace7adbd6b6d551224b2e9dab4b5738bbd8655 Mon Sep 17 00:00:00 2001 From: Ben van Werkhoven Date: Tue, 8 Apr 2025 09:51:27 +0200 Subject: [PATCH 1/3] support numpy 2.0 --- kernel_tuner/strategies/bayes_opt.py | 6 +++--- pyproject.toml | 4 ++-- test/strategies/test_bayesian_optimization.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/kernel_tuner/strategies/bayes_opt.py b/kernel_tuner/strategies/bayes_opt.py index bd20e29a9..024a3f8c0 100644 --- a/kernel_tuner/strategies/bayes_opt.py +++ b/kernel_tuner/strategies/bayes_opt.py @@ -235,7 +235,7 @@ def get_hyperparam(name: str, default, supported_values=list()): self.invalid_value = 1e20 self.opt_direction = opt_direction if opt_direction == "min": - self.worst_value = np.PINF + self.worst_value = np.inf self.argopt = np.argmin elif opt_direction == "max": self.worst_value = np.NINF @@ -262,7 +262,7 @@ def get_hyperparam(name: str, default, supported_values=list()): self.__visited_num = 0 self.__visited_valid_num = 0 self.__visited_searchspace_indices = [False] * self.searchspace_size - self.__observations = [np.NaN] * self.searchspace_size + self.__observations = [np.nan] * self.searchspace_size self.__valid_observation_indices = [False] * self.searchspace_size self.__valid_params = list() self.__valid_observations = list() @@ -311,7 +311,7 @@ def is_not_visited(self, index: int) -> bool: def is_valid(self, observation: float) -> bool: """Returns whether an observation is valid.""" - return not (observation is None or observation == self.invalid_value or observation == np.NaN) + return not (observation is None or observation == self.invalid_value or observation == np.nan) def get_af_by_name(self, name: str): """Get the basic acquisition functions by their name.""" diff --git a/pyproject.toml b/pyproject.toml index 8a8c08b20..a55280cfd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,7 +65,7 @@ priority = "explicit" # ATTENTION: if anything is changed here, run `poetry update` [tool.poetry.dependencies] python = ">=3.9,<4" # <4 is because of hip-python # NOTE when changing the supported Python versions, also change the test versions in the noxfile -numpy = "^1.26.0" # Python 3.12 requires numpy at least 1.26 +numpy = "^2.2.4" # Python 3.12 requires numpy at least 1.26 scipy = ">=1.11.0" # held back by Python 3.9 packaging = "*" # required by file_utils jsonschema = "*" @@ -153,4 +153,4 @@ select = [ "D", # pydocstyle, ] [tool.ruff.pydocstyle] -convention = "google" \ No newline at end of file +convention = "google" diff --git a/test/strategies/test_bayesian_optimization.py b/test/strategies/test_bayesian_optimization.py index dd206a37b..8d929054a 100644 --- a/test/strategies/test_bayesian_optimization.py +++ b/test/strategies/test_bayesian_optimization.py @@ -74,7 +74,7 @@ def test_bo_initialization(): assert BO.searchspace == pruned_parameter_space assert BO.unvisited_cache == pruned_parameter_space assert len(BO.observations) == len(pruned_parameter_space) - assert BO.current_optimum == np.PINF + assert BO.current_optimum == np.inf def test_bo_initial_sample_lhs(): sample = BO.draw_latin_hypercube_samples(num_samples=1) From 797900d382c9a51c5a4a73faa195b7c80772e365 Mon Sep 17 00:00:00 2001 From: Ben van Werkhoven Date: Tue, 8 Apr 2025 09:54:49 +0200 Subject: [PATCH 2/3] skip HIP tests if hip-python present but no HIP device --- test/context.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/context.py b/test/context.py index d1cbcf3c3..016ee0af6 100644 --- a/test/context.py +++ b/test/context.py @@ -55,8 +55,9 @@ try: from hip import hip + hip.hipDriverGetVersion() hip_present = True -except ImportError: +except (ImportError, RuntimeError): hip_present = False skip_if_no_pycuda = pytest.mark.skipif( @@ -78,7 +79,7 @@ ) skip_if_no_openmp = pytest.mark.skipif(not openmp_present, reason="No OpenMP found") skip_if_no_openacc = pytest.mark.skipif(not openacc_present, reason="No nvc++ on PATH") -skip_if_no_hip = pytest.mark.skipif(not hip_present, reason="No HIP Python found") +skip_if_no_hip = pytest.mark.skipif(not hip_present, reason="No HIP Python found or no HIP device detected") def skip_backend(backend: str): From e7d6a84612dd34aa6fa311582c697ff6e4e310b3 Mon Sep 17 00:00:00 2001 From: Ben van Werkhoven Date: Tue, 8 Apr 2025 10:07:15 +0200 Subject: [PATCH 3/3] lowering numpy version requirement to see if we can still support Python 3.9 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a55280cfd..6d117ffd1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,7 +65,7 @@ priority = "explicit" # ATTENTION: if anything is changed here, run `poetry update` [tool.poetry.dependencies] python = ">=3.9,<4" # <4 is because of hip-python # NOTE when changing the supported Python versions, also change the test versions in the noxfile -numpy = "^2.2.4" # Python 3.12 requires numpy at least 1.26 +numpy = "^2.0.0" # Python 3.12 requires numpy at least 1.26 scipy = ">=1.11.0" # held back by Python 3.9 packaging = "*" # required by file_utils jsonschema = "*"