Skip to content
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

lc0 truncated VerboseMoveStats output #1026

Closed
SimonBenhamou opened this issue Jul 20, 2023 · 1 comment
Closed

lc0 truncated VerboseMoveStats output #1026

SimonBenhamou opened this issue Jul 20, 2023 · 1 comment
Labels
engine Chess engine integration question

Comments

@SimonBenhamou
Copy link

Hello,

I would like to access lc0 detailed policy, which looks like this in the UCI engine:

info string g1h1  (153 ) N:       0 (+ 0) (P:  0.10%) (WL:  -.-----) (D: -.---) (M:  -.-) (Q: -0.36545) (U: 0.01526) (S: -0.35020) (V:  -.----) 
info string g2d5  (380 ) N:       0 (+ 0) (P:  0.10%) (WL:  -.-----) (D: -.---) (M:  -.-) (Q: -0.36545) (U: 0.01558) (S: -0.34987) (V:  -.----) 
info string h6f8  (1377) N:       0 (+ 0) (P:  0.13%) (WL:  -.-----) (D: -.---) (M:  -.-) (Q: -0.36545) (U: 0.02019) (S: -0.34526) (V:  -.----) 
info string d3a6  (526 ) N:       0 (+ 0) (P:  0.17%) (WL:  -.-----) (D: -.---) (M:  -.-) (Q: -0.36545) (U: 0.02703) (S: -0.33843) (V:  -.----) 
info string g2g6  (383 ) N:       0 (+ 0) (P:  0.17%) (WL:  -.-----) (D: -.---) (M:  -.-) (Q: -0.36545) (U: 0.02764) (S: -0.33781) (V:  -.----) 
info string g2f3  (373 ) N:       0 (+ 0) (P:  0.18%) (WL:  -.-----) (D: -.---) (M:  -.-) (Q: -0.36545) (U: 0.02918) (S: -0.33627) (V:  -.----) 
info string h6f4  (1361) N:       0 (+ 0) (P:  0.20%) (WL:  -.-----) (D: -.---) (M:  -.-) (Q: -0.36545) (U: 0.03159) (S: -0.33386) (V:  -.----) 
info string d3b5  (521 ) N:       0 (+ 0) (P:  0.22%) (WL:  -.-----) (D: -.---) (M:  -.-) (Q: -0.36545) (U: 0.03500) (S: -0.33046) (V:  -.----) 
info string g2h1  (364 ) N:       0 (+ 0) (P:  0.23%) (WL:  -.-----) (D: -.---) (M:  -.-) (Q: -0.36545) (U: 0.03577) (S: -0.32969) (V:  -.----) 
info string d3f1  (503 ) N:       0 (+ 0) (P:  0.25%) (WL:  -.-----) (D: -.---) (M:  -.-) (Q: -0.36545) (U: 0.04028) (S: -0.32517) (V:  -.----) 
info string b3b4  (453 ) N:       0 (+ 0) (P:  0.28%) (WL:  -.-----) (D: -.---) (M:  -.-) (Q: -0.36545) (U: 0.04385) (S: -0.32160) (V:  -.----) 
info string d1b1  (73  ) N:       0 (+ 0) (P:  0.28%) (WL:  -.-----) (D: -.---) (M:  -.-) (Q: -0.36545) (U: 0.04417) (S: -0.32128) (V:  -.----) 
info string h6d2  (1357) N:       0 (+ 0) (P:  0.29%) (WL:  -.-----) (D: -.---) (M:  -.-) (Q: -0.36545) (U: 0.04621) (S: -0.31924) (V:  -.----) 
info string g1f1  (152 ) N:       0 (+ 0) (P:  0.31%) (WL:  -.-----) (D: -.---) (M:  -.-) (Q: -0.36545) (U: 0.04848) (S: -0.31697) (V:  -.----) 

I use the following code to interact with the engine:

maia_model_path = 'maia_models/maia-1100.pb'
if 'maia_engine' in locals():
    maia_engine.quit()
maia_engine = chess.engine.SimpleEngine.popen_uci(['lc0/build/release/lc0', 
                                                   '-w', maia_model_path,
                                                   ])
maia_engine.configure({
    "WeightsFile": maia_model_path,
    "UCI_ShowWDL": True,
    # 'ScoreType': 'win_percentage',
    "NNCacheSize": "0",
    "PolicyTemperature": 1.0,
    # "HistoryFill": "fen_only",
    "PerPVCounters": "True",
    "VerboseMoveStats": "True",
    "CacheHistoryLength": 0
    # "Noise": "False",
})

board = chess.Board(fen='r5k1/1pp2p1p/p1qpr1pB/4p2P/3n4/1P1B4/n1P2PQP/3RK1R1 w - - 1 19')
maia_analysis = maia_engine.analyse(board, chess.engine.Limit(depth=5))

But the way the python chess module parses the lc0 outputs is problematic: I get a single value in the 'string' key of the maia analysis:

'string': 'node ( 42) N: 117 (+48) (P: 78.63%) (WL: -0.09076) (D: 0.138) (M: 4.4) (Q: -0.09076) (V: -.----) '}

It looks like the 'string' attribute is overwritten for each line starting with "info string" in the UCI engine... Is there any way to capture the full output directly ?

@niklasf niklasf added question engine Chess engine integration labels Jul 25, 2023
@niklasf
Copy link
Owner

niklasf commented Jul 25, 2023

Hi. You can use maia_engine.analysis(...) as in the following example to observe every bit of information coming from the engine: https://python-chess.readthedocs.io/en/latest/engine.html#indefinite-or-infinite-analysis

@niklasf niklasf closed this as completed Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
engine Chess engine integration question
Projects
None yet
Development

No branches or pull requests

2 participants