Writing bugs

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
Rebel
Posts: 6991
Joined: Thu Aug 18, 2011 12:04 pm

Re: Writing bugs

Post by Rebel »

syzygy wrote: Sun Jan 06, 2019 11:24 pm Funnily enough I made the same mistake today, but the compiler caught it for me. (See here.)
:lol:
90% of coding is debugging, the other 10% is writing bugs.
User avatar
Rebel
Posts: 6991
Joined: Thu Aug 18, 2011 12:04 pm

Re: Writing bugs

Post by Rebel »

hgm wrote: Sun Jan 06, 2019 8: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!
90% of coding is debugging, the other 10% is writing bugs.
chrisw
Posts: 4313
Joined: Tue Apr 03, 2012 4:28 pm

Re: Writing bugs

Post by chrisw »

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: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: Writing bugs

Post by Ras »

chrisw wrote: Thu Jan 10, 2019 6:46 pmWhat 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: 4313
Joined: Tue Apr 03, 2012 4:28 pm

Re: Writing bugs

Post by chrisw »

Ras wrote: Thu Jan 10, 2019 7:06 pm
chrisw wrote: Thu Jan 10, 2019 6:46 pmWhat 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: 395
Joined: Fri Aug 12, 2016 8:43 pm

Re: Writing bugs

Post by Fulvio »

chrisw wrote: Thu Jan 10, 2019 7:34 pm no, it's a more general problem ...
https://stackoverflow.com/questions/212 ... om-numbers
chrisw
Posts: 4313
Joined: Tue Apr 03, 2012 4:28 pm

Re: Writing bugs

Post by chrisw »

Fulvio wrote: Thu Jan 10, 2019 8:27 pm
chrisw wrote: Thu Jan 10, 2019 7: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: 2554
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: Writing bugs

Post by mar »

chrisw wrote: Thu Jan 10, 2019 9: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: 2554
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: Writing bugs

Post by mar »

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 9:17 pm

Re: Writing bugs

Post by mcostalba »

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 :-)