def save_game_to_sql(self, game):
        filename = "game"

        data = pickle.dumps(game)
        sql_conn = SqlUtil.connect()
        SqlUtil.game_data_insert_row(sql_conn, TimerUtil.get_computer_hostname(), filename, "sql blob testing",  data)
        print("Game inserted into sql database table")
def run_iteration_timing_test(log_type=None):
    # TEST STUFF
    print("run iteration timing test Latrunculi")
    game = Latrunculi(8, 42)
    state = game.start_state()

    time_b = time()

    counter = 0
    while counter < 3000:
        actions = game.actions(state)
        action = actions[int(uniform(0, len(actions)))]
        result = game.result(state, action)
        counter += 1

    time_taken = time() - time_b
    print("Time taken to play out game: {} s".format(time_taken))
    print("Iterations: {}".format(counter))

    if log_type == 'excel':
        # Appending results to standard excel file "test_results.xlsx"
        row = (ExcelUtil.get_datetime_str(), ExcelUtil.get_computer_hostname(), "Latrunculi", counter, (time() - time_b))
        ExcelUtil.excel_append_row(row)
    elif log_type == 'sql':
        row = (ExcelUtil.get_datetime_str(), ExcelUtil.get_computer_hostname(), "Latrunculi", counter, (time() - time_b))
        sql_conn = SqlUtil.connect()
        SqlUtil.test_iteration_timing_insert_row(sql_conn, row)

    return time_taken
Exemple #3
0
def start_training_status():
    if Config.STATUS_DB:
        if "-l" in argv:
            load_training_status()
        else:
            SqlUtil.connection = SqlUtil.connect()
            SqlUtil.add_status(SqlUtil.connection)
Exemple #4
0
def update_num_games(games=None):
    if games is not None:
        FancyLogger.total_games = games
        if Config.STATUS_DB:
            SqlUtil.set_status(SqlUtil.connection, "games=%s", games)
    else:
        FancyLogger.increment_total_games()
        if Config.STATUS_DB:
            SqlUtil.set_status(SqlUtil.connection, "games=games+1")
    def load_newest_network_from_sql(self):
        sql_conn = SqlUtil.connect()
        network_tuple = SqlUtil.network_data_select_newest_network(sql_conn) #dont know what datatype is returned from fetchone(), it seems to be a tuple
        network_config = network_tuple[0]

        config = pickle.loads(network_config)
        network_model = Model.from_config(config)
        print("Newest network selected from sql database table")
        return network_model
 def save_network_to_sql(self, network):
     print("save_network_to_sql called")
     filename = "network"
     
     config = network.model.get_config()
     data = pickle.dumps(config)
     
     sql_conn = SqlUtil.connect()
     SqlUtil.network_data_insert_row(sql_conn, TimerUtil.get_computer_hostname(), filename, "saved neural network",  data)
     print("Network inserted into sql database table")
    def load_games_from_sql(self):
        sql_conn = SqlUtil.connect()
        games = SqlUtil.game_data_select_newest_games(sql_conn) #games from sql, arranged as an array of tuples, each tuple containing (bin_data,(nothing for some reason))

        for g in games:
            game = g[0]
            if game is not None:
                unpickledGame = pickle.loads(game)
                self.buffer.append(unpickledGame)

        print("Games selected from sql database table, and inserted into replay_buffer")
Exemple #8
0
def update_perf_values(values):
    FancyLogger.set_performance_values(values)
    if Config.STATUS_DB:
        insert_str = None
        val = None
        if values[0] is not None:
            insert_str = "eval_rand=%s"
            val = values[0][0]
        elif values[1] is not None:
            insert_str = "eval_mini=%s"
            val = values[1][0]
        elif values[2] is not None:
            insert_str = "eval_mcts=%s"
            val = values[2][0]
        elif values[3] is not None:
            insert_str = "eval_macro=%s"
            val = values[3][0]
        SqlUtil.set_status(SqlUtil.connection, insert_str, float(val))
Exemple #9
0
def load_training_status():
    if Config.STATUS_DB:
        SqlUtil.connection = SqlUtil.connect()
        SqlUtil.get_latest_status(SqlUtil.connection)
        update_active(1)
Exemple #10
0
def set_total_steps(steps):
    if Config.STATUS_DB:
        SqlUtil.set_status(SqlUtil.connection, "total_steps=%s", steps)
Exemple #11
0
def update_active(active):
    if Config.STATUS_DB:
        SqlUtil.set_status(SqlUtil.connection, "active=%s", active)
        if not active:
            SqlUtil.connection.close()
Exemple #12
0
def update_loss(loss):
    FancyLogger.set_network_status(
        f"Training loss: Total: {loss[0]:.5f}. Policy: {loss[1]:.5f}. Value: {loss[2]:.5f}"
    )
    if Config.STATUS_DB:
        SqlUtil.set_status(SqlUtil.connection, "loss=%s", float(loss[0]))
Exemple #13
0
def update_training_step(step):
    FancyLogger.set_training_step(step)
    FancyLogger.eval_checkpoint = eval_checkpoint(step)
    if Config.STATUS_DB:
        SqlUtil.set_status(SqlUtil.connection, "step=%s", step)