-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature(pu): add alphazero ctree unittest #306
base: main
Are you sure you want to change the base?
Conversation
puyuan1996
commented
Dec 10, 2024
•
edited
Loading
edited
- add alphazero ctree unittest
- *_v0.py is backup files
|
||
sys.path.append('./LightZero/lzero/mcts/ctree/ctree_alphazero/build') | ||
|
||
sys.path.append('/Users/puyuan/code/LightZero/lzero/mcts/ctree/ctree_alphazero/build') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path = os.path.joins(os.path.dirname(__file__), 'xxx'))
sys.path.append(path)
@@ -10,7 +10,9 @@ | |||
update_per_collect = 50 | |||
batch_size = 256 | |||
max_env_step = int(2e5) | |||
mcts_ctree = False | |||
# mcts_ctree = False | |||
mcts_ctree = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove commented code
@@ -220,7 +220,7 @@ def _init_collect(self) -> None: | |||
self._collect_model = self._model | |||
if self._cfg.mcts_ctree: | |||
import sys | |||
sys.path.append('/Users/your_user_name/code/LightZero/lzero/mcts/ctree/ctree_alphazero/build') | |||
sys.path.append('/Users/puyuan/code/LightZero/lzero/mcts/ctree/ctree_alphazero/build') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
polish path
@@ -0,0 +1,289 @@ | |||
# ./lzero/mcts/ctree/ctree_alphazero/test/eval_alphazero_ctree_zh.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use pytest
|
||
class MockEnv: | ||
""" | ||
一个简单的模拟环境类,包含必要的属性和方法。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use English comments
if (battle_mode_in_simulation_env == "self_play_mode") { | ||
update(leaf_value); | ||
if (!is_root()) { | ||
if (!is_root() && parent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if a node is not the root node, its parent can't be null.
void update_recursive(float leaf_value, std::string battle_mode_in_simulation_env) { | ||
// If the mode is "self_play_mode", the leaf_value is subtracted from the parent's value | ||
// 递归更新节点和父节点的值 | ||
void update_recursive(float leaf_value, const std::string& battle_mode_in_simulation_env) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why use const std::string&
, add some comments
children[action] = node; | ||
// 获取子节点 | ||
const std::map<int, std::shared_ptr<Node>>& get_children() const { | ||
return children; | ||
} | ||
|
||
public: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why two public here
self.assertFalse(parent.is_leaf(), "添加子节点后,父节点不应为叶子节点") | ||
|
||
|
||
class TestMCTSAlphaZero(unittest.TestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add a test method to validate its effectiveness on 50 simulations
self.action_space = type('action_space', (), {'n': 3})() | ||
|
||
def reset(self, start_player_index, init_state, katago_policy_init, katago_game_state): | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe you should reset something in the reset method