Writing bugs

Discussion of chess software programming and technical issues.

Moderators: bob, hgm, Harvey Williamson

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
User avatar
Rebel
Posts: 4711
Joined: Thu Aug 18, 2011 10:04 am

Re: Writing bugs

Post by Rebel » Thu Jan 10, 2019 6:20 am

syzygy wrote:
Sun Jan 06, 2019 10:24 pm
Funnily enough I made the same mistake today, but the compiler caught it for me. (See here.)
:lol:
Everybody is unique, except me.

User avatar
Rebel
Posts: 4711
Joined: Thu Aug 18, 2011 10:04 am

Re: Writing bugs

Post by Rebel » Thu Jan 10, 2019 6:22 am

hgm wrote:
Sun Jan 06, 2019 7:43 pm
Nothing wring with

if((x&1) != engine) ...

If you dislike parentheses, you could also do

if(x-engine & 1) ...

I wouldn't say adding unnecessary dummy variables is "the right way to do it".
Maybe not, but I left it, it's a great reminder!
Everybody is unique, except me.

chrisw
Posts: 2124
Joined: Tue Apr 03, 2012 2:28 pm

Re: Writing bugs

Post by chrisw » Thu Jan 10, 2019 5:46 pm

Took me a while to track this one down .....

Code: Select all

while(the cows come home)
{
	selfplay(engine_1, engine_1)
	append game to file
	engine_weights += initial_weights + random(small_variation)
}
which produces lots of varied games.
Then same thing in parallel, the equivalent of this loop:

Code: Select all

for thread in range(cores)
{
	while(the cows come home)
	{
		selfplay(engine_1, engine_1)
		append game to file(thread)
		engine_weights += initial_weights + random(small_variation)
	}		
}
concatenate(files)
What could possibly go wrong?

Ras
Posts: 1161
Joined: Tue Aug 30, 2016 6:19 pm
Contact:

Re: Writing bugs

Post by Ras » Thu Jan 10, 2019 6:06 pm

chrisw wrote:
Thu Jan 10, 2019 5:46 pm
What could possibly go wrong?
If one thread finishes its game early and modifies the engine weights while the other threads are still playing, they might not like that? Also, it looks strange with the "+=" in both cases, but probably more serious in the parallel case.
Rasmus Althoff
https://www.ct800.net

chrisw
Posts: 2124
Joined: Tue Apr 03, 2012 2:28 pm

Re: Writing bugs

Post by chrisw » Thu Jan 10, 2019 6:34 pm

Ras wrote:
Thu Jan 10, 2019 6:06 pm
chrisw wrote:
Thu Jan 10, 2019 5:46 pm
What could possibly go wrong?
If one thread finishes its game early and modifies the engine weights while the other threads are still playing, they might not like that? Also, it looks strange with the "+=" in both cases, but probably more serious in the parallel case.
pardon the sloppy pseudo code.

no, it's a more general problem ...

Fulvio
Posts: 155
Joined: Fri Aug 12, 2016 6:43 pm

Re: Writing bugs

Post by Fulvio » Thu Jan 10, 2019 7:27 pm

chrisw wrote:
Thu Jan 10, 2019 6:34 pm
no, it's a more general problem ...
https://stackoverflow.com/questions/212 ... om-numbers

chrisw
Posts: 2124
Joined: Tue Apr 03, 2012 2:28 pm

Re: Writing bugs

Post by chrisw » Thu Jan 10, 2019 8:11 pm

Fulvio wrote:
Thu Jan 10, 2019 7:27 pm
chrisw wrote:
Thu Jan 10, 2019 6:34 pm
no, it's a more general problem ...
https://stackoverflow.com/questions/212 ... om-numbers
Each parallel batch contains identical games is (was) the problem

mar
Posts: 2001
Joined: Fri Nov 26, 2010 1:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: Writing bugs

Post by mar » Fri Jan 11, 2019 4:58 am

chrisw wrote:
Thu Jan 10, 2019 8:11 pm
Each parallel batch contains identical games is (was) the problem

Code: Select all

int random() {return 42;}
Wait - could this possibly be related to the fact that you used Python, where threads are completely useless due to GIL and you have to use multiple processes? :roll:

Then your "bug" is directly related to the language "features" you used, not at all to the pseudo-code which tells absolutely nothing.
Martin Sedlak

mar
Posts: 2001
Joined: Fri Nov 26, 2010 1:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: Writing bugs

Post by mar » Fri Jan 11, 2019 5:59 am

Ok, seriously: you forgot to reseed, no big deal.
This is suspicious as well:

Code: Select all

engine_weights += initial_weights + random(small_variation)
as it would skyrocket the weights quickly. I believe the first += should actually be =
Martin Sedlak

mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 7:17 pm

Re: Writing bugs

Post by mcostalba » Fri Jan 11, 2019 9:41 am

Code: Select all

for (x = engine; x < MAX_MOVES; x += 2)
If x <= MAX_MOVES happens to be correct, then make it wrong fixing the definition somewhere else: it should really be wrong :-)

Post Reply