@@ -4,7 +4,6 @@ using Graphs: add_vertex!, vertices
44# Trigger package extension.
55using GraphsFlows: GraphsFlows
66using ITensors: Index, ITensor, contract, noncommoninds, random_itensor
7- using ITensorMPS: MPS
87using ITensorNetworks:
98 _DensityMartrixAlgGraph,
109 _contract_deltas_ignore_leaf_partitions,
@@ -27,38 +26,6 @@ using StableRNGs: StableRNG
2726using TensorOperations: TensorOperations
2827using 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
8350 network = mapreduce (v -> collect (eachtensor (par[v])), vcat, vertices (par))
8451 @test isapprox (contract (tn), contract (network))
8552end
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
15953end
0 commit comments