Answers.Body: <p>The link refers to stockfish 11 and you are now using stockfish 14, so that article is irrelevant.</p>
  <ol>
  <li><p>To minimize processing time you can adjust the depth or movetime or both. The question is what analysis quality are you up to?</p>
  </li>
  <li><p>To control analysis time use the following example.</p>
  </li>
  </ol>
  <pre><code>engine = chess.engine.SimpleEngine.popen_uci(stockfish)
  movetimesec = 5
  def evaluate_game(game, engine, limit=chess.engine.Limit(time=movetimesec)):
     board = game.board()
     info = engine.analyse(board, limit=limit)
  </code></pre>
  <p>To use both depth and time you can use the following.</p>
  <pre><code>engine = chess.engine.SimpleEngine.popen_uci(stockfish)
  movetimesec = 5
  depth = 20
  def evaluate_game(game, engine, limit=chess.engine.Limit(time=movetimesec, depth=depth)):
     board = game.board()
     info = engine.analyse(board, limit=limit)
  </code></pre>
  <p>In this case, when the engine reaches depth 20 before the time limit of 5 sec, then the search is aborted. If analysis time of 5 sec is reached first before depth 20 then the search is also aborted.</p>
  <p>In ending phase reaching depth 20 is very fast as there are less pieces to evaluate while in the opening phase reaching depth 20 could be a challenge and movetimesec of 5 might be consumed first, depends on your hardware. It is a matter of analysis quality you want and the total time to finish the analysis.</p>
  <h4>Measuring quality and analysis time</h4>
  <ol>
  <li>Analyze game1 (more games and get the average) with depth 20, remember the total time.</li>
  <li>Analyze game1 (more games and get the average) at movetime of 5 sec, remember the total time.</li>
  <li>Run an engine vs engine match, sf14_depth20 vs sf14_5sec.</li>
  </ol>
  <p>step 1 and 2 compare the total analysis time while step 3 compares the analysis quality.</p>
  <p>I guess sf14_5sec will win over sf14_depth20, but you have to test this on that hardware.</p>
  <p>If sf14_5sec will beat sf14_depth20 in a match of 100 or so games and step 2 is lower than step 1 then sf14_5sec would be a candidate for a good setting.</p>
  <p>Now do some comparisons with <code>sf14_5sec vs sf14_5sec_depth20</code> and <code>sf14_depth20 vs sf14_5sec_depth20</code>. Keep a note on quality and total analysis time.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-02T11:38:01.233Z
Answers.Text: Good info. You're saying that the search terminates at the first instance of a limit being reached, time or depth, is that right?
Answers.UserDisplayName: David Smerdon
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-02T11:44:35.937Z
Answers.Text: That is correct.
Answers.UserDisplayName: ferdy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-02T11:51:16.940Z
Answers.Text: For step 2, analysing with movetime 5, how would I extract the final depth searched for each move?
Answers.UserDisplayName: David Smerdon
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-02T11:57:08.703Z
Answers.Text: `depth = info["depth"]`
Answers.UserDisplayName: ferdy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-02T10:59:04.453Z
Answers.LastActivityDate: 2022-02-02T11:23:36.927Z
Answers.LastEditDate: 2022-02-02T11:23:36.927Z
Answers.UserDisplayName: ferdy
Body: <p>I am running a python script that analyzes a large batch of PGN games (each of ~5,000 games) across  and exports the games evaluations. It calls Stockfish 14 to analyze each game at depth 20. **[EDIT: I've since <a href="https://chessify.me/blog/nps-vs-time-to-depth-what-you-should-look-at-when-analyzing-with-stockfish/" rel="nofollow noreferrer">read</a> that newer versions of Stockfish can actually take LONGER to reach the same depth as older versions, because they have a wider search and thus more nodes per second. So I am considering setting a position time limit rather than depth limit.] **I am using a virtual machine with 32 vCPUs and 64GB RAM but processing is slow (though <code>htop</code> claims it is using 99% of CPU%). I haven't modified any Stockfish settings since installing.</p>
  <ol>
  <li>What parameters should I set to minimize the processing time?</li>
  <li>How can I change these settings so that they will be recognized by the call from python-chess? The relevant lines of the python code are:</li>
  </ol>
  <pre><code>engine = chess.engine.SimpleEngine.popen_uci(stockfish)
  engine_depth = 20
  def evaluate_game(game, engine, limit=chess.engine.Limit(depth=engine_depth)):
     board = game.board()
     info = engine.analyse(board, limit=limit)
  </code></pre>
  
Tags: <engines><analysis><stockfish><python>
Title: Optimising Stockfish parameters when batch-analyzing with python-chess
ThreadText: # Optimising Stockfish parameters when batch-analyzing with python-chess
  
  (Asked by: username_0 on 2022-02-02)
  
  I am running a python script that analyzes a large batch of PGN games (each of ~5,000 games) across and exports the games evaluations. It calls Stockfish 14 to analyze each game at depth 20. \*\*[EDIT: I've since [read](https://chessify.me/blog/nps-vs-time-to-depth-what-you-should-look-at-when-analyzing-with-stockfish/) that newer versions of Stockfish can actually take LONGER to reach the same depth as older versions, because they have a wider search and thus more nodes per second. So I am considering setting a position time limit rather than depth limit.] \*\*I am using a virtual machine with 32 vCPUs and 64GB RAM but processing is slow (though `htop` claims it is using 99% of CPU%). I haven't modified any Stockfish settings since installing.
  
  1. What parameters should I set to minimize the processing time?
  2. How can I change these settings so that they will be recognized by the call from python-chess? The relevant lines of the python code are:
  
  ```
  engine = chess.engine.SimpleEngine.popen_uci(stockfish)
  engine_depth = 20
  def evaluate_game(game, engine, limit=chess.engine.Limit(depth=engine_depth)):
     board = game.board()
     info = engine.analyse(board, limit=limit)
  
  ```
  
  **Tags:** engines, analysis, stockfish, python
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-02-02. Score: 2 | Accepted answer
  
  The link refers to stockfish 11 and you are now using stockfish 14, so that article is irrelevant.
  
  1. To minimize processing time you can adjust the depth or movetime or both. The question is what analysis quality are you up to?
  2. To control analysis time use the following example.
  
  ```
  engine = chess.engine.SimpleEngine.popen_uci(stockfish)
  movetimesec = 5
  def evaluate_game(game, engine, limit=chess.engine.Limit(time=movetimesec)):
     board = game.board()
     info = engine.analyse(board, limit=limit)
  
  ```
  
  To use both depth and time you can use the following.
  
  ```
  engine = chess.engine.SimpleEngine.popen_uci(stockfish)
  movetimesec = 5
  depth = 20
  def evaluate_game(game, engine, limit=chess.engine.Limit(time=movetimesec, depth=depth)):
     board = game.board()
     info = engine.analyse(board, limit=limit)
  
  ```
  
  In this case, when the engine reaches depth 20 before the time limit of 5 sec, then the search is aborted. If analysis time of 5 sec is reached first before depth 20 then the search is also aborted.
  
  In ending phase reaching depth 20 is very fast as there are less pieces to evaluate while in the opening phase reaching depth 20 could be a challenge and movetimesec of 5 might be consumed first, depends on your hardware. It is a matter of analysis quality you want and the total time to finish the analysis.
  
  #### Measuring quality and analysis time
  
  1. Analyze game1 (more games and get the average) with depth 20, remember the total time.
  2. Analyze game1 (more games and get the average) at movetime of 5 sec, remember the total time.
  3. Run an engine vs engine match, sf14\_depth20 vs sf14\_5sec.
  
  step 1 and 2 compare the total analysis time while step 3 compares the analysis quality.
  
  I guess sf14\_5sec will win over sf14\_depth20, but you have to test this on that hardware.
  
  If sf14\_5sec will beat sf14\_depth20 in a match of 100 or so games and step 2 is lower than step 1 then sf14\_5sec would be a candidate for a good setting.
  
  Now do some comparisons with `sf14_5sec vs sf14_5sec_depth20` and `sf14_depth20 vs sf14_5sec_depth20`. Keep a note on quality and total analysis time.
  
  > **Comments:**
  > **username_0**: Good info. You're saying that the search terminates at the first instance of a limit being reached, time or depth, is that right?  
  > **username_1**: That is correct.  
  > **username_0**: For step 2, analysing with movetime 5, how would I extract the final depth searched for each move?  
  > **username_1**: `depth = info["depth"]`  
  
  ---
  
  