예제 #1
0
def test_parameters(_gamma):

    start_time = time_module.clock()

    environment = GridEnvironment(n_rows, n_cols, circuit)
    agent = SimpleDQNAgent(environment)

    train_model(environment,
                agent,
                training_episodes=training_episodes,
                should_print=False)

    average_test_time = 0.0
    average_circuit_depth_overhead = 0.0

    for e in range(test_episodes):
        actions, circuit_depth = schedule_swaps(environment,
                                                agent,
                                                experience_db=None)
        average_test_time += (1.0 / test_episodes) * len(actions)
        average_circuit_depth_overhead += (1.0 /
                                           test_episodes) * (circuit_depth - 1)

    end_time = time_module.clock()

    total_time = end_time - start_time

    return average_circuit_depth_overhead, total_time
예제 #2
0
def train_model_on_random_circuits(model_number):
    model_name = "random_circuits_" + str(model_number)
    training_circuit_generation_function = lambda: generate_completely_random_circuit(
        20, 50).to_dqn_rep()

    environment = IBMQ20Tokyo(training_circuit_generation_function())
    agent = DoubleDQNAgent(environment)

    train_model(
        environment,
        agent,
        training_episodes=training_episodes,
        circuit_generation_function=training_circuit_generation_function,
        should_print=False)
    agent.save_model(model_name)
def train_model_on_full_layers(model_number):
    model_name = "full_layers_" + str(model_number)

    def training_circuit_generation_function():
        return generate_multi_layer_circuit(20, 2).to_dqn_rep()

    environment = IBMQ20Tokyo(training_circuit_generation_function())
    agent = DoubleDQNAgent(environment)

    train_model(
        environment,
        agent,
        training_episodes=training_episodes,
        circuit_generation_function=training_circuit_generation_function,
        should_print=False)
    agent.save_model(model_name)
예제 #4
0
def train_model_on_random_circuits(f_model_number):
    model_name = "random_circuits_" + str(f_model_number)

    def training_circuit_generation_function():
        return generate_completely_random_circuit(16, 50).to_dqn_rep()

    environment = GridEnvironment(4, 4, training_circuit_generation_function())
    agent = DoubleDQNAgent(environment)

    train_model(
        environment,
        agent,
        training_episodes=training_episodes,
        circuit_generation_function=training_circuit_generation_function,
        should_print=False)
    agent.save_model(model_name)
예제 #5
0
def perform_run(num_rows, num_cols, training_episodes, test_episodes=100):
    """

    :param num_rows: dummy arg, number of rows of TODO???
    :param num_cols: dummy arg, number of rows of TODO???
    :param training_episodes: number of episodes to train for
    :param test_episodes: number of episodes to test for
    :return: datapoint: TODO what does that mean?
    """
    def circuit_generation_function():
        return generate_full_layer_circuit(num_rows * num_cols).to_dqn_rep()

    environment = GridEnvironment(num_rows, num_cols,
                                  circuit_generation_function())
    agent = DoubleDQNAgent(environment)

    start_time = time_module.perf_counter()
    # Pass the number of training steps and episodes to control how much we train for
    train_model(environment,
                agent,
                training_episodes=training_episodes,
                circuit_generation_function=circuit_generation_function,
                should_print=True)

    average_circuit_depth_overhead = 0.0

    for e in range(test_episodes):
        actions, circuit_depth = schedule_swaps(
            environment,
            agent,
            circuit=circuit_generation_function(),
            experience_db=None)
        average_circuit_depth_overhead += (1.0 /
                                           test_episodes) * (circuit_depth - 1)
    end_time = time_module.perf_counter()

    time_taken = end_time - start_time
    datapoint = (num_rows, num_cols, average_circuit_depth_overhead,
                 time_taken)
    print('Completed run:', datapoint)
    return datapoint
예제 #6
0
def perform_run(nrows, ncols, training_episodes):
    test_episodes = 100

    circuit_generation_function = lambda: generate_full_layer_circuit(
        nrows * ncols).to_dqn_rep()

    environment = GridEnvironment(nrows, ncols, circuit_generation_function())
    agent = DQNAgent(environment)

    start_time = time_module.clock()

    train_model(environment,
                agent,
                training_episodes=training_episodes,
                circuit_generation_function=circuit_generation_function,
                should_print=False)

    average_circuit_depth_overhead = 0.0

    for e in range(test_episodes):
        actions, circuit_depth = schedule_swaps(
            environment,
            agent,
            circuit=circuit_generation_function(),
            experience_db=None)
        average_circuit_depth_overhead += (1.0 /
                                           test_episodes) * (circuit_depth - 1)

    end_time = time_module.clock()

    total_time = end_time - start_time

    datapoint = (nrows, ncols, average_circuit_depth_overhead, total_time)

    print('Completed run:', datapoint)

    return datapoint
print(circuit)

environment = GridEnvironment(nrows,ncols,circuit)
agent = DQNAgent(environment)
db = ExperienceDB()

training_episodes = 200 if nrows*ncols >= 36 else 100
test_episodes = 100

if __name__ == "__main__":

    if use_saved_model:
        agent.load_model(experiment_name)
    else:
        train_model(environment, agent, training_episodes=training_episodes, circuit_generation_function=circuit_generation_function, should_print=True)
        agent.save_model(experiment_name)

    average_test_time = 0.0
    average_circuit_depth_overhead = 0.0

    for e in range(test_episodes):
        if circuit_generation_function is not None:
            circuit = circuit_generation_function()
        else:
            circuit = None

        actions, circuit_depth = schedule_swaps(environment, agent, circuit=circuit, experience_db=db)
        average_test_time += (1.0/test_episodes) * len(actions)
        average_circuit_depth_overhead += (1.0/test_episodes) * (circuit_depth - 1)