def export_agent(self, step): _dir = ospj(self._t_prof.path_agent_export_storage, str(self._t_prof.name), str(step)) file_util.create_dir_if_not_exist(_dir) # """""""""""""""""""""""""""" # Deep CFR # """""""""""""""""""""""""""" if self._AVRG: MODE = EvalAgentDeepCFR.EVAL_MODE_AVRG_NET t_prof = copy.deepcopy(self._t_prof) t_prof.eval_modes_of_algo = [MODE] eval_agent = EvalAgentDeepCFR(t_prof=t_prof) eval_agent.reset() w = {EvalAgentDeepCFR.EVAL_MODE_AVRG_NET: self._pull_avrg_net_eval_strat()} eval_agent.update_weights(w) eval_agent.set_mode(mode=MODE) eval_agent.store_to_disk(path=_dir, file_name="eval_agent" + MODE) # """""""""""""""""""""""""""" # SD-CFR # """""""""""""""""""""""""""" if self._SINGLE: MODE = EvalAgentDeepCFR.EVAL_MODE_SINGLE t_prof = copy.deepcopy(self._t_prof) t_prof.eval_modes_of_algo = [MODE] eval_agent = EvalAgentDeepCFR(t_prof=t_prof) eval_agent.reset() eval_agent._strategy_buffers = self._strategy_buffers # could copy - it's just for the export, so it's ok eval_agent.set_mode(mode=MODE) eval_agent.store_to_disk(path=_dir, file_name="eval_agent" + MODE)
def add_new_iteration_strategy_model(self, owner, adv_net_state_dict, cfr_iter): iter_strat = IterationStrategy(t_prof=self._t_prof, env_bldr=self._env_bldr, owner=owner, device=self._t_prof.device_inference, cfr_iter=cfr_iter) iter_strat.load_net_state_dict( self._ray.state_dict_to_torch( adv_net_state_dict, device=self._t_prof.device_inference)) self._strategy_buffers[iter_strat.owner].add( iteration_strat=iter_strat) # Store to disk if self._t_prof.export_each_net: path = ospj(self._t_prof.path_strategy_nets, self._t_prof.name) file_util.create_dir_if_not_exist(path) file_util.do_pickle(obj=iter_strat.state_dict(), path=path, file_name=str(iter_strat.cfr_iteration) + "_P" + str(iter_strat.owner) + ".pkl") if self._t_prof.log_verbose: if owner == 1: # Logs process = psutil.Process(os.getpid()) self.add_scalar(self._exp_mem_usage, "Debug/Memory Usage/Chief", cfr_iter, process.memory_info().rss)
def export_agent(self, step): _dir = ospj(self._t_prof.path_agent_export_storage, str(self._t_prof.name), str(step)) file_util.create_dir_if_not_exist(_dir) eval_agent = EvalAgentNFSP(t_prof=self._t_prof) w, _ = self.pull_current_eval_strategy() eval_agent.update_weights(weights_for_eval_agent=w) eval_agent.notify_of_reset() eval_agent.set_mode(EvalAgentNFSP.EVAL_MODE_AVG) eval_agent.store_to_disk(path=_dir, file_name="eval_agent")
def __init__( self, env_bldr, stack_size, stop_at_street, put_out_new_round_after_limit=False, is_debugging=False, ): """ To start the tree from a given scenario, set ""env"" to that scenario and it will be treated as the root. """ self._env_bldr = env_bldr self._is_debugging = is_debugging self._stack_size = stack_size # set up optional graphical tree export _dir_tree_vis = os.path.join( "C:\\" if os.name == 'nt' else os.path.expanduser('~/'), "PokerRL_Viz") # This is just me being over-cautious to not overwrite someones files... _tree_vis_installed = os.path.isdir(_dir_tree_vis) \ and os.path.isfile(os.path.join(_dir_tree_vis, "ALLOWED_TO_WRITE_HERE.dontdelete")) if _tree_vis_installed: self.dir_tree_vis_data = os.path.join(_dir_tree_vis, "data") file_util.create_dir_if_not_exist(self.dir_tree_vis_data) else: self.dir_tree_vis_data = None # _________________________________ tree vars __________________________________ self.root = None self._n_nodes = 0 self._n_nonterm = 0 self._env = self._env_bldr.get_new_env(is_evaluating=True, stack_size=stack_size) _ar = self._env.get_args() _ar.RETURN_PRE_TRANSITION_STATE_IN_INFO = True self._env.set_args(_ar) self._env.reset() self._n_seats = self._env_bldr.N_SEATS # _____________________ stops building tree at given round _____________________ self._stop_at_street = max( self._env.ALL_ROUNDS_LIST ) + 1 if stop_at_street is None else stop_at_street self._put_out_new_round_after_limit = put_out_new_round_after_limit self._value_filler = ValueFiller(tree=self) self._strategy_filler = StrategyFiller(tree=self, env_bldr=env_bldr)
def export_all(self, iter_nr): """ Exports all logs of the current run in Tensorboard's format and as json files. """ if self._path_log_storage is not None: path_crayon = ospj(self._path_log_storage, str(self._name), str(iter_nr), "crayon") path_json = ospj(self._path_log_storage, str(self._name), str(iter_nr), "as_json") create_dir_if_not_exist(path=path_crayon) create_dir_if_not_exist(path=path_json) for e in self._experiments.values(): e.to_zip(filename=ospj(path_crayon, e.xp_name + ".zip")) write_dict_to_file_json(dictionary=self._custom_logs, _dir=path_json, file_name="logs")
def __init__(self, name, runs_distributed, runs_cluster, chief_handle, path_log_storage=None, crayon_server_address="localhost"): self._name = name self._path_log_storage = path_log_storage if path_log_storage is not None: create_dir_if_not_exist(path_log_storage) self._chief_handle = chief_handle self._crayon = CrayonClient(hostname=crayon_server_address) self._experiments = {} self.clear() self._custom_logs = { } # dict of exps containing dict of graph names containing lists of {step: val, } dicts self._ray = MaybeRay(runs_distributed=runs_distributed, runs_cluster=runs_cluster)
def _get_export_hands_file_path(self, name, step, cls, worker_id): path = ospj(self._t_prof.path_export_hands, str(name), str(step)) file_util.create_dir_if_not_exist(path) return ospj(path, cls.__name__ + "_" + str(worker_id) + ".pkl")