4

I want to try some reinforcement learning techniques (borrowed from AlphaZero, etc.) and so I need a chess environment in order to run games.

I code in python, so I found python-chess but unfortunately it is too slow to generate a large amount of games. Playing 100 games with random moves (average length of ~400 moves for a random game) takes 8 seconds, which doesn't scale to higher orders of magnitude well. My profiling shows that over 99.9% of the time taken is with the library as opposed to other code, so I can't optimize any further.

Is there already an existing chess environment that is faster than this in python?

3
  • Would it be a problem to use a C library and link it from Python? Not that I would know of something in particular but I would suggest to look at what the Leela zero fork uses. You might find something useful there. Commented Jun 20, 2018 at 17:31
  • C library would be great as well. I would need to look up how to hook it up to python, but I'm familiar enough with C that I can read it at least. I don't know what leela uses... seems like a big enough project that it would be tough to jump into it cold and try to understand it. Commented Jun 20, 2018 at 18:16
  • I don't know either, just a suggestion where to start. Anyway, I would suggest to edit your question so that other people know C libraries are acceptable and don't skip it just because they do not know any other python library. Commented Jun 20, 2018 at 18:55

1 Answer 1

2

Generating high volume of data directly in an interpreting Python environment is a bad idea. Furthermore, the python-chess package is not made for high performance; the package is not a wrapper for native C/C++.

If you want to generate hundreds and thousands of games quickly, you don't have any reason for avoiding native coding such as C++. Take the Stockfish code base, modify it for making games. That was what the Leela project had done, and it worked!

Please consider going into C++. Mutlit-threading if you haven't done it already.

1
  • Whenever a programmer asks, "how can I make my python code run high performance computing tasks more efficiently?" the answer invariably is rewrite it in C or C++. Commented Aug 22, 2018 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.