opendilab/LightZero

alphazero MCTS not working: cannot import mcts_alphazero

marintoro opened this issue · 4 comments

Hello,

I try to run the following command
python -u zoo/board_games/tictactoe/config/tictactoe_alphazero_bot_mode_config.py

but it's not working saying
ModuleNotFoundError: No module named 'mcts_alphazero'

Did I miss something obvious to run tictactoe with alphazero?

It seems than the C implementation of the MCTS in alphazero (ctree_alphazero) is different than the one for muzero (ctree_muzero), is it normal? Or it's because this is still under developement? I can run tictactoe with muzero (tictactoe_muzero_bot_mode_config.py) and this look to run normally.

Hello,

To ensure the alphazero_ctree project operates properly, please follow these two key steps:

  • Compile the AlphaZero's ctree (ctree_alphazero) project: AlphaZero's ctree differs from MuZero's as it's implemented based on pybind11 and requires manual compilation. In contrast, MuZero's ctree is compiled automatically via cython during the pip install -e . process. To compile AlphaZero's ctree, follow the instructions at this link.

  • Modify file paths: Once you've completed the compilation, you'll need to modify two file paths in the alphazero.py file to point to your compiled ctree_alphazero project. You can find the alphazero.py file at this link.

After performing these steps, the project should run as expected.

However, if you'd prefer not to use the C++ version of tree, there is an alternative:

  • Use Python version of tree: Set the mcts_ctree option to False in the configuration file. This will allow you to use the Python version of tree directly without the need for the previous steps. You can find the Python version of tree at this link.

Best wishes.

Hello @puyuan1996 ,

Thank you for your guidance. I successfully compiled the AlphaZero's ctree following your instructions. However, I had to make a small modification in the CMakelist file to get it to work (but I am not familiar at all with C++ compilation):

# add_subdirectory(pybind11) # Commented this line
find_package(pybind11 REQUIRED) # Added this line

After this change, the compilation was successful. But now, when running the code, I encounter a new issue:
KeyError: 'katago_game_state' arises when trying to use the alphago_ctree.

Upon inspecting the mcts_alphazero.cpp file, I noticed numerous variables prefixed with "katago" (like "katago_game_state", "katago_policy_init"), which seem specific to the game of Go. This seems potentially problematic for environments other than Go, such as Tic-Tac-Toe. Is this C++ implementation only made for the game of Go?

As a short-term workaround, I switched the mcts_ctree option to False to use the Python implementation of the alphazero mcts (ptree_az.py) and this seems to be running fine.

Best.

Hello, thank you for your feedback. We have acknowledged the issue as a bug and have addressed it in the #148.

We have conducted tests on tictactoe and gomoku in a local environment, and everything seems to be functioning as expected. To ensure the efficacy of the fix, we recommend that you also test it in your own environment.

Once again, we sincerely appreciate your valuable input, which is crucial for the improvement of our project.
We look forward to hearing from you with further feedback.

Best regards.

We have acknowledged the issue as a bug and have addressed it in the #148.