Answers.Body: <p>Generating high volume of data directly in an interpreting Python environment is a bad idea. Furthermore, the <code>python-chess</code> package is not made for high performance; the package is not a wrapper for native C/C++.</p>
  
  <p>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 <code>Leela</code> project had done, and it worked!</p>
  
  <p>Please consider going into C++. Mutlit-threading if you haven't done it already.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-22T20:33:13.413Z
Answers.Text: 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++.
Answers.UserDisplayName: NoseKnowsAll
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-21T02:31:58.490Z
Answers.LastActivityDate: 2018-06-21T02:31:58.490Z
Answers.UserDisplayName: SmallChess
Body: <p>I want to try some reinforcement learning techniques (borrowed from AlphaZero, etc.) and so I need a chess environment in order to run games.</p>
  
  <p>I code in python, so I found <a href="https://pypi.org/project/python-chess/" rel="nofollow noreferrer">python-chess</a> 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.</p>
  
  <p>Is there already an existing chess environment that is faster than this in python?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-20T17:31:03.973Z
Comments.Text: 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.
Comments.UserDisplayName: IA Petr Harasimovic
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-20T18:16:42.870Z
Comments.Text: 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.
Comments.UserDisplayName: Paul Terwilliger
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-20T18:55:48.677Z
Comments.Text: 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.
Comments.UserDisplayName: IA Petr Harasimovic
Tags: <engines>
Title: Chess environments for reinforcement learning
ThreadText: # Chess environments for reinforcement learning
  
  (Asked by: username_0 on 2018-06-20)
  
  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](https://pypi.org/project/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?
  
  **Tags:** engines
  
  > **Comments:**
  > **username_1**: 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.  
  > **username_0**: 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.  
  > **username_1**: 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.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2018-06-21. Score: 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.
  
  > **Comments:**
  > **username_3**: 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++.  
  
  ---
  
  