-
Notifications
You must be signed in to change notification settings - Fork 3
/
run_heuristic.py
76 lines (64 loc) · 2.67 KB
/
run_heuristic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import argparse
import json
import pathlib
import time
from pathlib import Path
import numpy as np
from Cycles import GraphCreator, MemoryZone
from scheduling import create_initial_sequence, create_starting_config, run_simulation
def run_simulation_for_architecture(arch, seeds, pz, max_timesteps, time_1qubit_gate=1, time_2qubit_gate=3, max_chains_in_parking=3, compilation=True):
"""
Runs simulations for the given architecture and seeds, logs the results.
Args:
arch (list): Architecture parameters.
seeds (list): List of seed values.
pz (str): Position of Processing zone.
max_timesteps (int): Maximum timesteps.
compilation (bool): Compilation flag (Gate Selection Step).
Returns:
tuple: (timestep_arr, cpu_time_arr, number_of_registers, n_of_traps, seq_length)
"""
timestep_arr = []
cpu_time_arr = []
start_time = time.time()
for seed in seeds:
m, n, v, h = arch
graph = GraphCreator(m, n, v, h, pz).get_graph()
try:
ion_chains, number_of_registers = create_starting_config(num_ion_chains, graph, seed=seed)
except:
continue
print(f"ion chains: {ion_chains}, number of registers: {number_of_registers}")
print(f"arch: {arch}, seed: {seed}, registers: {number_of_registers}\n")
memorygrid = MemoryZone(
m, n, v, h, ion_chains, max_timesteps, max_chains_in_parking, pz,
time_2qubit_gate=time_2qubit_gate, time_1qubit_gate=time_1qubit_gate
)
memorygrid.update_distance_map()
seq, flat_seq, dag_dep, next_node_initial = create_initial_sequence(
memorygrid.distance_map, filename, compilation=compilation
)
timestep = run_simulation(
memorygrid, max_timesteps, seq, flat_seq, dag_dep, next_node_initial, max_length=10
)
timestep_arr.append(timestep)
cpu_time = time.time() - start_time
cpu_time_arr.append(cpu_time)
return timestep_arr, cpu_time_arr
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("config_file", help="path to json config file")
#parser.add_argument("--plot", action="store_true", help="plot grid")
args = parser.parse_args()
with pathlib.Path(args.config_file).open("r") as f:
config = json.load(f)
arch = config["arch"]
max_timesteps = config["max_timesteps"]
num_ion_chains = config["num_ion_chains"]
filename = config["qu_alg"]
seeds = [0]
pz = 'outer'
timestep_arr, cpu_time_arr = run_simulation_for_architecture(
arch, seeds, pz, max_timesteps
)
print(f"CPU time: {np.mean(cpu_time_arr)} s")