alphaghost package
The app package.
Submodules
alphaghost.alphazero module
A basic AlphaZero implementation.
A version of
open_spiel.python.algorithms.alpha_zero.alpha_zero
modified to use alphaghost.mcts.MCTSBot
and
alphaghost.model.AlphaGhostModel
to support imperfect information
games, specifically Phantom Go.
- class alphaghost.alphazero.Config
Bases:
NamedTuple
Configuration for the AlphaGhOst algorithm.
- class alphaghost.alphazero.Trajectory
Bases:
object
A sequence of observations, actions and policies, and the outcomes.
- __init__()
- add(information_state, action, policy)
- class alphaghost.alphazero.TrajectoryState
Bases:
object
A particular point along a trajectory.
- __init__(observation, current_player, legals_mask, action, policy, value)
- alphaghost.alphazero.actor(*, config, game, logger, queue)
Generate games and returns trajectories.
- Parameters:
config (Config)
game (pyspiel.Game)
- alphaghost.alphazero.alphazero(config=None)
Start all the worker processes for a full alphazero setup.
- Parameters:
config (Config | None)
- alphaghost.alphazero.evaluator(*, game, config, logger, queue)
Play the latest checkpoint vs standard MCTS.
- Parameters:
game (pyspiel.Game)
config (Config)
- alphaghost.alphazero.learner(*, game, config, actors, evaluators, broadcast_fn, logger)
Consume the replay buffer and train the network.
- alphaghost.alphazero.update_checkpoint(logger, queue, model, az_evaluator)
Read the queue for a checkpoint to load, or an exit signal.
- Return type:
- Parameters:
model (AlphaGhostModel)
az_evaluator (open_spiel.python.algorithms.alpha_zero.evaluator.AlphaZeroEvaluator)
alphaghost.mcts module
Monte-Carlo Tree Search algorithm for Phantom Go.
A version of open_spiel.python.algorithms.mcts.MCTSBot
extended to support imperfect information games, specifically Phantom Go.
- class alphaghost.mcts.MCTSBot
Bases:
Bot
Bot that uses Monte-Carlo Tree Search algorithm.
- __init__(game, uct_c, max_simulations, evaluator, solve=True, random_state=None, child_selection_fn=open_spiel.python.algorithms.mcts.SearchNode.uct_value, dirichlet_noise=None, verbose=False, dont_return_chance_node=False)
Initialize a MCTS Search algorithm in the form of a bot.
- Parameters:
game (
Game
) – A pyspiel.Game to play.uct_c (
float
) – The exploration constant for UCT.max_simulations (
int
) – How many iterations of MCTS to perform. Each simulation will result in one call to the evaluator. Memory usage should grow linearly with simulations * branching factor. How many nodes in the search tree should be evaluated. This is correlated with memory size and tree depth.evaluator (
Evaluator
) – A Evaluator object to use to evaluate a leaf node.solve (
bool
) – Whether to back up solved states.random_state (
RandomState
|None
) – An optional numpy RandomState to make it deterministic.child_selection_fn (
Callable
) – A function to select the child in the descent phase. The default is UCT.dirichlet_noise (
tuple
[float
,float
] |None
) – A tuple of (epsilon, alpha) for adding dirichlet noise to the policy at the root. This is from the alpha-zero paper.verbose (
bool
) – Whether to print information about the search tree before returning the action. Useful for confirming the search is working sensibly.dont_return_chance_node (
bool
) – If true, do not stop expanding at chance nodes. Enabled for AlphaZero.
- Return type:
None
- mcts_search(state)
Search with Monte-Carlo Tree Search algorithm.
- Return type:
SearchNode
- Parameters:
state (pyspiel.State)
alphaghost.model module
An AlphaZero style model with a policy and value head.
- class alphaghost.model.AlphaGhostModel
Bases:
Module
- __init__(input_shape, output_size, nn_width, nn_depth, learning_rate, weight_decay, path)
- forward(x)
- inference(obs, mask)
Run a forward pass through the network.
- class alphaghost.model.Losses
Bases:
NamedTuple
Losses from a training step.
- class alphaghost.model.TrainInput
Bases:
NamedTuple
Inputs for training the Model.
alphaghost.parsers module
Parsers for game states.
Methods for extracting additional information from
pyspiel.State
objects beyond the core python API.
- alphaghost.parsers.get_board(state, player_id=None)
Return the board positions visible to a player as a matrix.
- alphaghost.parsers.get_board_size(state)
Return the board size.
- Return type:
- Parameters:
state (pyspiel.State)
- alphaghost.parsers.get_board_svg(state, player_id=None)
Return the board as an SVG string.
- alphaghost.parsers.get_previous_move_info_string(state, player_id=None)
Return the previous move information.
- alphaghost.parsers.get_stones_count(state)
Return the number of stones for each player.
- Return type:
- Parameters:
state (pyspiel.State)
- alphaghost.parsers.get_visible_actions(state, player_id=None)
Return the visible board position’s indices.
alphaghost.phantom_go module
Module for playing Phantom Go against various bots.