@@ -14,39 +14,52 @@ def partially_traced_four_site_density_matrices(
1414 num_coarse_grained_physical_indices : int ,
1515 open_physical_indices : Tuple [Tuple [int ], Tuple [int ], Tuple [int ], Tuple [int ]],
1616) -> Tuple [jnp .ndarray , jnp .ndarray , jnp .ndarray , jnp .ndarray ]:
17+
18+ if not all (
19+ all (isinstance (open_idx , int ) for open_idx in tup ) or len (tup ) == 0
20+ for tup in open_physical_indices
21+ ):
22+ raise TypeError (
23+ "All elements of each tuple must be integers (or the tuple may be empty)."
24+ )
25+ if not all (
26+ len (tup ) <= num_coarse_grained_physical_indices for tup in open_physical_indices
27+ ):
28+ raise ValueError (
29+ f"At least one tuple in `open_physical_indices` { open_physical_indices } has length greater"
30+ f"than the number of coarse-grained physical sites { num_coarse_grained_physical_indices } "
31+ )
32+ peps_tensors = [
33+ t .reshape (
34+ t .shape [0 ],
35+ t .shape [1 ],
36+ * ((real_physical_dimension ,) * num_coarse_grained_physical_indices ),
37+ t .shape [3 ],
38+ t .shape [4 ],
39+ )
40+ for t in peps_tensors
41+ ]
1742 t_top_left , t_top_right , t_bottom_left , t_bottom_right = peps_tensors
1843 t_obj_top_left , t_obj_top_right , t_obj_bottom_left , t_obj_bottom_right = (
1944 peps_tensor_objs
2045 )
2146 top_left_i , top_right_i , bottom_left_i , bottom_right_i = open_physical_indices
2247
23- for t in ("t_top_left" , "t_top_right" , "t_bottom_left" , "t_bottom_right" ):
24- locals ()[t ] = locals ()[t ].reshape (
25- t_left .shape [0 ],
26- t_left .shape [1 ],
27- * ((real_physical_dimension ,) * num_coarse_grained_physical_indices ),
28- t_left .shape [3 ],
29- t_left .shape [4 ],
30- )
31-
32- if (
48+ if any (
3349 not hasattr (
3450 Definitions ,
35- f"partially_traced_four_site_density_matrices_top_left_{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ top_left_i } " ,
51+ (
52+ f"partially_traced_four_site_density_matrices_{ pos_name } _"
53+ f"{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ pos_idx } "
54+ ),
3655 )
37- or not hasattr (
38- Definitions ,
39- f"partially_traced_four_site_density_matrices_top_right_{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ top_right_i } " ,
40- )
41- or not hasattr (
42- Definitions ,
43- f"partially_traced_four_site_density_matrices_bottom_left_{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ bottom_left_i } " ,
44- )
45- or not hasattr (
46- Definitions ,
47- f"partially_traced_four_site_density_matrices_bottom_right_{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ bottom_right_i } " ,
56+ for pos_idx , pos_name in zip (
57+ open_physical_indices ,
58+ ["top_left" , "top_right" , "bottom_left" , "bottom_right" ],
59+ strict = True ,
4860 )
4961 ):
62+
5063 phys_contraction_i_top_left = list (
5164 range (7 , 7 + num_coarse_grained_physical_indices - len (top_left_i ))
5265 )
@@ -77,11 +90,17 @@ def partially_traced_four_site_density_matrices(
7790 }
7891 Definitions ._process_def (
7992 contraction_top_left ,
80- f"partially_traced_four_site_density_matrices_top_left_{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ top_left_i } " ,
93+ (
94+ f"partially_traced_four_site_density_matrices_top_left_"
95+ f"{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ top_left_i } "
96+ ),
8197 )
8298 setattr (
8399 Definitions ,
84- f"partially_traced_four_site_density_matrices_top_left_{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ top_left_i } " ,
100+ (
101+ f"partially_traced_four_site_density_matrices_top_left_"
102+ f"{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ top_left_i } "
103+ ),
85104 contraction_top_left ,
86105 )
87106
@@ -102,26 +121,45 @@ def partially_traced_four_site_density_matrices(
102121 contraction_top_right = {
103122 "tensors" : [["tensor" , "tensor_conj" , "T1" , "C2" , "T2" ]],
104123 "network" : [
124+ # With rotational consistent output order (ChiE, Ket chiB, Bra chiB)
105125 [
106- (- 2 * len (top_right_i ) - 2 , - 2 * len (top_right_i ) - 6 )
126+ (- 2 * len (top_right_i ) - 2 , - 2 * len (top_right_i ) - 5 )
107127 + phys_contraction_i_top_right
108128 + (4 , 3 ), # tensor
109- (- 2 * len (top_right_i ) - 3 , - 2 * len (top_right_i ) - 5 )
129+ (- 2 * len (top_right_i ) - 3 , - 2 * len (top_right_i ) - 6 )
110130 + phys_contraction_i_conj_top_right
111131 + (6 , 5 ), # tensor_conj
112132 (- 2 * len (top_right_i ) - 1 , 3 , 5 , 1 ), # T1
113133 (1 , 2 ), # C2
114134 (4 , 6 , - 2 * len (top_right_i ) - 4 , 2 ), # T2
115135 ]
136+ # Without rotational consistent output order
137+ # [
138+ # (-2 * len(top_right_i) - 2, -2 * len(top_right_i) - 6)
139+ # + phys_contraction_i_top_right
140+ # + (4, 3), # tensor
141+ # (-2 * len(top_right_i) - 3, -2 * len(top_right_i) - 5)
142+ # + phys_contraction_i_conj_top_right
143+ # + (6, 5), # tensor_conj
144+ # (-2 * len(top_right_i) - 1, 3, 5, 1), # T1
145+ # (1, 2), # C2
146+ # (4, 6, -2 * len(top_right_i) - 4, 2), # T2
147+ # ]
116148 ],
117149 }
118150 Definitions ._process_def (
119151 contraction_top_right ,
120- f"partially_traced_four_site_density_matrices_top_right_{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ top_right_i } " ,
152+ (
153+ f"partially_traced_four_site_density_matrices_top_right_"
154+ f"{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ top_right_i } "
155+ ),
121156 )
122157 setattr (
123158 Definitions ,
124- f"partially_traced_four_site_density_matrices_top_right_{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ top_right_i } " ,
159+ (
160+ f"partially_traced_four_site_density_matrices_top_right_"
161+ f"{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ top_right_i } "
162+ ),
125163 contraction_top_right ,
126164 )
127165
@@ -142,32 +180,57 @@ def partially_traced_four_site_density_matrices(
142180 contraction_bottom_left = {
143181 "tensors" : [["tensor" , "tensor_conj" , "T3" , "C4" , "T4" ]],
144182 "network" : [
183+ # With rotational consistent output order (ChiE, Ket chiB, Bra chiB)
145184 [
146185 (3 , 4 )
147186 + phys_contraction_i_bottom_left
148187 + (
149- - 2 * len (bottom_left_i ) - 3 ,
188+ - 2 * len (bottom_left_i ) - 2 ,
150189 - 2 * len (bottom_left_i ) - 5 ,
151190 ), # tensor
152191 (5 , 6 )
153192 + phys_contraction_i_conj_bottom_left
154193 + (
155- - 2 * len (bottom_left_i ) - 2 ,
194+ - 2 * len (bottom_left_i ) - 3 ,
156195 - 2 * len (bottom_left_i ) - 6 ,
157196 ), # tensor_conj
158197 (2 , - 2 * len (bottom_left_i ) - 1 , 6 , 4 ), # T3
159198 (2 , 1 ), # C4
160199 (1 , 5 , 3 , - 2 * len (bottom_left_i ) - 4 ), # T4
161200 ]
201+ # Without rotational consistent output order
202+ # [
203+ # (3, 4)
204+ # + phys_contraction_i_bottom_left
205+ # + (
206+ # -2 * len(bottom_left_i) - 3,
207+ # -2 * len(bottom_left_i) - 5,
208+ # ), # tensor
209+ # (5, 6)
210+ # + phys_contraction_i_conj_bottom_left
211+ # + (
212+ # -2 * len(bottom_left_i) - 2,
213+ # -2 * len(bottom_left_i) - 6,
214+ # ), # tensor_conj
215+ # (2, -2 * len(bottom_left_i) - 1, 6, 4), # T3
216+ # (2, 1), # C4
217+ # (1, 5, 3, -2 * len(bottom_left_i) - 4), # T4
218+ # ]
162219 ],
163220 }
164221 Definitions ._process_def (
165222 contraction_bottom_left ,
166- f"partially_traced_four_site_density_matrices_bottom_left_{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ bottom_left_i } " ,
223+ (
224+ f"partially_traced_four_site_density_matrices_bottom_left_"
225+ f"{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ bottom_left_i } "
226+ ),
167227 )
168228 setattr (
169229 Definitions ,
170- f"partially_traced_four_site_density_matrices_bottom_left_{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ bottom_left_i } " ,
230+ (
231+ f"partially_traced_four_site_density_matrices_bottom_left_"
232+ f"{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ bottom_left_i } "
233+ ),
171234 contraction_bottom_left ,
172235 )
173236
@@ -190,31 +253,53 @@ def partially_traced_four_site_density_matrices(
190253 contraction_bottom_right = {
191254 "tensors" : [["tensor" , "tensor_conj" , "T2" , "T3" , "C3" ]],
192255 "network" : [
256+ # With rotational consistent output order (ChiE, Ket chiB, Bra chiB)
193257 [
194- (- 2 * len (bottom_right_i ) - 6 , 3 )
258+ (- 2 * len (bottom_right_i ) - 5 , 3 )
195259 + phys_contraction_i_bottom_right
196- + (4 , - 2 * len (bottom_right_i ) - 3 ), # tensor
197- (- 2 * len (bottom_right_i ) - 5 , 5 )
260+ + (4 , - 2 * len (bottom_right_i ) - 2 ), # tensor
261+ (- 2 * len (bottom_right_i ) - 6 , 5 )
198262 + phys_contraction_i_conj_bottom_right
199- + (6 , - 2 * len (bottom_right_i ) - 2 ), # tensor_conj
263+ + (6 , - 2 * len (bottom_right_i ) - 3 ), # tensor_conj
200264 (4 , 6 , 2 , - 2 * len (bottom_right_i ) - 1 ), # T2
201265 (- 2 * len (bottom_right_i ) - 4 , 1 , 5 , 3 ), # T3
202266 (1 , 2 ), # C3
203267 ]
268+ # Without rotational consistent output order
269+ # [
270+ # (-2 * len(bottom_right_i) - 6, 3)
271+ # + phys_contraction_i_bottom_right
272+ # + (4, -2 * len(bottom_right_i) - 3), # tensor
273+ # (-2 * len(bottom_right_i) - 5, 5)
274+ # + phys_contraction_i_conj_bottom_right
275+ # + (6, -2 * len(bottom_right_i) - 2), # tensor_conj
276+ # (4, 6, 2, -2 * len(bottom_right_i) - 1), # T2
277+ # (-2 * len(bottom_right_i) - 4, 1, 5, 3), # T3
278+ # (1, 2), # C3
279+ # ]
204280 ],
205281 }
206282 Definitions ._process_def (
207283 contraction_bottom_right ,
208- f"partially_traced_four_site_density_matrices_bottom_right_{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ bottom_right_i } " ,
284+ (
285+ f"partially_traced_four_site_density_matrices_bottom_right_"
286+ f"{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ bottom_right_i } "
287+ ),
209288 )
210289 setattr (
211290 Definitions ,
212- f"partially_traced_four_site_density_matrices_bottom_right_{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ bottom_right_i } " ,
291+ (
292+ f"partially_traced_four_site_density_matrices_bottom_right_"
293+ f"{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ bottom_right_i } "
294+ ),
213295 contraction_bottom_right ,
214296 )
215297
216298 density_top_left = apply_contraction (
217- f"partially_traced_four_site_density_matrices_top_left_{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ top_left_i } " ,
299+ (
300+ f"partially_traced_four_site_density_matrices_top_left_"
301+ f"{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ top_left_i } "
302+ ),
218303 [t_top_left ],
219304 [t_obj_top_left ],
220305 [],
@@ -233,7 +318,10 @@ def partially_traced_four_site_density_matrices(
233318 )
234319
235320 density_top_right = apply_contraction (
236- f"partially_traced_four_site_density_matrices_top_right_{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ top_right_i } " ,
321+ (
322+ f"partially_traced_four_site_density_matrices_top_right_"
323+ f"{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ top_right_i } "
324+ ),
237325 [t_top_right ],
238326 [t_obj_top_right ],
239327 [],
@@ -252,7 +340,10 @@ def partially_traced_four_site_density_matrices(
252340 )
253341
254342 density_bottom_left = apply_contraction (
255- f"partially_traced_four_site_density_matrices_bottom_left_{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ bottom_left_i } " ,
343+ (
344+ f"partially_traced_four_site_density_matrices_bottom_left_"
345+ f"{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ bottom_left_i } "
346+ ),
256347 [t_bottom_left ],
257348 [t_obj_bottom_left ],
258349 [],
@@ -271,7 +362,10 @@ def partially_traced_four_site_density_matrices(
271362 )
272363
273364 density_bottom_right = apply_contraction (
274- f"partially_traced_four_site_density_matrices_bottom_right_{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ bottom_right_i } " ,
365+ (
366+ f"partially_traced_four_site_density_matrices_bottom_right_"
367+ f"{ real_physical_dimension } _{ num_coarse_grained_physical_indices } _{ bottom_right_i } "
368+ ),
275369 [t_bottom_right ],
276370 [t_obj_bottom_right ],
277371 [],
0 commit comments