fedden / poker_ai

🤖 An Open Source Texas Hold'em AI
Other
1.36k stars 367 forks source link

Cannot update plot state due to pickling error #63

Closed vdrumsta closed 4 years ago

vdrumsta commented 4 years ago

Describe the bug When trying to update the state of PokerPlot using the example provided in applications\visualisation\README.md the following error is returned: pluribus\games\short_deck\state.py", line 204, in _load_pickle_files f"File path not found {file_path}. Ensure pickle_dir is " ValueError: File path not found ../../research/blueprint_algo/preflop_lossless.pkl. Ensure pickle_dir is set to directory containing pickle files

To Reproduce Steps to reproduce the behavior:

  1. Go to path 'scripts\test_hand.py' (which is using the example provided in applications\visualisation\README.md
  2. Run command 'python test_hand.py'
  3. See error

Expected behavior PokerPlot state will be updated

Desktop (please complete the following information):

Additional comments I thought it might be due to Windows using \ to specify the path, but when I used "..\\..\\research\\blueprint_algo\\" path, I also got the same error

fedden commented 4 years ago

Yeah so as it stands you don't have the pickle files that the state class needs.

These can be produced by running the research code to produce the lossy abstractions, but you can also skip loading the pickle files in the state constructor by setting the below parameter to False on initialisation.

https://github.com/fedden/pluribus-poker-AI/blob/c6091b8be23257cd2b7c57a0f4b81749e7043ec3/pluribus/games/short_deck/state.py#L33

fedden commented 4 years ago

If the pickle files aren't produced and uploaded, then you'll not be able to produce information sets, but you may not need to do this

vdrumsta commented 4 years ago

Thanks for the quick reply! : )

vdrumsta commented 4 years ago

Now that it reaches pp.update_state(state) without any errors, it doesn't look like it actually updates the state of the front end as the table still doesn't have any players around it, it's just a blank table. image

The state variable doesn't seem to be an issue as it has all the right properties: image

Does the update_state(state) method work correctly for you?

fedden commented 4 years ago

Yeah, so this is what I get when I run the first part of the script in my IPython shell on the right:

Screenshot 2020-04-13 at 15 13 23

Then, once I have added the following:

state: ShortDeckPokerState = get_state()
pp.update_state(state)

It updates the visualisation to this:

Screenshot 2020-04-13 at 15 13 51
vdrumsta commented 4 years ago

The only differency that I have is that I disable the pickling of files

return ShortDeckPokerState(
        players=players, 
        load_pickle_files=False
    )

That seems to be the problem, so I tried generating the pickle files by running pluribus-poker-AI\research\blueprint_algo\blueprint_kuhn.py and pluribus-poker-AI\research\blueprint_algo\blueprint_short_deck_poker.py

blueprint_kuhn.py runs fine, but when I try to run blueprint_short_deck_poker.py I get a similar pickle error: train iter: 0%| | 0/20000 [00:00<?, ?it/s] Traceback (most recent call last): File "c:\Users\Vilius\OneDrive\workarea\programming\2020\Python\pluribus-poker-AI\research\blueprint_algo\blueprint_short_deck_poker.py", line 421, in train() File "C:\Users\Vilius\AppData\Local\Programs\Python\Python37\lib\site-packages\click\core.py", line 764, in call return self.main(args, kwargs) File "C:\Users\Vilius\AppData\Local\Programs\Python\Python37\lib\site-packages\click\core.py", line 717, in main rv = self.invoke(ctx) File "C:\Users\Vilius\AppData\Local\Programs\Python\Python37\lib\site-packages\click\core.py", line 956, in invoke return ctx.invoke(self.callback, ctx.params) File "C:\Users\Vilius\AppData\Local\Programs\Python\Python37\lib\site-packages\click\core.py", line 555, in invoke return callback(args, **kwargs) File "c:\Users\Vilius\OneDrive\workarea\programming\2020\Python\pluribus-poker-AI\research\blueprint_algo\blueprint_short_deck_poker.py", line 376, in train state: ShortDeckPokerState = new_game(n_players, info_set_lut) File "c:\Users\Vilius\OneDrive\workarea\programming\2020\Python\pluribus-poker-AI\research\blueprint_algo\blueprint_short_deck_poker.py", line 310, in new_game state = ShortDeckPokerState(players=players) File "C:\Users\Vilius\AppData\Local\Programs\Python\Python37\lib\site-packages\pluribus\games\short_deck\state.py", line 43, in init self.info_set_lut = self._load_pickle_files(pickle_dir) File "C:\Users\Vilius\AppData\Local\Programs\Python\Python37\lib\site-packages\pluribus\games\short_deck\state.py", line 204, in _load_pickle_files f"File path not found {file_path}. Ensure pickle_dir is " ValueError: File path not found .\preflop_lossless.pkl. Ensure pickle_dir is set to directory containing pickle files

I noticed that a pickle file pluribus-poker-AI\research\clustering\data\preflop_lossless.pkl so I tried moving that into pluribus-poker-AI\research\blueprint_algo\ folder but I still get the same error

fedden commented 4 years ago

That's not how to produce the pickle files you'll need.

That work is in the abstraction section of the research directory. At the moment we aren't supporting anything we leave in the research/ directory - this is our directory for hacking together ideas, and once they ready, we'll add them to the pluribus/ directory

fedden commented 4 years ago

Feel free to run the scripts here

fedden commented 4 years ago

But we can't really support this until it becomes an official part of the project (i.e until we are confident it works)

fedden commented 4 years ago

For the visualisation code, which again is very much a work in progress, you can initialise the state without the pickle files, in the way that you already have, and then there must be some other issue that is causing you not to have the players appear in the visualisation

fedden commented 4 years ago

If you can find the specific problem on your system that is preventing you from visualising the players I'd be very amenable to fixing it, but at the moment the visualisation is very much WIP so you'll need to debug it yourself as I can't replicate your problem as demonstrated here: https://github.com/fedden/pluribus-poker-AI/issues/63#issuecomment-612916394

fedden commented 4 years ago

Gonna close this until there is a more specific problem to fix!

fedden commented 4 years ago

(I also can't support Windows as I am a Linux/OS X user and don't have a Windows machine to test the software on)

vdrumsta commented 4 years ago

That;s understandable, thanks for the response. When you have the time, would you be able to run update_state with load_pickle_files=False just so I know whether it's due to pickle files or something specific to my setup

fedden commented 4 years ago

Sure thing @worm00111 , in the interests of reproducability, could you paste here the complete script you are calling, so I can call that without any questions of difference?

vdrumsta commented 4 years ago
from plot import PokerPlot
from pluribus.games.short_deck.player import ShortDeckPokerPlayer
from pluribus.games.short_deck.state import ShortDeckPokerState
from pluribus.poker.pot import Pot

def get_state() -> ShortDeckPokerState:
    """Gets a state to visualise"""
    n_players = 6
    pot = Pot()
    players = [
        ShortDeckPokerPlayer(player_i=player_i, initial_chips=10000, pot=pot)
        for player_i in range(n_players)
    ]
    return ShortDeckPokerState(
        players=players,
        load_pickle_files=False
    )

pp: PokerPlot = PokerPlot()
state: ShortDeckPokerState = get_state()
pp.update_state(state)
vdrumsta commented 4 years ago

Sorry, for the formatting, can't seem to enclose the entire thing in a code block

fedden commented 4 years ago

If you can format it as here that would be helpful to be sure I am running the same code as ou are! https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks

vdrumsta commented 4 years ago

Cheers, updated the message.

fedden commented 4 years ago

Okay great, I can confirm I can replicate the issue. For now the (disgusting/hacky) fix is to insert a lengthly sleep inbetween the call like so:

import time

from plot import PokerPlot
from pluribus.games.short_deck.player import ShortDeckPokerPlayer
from pluribus.games.short_deck.state import ShortDeckPokerState
from pluribus.poker.pot import Pot

def get_state() -> ShortDeckPokerState:
    """Gets a state to visualise"""
    n_players = 6
    pot = Pot()
    players = [
        ShortDeckPokerPlayer(player_i=player_i, initial_chips=10000, pot=pot)
        for player_i in range(n_players)
    ]
    return ShortDeckPokerState(players=players, load_pickle_files=False)

pp: PokerPlot = PokerPlot()
state: ShortDeckPokerState = get_state()
time.sleep(5)
print("updating state")
pp.update_state(state)
fedden commented 4 years ago

I'll try to dig into this (when I can) and will make sure this works in the future

fedden commented 4 years ago

The reason why I hadn't discovered this previously was because I was running this code in one IPython cell:

import time

from plot import PokerPlot
from pluribus.games.short_deck.player import ShortDeckPokerPlayer
from pluribus.games.short_deck.state import ShortDeckPokerState
from pluribus.poker.pot import Pot

def get_state() -> ShortDeckPokerState:
    """Gets a state to visualise"""
    n_players = 6
    pot = Pot()
    players = [
        ShortDeckPokerPlayer(player_i=player_i, initial_chips=10000, pot=pot)
        for player_i in range(n_players)
    ]
    return ShortDeckPokerState(players=players, load_pickle_files=False)

pp: PokerPlot = PokerPlot()

And this in a second IPython cell:

state: ShortDeckPokerState = get_state()
pp.update_state(state)

And there was a considerable time-gap in between the execution of the cells!

vdrumsta commented 4 years ago

Woop woop! It's good to know that there's a way to get around this : )