forked from nus-comparch/hamiltonian_engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
63 lines (55 loc) · 2.21 KB
/
test.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
# import the predefined library
import os
os.path.abspath(os.curdir)
os.path.sys.path.append('predefined_problems/')
import skeletor as sk
import numpy as np
# Create a graph for the problem its is also adviseable to instantiate the weight of the graphs else it
# be defaulted to 1
import networkx as nx
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
n = 5
V = np.arange(0,n,1)
E =[(0,1,6.0),(2,0,7.0),(1,2,8.0),(3,2,9.0),(3,4,10.0),(4,2,4.0)]
G = nx.Graph()
G.add_nodes_from(V)
G.add_weighted_edges_from(E)
print("Finished generating graph.......")
obj1 = '~x_1 & x_2 | ~x_2 & x_1'
v1 = ['x_1', 'x_2']
hamiltonian = sk.skeletor(60, obj1, v1, True, graph=G)
print("Instantiated Skeletor .......")
hyperparams = [np.pi, np.pi, np.pi, np.pi/2, np.pi/3,
np.pi, np.pi, np.pi, np.pi/2, np.pi/3,
np.pi, np.pi, np.pi, np.pi/2, np.pi/3,
np.pi, np.pi, np.pi, np.pi/2, np.pi/3,
np.pi, np.pi, np.pi, np.pi/2, np.pi/3,
np.pi, np.pi, np.pi, np.pi/2, np.pi/3,
np.pi, np.pi, np.pi, np.pi/2, np.pi/3,
np.pi, np.pi, np.pi, np.pi/2, np.pi/3,
np.pi, np.pi, np.pi, np.pi/2, np.pi/3,
np.pi, np.pi, np.pi, np.pi/2, np.pi/3,
np.pi, np.pi, np.pi, np.pi/2, np.pi/3,
np.pi, np.pi, np.pi, np.pi/2, np.pi/3,
np.pi, np.pi, np.pi, np.pi/2, np.pi/3,
np.pi, np.pi, np.pi, np.pi/2, np.pi/3,
np.pi, np.pi, np.pi, np.pi/2, np.pi/3,
np.pi, np.pi, np.pi, np.pi/2, np.pi/3,
np.pi, np.pi, np.pi, np.pi/2, np.pi/3,
np.pi, np.pi, np.pi, np.pi/2, np.pi/3,
np.pi, np.pi, np.pi, np.pi/2, np.pi/3,
np.pi, np.pi, np.pi, np.pi/2, np.pi/3,
np.pi, np.pi, np.pi, np.pi/2, np.pi/3,
np.pi, np.pi, np.pi, np.pi/2, np.pi/3,
np.pi, np.pi, np.pi, np.pi/2, np.pi/3,
np.pi, np.pi, np.pi, np.pi/2, np.pi/3]
hamiltonian.generate_quantumCircuit(hyperparams=hyperparams)
print("finshied circuit map.......")
opt_param = hamiltonian.run_QAOA(hyperparams,'COBYLA')
print("finshied obtaining hyperparams....... running circuit once more......")
hamiltonian.generate_quantumCircuit(opt_param)
res = hamiltonian.run_circuit()
print(res.get_counts())