feat: parallel processing - #15
Merged
Merged
Conversation
…g-features Fix backpropagate spelling and add parallel search tests
There was a problem hiding this comment.
Pull Request Overview
This PR introduces parallel processing support for the Monte Carlo Tree Search (MCTS) algorithm by adding a new method, search_parallel, and updating tests and documentation accordingly.
- Added search_parallel functionality for parallel rollouts.
- Updated tests to verify parallel processing behavior and error handling for unsupported configurations.
- Updated README to include instructions on using parallel processing.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/test_mcts.py | Adds new tests for parallel search and NotImplementedError case |
| mcts/searcher/mcts.py | Implements search_parallel and related multiprocessing changes |
| README.md | Documents the parallel processing feature |
Comments suppressed due to low confidence (1)
mcts/searcher/mcts.py:69
- [nitpick] Consider renaming the method 'all_child_have_at_least_one_visit' to something more grammatically clear such as 'all_children_visited' to improve readability.
def all_child_have_at_least_one_visit(self,) -> bool:
| import math | ||
| import random | ||
| import time | ||
| import copy |
There was a problem hiding this comment.
The 'copy' module is imported but not used. Removing unused imports can improve code clarity and maintainability.
Suggested change
| import copy |
Comment on lines
+167
to
+182
| #processes.append(Process(target=self.execute_rollout_parallel,args=(index,root_shared,return_dict))) | ||
|
|
||
| for p in processes: p.start() | ||
|
|
||
| for p in processes: p.join() | ||
|
|
||
| for index, reward in return_dict.items(): | ||
| #for index, rez in return_dict.items(): | ||
| self.backpropagate(input_nodes[index], reward) | ||
| #node, reward = rez | ||
| #self.backpropagate(node, reward) | ||
|
|
||
| best_child = self.get_best_child(self.root, 0) | ||
| #best_child = self.get_best_child(root_shared, 0) | ||
| action = (action for action, node in self.root.children.items() if node is best_child).__next__() | ||
| #action = (action for action, node in root_shared.children.items() if node is best_child).__next__() |
There was a problem hiding this comment.
[nitpick] Consider removing commented-out alternative code to reduce clutter and make the current implementation clearer.
Suggested change
| #processes.append(Process(target=self.execute_rollout_parallel,args=(index,root_shared,return_dict))) | |
| for p in processes: p.start() | |
| for p in processes: p.join() | |
| for index, reward in return_dict.items(): | |
| #for index, rez in return_dict.items(): | |
| self.backpropagate(input_nodes[index], reward) | |
| #node, reward = rez | |
| #self.backpropagate(node, reward) | |
| best_child = self.get_best_child(self.root, 0) | |
| #best_child = self.get_best_child(root_shared, 0) | |
| action = (action for action, node in self.root.children.items() if node is best_child).__next__() | |
| #action = (action for action, node in root_shared.children.items() if node is best_child).__next__() | |
| for p in processes: p.start() | |
| for p in processes: p.join() | |
| for index, reward in return_dict.items(): | |
| self.backpropagate(input_nodes[index], reward) | |
| best_child = self.get_best_child(self.root, 0) | |
| action = (action for action, node in self.root.children.items() if node is best_child).__next__() | |
…mprove-documentation Improve docs and type hints
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.
Implements #7