Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
adding support for lut as one joblib file
Browse files Browse the repository at this point in the history
  • Loading branch information
big-c-note committed Jun 30, 2020
1 parent e69c2a1 commit 9a2b93f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
7 changes: 5 additions & 2 deletions poker_ai/ai/multiprocess/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def __init__(
dump_iteration: int,
update_threshold: int,
save_path: Union[str, Path],
pickle_dir: Union[str, Path] = ".",
lut_path: Union[str, Path] = ".",
pickle_dir: bool = False,
agent_path: Optional[Union[str, Path]] = None,
sync_update_strategy: bool = False,
sync_cfr: bool = False,
Expand All @@ -51,6 +52,7 @@ def __init__(
self._dump_iteration = dump_iteration
self._update_threshold = update_threshold
self._save_path = save_path
self._lut_path = lut_path
self._pickle_dir = pickle_dir
self._agent_path = agent_path
self._sync_update_strategy = sync_update_strategy
Expand All @@ -59,7 +61,7 @@ def __init__(
self._sync_serialise = sync_serialise
self._start_timestep = start_timestep
self._info_set_lut: state.InfoSetLookupTable = utils.io.load_info_set_lut(
pickle_dir,
lut_path, pickle_dir
)
log.info("Loaded lookup table.")
self._job_queue: mp.JoinableQueue = mp.JoinableQueue(maxsize=n_processes)
Expand Down Expand Up @@ -144,6 +146,7 @@ def to_dict(self) -> Dict[str, Union[str, float, int, None]]:
dump_iteration=self._dump_iteration,
update_threshold=self._update_threshold,
save_path=self._save_path,
lut_path=self._lut_path,
pickle_dir=self._pickle_dir,
agent_path=self._agent_path,
sync_update_strategy=self._sync_update_strategy,
Expand Down
18 changes: 15 additions & 3 deletions poker_ai/ai/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,20 @@ def resume(server_config_path: str):
"updating the strategy."
),
)
@click.option(
"--lut_path",
default="./card_info_lut.joblib",
help=(
"The path to the files for clustering the infosets."
),
)
@click.option(
"--pickle_dir",
default="../blueprint_algo",
help="The path to the pickles for clustering the infosets.",
default=False,
help=(
"Whether or not the lut files are pickle files. This lookup "
"method is deprecated."
),
)
@click.option(
"--single_process/--multi_process",
Expand Down Expand Up @@ -242,7 +252,8 @@ def start(
n_players: int,
dump_iteration: int,
update_threshold: int,
pickle_dir: str,
lut_path: str,
pickle_dir: bool,
single_process: bool,
sync_update_strategy: bool,
sync_cfr: bool,
Expand Down Expand Up @@ -291,6 +302,7 @@ def start(
dump_iteration=dump_iteration,
update_threshold=update_threshold,
save_path=save_path,
lut_path=lut_path,
pickle_dir=pickle_dir,
sync_update_strategy=sync_update_strategy,
sync_cfr=sync_cfr,
Expand Down
16 changes: 9 additions & 7 deletions poker_ai/games/short_deck/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def __init__(
players: List[ShortDeckPokerPlayer],
small_blind: int = 50,
big_blind: int = 100,
pickle_dir: str = ".",
lut_path: str = ".",
pickle_dir: bool = False,
load_card_lut: bool = True,
):
"""Initialise state."""
Expand All @@ -79,7 +80,7 @@ def __init__(
f"were provided."
)
if load_card_lut:
self.card_info_lut = self.load_card_lut(pickle_dir)
self.card_info_lut = self.load_card_lut(lut_path, pickle_dir)
else:
self.card_info_lut = {}
# Get a reference of the pot from the first player.
Expand Down Expand Up @@ -226,18 +227,19 @@ def apply_action(self, action_str: Optional[str]) -> ShortDeckPokerState:
return new_state

@staticmethod
def load_card_lut(pickle_dir: str = "", lut_path: str = "") -> Dict[str, Dict[Tuple[int, ...], str]]:
def load_card_lut(lut_path: str = ".", pickle_dir: bool = False) -> Dict[str, Dict[Tuple[int, ...], str]]:
"""
Load card information lookup table.
...
Parameters
----------
pickle_dir : str
Directory of the pickle files for card information clustering.
lut_path : str
Path to lookupkup table.
pickle_dir : bool
Whether the lut_path is a path to pickle files or not. Pickle files
are deprecated for the lut.
Returns
-------
Expand All @@ -255,10 +257,10 @@ def load_card_lut(pickle_dir: str = "", lut_path: str = "") -> Dict[str, Dict[Tu
betting_stages = ["pre_flop", "flop", "turn", "river"]
card_info_lut: Dict[str, Dict[Tuple[int, ...], str]] = {}
for file_name, betting_stage in zip(file_names, betting_stages):
file_path = os.path.join(pickle_dir, file_name)
file_path = os.path.join(lut_path, file_name)
if not os.path.isfile(file_path):
raise ValueError(
f"File path not found {file_path}. Ensure pickle_dir is "
f"File path not found {file_path}. Ensure lut_path is "
f"set to directory containing pickle files"
)
with open(file_path, "rb") as fp:
Expand Down
6 changes: 3 additions & 3 deletions poker_ai/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
import logging
from pathlib import Path
from typing import Any, Dict
from typing import Any, Dict, Union

import numpy as np

Expand All @@ -27,9 +27,9 @@ def default(self, obj):
return super(NumpyJSONEncoder, self).default(obj)


def load_info_set_lut(path: str):
def load_info_set_lut(lut_path: Union[str, Path], pickle_dir: bool):
"""Load the info set abstraction lookup table."""
info_set_lut = state.ShortDeckPokerState.load_card_lut(path)
info_set_lut = state.ShortDeckPokerState.load_card_lut(lut_path, pickle_dir)
return info_set_lut


Expand Down

0 comments on commit 9a2b93f

Please sign in to comment.