lczerolens.play.sampling#

Classes for playing.

Classes#

Sampler

Helper class that provides a standard way to create an ABC using

RandomSampler

Helper class that provides a standard way to create an ABC using

ModelSampler

Helper class that provides a standard way to create an ABC using

PolicySampler

Helper class that provides a standard way to create an ABC using

SelfPlay

A class for generating games.

Module Contents#

class lczerolens.play.sampling.Sampler[source]#

Bases: abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

abstract get_utilities(boards, **kwargs)[source]#

Get the utility of the board.

Parameters:

boards (Iterable[LczeroBoard]) – The boards to evaluate.

Returns:

The iterable over utilities, legal indices, and log dictionaries.

Return type:

Iterable[Tuple[torch.Tensor, torch.Tensor, Dict[str, float]]]

choose_move(board, utility, legal_indices)[source]#

Choose the next moves.

Parameters:
  • board (LczeroBoard) – The board.

  • utility (torch.Tensor) – The utility of the board.

  • legal_indices (torch.Tensor) – The legal indices.

Returns:

The iterable over the moves.

Return type:

Iterable[chess.Move]

get_next_moves(boards, **kwargs)[source]#

Get the next move.

Parameters:

boards (Iterable[LczeroBoard]) – The boards to evaluate.

Returns:

The iterable over the moves and log dictionaries.

Return type:

Iterable[Tuple[chess.Move, Dict[str, float]]]

class lczerolens.play.sampling.RandomSampler[source]#

Bases: Sampler

Helper class that provides a standard way to create an ABC using inheritance.

get_utilities(boards, **kwargs)[source]#

Get the utility of the board.

Parameters:

boards (Iterable[LczeroBoard]) – The boards to evaluate.

Returns:

The iterable over utilities, legal indices, and log dictionaries.

Return type:

Iterable[Tuple[torch.Tensor, torch.Tensor, Dict[str, float]]]

class lczerolens.play.sampling.ModelSampler[source]#

Bases: Sampler

Helper class that provides a standard way to create an ABC using inheritance.

model: lczerolens.model.LczeroModel[source]#
use_argmax: bool = True[source]#
alpha: float = 1.0[source]#
beta: float = 1.0[source]#
gamma: float = 1.0[source]#
draw_score: float = 0.0[source]#
m_max: float = 0.0345[source]#
m_slope: float = 0.0027[source]#
k_0: float = 0.0[source]#
k_1: float = 1.6521[source]#
k_2: float = -0.6521[source]#
q_threshold: float = 0.8[source]#
choose_move(board, utility, legal_indices)[source]#

Choose the next moves.

Parameters:
  • board (LczeroBoard) – The board.

  • utility (torch.Tensor) – The utility of the board.

  • legal_indices (torch.Tensor) – The legal indices.

Returns:

The iterable over the moves.

Return type:

Iterable[chess.Move]

get_utilities(boards, **kwargs)[source]#

Get the utility of the board.

Parameters:

boards (Iterable[LczeroBoard]) – The boards to evaluate.

Returns:

The iterable over utilities, legal indices, and log dictionaries.

Return type:

Iterable[Tuple[torch.Tensor, torch.Tensor, Dict[str, float]]]

_get_batched_stats(boards, batch_size, use_next_boards=True, **kwargs)[source]#
_get_q_values(batch_stats, to_log)[source]#
_get_m_values(batch_stats, q_values, to_log)[source]#
_get_p_values(batch_stats, legal_indices, to_log)[source]#
_use_callback(callback, batch_stats, to_log)[source]#
class lczerolens.play.sampling.PolicySampler[source]#

Bases: ModelSampler

Helper class that provides a standard way to create an ABC using inheritance.

use_suboptimal: bool = False[source]#
get_utilities(boards, **kwargs)[source]#

Get the utility of the board.

Parameters:

boards (Iterable[LczeroBoard]) – The boards to evaluate.

Returns:

The iterable over utilities, legal indices, and log dictionaries.

Return type:

Iterable[Tuple[torch.Tensor, torch.Tensor, Dict[str, float]]]

class lczerolens.play.sampling.SelfPlay[source]#

A class for generating games.

white: Sampler[source]#
black: Sampler[source]#
play(board=None, max_moves=100, to_play=chess.WHITE, report_fn=None, white_kwargs=None, black_kwargs=None)[source]#

Plays a game.

Parameters:
  • board (Optional[lczerolens.board.LczeroBoard])

  • max_moves (int)

  • to_play (chess.Color)

  • report_fn (Optional[Callable[[dict, chess.Color], None]])

  • white_kwargs (Optional[Dict])

  • black_kwargs (Optional[Dict])