Skip to content

Commit 5941a90

Browse files
committed
Remove ITensorMPS from tests
1 parent ebeccc5 commit 5941a90

File tree

7 files changed

+0
-286
lines changed

7 files changed

+0
-286
lines changed

test/test_binary_tree_partition.jl

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ using Graphs: add_vertex!, vertices
44
# Trigger package extension.
55
using GraphsFlows: GraphsFlows
66
using ITensors: Index, ITensor, contract, noncommoninds, random_itensor
7-
using ITensorMPS: MPS
87
using ITensorNetworks:
98
_DensityMartrixAlgGraph,
109
_contract_deltas_ignore_leaf_partitions,
@@ -27,38 +26,6 @@ using StableRNGs: StableRNG
2726
using TensorOperations: TensorOperations
2827
using Test: @test, @testset
2928

30-
@testset "test mincut functions on top of MPS" begin
31-
i = Index(2, "i")
32-
j = Index(2, "j")
33-
k = Index(2, "k")
34-
l = Index(2, "l")
35-
m = Index(2, "m")
36-
n = Index(2, "n")
37-
o = Index(2, "o")
38-
p = Index(2, "p")
39-
40-
T = random_itensor(i, j, k, l, m, n, o, p)
41-
M = MPS(T, (i, j, k, l, m, n, o, p); cutoff=1e-5, maxdim=500)
42-
tn = ITensorNetwork(M[:])
43-
for out in [binary_tree_structure(tn), path_graph_structure(tn)]
44-
@test out isa DataGraph
45-
@test is_binary_arborescence(out)
46-
@test length(vertex_data(out).values) == 8
47-
end
48-
out = _mps_partition_inds_order(tn, [o, p, i, j, k, l, m, n])
49-
@test out in [[i, j, k, l, m, n, o, p], [p, o, n, m, l, k, j, i]]
50-
p1, p2 = _mincut_partitions(tn, [k, l], [m, n])
51-
# When MPS bond dimensions are large, the partition will not across internal inds
52-
@test (length(p1) == 0) || (length(p2) == 0)
53-
54-
M = MPS(T, (i, j, k, l, m, n, o, p); cutoff=1e-5, maxdim=2)
55-
tn = ITensorNetwork(M[:])
56-
p1, p2 = _mincut_partitions(tn, [k, l], [m, n])
57-
# When MPS bond dimensions are small, the partition will across internal inds
58-
@test sort(p1) == [1, 2, 3, 4]
59-
@test sort(p2) == [5, 6, 7, 8]
60-
end
61-
6229
@testset "test _binary_tree_partition_inds of a 2D network" begin
6330
N = (3, 3, 3)
6431
linkdim = 2
@@ -83,77 +50,4 @@ end
8350
network = mapreduce(v -> collect(eachtensor(par[v])), vcat, vertices(par))
8451
@test isapprox(contract(tn), contract(network))
8552
end
86-
87-
@testset "test partition with mincut_recursive_bisection alg and approx_itensornetwork" begin
88-
i = Index(2, "i")
89-
j = Index(2, "j")
90-
k = Index(2, "k")
91-
l = Index(2, "l")
92-
m = Index(2, "m")
93-
for dtype in (Float64, Complex{Float64})
94-
T = random_itensor(dtype, i, j, k, l, m)
95-
M = MPS(T, (i, j, k, l, m); cutoff=1e-5, maxdim=5)
96-
network = M[:]
97-
out1 = contract(network...)
98-
tn = ITensorNetwork(network)
99-
inds_btree = binary_tree_structure(tn)
100-
par = _partition(tn, inds_btree; alg="mincut_recursive_bisection")
101-
par = _contract_deltas_ignore_leaf_partitions(par; root=root_vertex(inds_btree))
102-
networks = map(v -> par[v], vertices(par))
103-
network2 = reduce(union, networks)
104-
out2 = contract(network2)
105-
@test isapprox(out1, out2)
106-
# test approx_itensornetwork (here we call `contract` to test the interface)
107-
for structure in [path_graph_structure, binary_tree_structure]
108-
for alg in ["density_matrix", "ttn_svd"]
109-
approx_tn, lognorm = contract(
110-
tn;
111-
alg,
112-
output_structure=structure,
113-
contraction_sequence_kwargs=(; alg="sa_bipartite"),
114-
)
115-
network3 = collect(eachtensor(approx_tn))
116-
out3 = contract(network3...) * exp(lognorm)
117-
i1 = noncommoninds(network...)
118-
i3 = noncommoninds(network3...)
119-
@test (length(i1) == length(i3))
120-
@test isapprox(out1, out3)
121-
end
122-
end
123-
end
124-
end
125-
126-
@testset "test caching in approx_itensornetwork" begin
127-
i = Index(2, "i")
128-
j = Index(2, "j")
129-
k = Index(2, "k")
130-
l = Index(2, "l")
131-
m = Index(2, "m")
132-
T = random_itensor(i, j, k, l, m)
133-
M = MPS(T, (i, j, k, l, m); cutoff=1e-5, maxdim=5)
134-
tn = ITensorNetwork(M[:])
135-
out_tree = path_graph_structure(tn)
136-
input_partition = _partition(tn, out_tree; alg="mincut_recursive_bisection")
137-
underlying_tree = underlying_graph(input_partition)
138-
# Change type of each partition[v] since they will be updated
139-
# with potential data type chage.
140-
p = DataGraph(NamedGraph())
141-
for v in vertices(input_partition)
142-
add_vertex!(p, v)
143-
p[v] = ITensorNetwork{Any}(input_partition[v])
144-
end
145-
alg_graph = _DensityMartrixAlgGraph(p, underlying_tree, root_vertex(out_tree))
146-
path = post_order_dfs_vertices(underlying_tree, root_vertex(out_tree))
147-
for v in path[1:2]
148-
_rem_vertex!(
149-
alg_graph,
150-
v;
151-
cutoff=1e-15,
152-
maxdim=10000,
153-
contraction_sequence_kwargs=(; alg="optimal"),
154-
)
155-
end
156-
# Check that a specific density matrix info has been cached
157-
@test haskey(alg_graph.caches.es_to_pdm, Set([NamedEdge(nothing, path[3])]))
158-
end
15953
end

test/test_opsum_to_ttn.jl

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ using ITensors:
1313
dag,
1414
inds,
1515
removeqns
16-
using ITensorMPS: ITensorMPS
1716
using ITensors.NDTensors: matrix
1817
using ITensorGaussianMPS: ITensorGaussianMPS
1918
using ITensorNetworks: ITensorNetworks, OpSum, ttn, siteinds
@@ -61,26 +60,6 @@ end
6160
# root_vertex = (1, 2)
6261
# println(leaf_vertices(is))
6362

64-
@testset "Svd approach" for root_vertex in leaf_vertices(is)
65-
# get TTN Hamiltonian directly
66-
Hsvd = ttn(H, is; root_vertex, cutoff=1e-10)
67-
# get corresponding MPO Hamiltonian
68-
Hline = ITensorMPS.MPO(replace_vertices(v -> vmap[v], H), sites)
69-
# compare resulting dense Hamiltonians
70-
@disable_warn_order begin
71-
Tttno = prod(Hline)
72-
Tmpo = contract(Hsvd)
73-
end
74-
@test Tttno Tmpo rtol = 1e-6
75-
76-
Hsvd_lr = ttn(Hlr, is; root_vertex, cutoff=1e-10)
77-
Hline_lr = ITensorMPS.MPO(replace_vertices(v -> vmap[v], Hlr), sites)
78-
@disable_warn_order begin
79-
Tttno_lr = prod(Hline_lr)
80-
Tmpo_lr = contract(Hsvd_lr)
81-
end
82-
@test Tttno_lr Tmpo_lr rtol = 1e-6
83-
end
8463
if auto_fermion_enabled
8564
ITensors.enable_auto_fermion()
8665
end
@@ -138,28 +117,6 @@ end
138117

139118
# root_vertex = (1, 2)
140119
# println(leaf_vertices(is))
141-
142-
@testset "Svd approach" for root_vertex in leaf_vertices(is)
143-
# get TTN Hamiltonian directly
144-
Hsvd = ttn(H, is; root_vertex, cutoff=1e-10)
145-
# get corresponding MPO Hamiltonian
146-
Hline = ITensorMPS.MPO(replace_vertices(v -> vmap[v], H), sites)
147-
# compare resulting sparse Hamiltonians
148-
149-
@disable_warn_order begin
150-
Tmpo = prod(Hline)
151-
Tttno = contract(Hsvd)
152-
end
153-
@test Tttno Tmpo rtol = 1e-6
154-
155-
Hsvd_lr = ttn(Hlr, is; root_vertex, cutoff=1e-10)
156-
Hline_lr = ITensorMPS.MPO(replace_vertices(v -> vmap[v], Hlr), sites)
157-
@disable_warn_order begin
158-
Tttno_lr = prod(Hline_lr)
159-
Tmpo_lr = contract(Hsvd_lr)
160-
end
161-
@test Tttno_lr Tmpo_lr rtol = 1e-6
162-
end
163120
end
164121

165122
@testset "OpSum to TTN Fermions" begin
@@ -182,37 +139,6 @@ end
182139
# add combination of longer range interactions
183140
Hlr = copy(H)
184141

185-
@testset "Svd approach" for root_vertex in leaf_vertices(is)
186-
# get TTN Hamiltonian directly
187-
Hsvd = ttn(H, is; root_vertex, cutoff=1e-10)
188-
# get corresponding MPO Hamiltonian
189-
sites = [only(is[v]) for v in reverse(post_order_dfs_vertices(c, root_vertex))]
190-
vmap = Dictionary(reverse(post_order_dfs_vertices(c, root_vertex)), 1:length(sites))
191-
Hline = ITensorMPS.MPO(replace_vertices(v -> vmap[v], H), sites)
192-
# compare resulting sparse Hamiltonians
193-
Hmat_sp = ITensorGaussianMPS.hopping_hamiltonian(replace_vertices(v -> vmap[v], H))
194-
@disable_warn_order begin
195-
Tmpo = prod(Hline)
196-
Tttno = contract(Hsvd)
197-
end
198-
199-
# verify that the norm isn't 0 and thus the same (which would indicate a problem with the autofermion system
200-
@test norm(Tmpo) > 0
201-
@test norm(Tttno) > 0
202-
@test norm(Tmpo) norm(Tttno) rtol = 1e-6
203-
204-
# TODO: fix comparison for fermionic tensors
205-
@test_broken Tmpo Tttno
206-
# In the meantime: matricize tensors and convert to dense Matrix to compare element by element
207-
dTmm = to_matrix(Tmpo)
208-
dTtm = to_matrix(Tttno)
209-
@test any(>(1e-14), dTmm - dTtm)
210-
211-
# also compare with energies obtained from single-particle Hamiltonian
212-
GS_mb, _, _ = eigsolve(dTtm, 1, :SR, eltype(dTtm))
213-
spectrum_sp = eigvals(Hmat_sp)
214-
@test minimum(cumsum(spectrum_sp)) GS_mb[1] atol = 1e-8
215-
end
216142
if !auto_fermion_enabled
217143
ITensors.disable_auto_fermion()
218144
end
@@ -252,28 +178,6 @@ end
252178
Hlr += -4, "Z", (1, 1), "Z", (2, 2)
253179
Hlr += 2.0, "Z", (2, 2), "Z", (3, 2)
254180
Hlr += -1.0, "Z", (1, 2), "Z", (3, 1)
255-
256-
@testset "Svd approach" for root_vertex in leaf_vertices(is)
257-
# get TTN Hamiltonian directly
258-
Hsvd = ttn(H, is_missing_site; root_vertex, cutoff=1e-10)
259-
# get corresponding MPO Hamiltonian
260-
Hline = ITensorMPS.MPO(replace_vertices(v -> vmap[v], H), sites)
261-
262-
# compare resulting sparse Hamiltonians
263-
@disable_warn_order begin
264-
Tmpo = prod(Hline)
265-
Tttno = contract(Hsvd)
266-
end
267-
@test Tttno Tmpo rtol = 1e-6
268-
269-
Hsvd_lr = ttn(Hlr, is_missing_site; root_vertex, cutoff=1e-10)
270-
Hline_lr = ITensorMPS.MPO(replace_vertices(v -> vmap[v], Hlr), sites)
271-
@disable_warn_order begin
272-
Tttno_lr = prod(Hline_lr)
273-
Tmpo_lr = contract(Hsvd_lr)
274-
end
275-
@test Tttno_lr Tmpo_lr rtol = 1e-6
276-
end
277181
end
278182
end
279183
end

test/test_tebd.jl

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
@eval module $(gensym())
22
using Graphs: vertices
33
using ITensors: ITensors
4-
using ITensorMPS: ITensorMPS
54
using ITensorNetworks: ITensorNetwork, cartesian_to_linear, dmrg, expect, siteinds, tebd
65
using ITensorNetworks.ITensorsExtensions: group_terms
76
using ITensorNetworks.ModelHamiltonians: ModelHamiltonians
@@ -20,18 +19,6 @@ ITensors.disable_warn_order()
2019

2120
s = siteinds("S=1/2", g)
2221

23-
#
24-
# DMRG comparison
25-
#
26-
g_dmrg = rename_vertices(v -> cartesian_to_linear(dims)[v], g)
27-
ℋ_dmrg = ModelHamiltonians.ising(g_dmrg; h)
28-
s_dmrg = [only(s[v]) for v in vertices(s)]
29-
H_dmrg = ITensorMPS.MPO(ℋ_dmrg, s_dmrg)
30-
ψ_dmrg_init = ITensorMPS.MPS(s_dmrg, j -> "")
31-
E_dmrg, ψ_dmrg = dmrg(
32-
H_dmrg, ψ_dmrg_init; nsweeps=20, maxdim=[fill(10, 10); 20], cutoff=1e-8, outputlevel=0
33-
)
34-
3522
#
3623
# PEPS TEBD optimization
3724
#
@@ -66,6 +53,5 @@ ITensors.disable_warn_order()
6653
#E2 = expect(ℋ, ψ)
6754
#@show E0, E1, E2, E_dmrg
6855
@test_broken (((abs((E2 - E1) / E2) < 1e-3) && (E1 < E0)) || (E2 < E1 < E0))
69-
@test_broken E2 E_dmrg rtol = 1e-3
7056
end
7157
end

test/test_ttn_contract.jl

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ using ITensorNetworks:
1717
siteinds
1818
using ITensorNetworks.ModelHamiltonians: ModelHamiltonians
1919
using ITensors: prime, replaceinds, replaceprime
20-
using ITensorMPS: ITensorMPS
2120
using LinearAlgebra: norm, normalize
2221
using NamedGraphs.NamedGraphGenerators: named_comb_tree
2322
using StableRNGs: StableRNG
@@ -150,23 +149,4 @@ end
150149
Hpsi = contract(H, psi; alg="fit", nsites=1, nsweeps=10, init=Hpsi_guess)
151150
@test inner(psit, Hpsi) inner(psit, H, psi) rtol = 1e-2
152151
end
153-
154-
@testset "Contract TTN with dangling inds" begin
155-
nbit = 3
156-
sites = siteinds("Qubit", nbit)
157-
158-
# random_mpo does not support linkdims keyword.
159-
M1 = replaceprime(
160-
ITensorMPS.random_mpo(sites) + ITensorMPS.random_mpo(sites), 1 => 2, 0 => 1
161-
)
162-
M2 = ITensorMPS.random_mpo(sites) + ITensorMPS.random_mpo(sites)
163-
M12_ref = contract(M1, M2; alg="naive")
164-
t12_ref = ttn([M12_ref[v] for v in eachindex(M12_ref)])
165-
166-
t1 = ttn([M1[v] for v in eachindex(M1)])
167-
t2 = ttn([M2[v] for v in eachindex(M2)])
168-
169-
# Test with good initial guess
170-
@test contract(t1, t2; alg="fit", init=t12_ref, nsweeps=1) t12_ref rtol = 1e-7
171-
end
172152
end

test/test_ttn_dmrg.jl

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using DataGraphs: edge_data, vertex_data
33
using Dictionaries: Dictionary
44
using Graphs: nv, vertices, uniform_tree
5-
using ITensorMPS: ITensorMPS
65
using ITensorNetworks:
76
ITensorNetworks,
87
OpSum,
@@ -52,16 +51,10 @@ ITensors.disable_auto_fermion()
5251
nsweeps = 10
5352
maxdim = [10, 20, 40, 100]
5453

55-
# Compare to `ITensors.MPO` version of `dmrg`
56-
H_mpo = ITensorMPS.MPO([H[v] for v in 1:nv(H)])
57-
psi_mps = ITensorMPS.MPS([psi[v] for v in 1:nv(psi)])
58-
e2, psi2 = dmrg(H_mpo, psi_mps; nsweeps, maxdim, outputlevel=0)
59-
6054
e, psi = dmrg(
6155
H, psi; nsweeps, maxdim, cutoff, nsites, updater_kwargs=(; krylovdim=3, maxiter=1)
6256
)
6357
@test inner(psi', H, psi) e
64-
@test inner(psi', H, psi) inner(psi2', H_mpo, psi2)
6558

6659
# Alias for `ITensorNetworks.dmrg`
6760
e, psi = eigsolve(
@@ -235,17 +228,6 @@ end
235228
H, psi; nsweeps, maxdim, cutoff, nsites, updater_kwargs=(; krylovdim=3, maxiter=1)
236229
)
237230

238-
# Compare to `ITensors.MPO` version of `dmrg`
239-
linear_order = [4, 1, 2, 5, 3, 6]
240-
vmap = Dictionary(collect(vertices(s))[linear_order], 1:length(linear_order))
241-
sline = only.(collect(vertex_data(s)))[linear_order]
242-
Hline = ITensorMPS.MPO(replace_vertices(v -> vmap[v], os), sline)
243-
rng = StableRNG(1234)
244-
psiline = ITensorMPS.random_mps(rng, sline, i -> isodd(i) ? "Up" : "Dn"; linkdims=20)
245-
e2, psi2 = dmrg(Hline, psiline; nsweeps, maxdim, cutoff, outputlevel=0)
246-
247-
@test inner(psi', H, psi) inner(psi2', Hline, psi2) atol = 1e-5
248-
249231
if !auto_fermion_enabled
250232
ITensors.disable_auto_fermion()
251233
end
@@ -273,14 +255,6 @@ end
273255
vmap = Dictionary(collect(vertices(s))[linear_order], 1:length(linear_order))
274256
sline = only.(collect(vertex_data(s)))[linear_order]
275257

276-
# get MPS / MPO with JW string result
277-
ITensors.disable_auto_fermion()
278-
Hline = ITensorMPS.MPO(replace_vertices(v -> vmap[v], os), sline)
279-
rng = StableRNG(1234)
280-
psiline = ITensorMPS.random_mps(rng, sline, i -> isodd(i) ? "Up" : "Dn"; linkdims=20)
281-
e_jw, psi_jw = dmrg(Hline, psiline; nsweeps, maxdim, cutoff, outputlevel=0)
282-
ITensors.enable_auto_fermion()
283-
284258
# now get auto-fermion results
285259
H = ttn(os, s)
286260
# make init_state
@@ -294,16 +268,6 @@ end
294268
H, psi; nsweeps, maxdim, cutoff, nsites, updater_kwargs=(; krylovdim=3, maxiter=1)
295269
)
296270

297-
# Compare to `ITensors.MPO` version of `dmrg`
298-
Hline = ITensorMPS.MPO(replace_vertices(v -> vmap[v], os), sline)
299-
rng = StableRNG(1234)
300-
psiline = ITensorMPS.random_mps(rng, sline, i -> isodd(i) ? "Up" : "Dn"; linkdims=20)
301-
e2, psi2 = dmrg(Hline, psiline; nsweeps, maxdim, cutoff, outputlevel=0)
302-
303-
@test inner(psi', H, psi) inner(psi2', Hline, psi2) atol = 1e-5
304-
@test e2 e_jw atol = 1e-5
305-
@test inner(psi2', Hline, psi2) e_jw atol = 1e-5
306-
307271
if !auto_fermion_enabled
308272
ITensors.disable_auto_fermion()
309273
end

0 commit comments

Comments
 (0)