|
| 1 | +import numpy as np |
| 2 | +import jax.numpy as jnp |
| 3 | + |
| 4 | +from jax import jit |
| 5 | + |
| 6 | +from varipeps.contractions import apply_contraction_jitted |
| 7 | + |
| 8 | + |
| 9 | +class Overlap_Four_Sites_Square: |
| 10 | + @staticmethod |
| 11 | + @jit |
| 12 | + def calc_overlap(unitcell): |
| 13 | + top_left = apply_contraction_jitted( |
| 14 | + "ctmrg_top_left", [unitcell[0, 0][0][0].tensor], [unitcell[0, 0][0][0]], [] |
| 15 | + ) |
| 16 | + top_left = top_left.reshape( |
| 17 | + np.prod(top_left.shape[:3]), np.prod(top_left.shape[3:]) |
| 18 | + ) |
| 19 | + |
| 20 | + top_right = apply_contraction_jitted( |
| 21 | + "ctmrg_top_right", [unitcell[0, 1][0][0].tensor], [unitcell[0, 1][0][0]], [] |
| 22 | + ) |
| 23 | + top_right = top_right.reshape( |
| 24 | + np.prod(top_right.shape[:3]), np.prod(top_right.shape[3:]) |
| 25 | + ) |
| 26 | + |
| 27 | + bottom_left = apply_contraction_jitted( |
| 28 | + "ctmrg_bottom_left", |
| 29 | + [unitcell[1, 0][0][0].tensor], |
| 30 | + [unitcell[1, 0][0][0]], |
| 31 | + [], |
| 32 | + ) |
| 33 | + bottom_left = bottom_left.reshape( |
| 34 | + np.prod(bottom_left.shape[:3]), np.prod(bottom_left.shape[3:]) |
| 35 | + ) |
| 36 | + |
| 37 | + bottom_right = apply_contraction_jitted( |
| 38 | + "ctmrg_bottom_right", |
| 39 | + [unitcell[1, 1][0][0].tensor], |
| 40 | + [unitcell[1, 1][0][0]], |
| 41 | + [], |
| 42 | + ) |
| 43 | + bottom_right = bottom_right.reshape( |
| 44 | + np.prod(bottom_right.shape[:3]), np.prod(bottom_right.shape[3:]) |
| 45 | + ) |
| 46 | + |
| 47 | + norm_with_sites = jnp.trace(top_left @ top_right @ bottom_left @ bottom_right) |
| 48 | + |
| 49 | + norm_corners = apply_contraction_jitted( |
| 50 | + "overlap_four_sites_square_only_corners", |
| 51 | + [ |
| 52 | + unitcell[0, 0][0][0].tensor, |
| 53 | + unitcell[0, 1][0][0].tensor, |
| 54 | + unitcell[1, 1][0][0].tensor, |
| 55 | + unitcell[1, 0][0][0].tensor, |
| 56 | + ], |
| 57 | + [ |
| 58 | + unitcell[0, 0][0][0], |
| 59 | + unitcell[0, 1][0][0], |
| 60 | + unitcell[1, 1][0][0], |
| 61 | + unitcell[1, 0][0][0], |
| 62 | + ], |
| 63 | + [], |
| 64 | + ) |
| 65 | + |
| 66 | + norm_horizontal = apply_contraction_jitted( |
| 67 | + "overlap_four_sites_square_transfer_horizontal", |
| 68 | + [ |
| 69 | + unitcell[0, 0][0][0].tensor, |
| 70 | + unitcell[0, 1][0][0].tensor, |
| 71 | + unitcell[1, 1][0][0].tensor, |
| 72 | + unitcell[1, 0][0][0].tensor, |
| 73 | + ], |
| 74 | + [ |
| 75 | + unitcell[0, 0][0][0], |
| 76 | + unitcell[0, 1][0][0], |
| 77 | + unitcell[1, 1][0][0], |
| 78 | + unitcell[1, 0][0][0], |
| 79 | + ], |
| 80 | + [], |
| 81 | + ) |
| 82 | + |
| 83 | + norm_vertical = apply_contraction_jitted( |
| 84 | + "overlap_four_sites_square_transfer_vertical", |
| 85 | + [ |
| 86 | + unitcell[0, 0][0][0].tensor, |
| 87 | + unitcell[0, 1][0][0].tensor, |
| 88 | + unitcell[1, 1][0][0].tensor, |
| 89 | + unitcell[1, 0][0][0].tensor, |
| 90 | + ], |
| 91 | + [ |
| 92 | + unitcell[0, 0][0][0], |
| 93 | + unitcell[0, 1][0][0], |
| 94 | + unitcell[1, 1][0][0], |
| 95 | + unitcell[1, 0][0][0], |
| 96 | + ], |
| 97 | + [], |
| 98 | + ) |
| 99 | + |
| 100 | + return (norm_with_sites * norm_corners) / (norm_horizontal * norm_vertical) |
0 commit comments