forked from turleya/Heisenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
threespins.py
169 lines (132 loc) · 3.74 KB
/
threespins.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import scipy as sp
import numpy as np
#Pauli matrices
x = np.matrix([[0,1],[1,0]])
y = np.matrix([[0, -1j], [1j,0]])
z = np.matrix([[1,0], [0,-1]])
#Spin up and down
Up = np.matrix([[1],[0]])
Down = np.matrix([[0], [1]])
#Spin operators
sx = 1./2*x
sy = 1./2*y
sz = 1./2*z
splus = np.matrix([[0,1],[0,0]])
sminus = np.matrix([[0,0],[1,0]])
#Identity matrix
I = np.identity(2)
ZeroMat = np.matrix([[0, 0], [0, 0]])
#Tensor products
#Sz
sz1 = np.tensordot(sz, I, axes=0)
S_1z = np.tensordot(sz1, I, axes=0)
sz2 = np.tensordot(I, sz, axes=0)
S_2z = np.tensordot(sz2, I, axes=0)
sz3 = np.tensordot(I, I, axes=0)
S_3z = np.tensordot(sz3, sz, axes=0)
#Sx
sx1 = np.tensordot(sx, I, axes=0)
S_1x = np.tensordot(sx1, I, axes=0)
sx2 = np.tensordot(I, sx, axes=0)
S_2x = np.tensordot(sx2, I, axes=0)
sx3 = np.tensordot(I, I, axes=0)
S_3x = np.tensordot(sx3, sx, axes=0)
#Sy
sy1 = np.tensordot(sy, I, axes=0)
S_1y = np.tensordot(sy1, I, axes=0)
sy2 = np.tensordot(I, sy, axes=0)
S_2y = np.tensordot(sy2, I, axes=0)
sy3 = np.tensordot(I, I, axes=0)
S_3y = np.tensordot(sy3, sy, axes=0)
"""
def main(particles):
l = [[0] for i in range(0, 2**particles)]
print(l)
#for i in range(0, particles):
main(3)
"""
def createMatrix(sign, index, particles):
if sign == "plus":
sign = splus
else:
sign = sminus
l = []
mat = np.array(l, ndmin=particles)
for i in range(0, particles):
l.append(ZeroMat)
np.append(mat, l)
print(mat)
def particleInit(particles):
a = [[0] for i in range(0,1<<particles)]
for i in range(0, 1<<particles):
arr = []
for j in range(0, particles):
if(i & (1<<j)):
arr.append(Up)
else:
arr.append(Down)
a[i] = arr
return a
def normaliseMatrices(list):
mats = []
for element in list:
l = []
for x in range(0, len(element)):
if element[x][0] == [1]:
l.append([1])
l.append([0])
else:
l.append([0])
l.append([1])
mat = np.matrix(l)
mats.append(mat)
return mats
#Defining basis for 3 particles
def main(particles):
parts = particleInit(particles)
for part in parts:
part.reverse()
parts.reverse()
main(2)
print("-------")
main(3)
#print(splus)
#print(sminus)
createMatrix("plus", 1, 2)
'''
def _init_(particles,J_xy,J_zz,counts):
#length of matrix
self.J_xy = J_xy #strength of flip-flop term
self.J_zz = J_zz #strength of Ising interaction
self.counts = counts #number of times the code will sweep through states
parts = particleInit(particles)
#Forming matrix containing each part of basis
self.B = np.vstack(part in parts.reshape((3,1<<particles)))
print self.B
l = 0.0
E = 0.0
E_sq = 0.0
for l in range(self.counts):
l += 1
for i in range(0,particles):
for j in range(0,1<<particles):
s = self.B[i,j]
#trying to define all operators to act on basis B
Z_i*Up = (1./2)*Up
Z_i*Down = (1./2)*Down
Plus_i*Up = 0
Plus_i*Down = (1./2)*Up
Minus_i*Up = (1./2)*Down
Minus_i*Down = 0
#Hamiltonian
H = J_zz*Z_i*Z_(i+1)*self.B + J_xy*Plus_i*Minus_(i+1)*self.B + J_xy*Minus_i*Plus_(i+1)*self.B
#How to turn this into the Hamiltonian matrix?
return H
print H
'''
"""
#Hamiltonian
H = S_1x*S_2x + S_1y*S_2y + S_1z*S_2z + S_2x*S_3x + S_2y*S_3y + S_2z*S_3z
print H
for j in range(
"""