Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Max recursion depth exceeded #27

Closed
brianprichardson opened this issue Jan 23, 2018 · 12 comments
Closed

Max recursion depth exceeded #27

brianprichardson opened this issue Jan 23, 2018 · 12 comments

Comments

@brianprichardson
Copy link
Contributor

Othello TF per below on iteration 1, epoch 10.
BTW: With TF less verbosity would be helpful (400 lines per epoch)

Training Net |############################### | (400/403) Data: 0.000s | Batch: 0.031s | Total: 0:00:12 | ETA: 0:00:01 | Loss_pi: 3.4790 |Training Net |############################### | (401/403) Data: 0.000s | Batch: 0.031s | Total: 0:00:12 | ETA: 0:00:01 | Loss_pi: 3.4789 |Training Net |############################### | (402/403) Data: 0.000s | Batch: 0.031s | Total: 0:00:12 | ETA: 0:00:01 | Loss_pi: 3.4789 |Training Net |################################| (403/403) Data: 0.000s | Batch: 0.031s | Total: 0:00:12 | ETA: 0:00:01 | Loss_pi: 3.4789 | Loss_v: 0.382
PITTING AGAINST PREVIOUS VERSION
/home/brian/hitme/bin/alpha-zero-general/MCTS.py:80: RuntimeWarning: invalid value encountered in true_divide
self.Ps[s] /= np.sum(self.Ps[s]) # renormalize
Traceback (most recent call last):
File "main.py", line 29, in
c.learn()
File "/home/brian/hitme/bin/alpha-zero-general/Coach.py", line 99, in learn
pwins, nwins, draws = arena.playGames(self.args.arenaCompare)
File "/home/brian/hitme/bin/alpha-zero-general/Arena.py", line 81, in playGames
gameResult = self.playGame(verbose=verbose)
File "/home/brian/hitme/bin/alpha-zero-general/Arena.py", line 46, in playGame
action = players[curPlayer+1](self.game.getCanonicalForm(board, curPlayer))
File "/home/brian/hitme/bin/alpha-zero-general/Coach.py", line 98, in
lambda x: np.argmax(nmcts.getActionProb(x, temp=0)), self.game)
File "/home/brian/hitme/bin/alpha-zero-general/MCTS.py", line 31, in getActionProb
self.search(canonicalBoard)
File "/home/brian/hitme/bin/alpha-zero-general/MCTS.py", line 106, in search
v = self.search(next_s)
File "/home/brian/hitme/bin/alpha-zero-general/MCTS.py", line 106, in search
v = self.search(next_s)
File "/home/brian/hitme/bin/alpha-zero-general/MCTS.py", line 106, in search
v = self.search(next_s)
[Previous line repeated 983 more times]
File "/home/brian/hitme/bin/alpha-zero-general/MCTS.py", line 103, in search
next_s, next_player = self.game.getNextState(canonicalBoard, 1, a)
File "/home/brian/hitme/bin/alpha-zero-general/othello/OthelloGame.py", line 31, in getNextState
b = Board(self.n)
File "/home/brian/hitme/bin/alpha-zero-general/othello/OthelloLogic.py", line 24, in init
for i in range(self.n):
RecursionError: maximum recursion depth exceeded in comparison

@evg-tyurin
Copy link
Contributor

Most likely game logic error leading to infinite loop in traversing position tree. Game over condition can't be detected.

@suragnair
Copy link
Owner

Would it be possible to have it print the state that causes this?

@brianprichardson
Copy link
Contributor Author

Any suggestions as to how to do so?

@evg-tyurin
Copy link
Contributor

You can catch the error by surrounding
next_s, next_player = self.game.getNextState(canonicalBoard, 1, a)
with try / except clause and in except part print the state or anything you want.

@emc2314
Copy link

emc2314 commented Feb 1, 2018

I've encountered the same problem. So I display the board using try / except. Here are some examples:

0 |1 |2 |3 |4 |5 |
 -----------------------
0 |b b b b b b |
1 |b b b b b b |
2 |W W b b b b |
3 |b b b b b b |
4 |b b W b - b |
5 |b b b W - - |
 -----------------------
0 |b b b b b b |
1 |b b b W b b |
2 |b b W b W b |
3 |b b b b b b |
4 |b b b b b b |
5 |b b b b - b |
 ------------------------
0 |b - b W W W |
1 |b b b b b W |
2 |b b b b b b |
3 |b b b b b b |
4 |b b b - b b |
5 |b b b b b b |
   -----------------------

@emc2314
Copy link

emc2314 commented Feb 1, 2018

And I decided to print states after the exception. Oops!

   -----------------------
0 |1 |2 |3 |4 |5 |
 -----------------------
0 |b b W W W W |
1 |b b b b b W |
2 |b b W b b W |
3 |b b b b - b |
4 |b b W b b b |
5 |b b b b b b |
   -----------------------
0 |1 |2 |3 |4 |5 |
 -----------------------
0 |W W b b b b |
1 |W W W W W b |
2 |W W b W W b |
3 |W W W W - W |
4 |W W b W W W |
5 |W W W W W W |
   -----------------------
0 |1 |2 |3 |4 |5 |
 -----------------------
0 |b b W W W W |
1 |b b b b b W |
2 |b b W b b W |
3 |b b b b - b |
4 |b b W b b b |
5 |b b b b b b |
   -----------------------
0 |1 |2 |3 |4 |5 |
 -----------------------
0 |W W b b b b |
1 |W W W W W b |
2 |W W b W W b |
3 |W W W W - W |
4 |W W b W W W |
5 |W W W W W W |
   -----------------------
...

@suragnair
Copy link
Owner

@emc2314 Are the above snapshots from the same game? Could you share your exact code with the try except?

@emc2314
Copy link

emc2314 commented Feb 1, 2018

Problem confirmed:
In Line 96 of MCTS.py, self.Ps[s][a] is nan, resulting a = -1, so the game cannot end.

My code is really kind of rubbish... I feel ashamed to put it here.
And the above snapshots are all from one checkpoint, but the problem dose not always come out so I have to try many times to debug. Sorry for the delay when reply.

@suragnair
Copy link
Owner

This should be linked to #23.

@evg-tyurin
Copy link
Contributor

evg-tyurin commented Feb 1, 2018

Related to the game logic, I'd propose to add the move validation into board.execute_move(). If the move supplied by an invoker is invalid for the current board position an error should be raised.

I mean the rule that the player must not pass the move (a=-1) if he has one valid.

@emc2314
Copy link

emc2314 commented Feb 1, 2018

Actually there is an assertion.

assert len(list(flips))>0

Sometimes it works, but sometimes it doesn't..

@suragnair
Copy link
Owner

suragnair commented Feb 14, 2018

Addressed in f67e87e .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants