From d2f32d12e9f3a05fca8244131e9d387ab9f7bbbb Mon Sep 17 00:00:00 2001 From: Jad <64837518+Jad-yehya@users.noreply.github.com> Date: Mon, 18 Nov 2024 16:45:40 +0100 Subject: [PATCH] Multiple changes to pass cli tests (CBLOF, skip solver, xfail, device management) (#21) - `test_parameters` added in datasets - Device management for DIF Solver - Removed GPU condition for skipping solver --- datasets/msl.py | 4 ++++ datasets/psm.py | 4 ++++ datasets/simulated.py | 7 +++++++ datasets/smap.py | 6 ++++++ solvers/cblof.py | 6 +++++- solvers/dif.py | 12 ++++++++---- solvers/lstm.py | 8 ++++---- test_config.py | 12 ++++++------ 8 files changed, 44 insertions(+), 15 deletions(-) diff --git a/datasets/msl.py b/datasets/msl.py index c581abe..4fb74a4 100644 --- a/datasets/msl.py +++ b/datasets/msl.py @@ -31,6 +31,10 @@ class Dataset(BaseDataset): "debug": [False], } + test_parameters = { + "debug": [True], + } + def get_data(self): path = config.get_data_path(key="MSL") # Check if the data is already here diff --git a/datasets/psm.py b/datasets/psm.py index c9d3421..84f7d18 100644 --- a/datasets/psm.py +++ b/datasets/psm.py @@ -26,6 +26,10 @@ class Dataset(BaseDataset): "debug": [False], } + test_parameters = { + "debug": [True], + } + def get_data(self): # Check if the data is already here path = config.get_data_path(key="PSM") diff --git a/datasets/simulated.py b/datasets/simulated.py index 8693c7f..6c7925e 100644 --- a/datasets/simulated.py +++ b/datasets/simulated.py @@ -18,6 +18,13 @@ class Dataset(BaseDataset): "n_anomaly": [90], } + test_parameters = { + "n_samples": [500], + "n_features": [5], + "noise": [0.1], + "n_anomaly": [90], + } + def get_data(self): X_train, _ = make_regression( n_samples=self.n_samples, diff --git a/datasets/smap.py b/datasets/smap.py index 88f521f..df02bac 100644 --- a/datasets/smap.py +++ b/datasets/smap.py @@ -31,6 +31,12 @@ class Dataset(BaseDataset): "validation_size": [0.2], } + test_parameters = { + "debug": [True], + "n_splits": [2], + "validation_size": [0.2], + } + def get_data(self): path = config.get_data_path(key="SMAP") diff --git a/solvers/cblof.py b/solvers/cblof.py index ba5bbca..fd9454f 100644 --- a/solvers/cblof.py +++ b/solvers/cblof.py @@ -17,6 +17,7 @@ class Solver(BaseSolver): parameters = { "contamination": [5e-4, 0.01, 0.02, 0.03, 0.04], "window": [True], + "n_clusters": [10], "window_size": [20], "stride": [1], } @@ -26,7 +27,10 @@ class Solver(BaseSolver): def set_objective(self, X_train, y_test, X_test): self.X_train = X_train self.X_test, self.y_test = X_test, y_test - self.clf = CBLOF(contamination=self.contamination, n_clusters=8) + self.clf = CBLOF( + contamination=self.contamination, + n_clusters=self.n_clusters + ) def run(self, _): diff --git a/solvers/dif.py b/solvers/dif.py index 08bf08b..3f0421b 100644 --- a/solvers/dif.py +++ b/solvers/dif.py @@ -3,6 +3,7 @@ from benchopt import safe_import_context with safe_import_context() as import_ctx: + from benchopt.utils.sys_info import get_cuda_version from pyod.models.dif import DIF import numpy as np @@ -25,7 +26,10 @@ class Solver(BaseSolver): def set_objective(self, X_train, y_test, X_test): self.X_train = X_train self.X_test, self.y_test = X_test, y_test - self.clf = DIF(contamination=self.contamination, device="cuda") + if get_cuda_version() is None: + self.clf = DIF(contamination=self.contamination) + else: + self.clf = DIF(contamination=self.contamination, device="cuda") def run(self, _): @@ -72,9 +76,9 @@ def run(self, _): def skip(self, X_train, X_test, y_test): # If cuda is not available, we skip the test because deep method - from benchopt.utils.sys_info import get_cuda_version - if get_cuda_version() is None: - return True, "Cuda is not available" + # from benchopt.utils.sys_info import get_cuda_version + # if get_cuda_version() is None: + # return True, "Cuda is not available" if X_train.shape[0] < self.window_size: return True, "Not enough samples to create a window" return False, None diff --git a/solvers/lstm.py b/solvers/lstm.py index a476b2e..fd5683e 100644 --- a/solvers/lstm.py +++ b/solvers/lstm.py @@ -147,10 +147,10 @@ def run(self, _): ) def skip(self, X_train, X_test, y_test): - from benchopt.utils.sys_info import get_cuda_version - if get_cuda_version() is None: - return True, "CUDA is not available. Skipping this solver." - elif X_train.shape[0] < self.window_size: + # from benchopt.utils.sys_info import get_cuda_version + # if get_cuda_version() is None: + # return True, "CUDA is not available. Skipping this solver." + if X_train.shape[0] < self.window_size: return True, "Not enough samples to create a window." return False, None diff --git a/test_config.py b/test_config.py index b3bf473..92e34d5 100644 --- a/test_config.py +++ b/test_config.py @@ -16,10 +16,10 @@ def check_test_solver_install(solver_class): if get_cuda_version() is None: pytest.xfail("Deep IsolationForest needs a working GPU hardware.") - if solver_class.name.lower() == "lstm": - if get_cuda_version() is None: - pytest.xfail("LSTM needs a working GPU hardware.") + # if solver_class.name.lower() == "lstm": + # if get_cuda_version() is None: + # pytest.xfail("LSTM needs a working GPU hardware.") - if solver_class.name.lower() == "transformer": - if get_cuda_version() is None: - pytest.xfail("Transformer needs a working GPU hardware.") + # if solver_class.name.lower() == "transformer": + # if get_cuda_version() is None: + # pytest.xfail("Transformer needs a working GPU hardware.")