@@ -13,6 +13,7 @@ using ITensors:
1313 dag,
1414 inds,
1515 removeqns
16+ using ITensorMPS: ITensorMPS
1617using ITensors. NDTensors: matrix
1718using ITensorNetworks: ITensorNetworks, OpSum, ttn, siteinds
1819using ITensorNetworks. ITensorsExtensions: replace_vertices
5960 # root_vertex = (1, 2)
6061 # println(leaf_vertices(is))
6162
63+ @testset " Svd approach" for root_vertex in leaf_vertices (is)
64+ # get TTN Hamiltonian directly
65+ Hsvd = ttn (H, is; root_vertex, cutoff= 1e-10 )
66+ # get corresponding MPO Hamiltonian
67+ Hline = ITensorMPS. MPO (replace_vertices (v -> vmap[v], H), sites)
68+ # compare resulting dense Hamiltonians
69+ @disable_warn_order begin
70+ Tttno = prod (Hline)
71+ Tmpo = contract (Hsvd)
72+ end
73+ @test Tttno ≈ Tmpo rtol = 1e-6
74+
75+ Hsvd_lr = ttn (Hlr, is; root_vertex, cutoff= 1e-10 )
76+ Hline_lr = ITensorMPS. MPO (replace_vertices (v -> vmap[v], Hlr), sites)
77+ @disable_warn_order begin
78+ Tttno_lr = prod (Hline_lr)
79+ Tmpo_lr = contract (Hsvd_lr)
80+ end
81+ @test Tttno_lr ≈ Tmpo_lr rtol = 1e-6
82+ end
6283 if auto_fermion_enabled
6384 ITensors. enable_auto_fermion ()
6485 end
116137
117138 # root_vertex = (1, 2)
118139 # println(leaf_vertices(is))
140+
141+ @testset " Svd approach" for root_vertex in leaf_vertices (is)
142+ # get TTN Hamiltonian directly
143+ Hsvd = ttn (H, is; root_vertex, cutoff= 1e-10 )
144+ # get corresponding MPO Hamiltonian
145+ Hline = ITensorMPS. MPO (replace_vertices (v -> vmap[v], H), sites)
146+ # compare resulting sparse Hamiltonians
147+
148+ @disable_warn_order begin
149+ Tmpo = prod (Hline)
150+ Tttno = contract (Hsvd)
151+ end
152+ @test Tttno ≈ Tmpo rtol = 1e-6
153+
154+ Hsvd_lr = ttn (Hlr, is; root_vertex, cutoff= 1e-10 )
155+ Hline_lr = ITensorMPS. MPO (replace_vertices (v -> vmap[v], Hlr), sites)
156+ @disable_warn_order begin
157+ Tttno_lr = prod (Hline_lr)
158+ Tmpo_lr = contract (Hsvd_lr)
159+ end
160+ @test Tttno_lr ≈ Tmpo_lr rtol = 1e-6
161+ end
119162 end
120163
121164 @testset " OpSum to TTN Fermions" begin
138181 # add combination of longer range interactions
139182 Hlr = copy (H)
140183
184+ @testset " Svd approach" for root_vertex in leaf_vertices (is)
185+ # get TTN Hamiltonian directly
186+ Hsvd = ttn (H, is; root_vertex, cutoff= 1e-10 )
187+ # get corresponding MPO Hamiltonian
188+ sites = [only (is[v]) for v in reverse (post_order_dfs_vertices (c, root_vertex))]
189+ vmap = Dictionary (reverse (post_order_dfs_vertices (c, root_vertex)), 1 : length (sites))
190+ Hline = ITensorMPS. MPO (replace_vertices (v -> vmap[v], H), sites)
191+ @disable_warn_order begin
192+ Tmpo = prod (Hline)
193+ Tttno = contract (Hsvd)
194+ end
195+
196+ # verify that the norm isn't 0 and thus the same (which would indicate a problem with the autofermion system
197+ @test norm (Tmpo) > 0
198+ @test norm (Tttno) > 0
199+ @test norm (Tmpo) ≈ norm (Tttno) rtol = 1e-6
200+
201+ # TODO : fix comparison for fermionic tensors
202+ @test_broken Tmpo ≈ Tttno
203+ # In the meantime: matricize tensors and convert to dense Matrix to compare element by element
204+ dTmm = to_matrix (Tmpo)
205+ dTtm = to_matrix (Tttno)
206+ @test any (> (1e-14 ), dTmm - dTtm)
207+ end
141208 if ! auto_fermion_enabled
142209 ITensors. disable_auto_fermion ()
143210 end
177244 Hlr += - 4 , " Z" , (1 , 1 ), " Z" , (2 , 2 )
178245 Hlr += 2.0 , " Z" , (2 , 2 ), " Z" , (3 , 2 )
179246 Hlr += - 1.0 , " Z" , (1 , 2 ), " Z" , (3 , 1 )
247+
248+ @testset " Svd approach" for root_vertex in leaf_vertices (is)
249+ # get TTN Hamiltonian directly
250+ Hsvd = ttn (H, is_missing_site; root_vertex, cutoff= 1e-10 )
251+ # get corresponding MPO Hamiltonian
252+ Hline = ITensorMPS. MPO (replace_vertices (v -> vmap[v], H), sites)
253+
254+ # compare resulting sparse Hamiltonians
255+ @disable_warn_order begin
256+ Tmpo = prod (Hline)
257+ Tttno = contract (Hsvd)
258+ end
259+ @test Tttno ≈ Tmpo rtol = 1e-6
260+
261+ Hsvd_lr = ttn (Hlr, is_missing_site; root_vertex, cutoff= 1e-10 )
262+ Hline_lr = ITensorMPS. MPO (replace_vertices (v -> vmap[v], Hlr), sites)
263+ @disable_warn_order begin
264+ Tttno_lr = prod (Hline_lr)
265+ Tmpo_lr = contract (Hsvd_lr)
266+ end
267+ @test Tttno_lr ≈ Tmpo_lr rtol = 1e-6
268+ end
180269 end
181270end
182271end
0 commit comments