Exemple #1
0
    def _self_evaluate(self, n_games, game_states, simulations_per_turn):
        results = []
        for _ in range(n_games):
            nn_executor_client_one = neural_network.NeuralNetworkClient(
                self.nn_client_host_one)
            nn_executor_client_two = neural_network.NeuralNetworkClient(
                self.nn_client_host_two)

            game_state = np.random.choice(game_states)

            params = (game_state, nn_executor_client_one,
                      nn_executor_client_two, simulations_per_turn,
                      self.config)
            result = self.process_pool.apply_async(
                PlayingSlave._play_evaluation_game,
                params,
                callback=PlayingSlave.eval_callback)
            results.append(result)

        total_score = [0, 0]
        for result in results:
            score = result.get()
            total_score[0] += score[0]
            total_score[1] += score[1]

        return total_score
Exemple #2
0
    def _setup_nn(self):
        neural_network.start_nn_server(
            self.config.nn_server_training_port(),
            self.nn_name,
            self.config,
            log_dir=self.log_dir,
            start_batch=self.progress.stats.progress.current_batch)
        self.nn_client = neural_network.NeuralNetworkClient(
            'tcp://localhost:{}'.format(self.config.nn_server_training_port()))
        self.nn_client.start(self.config)

        if self.progress.stats.progress.iteration > 0:
            checkpoint_name = 'checkpoint-{0:05d}.zip'.format(
                self.progress.stats.progress.iteration)
            with open(os.path.join(self.weights_dir, checkpoint_name),
                      'rb') as file:
                weights_binary = file.read()
                self.nn_client.load_weights(weights_binary)

            with open(os.path.join(self.work_dir, 'best-checkpoint.zip'),
                      'rb') as file:
                self.best_weights_binary = file.read()
        else:
            self.progress.stats.progress.iteration = 1
            self.best_weights_binary = self.nn_client.save_weights()
            self._save_best_weights()

        self.current_weights_binary = self.nn_client.save_weights()
        self._save_current_weights()
        self.progress.save_stats()
Exemple #3
0
    def _restart_network_two(self, nn_class_name):
        self.nn_class_name_two = nn_class_name
        if self.nn_client_two:
            self.nn_client_two.shutdown_server()
            self.nn_client_two.stop()
            time.sleep(15)

        neural_network.start_nn_server(self.config.nn_server_selfeval_port(), self.nn_class_name_two, self.config)
        self.nn_client_host_two = 'tcp://localhost:{}'.format(self.config.nn_server_selfeval_port())
        self.nn_client_two = neural_network.NeuralNetworkClient(self.nn_client_host_two)
        self.nn_client_two.start(self.config)
Exemple #4
0
    def _restart_network_one(self, nn_class_name):
        self.nn_class_name_one = nn_class_name
        if self.nn_client_one:
            self.nn_client_one.shutdown_server()
            self.nn_client_one.stop()
            time.sleep(15)

        neural_network.start_nn_server(self.config.nn_server_selfplay_port(), self.nn_class_name_one, self.config)
        self.nn_client_host_one = 'tcp://localhost:{}'.format(self.config.nn_server_selfplay_port())
        self.nn_client_one = neural_network.NeuralNetworkClient(self.nn_client_host_one)
        self.nn_client_one.start(self.config)
Exemple #5
0
    def _play_games(self, n_games, game_states, simulations_per_turn):
        results = []
        for _ in range(n_games):
            nn_executor_client = neural_network.NeuralNetworkClient(self.nn_client_host_one)
            game_state = np.random.choice(game_states)

            params = (game_state, nn_executor_client, simulations_per_turn, self.config)
            result = self.process_pool.apply_async(PlayingSlave._play_game, params,
                                                   callback=PlayingSlave.selfplay_callback)
            results.append(result)

        evaluation_lists = []
        for result in results:
            evaluation_lists.append(result.get())

        return evaluation_lists
Exemple #6
0
    def _ai_evaluate(self, n_games, game_states, turn_time):
        results = []
        for _ in range(n_games):
            nn_executor_client_one = neural_network.NeuralNetworkClient(self.nn_client_host_one)

            game_state = np.random.choice(game_states)

            params = (game_state, nn_executor_client_one, turn_time, self.config)
            result = self.process_pool.apply_async(PlayingSlave._play_ai_evaluation_game, params,
                                                   callback=PlayingSlave.ai_eval_callback)
            results.append(result)

        total_score = [0, 0]
        for result in results:
            score = result.get()
            for i in range(2):
                total_score[i] += score[i]

        return total_score