|
10 | 10 | from varipeps.contractions import apply_contraction, apply_contraction_jitted |
11 | 11 | from varipeps.utils.svd import gauge_fixed_svd |
12 | 12 | from varipeps.utils.periodic_indices import calculate_periodic_indices |
| 13 | +from varipeps.utils.projector_dict import Projector_Dict |
13 | 14 | from .projectors import ( |
14 | 15 | calc_left_projectors, |
15 | 16 | calc_right_projectors, |
16 | 17 | calc_top_projectors, |
17 | 18 | calc_bottom_projectors, |
18 | | - T_Projector, |
19 | 19 | ) |
20 | 20 | from varipeps.expectation.one_site import calc_one_site_single_gate_obj |
21 | 21 | from varipeps.config import PEPS_AD_Config |
|
27 | 27 | CTMRG_Orientation = Literal["top-left", "top-right", "bottom-left", "bottom-right"] |
28 | 28 |
|
29 | 29 |
|
30 | | -@dataclass |
31 | | -class _Projector_Dict(collections.abc.MutableMapping): |
32 | | - max_x: int |
33 | | - max_y: int |
34 | | - projector_dict: Dict[Tuple[int, int], T_Projector] = field(default_factory=dict) # type: ignore |
35 | | - |
36 | | - def __getitem__(self, key: Tuple[int, int]) -> T_Projector: |
37 | | - return self.projector_dict[key] |
38 | | - |
39 | | - def __setitem__(self, key: Tuple[int, int], value: T_Projector) -> None: |
40 | | - self.projector_dict[key] = value |
41 | | - |
42 | | - def __delitem__(self, key: Tuple[int, int]) -> None: |
43 | | - self.projector_dict.__delitem__(key) |
44 | | - |
45 | | - def __iter__(self): |
46 | | - return self.projector_dict.__iter__() |
47 | | - |
48 | | - def __len__(self): |
49 | | - return self.projector_dict.__len__() |
50 | | - |
51 | | - def get_projector( |
52 | | - self, |
53 | | - current_x: int, |
54 | | - current_y: int, |
55 | | - relative_x: int, |
56 | | - relative_y: int, |
57 | | - ) -> T_Projector: |
58 | | - select_x = (current_x + relative_x) % self.max_x |
59 | | - select_y = (current_y + relative_y) % self.max_y |
60 | | - |
61 | | - return self.projector_dict[(select_x, select_y)] |
62 | | - |
63 | | - |
64 | 30 | def _tensor_list_from_indices( |
65 | 31 | peps_tensors: Sequence[jnp.ndarray], indices: Sequence[Sequence[int]] |
66 | 32 | ) -> List[List[jnp.ndarray]]: |
@@ -150,7 +116,7 @@ def do_left_absorption( |
150 | 116 | all elements of the unitcell. |
151 | 117 | """ |
152 | 118 | max_x, max_y = unitcell.get_size() |
153 | | - left_projectors = _Projector_Dict(max_x=max_x, max_y=max_y) |
| 119 | + left_projectors = Projector_Dict(max_x=max_x, max_y=max_y) |
154 | 120 |
|
155 | 121 | working_unitcell = unitcell.copy() |
156 | 122 |
|
@@ -242,7 +208,7 @@ def do_right_absorption( |
242 | 208 | all elements of the unitcell. |
243 | 209 | """ |
244 | 210 | max_x, max_y = unitcell.get_size() |
245 | | - right_projectors = _Projector_Dict(max_x=max_x, max_y=max_y) |
| 211 | + right_projectors = Projector_Dict(max_x=max_x, max_y=max_y) |
246 | 212 |
|
247 | 213 | working_unitcell = unitcell.copy() |
248 | 214 |
|
@@ -338,7 +304,7 @@ def do_top_absorption( |
338 | 304 | all elements of the unitcell. |
339 | 305 | """ |
340 | 306 | max_x, max_y = unitcell.get_size() |
341 | | - top_projectors = _Projector_Dict(max_x=max_x, max_y=max_y) |
| 307 | + top_projectors = Projector_Dict(max_x=max_x, max_y=max_y) |
342 | 308 |
|
343 | 309 | working_unitcell = unitcell.copy() |
344 | 310 |
|
@@ -430,7 +396,7 @@ def do_bottom_absorption( |
430 | 396 | all elements of the unitcell. |
431 | 397 | """ |
432 | 398 | max_x, max_y = unitcell.get_size() |
433 | | - bottom_projectors = _Projector_Dict(max_x=max_x, max_y=max_y) |
| 399 | + bottom_projectors = Projector_Dict(max_x=max_x, max_y=max_y) |
434 | 400 |
|
435 | 401 | working_unitcell = unitcell.copy() |
436 | 402 |
|
|
0 commit comments