@@ -3,7 +3,7 @@ using ITensorMPS
33using ITensors
44using PyCall
55
6- function get_coefficients (N:: Int ):: Tuple{Array{Float64, 2}, Array{Float64, 8}}
6+ function get_coefficients (N:: Int ):: Tuple{Array{Float64,2},Array{Float64,8}}
77 py """
88 import numpy as np
99
1919
2020function electronic_structure (
2121 N:: Int ,
22- one_electron_coeffs:: Array{Float64, 2} ,
23- two_electron_coeffs:: Array{Float64, 8} ;
24- useITensorsAlg:: Bool = false
22+ one_electron_coeffs:: Array{Float64,2} ,
23+ two_electron_coeffs:: Array{Float64,8} ;
24+ useITensorsAlg:: Bool = false ,
2525):: MPO
26-
2726 os = OpSum {Float64} ()
2827 @time " \t Constructing OpSum" let
2928 for a in 1 : N
@@ -52,7 +51,16 @@ function electronic_structure(
5251 s_m = s_l
5352 (s_m, m) <= (s_k, k) && continue
5453
55- value = two_electron_coeffs[j, (s_j == " up" ) + 1 , l, (s_l == " up" ) + 1 , m, (s_m == " up" ) + 1 , k, (s_k == " up" ) + 1 ]
54+ value = two_electron_coeffs[
55+ j,
56+ (s_j == " up" ) + 1 ,
57+ l,
58+ (s_l == " up" ) + 1 ,
59+ m,
60+ (s_m == " up" ) + 1 ,
61+ k,
62+ (s_k == " up" ) + 1 ,
63+ ]
5664 os .+ = value, " Cdag$s_j " , j, " Cdag$s_l " , l, " C$s_m " , m, " C$s_k " , k
5765 os .+ = conj (value), " Cdag$s_k " , k, " Cdag$s_m " , m, " C$s_l " , l, " C$s_j " , j
5866 end
@@ -69,7 +77,39 @@ function electronic_structure(
6977 if useITensorsAlg
7078 return @time " \t Construcing MPO" MPO (os, sites)
7179 else
72- operatorNames = [[
80+ operatorNames = [
81+ [
82+ " I" ,
83+ " Cdn" ,
84+ " Cup" ,
85+ " Cdagdn" ,
86+ " Cdagup" ,
87+ " Ndn" ,
88+ " Nup" ,
89+ " Cup * Cdn" ,
90+ " Cup * Cdagdn" ,
91+ " Cup * Ndn" ,
92+ " Cdagup * Cdn" ,
93+ " Cdagup * Cdagdn" ,
94+ " Cdagup * Ndn" ,
95+ " Nup * Cdn" ,
96+ " Nup * Cdagdn" ,
97+ " Nup * Ndn" ,
98+ ] for _ in 1 : N
99+ ]
100+
101+ op_cache_vec = to_OpCacheVec (sites, operatorNames)
102+ return @time " \t Construcing MPO" MPO_new (os, sites; basis_op_cache_vec= op_cache_vec)
103+ end
104+ end
105+
106+ function electronic_structure_OpIDSum (
107+ N:: Int , one_electron_coeffs:: Array{Float64,2} , two_electron_coeffs:: Array{Float64,8}
108+ ):: MPO
109+ sites = siteinds (" Electron" , N; conserve_qns= true )
110+
111+ operatorNames = [
112+ [
73113 " I" ,
74114 " Cdn" ,
75115 " Cup" ,
@@ -86,38 +126,8 @@ function electronic_structure(
86126 " Nup * Cdn" ,
87127 " Nup * Cdagdn" ,
88128 " Nup * Ndn" ,
89- ] for _ in 1 : N]
90-
91- op_cache_vec = to_OpCacheVec (sites, operatorNames)
92- return @time " \t Construcing MPO" MPO_new (os, sites; basis_op_cache_vec= op_cache_vec)
93- end
94- end
95-
96- function electronic_structure_OpIDSum (
97- N:: Int ,
98- one_electron_coeffs:: Array{Float64, 2} ,
99- two_electron_coeffs:: Array{Float64, 8}
100- ):: MPO
101- sites = siteinds (" Electron" , N; conserve_qns= true )
102-
103- operatorNames = [[
104- " I" ,
105- " Cdn" ,
106- " Cup" ,
107- " Cdagdn" ,
108- " Cdagup" ,
109- " Ndn" ,
110- " Nup" ,
111- " Cup * Cdn" ,
112- " Cup * Cdagdn" ,
113- " Cup * Ndn" ,
114- " Cdagup * Cdn" ,
115- " Cdagup * Cdagdn" ,
116- " Cdagup * Ndn" ,
117- " Nup * Cdn" ,
118- " Nup * Cdagdn" ,
119- " Nup * Ndn" ,
120- ] for _ in 1 : N]
129+ ] for _ in 1 : N
130+ ]
121131
122132 op_cache_vec = to_OpCacheVec (sites, operatorNames)
123133
@@ -128,7 +138,7 @@ function electronic_structure_OpIDSum(
128138 opCdag (k:: Int , spin:: Bool ) = OpID {UInt8} (4 + spin, k)
129139 opN (k:: Int , spin:: Bool ) = OpID {UInt8} (6 + spin, k)
130140
131- os = OpIDSum {4, Float64, UInt8} (2 * N^ 4 , op_cache_vec)
141+ os = OpIDSum {4,Float64,UInt8} (2 * N^ 4 , op_cache_vec)
132142 @time " \t Constructing OpIDSum" let
133143 for a in 1 : N
134144 for b in a: N
@@ -169,16 +179,16 @@ function electronic_structure_OpIDSum(
169179 end
170180 end
171181
172- return @time " \t Constructing MPO" MPO_new (
173- os, sites; basis_op_cache_vec= op_cache_vec
174- )
182+ return @time " \t Constructing MPO" MPO_new (os, sites; basis_op_cache_vec= op_cache_vec)
175183end
176184
177185let
178186 for N in [10 ]
179187 println (" Constructing the electronic structure MPO for $N sites using ITensorMPS" )
180188 one_electron_coeffs, two_electron_coeffs = get_coefficients (N)
181- @time " Total construction time" mpo = electronic_structure (N, one_electron_coeffs, two_electron_coeffs; useITensorsAlg= true )
189+ @time " Total construction time" mpo = electronic_structure (
190+ N, one_electron_coeffs, two_electron_coeffs; useITensorsAlg= true
191+ )
182192 println (" The maximum bond dimension is $(maxlinkdim (mpo)) " )
183193 println (" The sparsity is $(ITensorMPOConstruction. sparsity (mpo)) " )
184194 println ()
187197
188198let
189199 for N in [10 ]
190- println (" Constructing the electronic structure MPO for $N sites using ITensorMPOConstruction" )
200+ println (
201+ " Constructing the electronic structure MPO for $N sites using ITensorMPOConstruction"
202+ )
191203 one_electron_coeffs, two_electron_coeffs = get_coefficients (N)
192- @time " Total construction time" mpo = electronic_structure_OpIDSum (N, one_electron_coeffs, two_electron_coeffs)
204+ @time " Total construction time" mpo = electronic_structure_OpIDSum (
205+ N, one_electron_coeffs, two_electron_coeffs
206+ )
193207 println (" The maximum bond dimension is $(maxlinkdim (mpo)) " )
194208 println (" The sparsity is $(ITensorMPOConstruction. sparsity (mpo)) " )
195209 # @time "splitblocks" mpo = ITensors.splitblocks(linkinds, mpo)
0 commit comments