def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Setup required for unit tests. print("Unit testing CWD:", os.getcwd()) self.config = DotDict.from_json("../Configurations/ModelConfigs/MuzeroCartpole.json") self.g = GymGame('CartPole-v1') self.net = GymNet(self.g, self.config.net_args) self.mcts = MuZeroMCTS(self.g, self.net, self.config.args)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Setup required for unit tests. print("Unit testing CWD:", os.getcwd()) self.config = DotDict.from_json("../Configurations/ModelConfigs/MuzeroBoard.json") self.g = HexGame(self.hex_board_size) self.net = HexNet(self.g, self.config.net_args) self.mcts = MuZeroMCTS(self.g, self.net, self.config.args)
def __init__(self, game, arg_file: typing.Optional[str] = None, name: str = "") -> None: super().__init__(game, arg_file, name, parametric=True) if self.player_args is not None: self.args = DotDict.from_json(self.player_args) self.model = DefaultMuZero(self.game, self.args.net_args, self.args.architecture) self.search_engine = MuZeroMCTS(self.game, self.model, self.args.args) self.name = self.args.name
def __init__(self, game, arg_file: typing.Optional[str] = None, name: str = "") -> None: super().__init__(game, arg_file, name, parametric=True) if self.player_args is not None: # Initialize AlphaZero by loading its parameter config and constructing the network and search classes. self.args = DotDict.from_json(self.player_args) self.model = DefaultAlphaZero(self.game, self.args.net_args, self.args.architecture) self.search_engine = AlphaZeroMCTS(self.game, self.model, self.args.args) self.name = self.args.name
def __init__(self, game, nested_config: typing.Optional[DotDict] = None, name: str = "") -> None: super().__init__(game, nested_config.file, name, parametric=True) if self.player_args is not None: self.args = DotDict.from_json(self.player_args) self.model = BlindMuZero(self.game, self.args.net_args, self.args.architecture, nested_config.refresh_freq) self.model.bind(self.history.actions) self.search_engine = MuZeroMCTS(self.game, self.model, self.args.args) self.name = self.args.name
def __init__(self, game, nested_config: typing.Optional[DotDict] = None, name: str = "") -> None: super().__init__(game, nested_config.file, name, parametric=True) if self.player_args is not None: # Initialize MuZero by loading its parameter config and constructing the network and search classes. # Additionally assign/ bind internal MDP memory to enable planning strictly within the learned model. self.args = DotDict.from_json(self.player_args) self.model = BlindMuZero(self.game, self.args.net_args, self.args.architecture, nested_config.refresh_freq) self.model.bind(self.history.actions) self.search_engine = MuZeroMCTS(self.game, self.model, self.args.args) self.name = self.args.name
def __init__(self, experiment_file: str) -> None: """ Initialize the experiment data container using a string path to a .json settings file. Not all variables are initialized directly (require an explicit call to construct) seeing as this may bloat the memory with large implementations when performing a large number of experiments sequentially. :param experiment_file: str Path to .json file containing experiment details. """ self.experiment_args = DotDict.from_json(experiment_file) self.type = self.experiment_args.experiment self.name = self.experiment_args.name self.output_directory = self.output_directory = f'./out/{self.experiment_args.output_dir}/' self.game_config = None self.game = None self.ablation_base = None self.ablation_grid = None self.player_configs = list()
def __enter__(self) -> AblationAnalysis: """ Initialize experiment by generating all ModelConfigs as specified by the hyperparameter grid, and storing them in a temporary folder. All config files will be assigned an unique name, which will later be accessed for training agents asynchronously. """ if not os.path.exists(self.config_dir): os.makedirs(self.config_dir) # First construct all possible hyperparameter configuration JSON contents. self.configs = list() base_config = DotDict.from_json(self.experiment.ablation_base.config) for param in self.experiment.ablation_grid: config = base_config.copy() config.recursive_update(param) self.configs.append(config) # Save ablation analysis configuration using time annotation. dt = datetime.now().strftime("%Y%m%d-%H%M%S") schedule = DotDict({i: self.experiment.ablation_grid[i] for i in range(len(self.experiment.ablation_grid))}) schedule.to_json(os.path.join(self.experiment.output_directory, f'ablation_schedule_{dt}.json')) # Store/ generate all unique JSON config files annotated by time and repetition number. for run in range(self.experiment.experiment_args.num_repeat): for i, config in enumerate(self.configs): c = config.copy() # Note: shallow copy. run_config_name = f'rep{run}_config{i}_dt{dt}' c.name = f'{c.name}_{run_config_name}' out = os.path.join(self.experiment.output_directory, c.args.checkpoint, run_config_name) c.args.checkpoint = out c.args.load_folder_file = (out, c.args.load_folder_file[1]) if not os.path.exists(c.args.checkpoint): os.makedirs(c.args.checkpoint) config_file = os.path.join(self.config_dir, run_config_name) + '.json' c.to_json(config_file) self.files.append(config_file) return self
def __enter__(self) -> AblationAnalysis: if not os.path.exists(self.config_dir): os.makedirs(self.config_dir) self.configs = list() base_config = DotDict.from_json(self.experiment.ablation_base.config) for param in self.experiment.ablation_grid: config = base_config.copy() config.recursive_update(param) self.configs.append(config) dt = datetime.now().strftime("%Y%m%d-%H%M%S") schedule = DotDict({ i: self.experiment.ablation_grid[i] for i in range(len(self.experiment.ablation_grid)) }) schedule.to_json( os.path.join(self.experiment.output_directory, f'ablation_schedule_{dt}.json')) for run in range(self.experiment.experiment_args.num_repeat): for i, config in enumerate(self.configs): c = config.copy() # Note: shallow copy. run_config_name = f'rep{run}_config{i}_dt{dt}' c.name = f'{c.name}_{run_config_name}' out = os.path.join(self.experiment.output_directory, c.args.checkpoint, run_config_name) c.args.checkpoint = out c.args.load_folder_file = (out, c.args.load_folder_file[1]) if not os.path.exists(c.args.checkpoint): os.makedirs(c.args.checkpoint) config_file = os.path.join(self.config_dir, run_config_name) + '.json' c.to_json(config_file) self.files.append(config_file) return self