Need help writing a script

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
M ANSARI
Posts: 3707
Joined: Thu Mar 16, 2006 7:10 pm

Need help writing a script

Post by M ANSARI »

I am trying to figure out how to run a script before an engine executable is loaded every time it is loaded... is that possible? Basically I would want that to run in a CB GUI. The script or batch file would do the following immediately after the engine is loaded ... it would

Open Engine Parameters
Add +1 to the CPU MAX string
Press OK

This is to try to see if we can find a permanent workaround for Rybka bug or initilization problem between Rybka and the CB GUI.

Thanks in advance
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Need help writing a script

Post by bob »

why not tell the GUI to run the script instead of the engine? then the last thing the script would do is execute the engine command itself...
User avatar
M ANSARI
Posts: 3707
Joined: Thu Mar 16, 2006 7:10 pm

Re: Need help writing a script

Post by M ANSARI »

Would it be possible to do it via GUI script? The problem is that the engine parameter in the GUI always takes n-1 from the CPU MAX (n being the number of CPU's you choose) ... so if you set 8 cores and unload the engine and then reload the engine again you will find out that it is at 7 cores. Actually it is a little more complicated than that and it follows the problem with the workaround in trying to get Rybka to play without exhibiting the EGTB bug. The workaround now is that you go to engine parameters and change the CPU MAX from 2048 to 7 then press OK and then press engine parameters again and switch it to 8. All will work well then but as soon as you unload the engine again and reload it again the engine parameter seems to have locked only the first change (7 in this case).

The problem arises when you want to try an engine match or tourney where engines are continuously loaded and unloaded. This is why I thought it would be better to have the script tied to the engine and not the GUI.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Need help writing a script

Post by bob »

M ANSARI wrote:Would it be possible to do it via GUI script? The problem is that the engine parameter in the GUI always takes n-1 from the CPU MAX (n being the number of CPU's you choose) ... so if you set 8 cores and unload the engine and then reload the engine again you will find out that it is at 7 cores. Actually it is a little more complicated than that and it follows the problem with the workaround in trying to get Rybka to play without exhibiting the EGTB bug. The workaround now is that you go to engine parameters and change the CPU MAX from 2048 to 7 then press OK and then press engine parameters again and switch it to 8. All will work well then but as soon as you unload the engine again and reload it again the engine parameter seems to have locked only the first change (7 in this case).

The problem arises when you want to try an engine match or tourney where engines are continuously loaded and unloaded. This is why I thought it would be better to have the script tied to the engine and not the GUI.
That was my idea. Rather than telling the GUI to execute "xyz.exe", tell it to execute "xyz.bat". In the xyz.bat file, you can do whatever you want, and then have the last line "xyz.exe" to execute the engine.
User avatar
M ANSARI
Posts: 3707
Joined: Thu Mar 16, 2006 7:10 pm

Re: Need help writing a script

Post by M ANSARI »

The idea for putting the batch file on the engine is that in an engine tourney the engine would have to be loaded and reloaded continuously. With the GUI it only starts once. If I could manage to find a way that whenever an engine call is made that the engine would load then quickly do the following:

F3 (opens the window where the parameters change)
TAB TAB ENTER (gets the correct window to open the engine parameter)
TAB TAB 8 (moves the cursor to the correct location and 8 is for 8 processors)
ENTER ENTER (this gets out of the parameter windows)

Is it possible to write a script or batchfile which would modify the rybka executable to have those things happen every time the engine is called? If not then is it possible to tell the GUI that IF engine X is called THEN do the steps mentioned above. Sorry if that sounds silly but I have never written a line of code in my life and missed the DOS part of computer timeline.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Need help writing a script

Post by bob »

M ANSARI wrote:The idea for putting the batch file on the engine is that in an engine tourney the engine would have to be loaded and reloaded continuously. With the GUI it only starts once. If I could manage to find a way that whenever an engine call is made that the engine would load then quickly do the following:

F3 (opens the window where the parameters change)
TAB TAB ENTER (gets the correct window to open the engine parameter)
TAB TAB 8 (moves the cursor to the correct location and 8 is for 8 processors)
ENTER ENTER (this gets out of the parameter windows)

Is it possible to write a script or batchfile which would modify the rybka executable to have those things happen every time the engine is called? If not then is it possible to tell the GUI that IF engine X is called THEN do the steps mentioned above. Sorry if that sounds silly but I have never written a line of code in my life and missed the DOS part of computer timeline.
I am not following. If the GUI will start something like rybka3.exe for each game, then you ought to be able to tell it to start "rybka3.bat" instead. And inside that .bat file, do whatever you want first, and the last command would be to execute rybka3.exe. The gui would have no idea that a script executed first, it just executes "something"... where that "something" is "rybka3.bat" and it behaves identically to executing rybka3.exe as far as the GUI is concerned.
User avatar
M ANSARI
Posts: 3707
Joined: Thu Mar 16, 2006 7:10 pm

Re: Need help writing a script

Post by M ANSARI »

Well we narrowed it down to a problem with the Fritz GUI intialization of the engine. Somehow the initialization order of Rybka engine by the Fritz GUI. The idea is to workaround that until the GUI gets patched ... which might take forever. With the GUI engine initialization as it is Rybka 3 will only be able to work properly with EGTB's if there is one core left open or if you "trick" the GUI into loading 7 cores first and then loading 8 cores by changing parameters (on an 8 core system). Unfortunately this change does not stick and will revert to the first change (which is 7) and thus give you one less usable CPU. This means that a "fixed" engine with the parameter changes cannot be used in a tournament as every time the engine loads and unloads you lose the fix. So my idea was to automatically do the "workaround" everytime the engine is called.

By the way from Rybka forum here is snippet of a Lukas post which seems to indicate that it is a problem with the GUI using a wrong initialization order. Maybe something to do with Rybka using processes instead of threads?

This is part of the post by Lukas which is comparing communication between Rybka and Aquarium (where there is no EGTB bug) and with Fritz GUI (where the bug comes up):

btw. this is Aquarium's communication with Rybka 3:

>>uci

<<id name Rybka 3
<<id author Vasik Rajlich, Larry Kaufman
<<option name UCI_Query type button
<<option name Hash type spin min 2 max 4096 default 32
<<option name Max CPUs type spin min 1 max 2048 default 2048
<<option name NalimovPath type string default <empty>
<<option name NalimovCache type spin min 1 max 256 default 1
<<option name NalimovUsage type combo default Rarely var Frequently var Normally var Rarely var Never
<<option name Preserve Analysis type check default false
<<option name Clear Hash type button
<<option name Saved Hash File type string default <empty>
<<option name Save Hash type button
<<option name Load Hash type button
<<option name Persistent Hash Enabled type check default false
<<option name Persistent Hash File type string default <empty>
<<option name Persistent Hash Play Depth type spin default 64 min 8 max 64
<<option name Persistent Hash Write Depth type spin default 10 min 8 max 64
<<option name Persistent Hash Size type spin default 16 min 8 max 65536
<<option name Persistent Hash Reset type button
<<option name Persistent Hash Resize type button
<<option name Persistent Hash Merge File type string default <empty>
<<option name Persistent Hash Do Merge type button
<<option name Ponder type check default false
<<option name MultiPV type spin default 1 min 1 max 100
<<option name MultiPV_cp type spin default 32768 min 0 max 32768
<<option name Contempt Play type spin default 15 min -250 max 250
<<option name Contempt Analyze type spin default 0 min -250 max 250
<<option name UCI_LimitStrength type check default false
<<option name UCI_Elo type spin default 1200 min 1200 max 2400
<<option name UCI_EngineAbout type string default www.rybkachess.com
<<option name Time Buffer type spin default 0 min 0 max 900
<<uciok

>>setoption name max cpus value 2048

>>setoption name nalimovpath value E:\TBS;E:\TB6

>>setoption name nalimovcache value 16
>>setoption name nalimovusage value frequently
>>setoption name preserve analysis value false
>>setoption name saved hash file value <empty>
>>setoption name persistent hash enabled value false
>>setoption name persistent hash file value <empty>
>>setoption name persistent hash play depth value 64
>>setoption name persistent hash write depth value 10
>>setoption name persistent hash size value 16
>>setoption name persistent hash merge file value <empty>
>>setoption name ponder value false
>>setoption name multipv value 1
>>setoption name multipv_cp value 32768
>>setoption name contempt play value 15
>>setoption name contempt analyze value 0
>>setoption name uci_limitstrength value false
>>setoption name uci_elo value 1200
>>setoption name uci_engineabout value www.rybkachess.com
>>setoption name time buffer value 0

>>setoption name Hash value 32

>>isready

<<info string Max CPUs set to 2048
<<info string saved hash path set to <empty>
<<info string persistent hash is disabled
<<info string persistent hash file set but persistent hash itself is disabled
<<info string persistent hash play depth set to 64
<<info string persistent hash write depth set to 10
<<info string persistent hash size set to 16 mb
<<info string persistent hash merge file set to <empty>
<<info strong time buffer set to 0 seconds
<<readyok

>>setoption name MultiPV value 1
>>setoption name MultiPV_cp value 0
>>isready

<<readyok

>>cbr3
>>setoption name MultiPV value 1
>>setoption name MultiPV_cp value 30000
>>isready

<<option name cbr3_randomizer_threshold type spin default 8 min 1 max 512
<<option name cbr3_randomizer_mode type check default false
<<option name cbr3_randomizer_reset type button
<<cbr3ok
<<readyok




and this is Fritz GUI talking to Rybka:

>>uci

<<id name Rybka 3
<<id author Vasik Rajlich, Larry Kaufman
<<option name UCI_Query type button
<<option name Hash type spin min 2 max 4096 default 32
<<option name Max CPUs type spin min 1 max 2048 default 2048
<<option name NalimovPath type string default <empty>
<<option name NalimovCache type spin min 1 max 256 default 1
<<option name NalimovUsage type combo default Rarely var Frequently var Normally var Rarely var Never
<<option name Preserve Analysis type check default false
<<option name Clear Hash type button
<<option name Saved Hash File type string default <empty>
<<option name Save Hash type button
<<option name Load Hash type button
<<option name Persistent Hash Enabled type check default false
<<option name Persistent Hash File type string default <empty>
<<option name Persistent Hash Play Depth type spin default 64 min 8 max 64
<<option name Persistent Hash Write Depth type spin default 10 min 8 max 64
<<option name Persistent Hash Size type spin default 16 min 8 max 65536
<<option name Persistent Hash Reset type button
<<option name Persistent Hash Resize type button
<<option name Persistent Hash Merge File type string default <empty>
<<option name Persistent Hash Do Merge type button
<<option name Ponder type check default false
<<option name MultiPV type spin default 1 min 1 max 100
<<option name MultiPV_cp type spin default 32768 min 0 max 32768
<<option name Contempt Play type spin default 15 min -250 max 250
<<option name Contempt Analyze type spin default 0 min -250 max 250
<<option name UCI_LimitStrength type check default false
<<option name UCI_Elo type spin default 1200 min 1200 max 2400
<<option name UCI_EngineAbout type string default www.rybkachess.com
<<option name Time Buffer type spin default 0 min 0 max 900
<<uciok

>>setoption name UCI_Query

<<info string uci3 supported
<<info string cbr3 supported
<<info string car3 supported
<<info string queryok

>>uci3

<<option name NalimovPath type path default <empty>
<<option name NalimovCache type slider min 1 max 256 default 1
<<option name Saved Hash File type file default *.rsh
<<option name Persistent Hash File type file default *.rph
<<option name Persistent Hash Merge File type file default *.rph
<<uci3ok

>>cbr3

<<option name cbr3_randomizer_threshold type spin default 8 min 1 max 512
<<option name cbr3_randomizer_mode type check default false
<<option name cbr3_randomizer_reset type button
<<cbr3ok
>>setoption name Hash value 32
>>setoption name NalimovPath value E:\TBS;E:\TB6

>>setoption name NalimovCache value 16
>>setoption name NalimovUsage value Frequently
>>isready

<<readyok

So I think, after loading tablebases Rybka needs a command that restarts children tasks - setoption name hash or setoption name Max CPUs

Fritz GUI just gives the wrong order of commands.
User avatar
hgm
Posts: 27795
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Need help writing a script

Post by hgm »

How do you mean "until the GUI gets patched"? This is a Rybka 3 bug, not? The GUI is not going to be patched to provide work-arounds for non-compliant engines.
User avatar
M ANSARI
Posts: 3707
Joined: Thu Mar 16, 2006 7:10 pm

Re: Need help writing a script

Post by M ANSARI »

To be honest I have no clue if the problem is with Rybka or the GUI ... most likely it is a combination of both since the Rybka I have is Rybka 3 from CB with the Fritz GUI. This could be due to the fact that Rybka uses processes instead of threads, which is not the norm for the other engines. Somehow by changing something like the hash by even 1mb and everything starts working fine. Only problem is that this has to be done everytime you load the engine which makes it not possible to use it in tourneys or on Playchess (except for 1 game at a time).
Gian-Carlo Pascutto
Posts: 1243
Joined: Sat Dec 13, 2008 7:00 pm

Re: Need help writing a script

Post by Gian-Carlo Pascutto »

The GUI is free to set the UCI options in any order it wants to. The bug is with the engine.