Ambiguous: UCI and option Clear Hash

Discussion of chess software programming and technical issues.

Moderators: hgm, Harvey Williamson, bob

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Post Reply
User avatar
phhnguyen
Posts: 337
Joined: Wed Apr 21, 2010 2:58 am
Location: Australia
Full name: Nguyen Hong Pham
Contact:

Ambiguous: UCI and option Clear Hash

Post by phhnguyen » Thu Jun 20, 2019 12:52 am

I got confused when working with option “Clear Hash”. From UCI documents that option is described shortly:

Code: Select all

option name Clear Hash type button
I may guess the purpose of the option based on the meaning of the name (clear hash). I understand the GUI should show a button for that option too. However look like I missed the commands from GUI to order engines to do that task (clear hash tables).

Can someone explain to me how the option work? What happens when user clicks to “clear hash” button? What commands GUI should send to engines? What “standard” reactions by GUI when working with option type of button? Thanks.
https://github.com/nguyenpham/Banksia
An open source C++11 chess tournament manager

MikeB
Posts: 3158
Joined: Thu Mar 09, 2006 5:34 am
Location: Pen Argyl, Pennsylvania

Re: Ambiguous: UCI and option Clear Hash

Post by MikeB » Thu Jun 20, 2019 3:57 am

phhnguyen wrote:
Thu Jun 20, 2019 12:52 am
I got confused when working with option “Clear Hash”. From UCI documents that option is described shortly:

Code: Select all

option name Clear Hash type button
I may guess the purpose of the option based on the meaning of the name (clear hash). I understand the GUI should show a button for that option too. However look like I missed the commands from GUI to order engines to do that task (clear hash tables).

Can someone explain to me how the option work? What happens when user clicks to “clear hash” button? What commands GUI should send to engines? What “standard” reactions by GUI when working with option type of button? Thanks.
You might be over thinking this. It works like any other UCI command the GUI sends to the engine. The GUI will send the command "setoption name Clear Hash" to the engine. The engine will reinitiate the hashtable by however method the programmer had decided when it receives the command.

In stockfish, when that that command is sent to the engine, it will call the the Search:clear() function, as if it was a new game. A user would click that button when they want the engine to start a with clean search when analyzing. Probably more used by programmers and hardcore computer chess enthusiasts than an average user.

Code: Select all

void Search::clear() {

  Threads.main()->wait_for_search_finished();

  Time.availableNodes = 0;
  TT.clear();
  Threads.clear();
  Tablebases::init(Options["SyzygyPath"]); // Free mapped files
}

MikeB
Posts: 3158
Joined: Thu Mar 09, 2006 5:34 am
Location: Pen Argyl, Pennsylvania

Re: Ambiguous: UCI and option Clear Hash

Post by MikeB » Thu Jun 20, 2019 4:10 am

MikeB wrote:
Thu Jun 20, 2019 3:57 am
phhnguyen wrote:
Thu Jun 20, 2019 12:52 am
I got confused when working with option “Clear Hash”. From UCI documents that option is described shortly:

Code: Select all

option name Clear Hash type button
I may guess the purpose of the option based on the meaning of the name (clear hash). I understand the GUI should show a button for that option too. However look like I missed the commands from GUI to order engines to do that task (clear hash tables).

Can someone explain to me how the option work? What happens when user clicks to “clear hash” button? What commands GUI should send to engines? What “standard” reactions by GUI when working with option type of button? Thanks.
You might be over thinking this. It works like any other UCI command the GUI sends to the engine. The GUI will send the command "setoption name Clear Hash" to the engine. The engine will reinitiate the hashtable by however method the programmer had decided when it receives the command.

In stockfish, when that that command is sent to the engine, it will call the the Search:clear() function, as if it was a new game. A user would click that button when they want the engine to start a with clean search when analyzing. Probably more used by programmers and hardcore computer chess enthusiasts than an average user.

Code: Select all

void Search::clear() {

  Threads.main()->wait_for_search_finished();

  Time.availableNodes = 0;
  TT.clear();
  Threads.clear();
  Tablebases::init(Options["SyzygyPath"]); // Free mapped files
}
Also, you might want to download the GUI Arena, Arena has a logging function that can be turned on . When it is turned on, it will record all the communication being sent between the GUI and the engine to a file. You should play around with that to see how the communication works between GUI and engine actually occurs - the commands being sent back and forth.

User avatar
hgm
Posts: 23295
Joined: Fri Mar 10, 2006 9:06 am
Location: Amsterdam
Full name: H G Muller
Contact:

Re: Ambiguous: UCI and option Clear Hash

Post by hgm » Thu Jun 20, 2019 6:30 am

phhnguyen wrote:
Thu Jun 20, 2019 12:52 am
Can someone explain to me how the option work? What happens when user clicks to “clear hash” button? What commands GUI should send to engines? What “standard” reactions by GUI when working with option type of button? Thanks.
So options of type 'button' are treated a bit different from other engine-defined options: when the buttons appearing in the engine-settings dialog are pressed this will send a 'setoption' command to the engine immediately, and that command will differ from 'setoption' commands for other types, in that it does not have a 'value' part. Changes in other option types will only be sent to the engine when you close the Engine Settings dialog through 'OK'.

'Clear Hash' is not a standard option, so UCI engines are not obliged to have it. So it might not be wise to implement features in a GUI that rely on it. OTOH, many engines are likely to have it, with exactly that name. So if a GUI would for instance have a mode to run EPD test suites, it might want to explicitly exercise the option before starting the new search, if the engine has it.

User avatar
phhnguyen
Posts: 337
Joined: Wed Apr 21, 2010 2:58 am
Location: Australia
Full name: Nguyen Hong Pham
Contact:

Re: Ambiguous: UCI and option Clear Hash

Post by phhnguyen » Thu Jun 20, 2019 6:41 am

MikeB wrote: You might be over thinking this. It works like any other UCI command the GUI sends to the engine. The GUI will send the command "setoption name Clear Hash" to the engine. The engine will reinitiate the hashtable by however method the programmer had decided when it receives the command.
Wow, thanks. You are right. Simpler than my thought (I thought being an option it should have some values to select and send).

BTW, "setoption name Clear Hash" is... no meaning (in term of logic and English), right? :wink:
MikeB wrote: Also, you might want to download the GUI Arena, Arena has a logging function that can be turned on .
Thanks again but it is useless for me since I am in Mac world :)
https://github.com/nguyenpham/Banksia
An open source C++11 chess tournament manager

User avatar
phhnguyen
Posts: 337
Joined: Wed Apr 21, 2010 2:58 am
Location: Australia
Full name: Nguyen Hong Pham
Contact:

Re: Ambiguous: UCI and option Clear Hash

Post by phhnguyen » Thu Jun 20, 2019 7:14 am

hgm wrote:
Thu Jun 20, 2019 6:30 am
phhnguyen wrote:
Thu Jun 20, 2019 12:52 am
Can someone explain to me how the option work? What happens when user clicks to “clear hash” button? What commands GUI should send to engines? What “standard” reactions by GUI when working with option type of button? Thanks.
So options of type 'button' are treated a bit different from other engine-defined options: when the buttons appearing in the engine-settings dialog are pressed this will send a 'setoption' command to the engine immediately, and that command will differ from 'setoption' commands for other types, in that it does not have a 'value' part. Changes in other option types will only be sent to the engine when you close the Engine Settings dialog through 'OK'.

'Clear Hash' is not a standard option, so UCI engines are not obliged to have it. So it might not be wise to implement features in a GUI that rely on it. OTOH, many engines are likely to have it, with exactly that name. So if a GUI would for instance have a mode to run EPD test suites, it might want to explicitly exercise the option before starting the new search, if the engine has it.
Thanks HGM! I have never seen that button in xboard. Does it have when working with UCI engines?
https://github.com/nguyenpham/Banksia
An open source C++11 chess tournament manager

User avatar
hgm
Posts: 23295
Joined: Fri Mar 10, 2006 9:06 am
Location: Amsterdam
Full name: H G Muller
Contact:

Re: Ambiguous: UCI and option Clear Hash

Post by hgm » Thu Jun 20, 2019 8:43 am

The button should be in the Engine Settings dialog when you have loaded an engine that declares this option. Fairy-Max also supports it.

User avatar
abik
Posts: 724
Joined: Fri Dec 01, 2006 9:46 pm
Location: Mountain View, CA, USA
Full name: Aart Bik
Contact:

Re: Ambiguous: UCI and option Clear Hash

Post by abik » Thu Jun 20, 2019 4:00 pm

hgm wrote:
Thu Jun 20, 2019 6:30 am
So options of type 'button' are treated a bit different from other engine-defined options: when the buttons appearing in the engine-settings dialog are pressed this will send a 'setoption' command to the engine immediately, and that command will differ from 'setoption' commands for other types, in that it does not have a 'value' part. Changes in other option types will only be sent to the engine when you close the Engine Settings dialog through 'OK'.
H.G.,
Is this immediate behavior defined in the standard? I opted to implement this just like any other option (viz. if the user has pressed the button during the lifetime of the dialog, the option will be send (and without value obviously)) when closing the dialog. Both the direct and delayed interpretation make some sort of sense, but I was not sure from reading the protocol description.
Aart

User avatar
hgm
Posts: 23295
Joined: Fri Mar 10, 2006 9:06 am
Location: Amsterdam
Full name: H G Muller
Contact:

Re: Ambiguous: UCI and option Clear Hash

Post by hgm » Thu Jun 20, 2019 6:34 pm

I don't think this is anything the standard would care about; this just defines what effect the commands have on the engine. The GUI designer has the freedom to use them as he says fit. There is also no requirement that the Engine Settings dialog should have an 'OK' button, or indeed that there should be a separate Engine Settings dialog at all.

As a user I would be surprised if buttons did not have an immediate effect, and I never considered the method you describe. But come to think of it, I am not sure it would ever make any observable difference, though. Perhaps if there was a button that toggled something in the engine. (But why would one not use a checkbox for that.)

User avatar
abik
Posts: 724
Joined: Fri Dec 01, 2006 9:46 pm
Location: Mountain View, CA, USA
Full name: Aart Bik
Contact:

Re: Ambiguous: UCI and option Clear Hash

Post by abik » Thu Jun 20, 2019 7:21 pm

hgm wrote:
Thu Jun 20, 2019 6:34 pm
As a user I would be surprised if buttons did not have an immediate effect, and I never considered the method you describe. But come to think of it, I am not sure it would ever make any observable difference, though. Perhaps if there was a button that toggled something in the engine. (But why would one not use a checkbox for that.)
Thanks for your thoughts.

For that reason, I found the button widget a bit "impure" compared to the others. Perhaps it would have been better to split the options setup (shown during a first setup dialog) from widgets like this (which could have been shown next to the chessboard during regular play). It generally does not make sense to clear the hash when the engine starts, but it makes sense to request clearing the hash after some games have been played, without affecting other options.

Post Reply