Designing an analysis friendly Stockfish?

Code, algorithms, languages, construction...
User avatar
Uly
Posts: 838
Joined: Thu Jun 10, 2010 5:33 am

Re: Designing an analysis friendly Stockfish?

Post by Uly » Sun Jan 30, 2011 3:40 am

Hannibal of Rybka forum has provided compiles that implement these changes!:

http://dl.dropbox.com/u/11904592/stockfish_201_PH_C.zip

And, wow, they do work, not only does Stockfish present the expected behavior, the analysis and score seem stable now, and the granularity is gone!

rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq -

Analysis starts normally.

10/09 0:00 +0.09 1.e4 Nc6 2.Nc3 Nf6 3.Nf3 d5 4.exd5 Nxd5 5.Bc4 (20.425) 217
10/09 0:00 +0.09 1.d4 Nf6 2.Nc3 Nc6 3.d5 Nb4 4.e4 Ng4 5.Nf3 (24.212) 220
11/08 0:00 +0.19 1.d4 Nf6 2.Nc3 e6 3.Nf3 d5 4.Be3 Nc6 (50.212) 356
11/09 0:00 +0.19 1.e4 Nc6 2.Nc3 Nf6 3.Nf3 d5 4.exd5 Nxd5 5.Bc4 (61.446) 391
12/09 0:00 +0.21 1.e4 Nc6 2.Nf3 Nf6 3.Nc3 d5 4.exd5 Nxd5 5.Bc4 (95.063) 465
13/11 0:00 +0.27 1.e4 Nc6 2.d4 d5 3.exd5 Qxd5 4.Nf3 Qe4+ 5.Be3 Nf6 6.Nc3 (174.351) 557
14/10 0:00 +0.27 1.e4 e5 2.Nc3 Nf6 3.Nf3 Nc6 4.d4 exd4 5.Nxd4 Bb4 (344.756) 648
15/09 0:00 +0.27 1.e4 e5 2.Nf3 Nf6 3.Nxe5 Qe7 4.Nf3 Nxe4 5.Be2 (564.697) 681
16/09 0:01 +0.27 1.e4 e5 2.Nf3 Nf6 3.Nxe5 Qe7 4.Nf3 Nxe4 5.Be2 (830.597) 708
17/09 0:02 +0.35++ 1.e4 e5 2.Nf3 Nf6 3.Nxe5 Qe7 4.Nf3 Nxe4 5.Be2 (1.460.112) 718
17/09 0:02 +0.35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f3 Nf6 3.Nxe5 Nc6 4.Nxc6 dxc6 5.e5 Bg4 6.Be2 (295.344) 787
16/10 0:00 +0.37 1...e5 2.Nf3 Nf6 3.Nxe5 Nc6 4.Nxc6 dxc6 5.e5 Bg4 6.Be2 (365.389) 834
17/10 0:00 +0.37 1...e5 2.Nf3 Nf6 3.Nxe5 Qe7 4.Nf3 Nxe4 5.Be2 Nc6 6.d3 (554.778) 825
18/17 0:02 +0.44 1...e5 2.Nf3 Nc6 3.Bb5 Nf6 4.O-O Bd6 5.d4 Nxd4 6.Nxd4 exd4 7.Qxd4 Qe7 8.Nc3 c6 9.Be2 Be5 (1.617.494) 778

(Here one wonders where that 0.25 came from, but the behavior at depth 17 is as expected)

rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -

Back to the root.

10/16 0:00 +0.44 1.e4 Nf6 2.e5 Nd5 3.Nf3 d6 4.c4 Nb6 5.Nc3 c5 6.exd6 Nc6 7.dxe7 Bxe7 8.Be2 O-O (6.298) 203
11/16 0:00 +0.44 1.e4 Nf6 2.e5 Nd5 3.Nf3 d6 4.c4 Nb6 5.Nc3 c5 6.exd6 Nc6 7.dxe7 Bxe7 8.Be2 O-O (8.301) 267
12/12 0:00 +0.44 1.e4 e5 2.Nf3 Nc6 3.d4 exd4 4.Nxd4 Nf6 5.Nc3 Bb4 6.Nxc6 dxc6 (17.617) 374
13/16 0:00 +0.44 1.e4 e5 2.Nf3 Nc6 3.Bc4 Nf6 4.Ng5 d5 5.exd5 Na5 6.Bb5+ c6 7.dxc6 bxc6 8.Be2 h6 (31.176) 494
14/16 0:00 +0.44 1.e4 e5 2.Nf3 Nc6 3.Bc4 Nf6 4.Ng5 d5 5.exd5 Na5 6.Bb5+ c6 7.dxc6 bxc6 8.Be2 h6 (57.540) 612
15/16 0:00 +0.44 1.e4 e5 2.Nf3 Nc6 3.Bc4 Nf6 4.Ng5 d5 5.exd5 Na5 6.Bb5+ c6 7.dxc6 bxc6 8.Be2 h6 (76.885) 698
16/09 0:00 +0.38 1.e4 e5 2.Nf3 Nc6 3.Bb5 Nf6 4.O-O Nxe4 5.Qe2 (216.248) 769
17/15 0:00 +0.44 1.e4 e5 2.Nf3 Nc6 3.Bb5 Nf6 4.O-O Bd6 5.Bxc6 bxc6 6.d4 Ba6 7.dxe5 Bxf1 8.exd6 (508.435) 756
18/17 0:00 +0.44 1.e4 e5 2.Nf3 Nc6 3.Bc4 Nf6 4.Ng5 d5 5.exd5 Na5 6.Bb5+ c6 7.dxc6 bxc6 8.Qf3 h6 9.Ne4 (765.583) 777
19/14 0:02 +0.43 1.e4 e5 2.Nf3 Nc6 3.Bc4 Be7 4.O-O Nf6 5.Nc3 O-O 6.d4 Nxe4 7.Nxe4 d5 (1.518.660) 759

Excellent! One wonders how is it possible that the clear improvement in behavior (the new code is killing 4 birds with 2 stones!) is costing Stockfish 133 elo on games.

But indeed, here's a report by Moz that indeed something more has changed.

"There are some scary differences between this and the default SF. I'm not sure what to make of them but analyzing the following position in multipv mode will give you an idea of what I'm referring to (this is from my WBCCC game with ralunger so please refrain from making comments about the game itself)"

6k1/2r2pb1/p1NR2p1/8/Pp5r/8/1PP2R1P/1K6 w - - 0 33

For some reason, the PH version has a *lot* of trouble in this position - Na5 and Nb8 should be the top 2 moves in multipv mode but it's all over the place. The analysis seems to confirm Marco's test results -- performance is much worse.

Use with caution."

And indeed:

Default Stockfish at MultiPV=4:

15 0:10 -0.28 1.Na5 Be5 2.Rxa6 Bxh2 3.Nc6 Bd6 4.Rd2 Bf8 5.Ka2 g5 6.Ne5 Re4 7.Rd7 Rxd7 8.Nxd7 Be7 9.Nf6+ Bxf6 10.Rxf6 Kg7 11.Rf1 (10.067.993) 935
15 0:10 -0.32 1.Rd8+ Kh7 2.Rd6 f5 3.a5 Re4 4.Nd8 Ra7 5.Ne6 Bf6 6.Rg2 Re1+ 7.Ka2 Be7 8.Ng5+ Kg7 9.Rxg6+ Kxg6 10.Nf3+ Kf6 11.Nxe1 f4 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a5 Bf4 7.Rb8 Bg5 8.a6 Be7 (12.725.035) 883
17 0:14 -1.18 1.c4 Bf8 2.Rd4 Rxd4 3.Nxd4 Rxc4 4.Nf3 Kg7 5.Ka2 Rc7 (12.725.035) 882
17 0:14 -1.87 1.Rf3 Bf8 2.Rd4 Rxh2 3.Nxb4 Bxb4 4.Rxb4 Rhxc2 5.Rf6 a5 6.Rb8+ Kg7 7.Ra6 R7c5 8.Rb5 (12.725.035) 882
17 0:14 -5.17 1.Nxb4 Rxb4 2.Rd8+ Kh7 3.b3 f5 4.Re8 (12.725.035) 882
-----
18 0:21 -0.25 1.Nd8 a5 2.Ra6 Be5 3.Rxa5 Rxh2 4.Rxh2 Bxh2 5.Rb5 Kg7 6.a5 Rc8 7.Nb7 (19.612.198) 912
18 0:21 -2.22 1.c4 bxc3 2.b3 Bf8 3.Rd4 Rh5 4.Nb8 Rb7 5.Nxa6 Rxb3+ (19.612.198) 911
18 0:21 -2.64 1.Rf3 Bf8 2.Rdf6 Rxh2 3.Rf1 Bg7 4.Rd6 Bf8 5.Rdf6 (19.612.198) 911
18 0:21 -5.03 1.c3 bxc3 2.b3 Bf8 3.Rd4 Rh5 4.Nb8 Rb7 5.Nxa6 Rxb3+ (19.612.198) 911

So, something broke, why is this?

hyatt
Posts: 1242
Joined: Thu Jun 10, 2010 2:13 am
Real Name: Bob Hyatt (Robert M. Hyatt)
Location: University of Alabama at Birmingham
Contact:

Re: Designing an analysis friendly Stockfish?

Post by hyatt » Sun Jan 30, 2011 3:53 am

Here is what you are basically doing with the default stockfish. You eschew a table hit, and instead elect to do the search. Programs that probe and allow EXACT matches in the PV replace that search with a single hash probe. All this does is save effort. If it weakens the program, then either there is an undiscovered bug, or there is an undiscovered interaction that makes repeating the search somehow help. This could be from poor hash replacement policy, or a subtle change in what gets pruned/reduced. Who knows.

But the idea of the hash is to save effort. That is the _primary_ goal. And not allowing EXACT matches is contrary to any graph theory logic I can speculate on. If anything, I suspect my last suggestion above is the explanation, because it is possible to get EXACT matches without an EXACT depth / draft, which could replace a sub-tree with a significantly different sub-tree. This still suggests something intrinsically wrong somewhere, however...

Your last position is not worrisome to me. What would be more important would be how it does over tens of thousands of games. I suppose I could give this a run on my cluster, modifying stockfish...

User avatar
Uly
Posts: 838
Joined: Thu Jun 10, 2010 5:33 am

Re: Designing an analysis friendly Stockfish?

Post by Uly » Sun Jan 30, 2011 4:05 am

Can you comment on the extreme change in behavior in MultiPV after applying the changes? Could it point more to where a bug lies?

Ancalagon
Posts: 15
Joined: Sat Sep 11, 2010 1:24 pm

Re: Designing an analysis friendly Stockfish?

Post by Ancalagon » Sun Jan 30, 2011 5:20 am

Uly wrote:Can you comment on the extreme change in behavior in MultiPV after applying the changes? Could it point more to where a bug lies?
A small part of the problem is probably that Stockfish in PV nodes still does not test for EXACT hashmatches but also accepts value >= beta in case of a lower limit or hashvalue < beta in case of an upper limit entry (in ok_to_use_TT()). The PV search is supposed to return an exact value however, if it is within the αβ window, so these upper and lower limits should not be accepted I think, only the VALUE_EXACT ones. If the hashhit is outside the window it is probably better to search on, even if EXACT but that would be the next proposal I suppose. I don't know if code as below would solve the problem or could explain 133 elo difference, that seems a bit doubtful to me. But this is at least in theory more in line with what Bob means I think? This would be my proposal for qsearch()

Code: Select all

    // Transposition table lookup. At PV nodes, we don't use the TT for
    // pruning, but only for move ordering.
    tte = TT.retrieve(pos.get_key());
    ttMove = (tte ? tte->move() : MOVE_NONE);

    if (tte && (PvNode ? tte->type() == VALUE_TYPE_EXACT : ok_to_use_TT(tte, ttDepth, beta, ply)))
    {
        ss->bestMove = ttMove; // Can be MOVE_NONE
        return value_from_tt(tte->value(), ply);
    }


gaard
Posts: 127
Joined: Thu Jun 10, 2010 1:39 am
Real Name: Martin Wyngaarden
Location: Holland, Michigan

Re: Designing an analysis friendly Stockfish?

Post by gaard » Sun Jan 30, 2011 6:16 am

Uly wrote:Can you comment on the extreme change in behavior in MultiPV after applying the changes? Could it point more to where a bug lies?
I missed the !PvNode in qsearch. See if this one still exhibits the crazy behavior in Multi-PV mode:
http://dl.dropbox.com/u/11904592/stockfish_201_PH_D.zip

mcostalba
Posts: 91
Joined: Thu Jun 10, 2010 11:45 pm
Real Name: Marco Costalba

Re: Designing an analysis friendly Stockfish?

Post by mcostalba » Sun Jan 30, 2011 12:24 pm

hyatt wrote: Your last position is not worrisome to me. What would be more important would be how it does over tens of thousands of games. I suppose I could give this a run on my cluster, modifying stockfish...
Thanks for your help. I think I have found the problem. Removing !PvNode is not enough.

Problem is that in non-pv nodes we use TT when stored value is a lower bound higher then beta or an upper bound lower then alpha, IOW we use TT to detects fails high /low.

In case of PV-node we need to do the opposite and use TT value when is inside (alpha, beta) interval, not ouside !

So we need a specialized ok_to_use_tt() function tailored for PV nodes, something along these lines:

Code: Select all

  bool ok_to_use_TT_PV(const TTEntry* tte, Depth depth, Value alpha, Value beta, int ply) {

    Value v = value_from_tt(tte->value(), ply);

     return   tte->depth() >= depth
           && tte->type() == VALUE_TYPE_EXACT
           && tte->move() != MOVE_NONE
           && v < beta
           && v > alpha;
  }

gaard
Posts: 127
Joined: Thu Jun 10, 2010 1:39 am
Real Name: Martin Wyngaarden
Location: Holland, Michigan

Re: Designing an analysis friendly Stockfish?

Post by gaard » Sun Jan 30, 2011 3:36 pm

mcostalba wrote:
hyatt wrote: Your last position is not worrisome to me. What would be more important would be how it does over tens of thousands of games. I suppose I could give this a run on my cluster, modifying stockfish...
Thanks for your help. I think I have found the problem. Removing !PvNode is not enough.

Problem is that in non-pv nodes we use TT when stored value is a lower bound higher then beta or an upper bound lower then alpha, IOW we use TT to detects fails high /low.

In case of PV-node we need to do the opposite and use TT value when is inside (alpha, beta) interval, not ouside !

So we need a specialized ok_to_use_tt() function tailored for PV nodes, something along these lines:

Code: Select all

  bool ok_to_use_TT_PV(const TTEntry* tte, Depth depth, Value alpha, Value beta, int ply) {

    Value v = value_from_tt(tte->value(), ply);

     return   tte->depth() >= depth
           && tte->type() == VALUE_TYPE_EXACT
           && tte->move() != MOVE_NONE
           && v < beta
           && v > alpha;
  }


Would it look like this:

Code: Select all

    if (   tte 
	     && ok_to_use_TT(tte, depth, beta, ply) 
		  && ok_to_use_TT_PV(tte, depth, alpha, beta, ply))
    {
        TT.refresh(tte);
        ss->bestMove = ttMove; // Can be MOVE_NONE
        return value_from_tt(tte->value(), ply);
    }

or

if ((   tte 
     && ok_to_use_TT(tte, depth, beta, ply)) 
     && (PvNode && (ok_to_use_TT_PV(tte, depth, alpha, beta, ply))
     || !PvNode)))
    {
        TT.refresh(tte);
        ss->bestMove = ttMove; // Can be MOVE_NONE
        return value_from_tt(tte->value(), ply);
    }

mcostalba
Posts: 91
Joined: Thu Jun 10, 2010 11:45 pm
Real Name: Marco Costalba

Re: Designing an analysis friendly Stockfish?

Post by mcostalba » Sun Jan 30, 2011 6:40 pm

It would look like this:

Code: Select all

if (tte && (PvNode ? ok_to_use_TT_PV(tte, depth, alpha, beta, ply) : ok_to_use_TT(tte, depth, beta, ply))
 {
    TT.refresh(tte);
    ss->bestMove = ttMove; // Can be MOVE_NONE
    return value_from_tt(tte->value(), ply);
}

gaard
Posts: 127
Joined: Thu Jun 10, 2010 1:39 am
Real Name: Martin Wyngaarden
Location: Holland, Michigan

Re: Designing an analysis friendly Stockfish?

Post by gaard » Sun Jan 30, 2011 8:42 pm

gaard wrote:
Uly wrote:Can you comment on the extreme change in behavior in MultiPV after applying the changes? Could it point more to where a bug lies?
I missed the !PvNode in qsearch. See if this one still exhibits the crazy behavior in Multi-PV mode:
http://dl.dropbox.com/u/11904592/stockfish_201_PH_D.zip
http://dl.dropbox.com/u/11904592/stockfish_201_PH_E.zip

This one incorporates the changes suggested by M.Costalba. At first glance, it appears to be behaving correctly.

gaard
Posts: 127
Joined: Thu Jun 10, 2010 1:39 am
Real Name: Martin Wyngaarden
Location: Holland, Michigan

Re: Designing an analysis friendly Stockfish?

Post by gaard » Mon Jan 31, 2011 1:13 am

mcostalba wrote:It would look like this:

Code: Select all

if (tte && (PvNode ? ok_to_use_TT_PV(tte, depth, alpha, beta, ply) : ok_to_use_TT(tte, depth, beta, ply))
 {
    TT.refresh(tte);
    ss->bestMove = ttMove; // Can be MOVE_NONE
    return value_from_tt(tte->value(), ply);
}
I made the changes both in the normal and qsearch parts of search.cpp. I am seeing a slow down of ~15%. Is this to be expected?

Post Reply