fsmosca / chess-artist

A python script that can annotate chess games in pgn file with static evaluation or search score of an engine, can annotate an epd file with acd, acs, bm, and ce opcodes, can test engine with epd test suite and can generate chess puzzles.
GNU General Public License v3.0
70 stars 18 forks source link

After ucinewgame an isready/readyok check is required #69

Closed borg323 closed 4 years ago

borg323 commented 4 years ago

This is explicitly stated in the UCI spec and is an issue with lc0, that initializes the neural network after receiving ucinewgame, a process that may take a few seconds.

fsmosca commented 4 years ago

Thanks for posting this issue. I see in one occasion that chess artist has sent isready without waiting for readyok from engine. I will fix this issue next week together with other minor modifications.

Regarding Lc0 and NN init, the usual procedure as specified in UCI protocol is:

  1. interface to engine: uci wait for uciok from engine

  2. interface to engine: setoption ...

  3. interface to engine: isready

engine/Lc0 should init/load its NN and others here. When everything is done, send readyok to interface.

wait for readyok from engine

  1. interface to engine: ucinewgame

  2. interface to engine: position ...

But of course if the engine could not handle it, I will send isready/wait readyok, even after position command to make sure that engine and interface are in sync.

borg323 commented 4 years ago

Note that the uci spec says:

As the engine's reaction to "ucinewgame" can take some time the GUI should always send "isready" after "ucinewgame" to wait for the engine to finish its operation.

Regarding lc0, we used to also initialize the NN with isready as you suggest, but this caused us some trouble so we now only do it on ucinewgame with a fallback on the first position. I can dig up the gory details if you are interested.

fsmosca commented 4 years ago

All right I will send isready after ucinewgame.

fsmosca commented 4 years ago

A. Test engine with test suite

chess-artist.py --infile epd\wacnew.epd --outfile wacnew.txt --enginefile D:\Chess\Engines\Lc0\lc0-v0.23.1-windows-cpu-openblas\lc0.exe --engineoptions "Threads value 1, WeightsFile value D:\Chess\Engines\Lc0\id\LD2.pb.gz, MinibatchSize value 32" --movetime 1000 --job test --eval search --log

Log

2020-01-01 11:06:54,186 :: pid: 1720 :: tid: 12384 :: DEBUG :: << uciok
2020-01-01 11:06:54,186 :: pid: 1720 :: tid: 12384 :: DEBUG :: >> setoption name Threads value 1
2020-01-01 11:06:54,186 :: pid: 1720 :: tid: 12384 :: DEBUG :: >> setoption name WeightsFile value D:\Chess\Engines\Lc0\id\LD2.pb.gz
2020-01-01 11:06:54,186 :: pid: 1720 :: tid: 12384 :: DEBUG :: >> setoption name MinibatchSize value 32
2020-01-01 11:06:54,186 :: pid: 1720 :: tid: 12384 :: DEBUG :: >> isready
2020-01-01 11:06:54,186 :: pid: 1720 :: tid: 12384 :: DEBUG :: << readyok
2020-01-01 11:06:54,186 :: pid: 1720 :: tid: 12384 :: DEBUG :: >> ucinewgame
2020-01-01 11:06:54,186 :: pid: 1720 :: tid: 12384 :: DEBUG :: >> isready
2020-01-01 11:06:54,186 :: pid: 1720 :: tid: 12384 :: DEBUG :: << Loading weights file from: D:\Chess\Engines\Lc0\id\LD2.pb.gz
2020-01-01 11:06:54,249 :: pid: 1720 :: tid: 12384 :: DEBUG :: << Creating backend [blas]...
2020-01-01 11:06:54,311 :: pid: 1720 :: tid: 12384 :: DEBUG :: << BLAS vendor: OpenBLAS.
2020-01-01 11:06:54,311 :: pid: 1720 :: tid: 12384 :: DEBUG :: << OpenBLAS [NO_LAPACK NO_LAPACKE DYNAMIC_ARCH NO_AFFINITY Sandybridge MAX_THREADS=128].
2020-01-01 11:06:54,311 :: pid: 1720 :: tid: 12384 :: DEBUG :: << OpenBLAS found 8 Sandybridge core(s).
2020-01-01 11:06:54,311 :: pid: 1720 :: tid: 12384 :: DEBUG :: << OpenBLAS using 1 core(s) for this backend.
2020-01-01 11:06:54,311 :: pid: 1720 :: tid: 12384 :: DEBUG :: << BLAS max batch size is 256.
2020-01-01 11:06:54,311 :: pid: 1720 :: tid: 12384 :: DEBUG :: << readyok
2020-01-01 11:06:54,311 :: pid: 1720 :: tid: 12384 :: DEBUG :: >> position fen 2br2k1/2q3rn/p2NppQ1/2p1P3/Pp5R/4P3/1P3PPP/3R2K1 w - - 0 1
2020-01-01 11:06:54,311 :: pid: 1720 :: tid: 12384 :: DEBUG :: >> go movetime 1000

B. Analyze game

chess-artist.py --infile pgn\iommast19.pgn --outfile ana_iommast19.pgn --enginefile D:\Chess\Engines\Lc0\lc0-v0.23.1-windows-cpu-openblas\lc0.exe --engineoptions "Threads value 1,WeightsFile value D:\Chess\Engines\Lc0\id\LD2.pb.gz" --movestart 15 --movetime 1000 --job analyze --eval search --log

Log

2020-01-01 11:29:52,150 :: pid: 4996 :: tid: 1296 :: DEBUG :: << uciok
2020-01-01 11:29:52,150 :: pid: 4996 :: tid: 1296 :: DEBUG :: >> setoption name Threads value 1
2020-01-01 11:29:52,150 :: pid: 4996 :: tid: 1296 :: DEBUG :: >> setoption name WeightsFile value D:\Chess\Engines\Lc0\id\LD2.pb.gz
2020-01-01 11:29:52,150 :: pid: 4996 :: tid: 1296 :: DEBUG :: >> isready
2020-01-01 11:29:52,150 :: pid: 4996 :: tid: 1296 :: DEBUG :: << readyok
2020-01-01 11:29:52,150 :: pid: 4996 :: tid: 1296 :: DEBUG :: >> ucinewgame
2020-01-01 11:29:52,150 :: pid: 4996 :: tid: 1296 :: DEBUG :: >> isready
2020-01-01 11:29:52,150 :: pid: 4996 :: tid: 1296 :: DEBUG :: << Loading weights file from: D:\Chess\Engines\Lc0\id\LD2.pb.gz
2020-01-01 11:29:52,212 :: pid: 4996 :: tid: 1296 :: DEBUG :: << Creating backend [blas]...
2020-01-01 11:29:52,275 :: pid: 4996 :: tid: 1296 :: DEBUG :: << BLAS vendor: OpenBLAS.
2020-01-01 11:29:52,275 :: pid: 4996 :: tid: 1296 :: DEBUG :: << OpenBLAS [NO_LAPACK NO_LAPACKE DYNAMIC_ARCH NO_AFFINITY Sandybridge MAX_THREADS=128].
2020-01-01 11:29:52,275 :: pid: 4996 :: tid: 1296 :: DEBUG :: << OpenBLAS found 8 Sandybridge core(s).
2020-01-01 11:29:52,275 :: pid: 4996 :: tid: 1296 :: DEBUG :: << OpenBLAS using 1 core(s) for this backend.
2020-01-01 11:29:52,275 :: pid: 4996 :: tid: 1296 :: DEBUG :: << BLAS max batch size is 256.
2020-01-01 11:29:52,275 :: pid: 4996 :: tid: 1296 :: DEBUG :: << readyok
2020-01-01 11:29:52,275 :: pid: 4996 :: tid: 1296 :: DEBUG :: >> position fen r3kb1r/pp3pq1/1np1b2p/3pP1p1/3P4/2NB2P1/PPQ2PPN/2KR3R b kq - 2 15

C. Create puzzle

chess-artist.py --infile pgn\iommast19.pgn --outfile out_iommast19.pgn --enginefile D:\Chess\Engines\Lc0\lc0-v0.23.1-windows-cpu-openblas\lc0.exe --engineoptions "Threads value 1,WeightsFile value D:\Chess\Engines\Lc0\id\LD2.pb.gz" --movestart 15 --movetime 10000 --job createpuzzle --eval search --log

Log

2020-01-01 11:39:50,785 :: pid: 15072 :: tid: 8940 :: DEBUG :: << uciok
2020-01-01 11:39:50,785 :: pid: 15072 :: tid: 8940 :: DEBUG :: >> setoption name Threads value 1
2020-01-01 11:39:50,785 :: pid: 15072 :: tid: 8940 :: DEBUG :: >> setoption name WeightsFile value D:\Chess\Engines\Lc0\id\LD2.pb.gz
2020-01-01 11:39:50,785 :: pid: 15072 :: tid: 8940 :: DEBUG :: >> isready
2020-01-01 11:39:50,785 :: pid: 15072 :: tid: 8940 :: DEBUG :: << readyok
2020-01-01 11:39:50,785 :: pid: 15072 :: tid: 8940 :: DEBUG :: >> ucinewgame
2020-01-01 11:39:50,785 :: pid: 15072 :: tid: 8940 :: DEBUG :: >> isready
2020-01-01 11:39:50,785 :: pid: 15072 :: tid: 8940 :: DEBUG :: << Loading weights file from: D:\Chess\Engines\Lc0\id\LD2.pb.gz
2020-01-01 11:39:50,847 :: pid: 15072 :: tid: 8940 :: DEBUG :: << Creating backend [blas]...
2020-01-01 11:39:50,910 :: pid: 15072 :: tid: 8940 :: DEBUG :: << BLAS vendor: OpenBLAS.
2020-01-01 11:39:50,910 :: pid: 15072 :: tid: 8940 :: DEBUG :: << OpenBLAS [NO_LAPACK NO_LAPACKE DYNAMIC_ARCH NO_AFFINITY Sandybridge MAX_THREADS=128].
2020-01-01 11:39:50,910 :: pid: 15072 :: tid: 8940 :: DEBUG :: << OpenBLAS found 8 Sandybridge core(s).
2020-01-01 11:39:50,910 :: pid: 15072 :: tid: 8940 :: DEBUG :: << OpenBLAS using 1 core(s) for this backend.
2020-01-01 11:39:50,910 :: pid: 15072 :: tid: 8940 :: DEBUG :: << BLAS max batch size is 256.
2020-01-01 11:39:50,910 :: pid: 15072 :: tid: 8940 :: DEBUG :: << readyok
2020-01-01 11:39:50,910 :: pid: 15072 :: tid: 8940 :: DEBUG :: >> position fen r1bqkb1r/pp3p2/1np4p/3p2p1/3P4/2N2NP1/PPQ1PPP1/2KR1B1R w kq - 1 12
2020-01-01 11:39:50,910 :: pid: 15072 :: tid: 8940 :: DEBUG :: >> go movetime 10000

D. Annotate epd

chess-artist.py --infile opening.epd --outfile out_opening.epd --enginefile D:\Chess\Engines\Lc0\lc0-v0.23.1-windows-cpu-openblas\lc0.exe --engineoptions "Threads value 1,WeightsFile value D:\Chess\Engines\Lc0\id\LD2.pb.gz" --movetime 30000 --job analyze --eval search --log

Log

2020-01-01 11:50:43,818 :: pid: 9008 :: tid: 1084 :: DEBUG :: << uciok
2020-01-01 11:50:43,818 :: pid: 9008 :: tid: 1084 :: DEBUG :: >> setoption name Threads value 1
2020-01-01 11:50:43,818 :: pid: 9008 :: tid: 1084 :: DEBUG :: >> setoption name WeightsFile value D:\Chess\Engines\Lc0\id\LD2.pb.gz
2020-01-01 11:50:43,834 :: pid: 9008 :: tid: 1084 :: DEBUG :: >> isready
2020-01-01 11:50:43,834 :: pid: 9008 :: tid: 1084 :: DEBUG :: << readyok
2020-01-01 11:50:43,834 :: pid: 9008 :: tid: 1084 :: DEBUG :: >> ucinewgame
2020-01-01 11:50:43,834 :: pid: 9008 :: tid: 1084 :: DEBUG :: >> isready
2020-01-01 11:50:43,834 :: pid: 9008 :: tid: 1084 :: DEBUG :: << Loading weights file from: D:\Chess\Engines\Lc0\id\LD2.pb.gz
2020-01-01 11:50:43,897 :: pid: 9008 :: tid: 1084 :: DEBUG :: << Creating backend [blas]...
2020-01-01 11:50:43,959 :: pid: 9008 :: tid: 1084 :: DEBUG :: << BLAS vendor: OpenBLAS.
2020-01-01 11:50:43,959 :: pid: 9008 :: tid: 1084 :: DEBUG :: << OpenBLAS [NO_LAPACK NO_LAPACKE DYNAMIC_ARCH NO_AFFINITY Sandybridge MAX_THREADS=128].
2020-01-01 11:50:43,959 :: pid: 9008 :: tid: 1084 :: DEBUG :: << OpenBLAS found 8 Sandybridge core(s).
2020-01-01 11:50:43,959 :: pid: 9008 :: tid: 1084 :: DEBUG :: << OpenBLAS using 1 core(s) for this backend.
2020-01-01 11:50:43,959 :: pid: 9008 :: tid: 1084 :: DEBUG :: << BLAS max batch size is 256.
2020-01-01 11:50:43,959 :: pid: 9008 :: tid: 1084 :: DEBUG :: << readyok
2020-01-01 11:50:43,959 :: pid: 9008 :: tid: 1084 :: DEBUG :: >> position fen r1bqk1nr/pppp1ppp/2n5/2b1p3/2B1P3/2P2N2/PP1P1PPP/RNBQK2R b KQkq - 0 1
2020-01-01 11:50:43,959 :: pid: 9008 :: tid: 1084 :: DEBUG :: >> go movetime 30000