-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdynamics.py
More file actions
85 lines (56 loc) · 1.81 KB
/
Copy pathdynamics.py
File metadata and controls
85 lines (56 loc) · 1.81 KB
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
77
78
79
80
81
82
83
"""
Created on Fri Oct 25 14:46:36 2019
@author: yuqinchen
"""
import numpy as np
from qutip import *
from numpy import *
class SatSearchEfficient():
def __init__(self, n_qubit, T, Mcut,HB,HP,psi0,psif):
self.n_qubit = n_qubit
self.N = 2**self.n_qubit
self.T = T
self.Mcut = Mcut
self.psi0 =psi0
self.psif =psif
self.H1=Qobj(HB)
self.H2=Qobj(HP)
def H1_coef(self, t, args):
s = t/self.T
j = 1
for b in args:
s += args[b] * np.sin(j*np.pi*t/self.T)
j += 1
return 1-s
def H2_coef(self, t, args):
s = t/self.T
j = 1
for b in args:
s += args[b] * np.sin(j*np.pi*t/self.T)
j += 1
return s
def evolution(self, bstate):
"""
bstate: 1D array
Return energy expectation and fidelity
"""
args = {}
for i, b in enumerate(list(bstate)):
args['b{}'.format(i+1)] = b
dt=0.5
NL=self.T/dt
t = np.linspace(dt, self.T-dt, int(NL))
H = [[self.H1, self.H1_coef], [self.H2, self.H2_coef]]
output = mesolve(H, self.psi0, t, args=args)
states = output.states[-1]
c= (self.psif.dag()) * states ####overlap
fidelity=np.abs(c[0,0])**2
x=states.dag()*self.H2*states ###energy
energy=x[0,0]
return energy, fidelity
def fidelity(self, args):
H = [[self.H1, self.H1_coef], [self.H2, self.H2_coef]]
t = np.linspace(0, self.T, 100)
output = mesolve(H, self.psi0, t, e_ops=self.obs, args=args)
fidelity = output.expect[0][-1]
return fidelity