Engines losing on time in won/drew games

Discussion of anything and everything relating to chess playing software and machines.

Moderators: hgm, Rebel, chrisw

Aaron Becker
Posts: 292
Joined: Tue Jul 07, 2009 4:56 am

Re: Engines losing on time in won/drew games

Post by Aaron Becker »

Carlos777 wrote:
Hi Miguel and Aaaron,

Thanks for the explanation. This confirms that Arena is the problem here. As I said before, there were reports from programmers and users about Arena stealing time from engines. I will try WB + PSWBTM next, it seems more reliable about time allocating. I'd like that these issues were solved in the next version of Arena, because (as I stated before) it is my favorite GUI.

Best regards,
Carlos

PS: Also thanks to HGM for his informative posts.
I should point out that Daydreamer 1.75 really does have a time management bug that turns up in maybe 1% of games. Arena seems to be responsible for the weird time loss issues I pointed out in my earlier post, as Miguel said, but there is an unrelated problem with Daydreamer that can also cause losses on time.

Aaron
User avatar
michiguel
Posts: 6401
Joined: Thu Mar 09, 2006 8:30 pm
Location: Chicago, Illinois, USA

Re: Engines losing on time in won/drew games

Post by michiguel »

Matthias Gemuh wrote:
Matthias Gemuh wrote:
michiguel wrote:
Matthias Gemuh wrote: Hi Miguel,

if you ever have time for it, can you test ChessGUI's time management (even in bullet games).
I try to account for every millisecond.
BTW, ChessGUI has a time overstep margin (set to zero by default).

Matthias.
I will.

In the meantime, before I put my hands on a windows machine (I am using Linux, mostly), if you play few games with Gaviota, send me the log files (my gmail account is mballicora) and I can extract the information from there.

Miguel

Which fast time control should I use ?
I tried "Game/30sec" and Gaviota lost one game (8 games played) on time at move 90.
It produced no logs.

Code: Select all

log         = on
max_logs    = 8
Is the ini file really gaviota.ini.txt ?
No logs created at 1+1 either.

Renaming to gaviota.ini did not help.

I am using a later Gaviota renamed to Gaviota 0.74.12

Matthias.
That is odd.

Could you try the latest release? The direct link is
http://sites.google.com/site/gaviotache ... ects=0&d=1
Use the whole folder. The logs will be in the logs sub folder.

In case that I made a mistake, open gaviota.ini.txt with notepad and make sure I did not mess up the carriage returns coming from linux. If you open it with word, and save it back as text file, it should correct the problem. I do not think I made that mistake, but just in case.

Miguel
User avatar
ilari
Posts: 750
Joined: Mon Mar 27, 2006 7:45 pm
Location: Finland

Re: Engines losing on time in won/drew games

Post by ilari »

michiguel wrote:Very simple: Arena steals time from the engines and it may not be the only GUI who do that in windows (Ilari said he needed to replace some libraries to avoid similar problems with cutechess in windows). I measured it and posted about it some time ago. On average, in one computer I tested Arena steals from 0.2 to 0.4 seconds / move, and for some reason, that gets much bigger when the engine is probing the hard drive. In some cases, I measured a delay of 4 seconds, but it was not so rare to see delays of 0.5 to 2 seconds. You just need one event like that once in a while, and the engine loses on time.
More specifically, I had to reimplement a class in the Qt library to make Cute Chess react to new input from an engine immediately. The problem was that Qt on Windows polls for input every x milliseconds. If x is too high, there's a lot of lag (stolen time); if it's too low, a lot of CPU cycles are wasted. That kind of compromise is not suitable for computer chess at fast time controls, so I switched from asynchronous reads (polling) to synchronous reads in a separate PipeReader thread.

It was just a wild guess that Arena's bug could also be caused by polling, but it could be something else. I'd be surprised if the Arena developers didn't know the source of the bug, but it may simply be too tedious to fix. If the design is bad enough, they may have to rewrite a lot of code.

Edmund wrote:Am I right to assume using GetProcessTimes() instead of any wall-time meassures solves the problem?
Even if the time-stealing bug could be fixed by having the GUI know exactly how much time the engines spent thinking, the lag would still be there, and testing under very fast time controls would still be too slow.
User avatar
Matthias Gemuh
Posts: 3245
Joined: Thu Mar 09, 2006 9:10 am

Re: Engines losing on time in won/drew games

Post by Matthias Gemuh »

michiguel wrote: That is odd.

Could you try the latest release? The direct link is
http://sites.google.com/site/gaviotache ... ects=0&d=1
Use the whole folder. The logs will be in the logs sub folder.

In case that I made a mistake, open gaviota.ini.txt with notepad and make sure I did not mess up the carriage returns coming from linux. If you open it with word, and save it back as text file, it should correct the problem. I do not think I made that mistake, but just in case.

Miguel
Logs sent.
My engine was quite strong till I added knowledge to it.
http://www.chess.hylogic.de
Edmund
Posts: 670
Joined: Mon Dec 03, 2007 3:01 pm
Location: Barcelona, Spain

Re: Engines losing on time in won/drew games

Post by Edmund »

ilari wrote:if it's too low, a lot of CPU cycles are wasted.
In a Tournament manager I wrote I have a while loop which keeps executing:
Sleep(1);
PeekNamedPipe(Engine1);
PeekNamedPipe(Engine2);

due to the sleep command the task manager reports a 0% processor occupation of the tournament manager. Am I missing something?
User avatar
michiguel
Posts: 6401
Joined: Thu Mar 09, 2006 8:30 pm
Location: Chicago, Illinois, USA

Re: Engines losing on time in won/drew games

Post by michiguel »

Matthias Gemuh wrote:
michiguel wrote: That is odd.

Could you try the latest release? The direct link is
http://sites.google.com/site/gaviotache ... ects=0&d=1
Use the whole folder. The logs will be in the logs sub folder.

In case that I made a mistake, open gaviota.ini.txt with notepad and make sure I did not mess up the carriage returns coming from linux. If you open it with word, and save it back as text file, it should correct the problem. I do not think I made that mistake, but just in case.

Miguel
Logs sent.
Very good!
The average lag is 16 milliseconds. It is weird that there is some negative lag sometimes. ChessGUI tries to compensate somehow? if I eliminate those negative values, the average lag is 36 ms. Excellent anyway!

The distribution of the lags is this. There is ~3% chances that the lag could be >100 ms.

Miguel

I cannot show it in the page. This is the link

http://sites.google.com/site/gaviotache ... edirects=0
User avatar
Matthias Gemuh
Posts: 3245
Joined: Thu Mar 09, 2006 9:10 am

Re: Engines losing on time in won/drew games

Post by Matthias Gemuh »

michiguel wrote:
Matthias Gemuh wrote:
michiguel wrote: That is odd.

Could you try the latest release? The direct link is
http://sites.google.com/site/gaviotache ... ects=0&d=1
Use the whole folder. The logs will be in the logs sub folder.

In case that I made a mistake, open gaviota.ini.txt with notepad and make sure I did not mess up the carriage returns coming from linux. If you open it with word, and save it back as text file, it should correct the problem. I do not think I made that mistake, but just in case.

Miguel
Logs sent.
Very good!
The average lag is 16 milliseconds. It is weird that there is some negative lag sometimes. ChessGUI tries to compensate somehow? if I eliminate those negative values, the average lag is 36 ms. Excellent anyway!

The distribution of the lags is this. There is ~3% chances that the lag could be >100 ms.

Miguel

I cannot show it in the page. This is the link

http://sites.google.com/site/gaviotache ... edirects=0
ChessGUI measures lag and gives that lag (not more) back to engine.
The lags are documented in ChessGUI's debug files.

Matthias.
My engine was quite strong till I added knowledge to it.
http://www.chess.hylogic.de
User avatar
WinPooh
Posts: 267
Joined: Fri Mar 17, 2006 8:01 am
Location: Russia
Full name: Vladimir Medvedev

Re: Engines losing on time in won/drew games

Post by WinPooh »

Carlos777 wrote:Hello,

I have seen some games where engines lost won/drew games on time because they keep searching until the last ply depht.

103. ... {0-1 White forfeits on time} 0-1
I ovserved this many times. In my case, the problem always was in this "..." which Arena likes to send. If engine can't parse this token, it remains in thinking mode and gets loss on time.
I don't know what Arena wants to say with "..." - may be, it is signal of opponent's resignation?
The easiest way to handle is to use something like this in user-input code:

Code: Select all

read_input();
if (!strstr(buf, "...")) exit(0); // bye-bye, Arena!
User avatar
ilari
Posts: 750
Joined: Mon Mar 27, 2006 7:45 pm
Location: Finland

Re: Engines losing on time in won/drew games

Post by ilari »

Edmund wrote:
ilari wrote:if it's too low, a lot of CPU cycles are wasted.
In a Tournament manager I wrote I have a while loop which keeps executing:
Sleep(1);
PeekNamedPipe(Engine1);
PeekNamedPipe(Engine2);

due to the sleep command the task manager reports a 0% processor occupation of the tournament manager. Am I missing something?
I don't know what exactly your tournament manager does, maybe that sleep & peek loop is suitable for it. But it wouldn't work that well in a chess GUI:
- Sleep(1) doesn't mean that the thread will sleep for 1 ms because the resolution of the system clock is not quite that good. So the lag will certainly be a lot more than 1 ms.
- In a chess GUI the main thread should never sleep because it should always be ready to process events. So the while loop should be in a separate thread anyway, and in that case you could just as well use synchronous (blocking) reads to eliminate any lag.