Esempio n. 1
0
 def switch_model(self, model_type, model_file=None):
     """
     :param model_type: choices in [policy_dl, policy_rl, policy_rollout, value_net]
     :return:
     """
     if model_type not in self.hosts:
         logger.error("not supported model type=%s" % model_type, to_exit=True)
     url = "%s/switch_model?model=%s" % (self.hosts[model_type], model_type)
     if model_file is not None:
         url = "%s&file=%s" % (url, model_file)
     result = rpc(url)
     if result["status"] != 0:
         logger.error("fail to switch model, type=%s, file=%s" % (model_type, model_file), to_exit=True)
     logger.info("success to switch model, type=%s, file=%s" % (model_type, model_file))
Esempio n. 2
0
 def simulate_rpc(self, model_type, board_stream, player, host=None):
     """
     :param model_type: choices in [policy_dl, policy_rl, policy_rollout, value_net]
     :param board_stream:
     :param player:   choices=[black, white]
     :return:
     """
     if host is None:
         host = self.hosts[model_type]
     url = "%s/simulate" % host
     data = json.dumps({"board": board_stream, "player": player})
     result = rpc(url, data=data)
     if result["status"] != 0:
         logger.error("fail to request to url = %s" % url)
     return result["reward"]