|
| 1 | +function correlator_horizontal( |
| 2 | + bra::InfinitePEPS, |
| 3 | + operator, |
| 4 | + i::CartesianIndex{2}, |
| 5 | + js::AbstractVector{CartesianIndex{2}}, |
| 6 | + ket::InfinitePEPS, |
| 7 | + env::CTMRGEnv, |
| 8 | +) |
| 9 | + size(ket) == size(bra) || |
| 10 | + throw(DimensionMismatch("The ket and bra must have the same unit cell.")) |
| 11 | + all(==(i[1]) ∘ first ∘ Tuple, js) || |
| 12 | + throw(ArgumentError("Not a horizontal correlation function")) |
| 13 | + issorted(vcat(i, js); by=last ∘ Tuple) || |
| 14 | + throw(ArgumentError("Not an increasing sequence of coordinates")) |
| 15 | + |
| 16 | + O = FiniteMPO(operator) |
| 17 | + length(O) == 2 || throw(ArgumentError("Operator must act on two sites")) |
| 18 | + |
| 19 | + # preallocate with correct scalartype |
| 20 | + G = similar( |
| 21 | + js, |
| 22 | + TensorOperations.promote_contract( |
| 23 | + scalartype(bra), scalartype(ket), scalartype(env), scalartype.(O)... |
| 24 | + ), |
| 25 | + ) |
| 26 | + |
| 27 | + # left start for operator and norm contractions |
| 28 | + Vn, Vo = start_correlator(i, bra, O[1], ket, env) |
| 29 | + i += CartesianIndex(0, 1) |
| 30 | + |
| 31 | + for (k, j) in enumerate(js) |
| 32 | + # transfer until left of site j |
| 33 | + while j > i |
| 34 | + Atop = env.edges[NORTH, _prev(i[1], end), mod1(i[2], end)] |
| 35 | + Abot = env.edges[SOUTH, _next(i[1], end), mod1(i[2], end)] |
| 36 | + sandwich = ( |
| 37 | + ket[mod1(i[1], end), mod1(i[2], end)], bra[mod1(i[1], end), mod1(i[2], end)] |
| 38 | + ) |
| 39 | + T = TransferMatrix(Atop, sandwich, _dag(Abot)) |
| 40 | + Vo = Vo * T |
| 41 | + Vn = Vn * T |
| 42 | + i += CartesianIndex(0, 1) |
| 43 | + end |
| 44 | + |
| 45 | + # compute overlap with operator |
| 46 | + numerator = end_correlator_numerator(j, Vo, bra, O[2], ket, env) |
| 47 | + |
| 48 | + # transfer right of site j |
| 49 | + Atop = env.edges[NORTH, _prev(i[1], end), mod1(i[2], end)] |
| 50 | + Abot = env.edges[SOUTH, _next(i[1], end), mod1(i[2], end)] |
| 51 | + sandwich = ( |
| 52 | + ket[mod1(i[1], end), mod1(i[2], end)], bra[mod1(i[1], end), mod1(i[2], end)] |
| 53 | + ) |
| 54 | + T = TransferMatrix(Atop, sandwich, _dag(Abot)) |
| 55 | + Vo = Vo * T |
| 56 | + Vn = Vn * T |
| 57 | + i += CartesianIndex(0, 1) |
| 58 | + |
| 59 | + # compute overlap without operator |
| 60 | + denominator = end_correlator_denominator(j, Vn, env) |
| 61 | + |
| 62 | + G[k] = numerator / denominator |
| 63 | + end |
| 64 | + |
| 65 | + return G |
| 66 | +end |
| 67 | + |
| 68 | +function start_correlator( |
| 69 | + i::CartesianIndex{2}, |
| 70 | + below::InfinitePEPS, |
| 71 | + O::MPOTensor, |
| 72 | + above::InfinitePEPS, |
| 73 | + env::CTMRGEnv, |
| 74 | +) |
| 75 | + r, c = Tuple(i) |
| 76 | + E_north = env.edges[NORTH, _prev(r, end), mod1(c, end)] |
| 77 | + E_south = env.edges[SOUTH, _next(r, end), mod1(c, end)] |
| 78 | + E_west = env.edges[WEST, mod1(r, end), _prev(c, end)] |
| 79 | + C_northwest = env.corners[NORTHWEST, _prev(r, end), _prev(c, end)] |
| 80 | + C_southwest = env.corners[SOUTHWEST, _next(r, end), _prev(c, end)] |
| 81 | + sandwich = (below[mod1(r, end), mod1(c, end)], above[mod1(r, end), mod1(c, end)]) |
| 82 | + |
| 83 | + # TODO: part of these contractions is duplicated between the two output tensors, |
| 84 | + # so could be optimized further |
| 85 | + @autoopt @tensor Vn[χSE Detop Debot; χNE] := |
| 86 | + E_south[χSE Dstop Dsbot; χSW2] * |
| 87 | + C_southwest[χSW2; χSW] * |
| 88 | + E_west[χSW Dwtop Dwbot; χNW] * |
| 89 | + C_northwest[χNW; χN] * |
| 90 | + conj(bra(sandwich)[d; Dnbot Debot Dsbot Dwbot]) * |
| 91 | + ket(sandwich)[d; Dntop Detop Dstop Dwtop] * |
| 92 | + E_north[χN Dntop Dnbot; χNE] |
| 93 | + |
| 94 | + @autoopt @tensor Vo[χSE Detop dstring Debot; χNE] := |
| 95 | + E_south[χSE Dstop Dsbot; χSW2] * |
| 96 | + C_southwest[χSW2; χSW] * |
| 97 | + E_west[χSW Dwtop Dwbot; χNW] * |
| 98 | + C_northwest[χNW; χN] * |
| 99 | + conj(bra(sandwich)[d1; Dnbot Debot Dsbot Dwbot]) * |
| 100 | + removeunit(O, 1)[d1; d2 dstring] * |
| 101 | + ket(sandwich)[d2; Dntop Detop Dstop Dwtop] * |
| 102 | + E_north[χN Dntop Dnbot; χNE] |
| 103 | + |
| 104 | + return Vn, Vo |
| 105 | +end |
| 106 | + |
| 107 | +function end_correlator_numerator( |
| 108 | + j::CartesianIndex{2}, |
| 109 | + V, |
| 110 | + above::InfinitePEPS, |
| 111 | + O::MPOTensor, |
| 112 | + below::InfinitePEPS, |
| 113 | + env::CTMRGEnv, |
| 114 | +) |
| 115 | + r, c = Tuple(j) |
| 116 | + E_north = env.edges[NORTH, _prev(r, end), mod1(c, end)] |
| 117 | + E_east = env.edges[EAST, mod1(r, end), _next(c, end)] |
| 118 | + E_south = env.edges[SOUTH, _next(r, end), mod1(c, end)] |
| 119 | + C_northeast = env.corners[NORTHEAST, _prev(r, end), _next(c, end)] |
| 120 | + C_southeast = env.corners[SOUTHEAST, _next(r, end), _next(c, end)] |
| 121 | + sandwich = (above[mod1(r, end), mod1(c, end)], below[mod1(r, end), mod1(c, end)]) |
| 122 | + |
| 123 | + return @autoopt @tensor contractcheck = true V[χSW DWt dstring DWb; χNW] * |
| 124 | + E_south[χSSE DSt DSb; χSW] * |
| 125 | + E_east[χNEE DEt DEb; χSEE] * |
| 126 | + E_north[χNW DNt DNb; χNNE] * |
| 127 | + C_northeast[χNNE; χNEE] * |
| 128 | + C_southeast[χSEE; χSSE] * |
| 129 | + conj(bra(sandwich)[db; DNb DEb DSb DWb]) * |
| 130 | + ket(sandwich)[dt; DNt DEt DSt DWt] * |
| 131 | + removeunit(O, 4)[dstring db; dt] |
| 132 | +end |
| 133 | + |
| 134 | +function end_correlator_denominator(j::CartesianIndex{2}, V, env::CTMRGEnv) |
| 135 | + r, c = Tuple(j) |
| 136 | + C_northeast = env.corners[NORTHEAST, _prev(r, end), _next(c, end)] |
| 137 | + E_east = env.edges[EAST, mod1(r, end), _next(c, end)] |
| 138 | + C_southeast = env.corners[SOUTHEAST, _next(r, end), _next(c, end)] |
| 139 | + |
| 140 | + return @autoopt @tensor V[χS DEt DEb; χN] * |
| 141 | + C_northeast[χN; χNE] * |
| 142 | + E_east[χNE DEt DEb; χSE] * |
| 143 | + C_southeast[χSE; χS] |
| 144 | +end |
| 145 | + |
| 146 | +function correlator_vertical( |
| 147 | + bra::InfinitePEPS, |
| 148 | + O, |
| 149 | + i::CartesianIndex{2}, |
| 150 | + js::AbstractVector{CartesianIndex{2}}, |
| 151 | + ket::InfinitePEPS, |
| 152 | + env::CTMRGEnv, |
| 153 | +) |
| 154 | + rotated_bra = rotl90(bra) |
| 155 | + rotated_ket = bra === ket ? rotated_bra : rotl90(ket) |
| 156 | + |
| 157 | + rotated_i = rotl90(i) |
| 158 | + rotated_j = map(rotl90, js) |
| 159 | + |
| 160 | + return correlator_horizontal( |
| 161 | + rotated_bra, O, rotated_i, rotated_j, rotated_ket, rotl90(env) |
| 162 | + ) |
| 163 | +end |
| 164 | + |
| 165 | +const CoordCollection{N} = Union{AbstractVector{CartesianIndex{N}},CartesianIndices{N}} |
| 166 | + |
| 167 | +function MPSKit.correlator( |
| 168 | + bra::InfinitePEPS, |
| 169 | + O, |
| 170 | + i::CartesianIndex{2}, |
| 171 | + js::CoordCollection{2}, |
| 172 | + ket::InfinitePEPS, |
| 173 | + env::CTMRGEnv, |
| 174 | +) |
| 175 | + js = vec(js) # map CartesianIndices to actual Vector instead of Matrix |
| 176 | + |
| 177 | + if all(==(i[1]) ∘ first ∘ Tuple, js) |
| 178 | + return correlator_horizontal(bra, O, i, js, ket, env) |
| 179 | + elseif all(==(i[2]) ∘ last ∘ Tuple, js) |
| 180 | + return correlator_vertical(bra, O, i, js, ket, env) |
| 181 | + else |
| 182 | + error("Only horizontal or vertical correlators are implemented") |
| 183 | + end |
| 184 | +end |
| 185 | + |
| 186 | +function MPSKit.correlator( |
| 187 | + bra::InfinitePEPS, |
| 188 | + O, |
| 189 | + i::CartesianIndex{2}, |
| 190 | + j::CartesianIndex{2}, |
| 191 | + ket::InfinitePEPS, |
| 192 | + env::CTMRGEnv, |
| 193 | +) |
| 194 | + return only(correlator(bra, O, i, j:j, ket, env)) |
| 195 | +end |
| 196 | + |
| 197 | +function MPSKit.correlator(state::InfinitePEPS, O, i::CartesianIndex{2}, j, env::CTMRGEnv) |
| 198 | + return MPSKit.correlator(state, O, i, j, state, env) |
| 199 | +end |
0 commit comments