Repository navigation
Refactor BruteForceSampler - #6645
Merged
Merged
Conversation
This was referenced May 3, 2026
nabenabe0928
force-pushed
the
refactor-brute-force
branch
from
May 4, 2026 17:09
001a25f to
86afd8d
Compare
c-bata
reviewed
May 11, 2026
Comment on lines
-31
to
-36
| # This is a class to represent the tree of search space. | ||
| """ | ||
| This is a class to represent the tree of search space. | ||
|
|
||
| A tree node has three states: | ||
| 1. Unexpanded. This is represented by children=None. | ||
| 2. Leaf. This is represented by children={} and param_name=None. | ||
| 3. Normal node. It has a param_name and non-empty children. | ||
|
|
||
| # A tree node has three states: | ||
| # 1. Unexpanded. This is represented by children=None. | ||
| # 2. Leaf. This is represented by children={} and param_name=None. | ||
| # 3. Normal node. It has a param_name and non-empty children. |
Member
There was a problem hiding this comment.
I’m not sure about the motivation for turning this comment into a docstring. Since it is just an internal explanatory comment, it does not seem necessary to include it in __doc__. This change is harmless, but would you mind keeping it as a regular comment to reduce unnecessary diff?
Contributor
Author
There was a problem hiding this comment.
I slightly changed the doc-string.
Contributor
Author
|
The test fail is unrelated to this PR. |
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.
Important
I splited this PR into a few smaller PRs.
This PR is already made small at:
Motivation
Since some variables are created billions times, it is not negligible to refactor
BruteForceSamplerso that the number of access will be reduced.This PR is a precursor of subsequent PRs.
Although this PR is mostly a refactoring, this PR makes the sampler slightly quicker (66 seconds --> 58 seconds; ~13% speedup)
Benchmark Script
Description of the changes
_TreeNode.expand()now returnsdict[float, _TreeNode]: This eliminates the need for callers to access.childrenseparately and assert it's notNone_get_non_waiting_trials_and_current_trial_index()sample_independent(): Uses the new helper to get trials and pops the current trial by index, replacing the inline storage query and the generator expression that filtered byt.number != trial.number.after_trial(): Uses the new helper, then replaces the current trial in-place at its index with acreate_trial(...)call, instead of using a complex generator expression with an inline ternary. The_populate_treecall is now a clean one-liner over the modified list.