From 204d9687fc6a22b78c4ed40cc19a63dc2b17e931 Mon Sep 17 00:00:00 2001 From: Imran Ahamed Date: Sat, 6 Jun 2026 15:18:13 -0500 Subject: [PATCH 1/2] fix: FLOW2.reach() handles mixed-type conditional parameters (#903) --- flaml/tune/searcher/flow2.py | 5 ++++- test/tune/test_searcher.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/flaml/tune/searcher/flow2.py b/flaml/tune/searcher/flow2.py index 7ccf6fa6bb..371b503273 100644 --- a/flaml/tune/searcher/flow2.py +++ b/flaml/tune/searcher/flow2.py @@ -674,5 +674,8 @@ 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/tune/test_searcher.py b/test/tune/test_searcher.py index e49c1aa5c1..6bec37f3dc 100644 --- a/test/tune/test_searcher.py +++ b/test/tune/test_searcher.py @@ -345,5 +345,25 @@ def test_unresolved_search_space(caplog): ), "BlendSearch should not produce warning about unresolved search space" +def test_flow2_reach_mixed_type_incumbents(): + """Regression test for #903: FLOW2.reach() must return False instead of raising + TypeError when conditional choice parameters lead to mixed-type incumbents.""" + from flaml.tune.searcher.flow2 import FLOW2 + + f1 = FLOW2.__new__(FLOW2) + f1.best_config = {"x": 1.0} + f1.incumbent = {"x": 1.0} + f1._resource = None + f1._unordered_cat_hp = {} + f1._tunable_keys = ["x"] + f1.step = 0.5 + + f2 = FLOW2.__new__(FLOW2) + f2.best_config = {"x": "None"} + f2.incumbent = {"x": "None"} + + assert f1.reach(f2) is False + + if __name__ == "__main__": test_unresolved_search_space(None) From 14f9e989231d68ecfa00d3e63ab1ed356cf71d14 Mon Sep 17 00:00:00 2001 From: Li Jiang Date: Mon, 8 Jun 2026 16:17:27 +0800 Subject: [PATCH 2/2] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- test/tune/test_searcher.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/tune/test_searcher.py b/test/tune/test_searcher.py index 6bec37f3dc..de33e545cf 100644 --- a/test/tune/test_searcher.py +++ b/test/tune/test_searcher.py @@ -346,8 +346,10 @@ def test_unresolved_search_space(caplog): def test_flow2_reach_mixed_type_incumbents(): - """Regression test for #903: FLOW2.reach() must return False instead of raising - TypeError when conditional choice parameters lead to mixed-type incumbents.""" + """Regression test for #903. + + FLOW2.reach() must return False instead of raising TypeError when conditional choice parameters lead to mixed-type incumbents. + """ from flaml.tune.searcher.flow2 import FLOW2 f1 = FLOW2.__new__(FLOW2)