diff --git a/flaml/tune/searcher/flow2.py b/flaml/tune/searcher/flow2.py index 035e3d8688..7c0f48472f 100644 --- a/flaml/tune/searcher/flow2.py +++ b/flaml/tune/searcher/flow2.py @@ -746,10 +746,13 @@ def reach(self, other: Searcher) -> bool: # unordered cat choice is hard to reach by chance if config1[key] != config2.get(key): return False - delta = np.array( - [ - incumbent1[key] - incumbent2.get(key, np.inf) - for key in self._tunable_keys - ] - ) + try: + delta = np.array( + [ + incumbent1[key] - incumbent2.get(key, np.inf) + for key in self._tunable_keys + ] + ) + except TypeError: + return False return np.linalg.norm(delta) <= self.step diff --git a/test/automl/test_classification.py b/test/automl/test_classification.py index adb3081662..aab0370861 100644 --- a/test/automl/test_classification.py +++ b/test/automl/test_classification.py @@ -408,6 +408,14 @@ def test_sparse_matrix_lr(self): print(automl_experiment.best_iteration) print(automl_experiment.best_estimator) + def test_reach(self): + search_space = { + "params": tune.choice( + [{"param": "None"}, {"param": tune.qrandint(10, 100, 10)}] + ), + } + return search_space + if __name__ == "__main__": test = TestClassification()