fix: FLOW2.reach() handles mixed-type conditional parameters (#903)#1557
Merged
thinkall merged 2 commits intoJun 11, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a crash in FLOW2.reach() when conditional/choice parameters produce incumbents with mixed types (e.g., numeric vs string), by treating such comparisons as “not reachable” instead of raising a TypeError. This improves robustness of the FLOW2 local search logic in flaml/tune/searcher/flow2.py for hierarchical/conditional search spaces.
Changes:
- Wrap the incumbent delta computation in
FLOW2.reach()with atry/except TypeErrorand returnFalseon mixed-type subtraction. - Add a regression test ensuring
reach()returnsFalse(and does not crash) for mixed-type incumbents.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
flaml/tune/searcher/flow2.py |
Prevents FLOW2.reach() from crashing on mixed-type incumbent comparisons by returning False on TypeError. |
test/tune/test_searcher.py |
Adds a regression test covering the mixed-type incumbent case reported in #903. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
whiskyboy
approved these changes
Jun 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why are these changes needed?
FLOW2.reachinflaml/tune/searcher/flow2.pybuilds a numericdeltaarray by subtracting two incumbents element-wise:When a search space contains a conditional
tune.choicewhose branches yield values of different types — e.g. one branch returns the literal string'None'and another returns an int fromtune.qrandint(the exact pattern from #903) — two FLOW2 instances can hold incumbents whose values are different types for the same key. The subtraction then raises:This was reported by @bbudescu in #903 (2023-01); @sonichi's suggested fix in that thread is to wrap the line in
try/except TypeErrorand returnFalse. This PR implements exactly that. ReturningFalseis the right semantics here — a string-vs-numeric incumbent comparison is structurally not "within step" of each other, so reporting "cannot reach" is correct.Verified
FLOW2.reach()(TypeError: unsupported operand type(s) for -: 'float' and 'str').reach()returnsFalsefor the mixed-type case (no crash).test/tune/test_searcher.py::test_flow2_reach_mixed_type_incumbents— verified to fail on main without the fix and pass with it.test/tune/test_searcher.pycontinue to pass.pre-commit run --files flaml/tune/searcher/flow2.py test/tune/test_searcher.py— all hooks pass.Related issue number
Closes #903
Checks