@@ -5,69 +5,93 @@ using ITensors
55using TensorKit
66
77@testset " ITensor" begin
8- for T in [ComplexF64,ComplexF64, Float64]
9- for tag in [missing , " Link" ," Site,c=2,n=1" ]
10- for plev in Iterators. product (0 : 2 ,0 : 4 )
11- plev[1 ] == plev[2 ] && continue
8+ @testset " Conversion ITensor <-> TensorMap" begin
9+ for T in [ComplexF16,ComplexF64, Float64]
10+ for tag in [missing , " Link" ," Site,c=2,n=1" ]
11+ for plev in Iterators. product (0 : 2 ,0 : 4 )
12+ plev[1 ] == plev[2 ] && continue
1213
13- tags = ismissing (tag) ? missing : [tag, tag]
14- if ismissing (tag)
15- i = Index (10 ;dir= ITensors. Out)
16- iqn = ITensors. combineblocks (Index ([QN ((" N" ,2 ))=> 5 , QN (" N" ,0 )=> 5 ]))[1 ]
17- iqn2 = ITensors. combineblocks (Index ([QN ((" N" ,2 ))=> 3 , QN ((" N" ,0 ),(" P" ,3 ))=> 7 ]))[1 ]
18- # # This guarantees consistent sorting of the blocks for the comparison
19- # # Here, we test combining blocks with the same QN:
20- iqn3 = Index ([QN (" Sz" ,- 1 )=> 2 , QN (" Sz" ,1 )=> 14 ,QN (" Sz" ,- 1 )=> 4 ])
21- else
22- i = Index (10 ;dir= ITensors. Out,tags= tag)
23- iqn = ITensors. combineblocks (Index ([QN ((" N" ,2 ))=> 5 , QN (" N" ,0 )=> 5 ];tags= tag))[1 ]
24- iqn2 = ITensors. combineblocks (Index ([QN ((" N" ,2 ))=> 3 , QN ((" N" ,0 ),(" P" ,3 ))=> 7 ];tags= tag))[1 ]
25- iqn3 = Index ([QN (" Sz" ,- 1 )=> 2 , QN (" Sz" ,1 )=> 14 ,QN (" Sz" ,- 1 )=> 4 ]; tags= tag)
26- end
14+ tags = ismissing (tag) ? missing : [tag, tag]
15+ if ismissing (tag)
16+ i = Index (10 ;dir= ITensors. Out)
17+ iqn = ITensors. combineblocks (Index ([QN ((" N" ,2 , 4 ))=> 5 , QN (" N" ,0 , 4 )=> 5 ]))[1 ]
18+ iqn2 = ITensors. combineblocks (Index ([QN ((" N" ,2 ))=> 3 , QN ((" N" ,0 ),(" P" ,3 ))=> 7 ]))[1 ]
19+ # # This guarantees consistent sorting of the blocks for the comparison
20+ # # Here, we test combining blocks with the same QN:
21+ iqn3 = Index ([QN (" Sz" ,- 1 )=> 2 , QN (" Sz" ,1 )=> 14 ,QN (" Sz" ,- 1 )=> 4 ])
22+ else
23+ i = Index (10 ;dir= ITensors. Out,tags= tag)
24+ iqn = ITensors. combineblocks (Index ([QN ((" N" ,2 ))=> 5 , QN (" N" ,0 )=> 5 ];tags= tag))[1 ]
25+ iqn2 = ITensors. combineblocks (Index ([QN ((" N" ,2 ))=> 3 , QN ((" N" ,0 ),(" P" ,3 ))=> 7 ];tags= tag))[1 ]
26+ iqn3 = Index ([QN (" Sz" ,- 1 )=> 2 , QN (" Sz" ,1 )=> 14 ,QN (" Sz" ,- 1 )=> 4 ]; tags= tag)
27+ end
2728
28- i_p1 = prime (i, plev[1 ])
29- iqn_p1 = prime (iqn, plev[1 ])
30- iqn2_p1 = prime (iqn2, plev[1 ])
31- iqn3_p1 = prime (iqn3, plev[1 ])
29+ i_p1 = prime (i, plev[1 ])
30+ iqn_p1 = prime (iqn, plev[1 ])
31+ iqn2_p1 = prime (iqn2, plev[1 ])
32+ iqn3_p1 = prime (iqn3, plev[1 ])
3233
33- i_p2 = dag (prime (i, plev[2 ]))
34- iqn_p2 = dag (prime (iqn, plev[2 ]))
35- iqn2_p2 = dag (prime (iqn2, plev[2 ]))
36- iqn3_p2 = dag (prime (iqn3, plev[2 ]))
34+ i_p2 = dag (prime (i, plev[2 ]))
35+ iqn_p2 = dag (prime (iqn, plev[2 ]))
36+ iqn2_p2 = dag (prime (iqn2, plev[2 ]))
37+ iqn3_p2 = dag (prime (iqn3, plev[2 ]))
3738
38- A = random_itensor (T,i_p1, i_p2)
39- B = random_itensor (T,iqn_p1, iqn_p2)
40- C = random_itensor (T,iqn2_p1, iqn2_p2)
41- D = random_itensor (T,iqn3_p1, iqn3_p2)
39+ A = random_itensor (T,i_p1, i_p2)
40+ B = random_itensor (T,iqn_p1, iqn_p2)
41+ C = random_itensor (T,iqn2_p1, iqn2_p2)
42+ D = random_itensor (T,iqn3_p1, iqn3_p2)
4243
43- x = TensorMap (A)
44- y = TensorMap (B)
45- z = TensorMap (C)
46- w = TensorMap (D)
44+ x = TensorMap (A)
45+ y = TensorMap (B)
46+ z = TensorMap (C)
47+ w = TensorMap (D)
4748
48- if ismissing (tag)
49- A2 = ITensor (x;ids= ITensors. id .(inds (A)),plevs= plev,qn_names= [" N" ," P" ])
50- B2 = ITensor (y;ids= ITensors. id .(inds (B)),plevs= plev,qn_names= [" N" ])
51- C2 = ITensor (z;ids= ITensors. id .(inds (C)),plevs= plev,qn_names= [" N" ," P" ])
52- else
53- A2 = ITensor (x;ids= ITensors. id .(inds (A)),tags= tags,plevs= plev,qn_names= [" N" ," P" ])
54- B2 = ITensor (y;ids= ITensors. id .(inds (B)),tags= tags,plevs= plev,qn_names= [" N" ])
55- C2 = ITensor (z;ids= ITensors. id .(inds (C)),tags= tags,plevs= plev,qn_names= [" N" ," P" ])
56- end
57- @test isapprox (norm (A2- A),0 ;atol= 1.0e-10 )
58- @test isapprox (norm (B2- B),0 ;atol= 1.0e-10 )
59- @test isapprox (norm (C2- C),0 ;atol= 1.0e-10 )
49+ if ismissing (tag)
50+ A2 = ITensor (x;ids= ITensors. id .(inds (A)),plevs= plev,qn_names= [" N" ," P" ])
51+ B2 = ITensor (y;ids= ITensors. id .(inds (B)),plevs= plev,qn_names= [" N" ])
52+ C2 = ITensor (z;ids= ITensors. id .(inds (C)),plevs= plev,qn_names= [" N" ," P" ])
53+ else
54+ A2 = ITensor (x;ids= ITensors. id .(inds (A)),tags= tags,plevs= plev,qn_names= [" N" ," P" ])
55+ B2 = ITensor (y;ids= ITensors. id .(inds (B)),tags= tags,plevs= plev,qn_names= [" N" ])
56+ C2 = ITensor (z;ids= ITensors. id .(inds (C)),tags= tags,plevs= plev,qn_names= [" N" ," P" ])
57+ end
58+ @test isapprox (norm (A2- A),0 ;atol= 1.0e-10 )
59+ @test isapprox (norm (B2- B),0 ;atol= 1.0e-10 )
60+ @test isapprox (norm (C2- C),0 ;atol= 1.0e-10 )
61+
62+
63+ x2 = TensorMap (A2)
64+ y2 = TensorMap (B2)
65+ z2 = TensorMap (C2)
66+ w2 = TensorMap (ITensor (w;ids= ITensors. id .(inds (D)),plevs= plev,qn_names= [" N" ," P" ]))
67+ @test isapprox (norm (x2 - x), 0 ; atol= 1.0e-10 )
68+ @test isapprox (norm (y2 - y), 0 ; atol= 1.0e-10 )
69+ @test isapprox (norm (z2 - z), 0 ; atol= 1.0e-10 )
70+ @test isapprox (norm (w2 - w), 0 ; atol= 1.0e-10 )
6071
72+ A3 = ITensor (x2)
73+ B3 = ITensor (y2)
74+ C3 = ITensor (z2)
75+ D3 = ITensor (w2)
6176
62- x2 = TensorMap (A2)
63- y2 = TensorMap (B2)
64- z2 = TensorMap (C2)
65- w2 = TensorMap (ITensor (w;ids= ITensors. id .(inds (D)),plevs= plev,qn_names= [" N" ," P" ]))
66- @test isapprox (norm (x2 - x), 0 ; atol= 1.0e-10 )
67- @test isapprox (norm (y2 - y), 0 ; atol= 1.0e-10 )
68- @test isapprox (norm (z2 - z), 0 ; atol= 1.0e-10 )
69- @test isapprox (norm (w2 - w), 0 ; atol= 1.0e-10 )
77+ @test isapprox (norm (TensorMap (A3) - x2), 0 ; atol= 1.0e-10 )
78+ @test isapprox (norm (TensorMap (B3) - y2), 0 ; atol= 1.0e-10 )
79+ @test isapprox (norm (TensorMap (C3) - z2), 0 ; atol= 1.0e-10 )
80+ @test isapprox (norm (TensorMap (D3) - w2), 0 ; atol= 1.0e-10 )
81+ end
7082 end
7183 end
7284 end
85+
86+ @testset " Half Integer" begin
87+ data = zeros (2 ,2 ,2 ,2 )
88+ data[1 ,1 ,1 ,1 ] = data[2 ,2 ,2 ,2 ] = data[1 ,2 ,2 ,1 ] = data[2 ,1 ,1 ,2 ] = 1
89+
90+ V = U1Space (1 / 2 => 1 ,- 1 / 2 => 1 )
91+ x = TensorMap (data, V ⊗ V, V ⊗ V)
92+ A = ITensor (x)
93+ x2 = TensorMap (A)
94+ A2 = ITensor (x2; ids = ITensors. id .(inds (A)))
95+ @test isapprox (norm (A - A2), 0 ; atol= 1.0e-10 )
96+ end
7397end
0 commit comments