league.league¶
base_league¶
BaseLeague¶
- class ding.league.base_league.BaseLeague(cfg: EasyDict)[source]¶
- Overview:
League, proposed by Google Deepmind AlphaStar. Can manage multiple players in one league.
- Interface:
get_job_info, judge_snapshot, update_active_player, finish_job, save_checkpoint
Note
In
__init__method, league would also initialized players as well(in_init_playersmethod).- finish_job(job_info: dict) None[source]¶
- Overview:
Finish current job. Update shared payoff to record the game results.
- Arguments:
job_info (
dict): A dict containing job result information.
- get_job_info(player_id: str | None = None, eval_flag: bool = False) dict[source]¶
- Overview:
Get info dict of the job which is to be launched to an active player.
- Arguments:
player_id (
str): The active player’s id.eval_flag (
bool): Whether this is an evaluation job.
- Returns:
job_info (
dict): Job info.
- ReturnsKeys:
necessary:
launch_player(the active player)
- judge_snapshot(player_id: str, force: bool = False) bool[source]¶
- Overview:
Judge whether a player is trained enough for snapshot. If yes, call player’s
snapshot, create a historical player(prepare the checkpoint and add it to the shared payoff), then mutate it, and return True. Otherwise, return False.- Arguments:
player_id (
ActivePlayer): The active player’s id.
- Returns:
snapshot_or_not (
dict): Whether the active player is snapshotted.
- static save_checkpoint(src_checkpoint, dst_checkpoint) None[source]¶
- Overview:
Copy a checkpoint from path
src_checkpointto pathdst_checkpoint.- Arguments:
src_checkpoint (
str): Source checkpoint’s path, e.g. s3://alphastar_fake_data/ckpt.pthdst_checkpoint (
str): Destination checkpoint’s path, e.g. s3://alphastar_fake_data/ckpt.pth
create_league¶
- Overview:
Given the key (league_type), create a new league instance if in league_mapping’s values, or raise an KeyError. In other words, a derived league must first register then call
create_leagueto get the instance object.- Arguments:
cfg (
EasyDict): league config, necessary keys: [league.import_module, league.learner_type]
- Returns:
league (
BaseLeague): the created new league, should be an instance of one of league_mapping’s values
league.one_vs_one_league¶
one_vs_one_league¶
OneVsOneLeague¶
- class ding.league.one_vs_one_league.OneVsOneLeague(cfg: EasyDict)[source]¶
- Overview:
One vs One battle game league. Decide which two players will play against each other.
- Interface:
__init__, run, close, finish_job, update_active_player
- finish_job(job_info: dict) None¶
- Overview:
Finish current job. Update shared payoff to record the game results.
- Arguments:
job_info (
dict): A dict containing job result information.
- get_job_info(player_id: str | None = None, eval_flag: bool = False) dict¶
- Overview:
Get info dict of the job which is to be launched to an active player.
- Arguments:
player_id (
str): The active player’s id.eval_flag (
bool): Whether this is an evaluation job.
- Returns:
job_info (
dict): Job info.
- ReturnsKeys:
necessary:
launch_player(the active player)
- judge_snapshot(player_id: str, force: bool = False) bool¶
- Overview:
Judge whether a player is trained enough for snapshot. If yes, call player’s
snapshot, create a historical player(prepare the checkpoint and add it to the shared payoff), then mutate it, and return True. Otherwise, return False.- Arguments:
player_id (
ActivePlayer): The active player’s id.
- Returns:
snapshot_or_not (
dict): Whether the active player is snapshotted.
- static save_checkpoint(src_checkpoint, dst_checkpoint) None¶
- Overview:
Copy a checkpoint from path
src_checkpointto pathdst_checkpoint.- Arguments:
src_checkpoint (
str): Source checkpoint’s path, e.g. s3://alphastar_fake_data/ckpt.pthdst_checkpoint (
str): Destination checkpoint’s path, e.g. s3://alphastar_fake_data/ckpt.pth
- update_active_player(player_info: dict) None¶
- Overview:
Update an active player’s info.
- Arguments:
player_info (
dict): Info dict of the player which is to be updated.
- ArgumentsKeys:
necessary: player_id, train_iteration