-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqaTest.py
183 lines (137 loc) · 5.31 KB
/
sqaTest.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# Copyright 2018-2022 SecondQuantizationAlgebra Developers. All Rights Reserved.
#
# Licensed under the GNU General Public License v3.0;
# you may not use this file except in compliance with the License.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Authors: Alexander Yu. Sokolov <[email protected]>
# Koushik Chatterjee <[email protected]>
# Ilia Mazin <[email protected]>
# Carlos E. V. de Moura <[email protected]>
#
import sqa_plus as sqa
import time
# Define operator types
tg_c = sqa.options.core_type
tg_a = sqa.options.active_type
tg_v = sqa.options.virtual_type
tg_g = tg_c + tg_a + tg_v
# Define indices
dummy = True
# Test 1: Double commutator evaluation for a first order contribution to the M_00 block of the effective Hamiltonian matrix
print("\n# Starting Test 1:\n")
startTime = time.time()
# Create left hand side operator list
i = sqa.index('I', [tg_c])
x = sqa.index('X', [tg_a])
l_op = [sqa.creOp(i), sqa.desOp(x)]
# Create right hand side operator list
j = sqa.index('J', [tg_c])
y = sqa.index('Y', [tg_a])
r_op = [sqa.creOp(y), sqa.desOp(j)]
# Define order of the effective Hamiltonian
effH = []
effH = sqa.Heff(1)
# Define terms from operator lists
term1 = sqa.term(1.0, [], r_op)
term2 = sqa.term(1.0, [], l_op)
print("> First Commutator...")
term3 = sqa.commutator(effH, term1)
print("> Second Commutator...")
term4 = sqa.commutator(term2, term3)
term5 = sqa.matrixBlock(term4)
test1_string_output = ''
for t in term5:
test1_string_output += str(t) + '\n'
test1_correct_answer = " ( -1.00000) v(I,Y,J,X) \n" + \
" ( 1.00000) kdelta(X,Y) v(I,x,J,y) rdm(x,y) \n" + \
" ( 1.00000) v(I,Y,J,x) cre(x) des(X) \n" + \
" ( 1.00000) v(I,x,J,X) cre(Y) des(x) \n" + \
" ( -1.00000) kdelta(X,Y) v(I,x,J,y) cre(y) des(x) \n" + \
" ( -1.00000) v(I,x,J,y) rdm(x,y) cre(Y) des(X) \n" + \
" ( -1.00000) v(I,x,J,y) cre(Y) cre(y) des(X) des(x) \n"
print("\n> Test 1 output:\n")
print(test1_string_output)
if test1_string_output == test1_correct_answer:
print(">> Test 1 passed!\n")
else:
print(">> Test 1 failed!\n")
print("({:.3f} seconds) \n".format(time.time() - startTime))
# Test 2: Construction of the overlap matrix for an M_01 sector of the effective Hamiltonian matrix
print("\n# Starting Test 2:\n")
startTime = time.time()
# Create left hand side operator list
i = sqa.index('I', [tg_c])
x = sqa.index('X', [tg_a])
l_op = [sqa.creOp(i), sqa.desOp(x)]
# Create right hand side operator list
j = sqa.index('J', [tg_c])
y = sqa.index('Y', [tg_a])
z = sqa.index('Z', [tg_a])
u = sqa.index('U', [tg_a])
r_op = [sqa.creOp(z), sqa.creOp(u), sqa.desOp(y), sqa.desOp(j)]
# Define terms from operator lists
term1 = sqa.term(1.0, [], l_op)
term2 = sqa.term(1.0, [], r_op)
# Perform commutator
term3 = sqa.commutator(term1, term2)
term4 = sqa.matrixBlock(term3)
test2_string_output = ''
for t in term4:
test2_string_output += str(t) + '\n'
test2_correct_answer = " ( -1.00000) kdelta(I,J) kdelta(U,X) cre(Z) des(Y) \n" + \
" ( 1.00000) kdelta(I,J) kdelta(X,Z) cre(U) des(Y) \n" + \
" ( -1.00000) kdelta(I,J) cre(U) cre(Z) des(X) des(Y) \n"
print("\n> Test 2 output:\n")
print(test2_string_output)
if test2_string_output == test2_correct_answer:
print(">> Test 2 passed!\n")
else:
print(">> Test 2 failed!\n")
print("({:.3f} seconds) \n".format(time.time() - startTime))
# Test 3: Multiply perturbation operator by single excitation operators from either side
print("\n# Starting Test 3:\n")
startTime = time.time()
# Create left hand side operator list
x = sqa.index('X', [tg_a])
a = sqa.index('A', [tg_v])
l_op = [sqa.creOp(x), sqa.desOp(a)]
# Create right hand side operator list
j = sqa.index('J', [tg_c])
b = sqa.index('B', [tg_v])
r_op = [sqa.creOp(b), sqa.desOp(j)]
# Define terms from operator lists
term1 = sqa.term(1.0, [], r_op)
term2 = sqa.term(1.0, [], l_op)
# Create empty lists to store products
term3 = []
term4 = []
# Get perturbation operator
V = sqa.getV()
# Multiply every term in V by the operators in term2, store as term3
for v in V:
term3.append(sqa.multiplyTerms(term2, v))
# Multiply every product stored in term3 by the operators in term1
for t in term3:
term4.append(sqa.multiplyTerms(t, term1))
term5 = []
term5 = sqa.matrixBlock(term4)
test3_string_output = ''
for t in term5:
test3_string_output += str(t) + '\n'
test3_correct_answer = " ( -1.00000) v(x,B,J,A) cre(X) des(x) \n" + \
" ( -1.00000) h(J,x) kdelta(A,B) cre(X) des(x) \n" + \
" ( 1.00000) kdelta(A,B) v(i,x,J,i) cre(X) des(x) \n" + \
" ( 0.50000) kdelta(A,B) v(x,y,J,z) cre(X) cre(z) des(x) des(y) \n"
print("\n> Test 3 output:\n")
print(test3_string_output)
if test3_string_output == test3_correct_answer:
print(">> Test 3 passed!\n")
else:
print(">> Test 3 failed!\n")
print("({:.3f} seconds) \n".format(time.time() - startTime))