-
Notifications
You must be signed in to change notification settings - Fork 1
/
vqe.py
60 lines (45 loc) · 1.5 KB
/
vqe.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
#from FnLibrary import *
from qaoaLibrary import *
import sys
import time
start_time = time.time()
# Read in parameters
n = int(sys.argv[1])
N = 1<<n
alpha = float(sys.argv[2])
Xcoeff = float(sys.argv[3])
Zcoeff = float(sys.argv[4])
p = int(sys.argv[5])
Tmax = 10.0
# Initialize state and hamiltonian
psi, H = initialize(n)
# Hamiltonian Input
# OPTION 1: Generate long-range power-law Hamiltonian
qc.lr(byref(H), c_double(Zcoeff), c_double(Xcoeff), c_double(alpha))
#qc.lrPer(byref(H), c_double(Zcoeff), c_double(Xcoeff), c_double(alpha))
H.zc = (c_double * n)(*([-0.00]*n))
# OPTION 2: Read in actual Hamiltonian parameters
#Jij = np.loadtxt('expJ-n%d.dat'%n)
#hamGen(H, Jij, Xcoeff*np.ones(n), np.zeros(n))
#Zcoeff = np.mean([Jij[i,i+1] for i in range(n-1)])
Neigs = 2
val, vec = ground(H, Neigs)
######################################################################
# This part focuses on optimizing and comparing with the true ground state of the Hamiltonian
bgOpt, Eopt = optQAOA(psi,H, p, 'BFGS')
printOut(psi, val, vec, bgOpt, Eopt)
trials = 1
EFull = np.inf
bgFull = []
#for i in range(trials):
# bgCur, ECur= optQAOAgreedy(psi, H, p)#100, 2.0, 2000)
# bgFull = bgFull if ECur>EFull else bgCur
# EFull = EFull if ECur>EFull else ECur
#printOut(psi, val, vec, bgFull, EFull)
##### ENTANGLEMENT ENTROPY ##########
# True Ground state
#symGS = z2symmetrize(vec[:,0])
#print entent(symGS,1)
#print(entent(symGS,n/2))
# Print execution time
#print time.time() - start_time