poker_ai.ai.multiprocess package

Submodules

poker_ai.ai.multiprocess.server module

class poker_ai.ai.multiprocess.server.Server(strategy_interval: int, n_iterations: int, lcfr_threshold: int, discount_interval: int, prune_threshold: int, c: int, n_players: int, dump_iteration: int, update_threshold: int, save_path: Union[str, pathlib.Path], lut_path: Union[str, pathlib.Path] = '.', pickle_dir: bool = False, agent_path: Union[str, pathlib.Path, None] = None, sync_update_strategy: bool = False, sync_cfr: bool = False, sync_discount: bool = False, sync_serialise: bool = False, start_timestep: int = 1, n_processes: int = 1)

Bases: object

Server class to manage all workers optimising CFR algorithm.

_send_job(job_name: str, **kwargs)

Send job of type name with arguments kwargs to worker pool.

_start_workers(n_processes: int) → Dict[str, poker_ai.ai.multiprocess.worker.Worker]

Begin the processes.

_syncronised_job(job_name: str, **kwargs)

Only perform this job with one process.

_wait_until_all_workers_are_idle(sleep_secs=0.5)

Blocks until all workers have finished their current job.

static from_dict(config)

Load serialised server and return instance.

job(job_name: str, sync_workers: bool = False, **kwargs)

Create a job for the workers.

Parameters
  • job_name (str) – Name of job.

  • sync_wrokers (bool) – Whether or not to synchronize workers.

search()

Perform MCCFR and train the agent.

If all sync_* parameters are set to True then there shouldn’t be any difference between this and the original MCCFR implementation.

terminate(safe: bool = False)

Kill all workers.

to_dict() → Dict[str, Union[str, float, int, None]]

Serialise the server object to save the progress of optimisation.

poker_ai.ai.multiprocess.worker module

class poker_ai.ai.multiprocess.worker.Worker(job_queue: multiprocessing.context.BaseContext.Queue, status_queue: multiprocessing.context.BaseContext.Queue, logging_queue: multiprocessing.context.BaseContext.Queue, locks: Dict[str, multiprocessing.synchronize.Lock], agent: poker_ai.ai.agent.Agent, info_set_lut: Dict[str, Dict[Tuple[int, …], str]], n_players: int, prune_threshold: int, c: int, lcfr_threshold: int, discount_interval: int, update_threshold: int, dump_iteration: int, save_path: pathlib.Path)

Bases: multiprocessing.context.Process

Subclass of multiprocessing Process to handle agent optimisation.

_cfr(t, i)

Search over random game and calculate the strategy.

_discount(t)

Discount previous regrets and strategy.

_serialise(t: int, server_state: Dict[str, Union[str, float, int, None]])

Write progress of optimising agent (and server state) to file.

_set_seed()

Lose all reproducability as we need unique streams per worker.

_setup_new_game()

Setup up new poker game.

_update_status(status, log_status: bool = True)

Update the status of this worker by posting it to the server.

_update_strategy(t, i)

Update the strategy.

run()

Compute the next job the server sent.

Module contents