def perform_run(n_gates, model_number): model_name = "random_circuits_" + str(model_number) start_time = time_module.clock() test_circuit_generation_function = lambda: generate_completely_random_circuit( 20, n_gates) environment = IBMQ20Tokyo(test_circuit_generation_function().to_dqn_rep()) agent = DoubleDQNAgent(environment) agent.load_model(model_name) average_test_time = 0.0 average_circuit_depth_overhead = 0.0 average_circuit_depth_ratio = 0.0 for e in range(test_episodes): circuit = test_circuit_generation_function() original_depth = circuit.depth() actions, circuit_depth = schedule_swaps(environment, agent, circuit=circuit.to_dqn_rep(), experience_db=None) average_test_time += (1.0 / test_episodes) * len(actions) average_circuit_depth_overhead += (1.0 / test_episodes) * ( circuit_depth - original_depth) average_circuit_depth_ratio += (1.0 / test_episodes) * ( float(circuit_depth) / float(original_depth)) end_time = time_module.clock() total_time = end_time - start_time result = (n_gates, average_test_time, average_circuit_depth_overhead, average_circuit_depth_ratio, total_time) print('Completed run:', result) return result
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)