-
Notifications
You must be signed in to change notification settings - Fork 0
/
multi_runs.py
57 lines (42 loc) · 1.76 KB
/
multi_runs.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
from time import time
from pyqcd.algorithms import *
from pyqcd.alphabet import Alphabet
from pyqcd.gates import CX, U3, I
from pyqcd.logger import Logger
from pyqcd.matrices import QFT
def main():
"""Submit several runs"""
qubits = 2
target_name = "QFT"
gates_set = [I, U3, CX]
n_runs = 4
target = QFT(qubits)
# Instantiate a custom set of gates, an alphabet whose words are gates
alphabet = Alphabet(Q=qubits)
alphabet.register_gates(gates_set)
for n_run in range(n_runs):
start_time = int(time())
solver = MLOA(target=target, alphabet=alphabet,
n_groups=50, group_size=5, circuit_size=15)
#solver = GA(target=target, alphabet=alphabet, pop_size=50, circuit_size=15)
# Instantiate the logger class to keep track of fitness evolution
logger = Logger("data/%s/%s_%s%d.pickle" %
(solver.__class__.__name__, start_time, target_name, qubits), True)
logger.add_variables(*solver.stats().keys())
while solver.n_evals < 100000:
# One step evolution
solver.evolve()
# Gather and save statistics
logger.register(**solver.stats())
print("=============================")
print("%s %s%d #%d" %
(solver.__class__.__name__, target_name, qubits, n_run))
print("Generations %d" % solver.gen)
print("Fitness evals %d" % solver.n_evals)
print("Score %0.5f" % solver.best.score)
print("%s" % solver.best)
print("=============================")
with open("data/%s/%s_%s%d.qasm" % (solver.__class__.__name__, start_time, target_name, qubits), 'w') as f:
f.write(solver.best.to_qasm())
if __name__ == "__main__":
main()