|
| 1 | +function left_canonicalize!( |
| 2 | + H::FiniteMPOHamiltonian, i::Int; |
| 3 | + alg = QRpos(), trscheme::TruncationScheme = notrunc() |
| 4 | + ) |
| 5 | + 1 ≤ i < length(H) || throw(ArgumentError("Bounds error in canonicalize")) |
| 6 | + |
| 7 | + W = H[i] |
| 8 | + S = spacetype(W) |
| 9 | + d = sqrt(dim(physicalspace(W))) |
| 10 | + |
| 11 | + # orthogonalize second column against first |
| 12 | + WI = removeunit(W[1, 1, 1, 1], 1) |
| 13 | + @tensor t[l; r] := conj(WI[p; p' l]) * W.C[p; p' r] |
| 14 | + # TODO: the following is currently broken due to a TensorKit bug |
| 15 | + # @plansor C′[p; p' r] := W.C[p; p' r] - WI[p; p' l] * t[l; r] |
| 16 | + @plansor C′[p; p' r] := -WI[p; p' l] * t[l; r] |
| 17 | + add!(C′, W.C) |
| 18 | + |
| 19 | + # QR of second column |
| 20 | + if size(W, 1) == 1 |
| 21 | + tmp = transpose(C′, ((2, 1), (3,))) |
| 22 | + |
| 23 | + if trscheme == notrunc() |
| 24 | + Q, R = leftorth!(tmp; alg) |
| 25 | + else |
| 26 | + @assert alg == SVD() || alg == SDD() |
| 27 | + Q, Σ, Vᴴ = tsvd!(tmp; alg, trunc = trscheme) |
| 28 | + R = Σ * Vᴴ |
| 29 | + end |
| 30 | + |
| 31 | + if dim(R) == 0 # fully truncated |
| 32 | + V = BlockTensorKit.oplus(oneunit(S), oneunit(S)) |
| 33 | + Q1 = typeof(W.A)(undef, SumSpace{S}() ⊗ physicalspace(W) ← physicalspace(W) ⊗ SumSpace{S}()) |
| 34 | + Q2 = typeof(W.C)(undef, physicalspace(W) ← physicalspace(W) ⊗ SumSpace{S}()) |
| 35 | + else |
| 36 | + V = BlockTensorKit.oplus(oneunit(S), space(R, 1), oneunit(S)) |
| 37 | + scale!(Q, d) |
| 38 | + scale!(R, inv(d)) |
| 39 | + Q1 = typeof(W.A)(undef, SumSpace{S}() ⊗ physicalspace(W) ← physicalspace(W) ⊗ space(R, 1)) |
| 40 | + Q2 = transpose(Q, ((2,), (1, 3))) |
| 41 | + end |
| 42 | + H[i] = JordanMPOTensor(codomain(W) ← physicalspace(W) ⊗ V, Q1, W.B, Q2, W.D) |
| 43 | + else |
| 44 | + tmp = transpose(cat(insertleftunit(C′, 1), W.A; dims = 1), ((3, 1, 2), (4,))) |
| 45 | + if trscheme == notrunc() |
| 46 | + Q, R = leftorth!(tmp; alg) |
| 47 | + else |
| 48 | + @assert alg == SVD() || alg == SDD() |
| 49 | + Q, Σ, Vᴴ = tsvd!(tmp; alg, trunc = trscheme) |
| 50 | + R = Σ * Vᴴ |
| 51 | + end |
| 52 | + if dim(R) == 0 # fully truncated |
| 53 | + V = BlockTensorKit.oplus(oneunit(S), oneunit(S)) |
| 54 | + Q1 = typeof(W.A)(undef, SumSpace{S}() ⊗ physicalspace(W) ← physicalspace(W) ⊗ SumSpace{S}()) |
| 55 | + Q2 = typeof(W.C)(undef, physicalspace(W) ← physicalspace(W) ⊗ SumSpace{S}()) |
| 56 | + else |
| 57 | + scale!(Q, d) |
| 58 | + scale!(R, inv(d)) |
| 59 | + Q′ = transpose(Q, ((2, 3), (1, 4))) |
| 60 | + Q1 = Q′[2:end, 1, 1, 1] |
| 61 | + Q2 = removeunit(SparseBlockTensorMap(Q′[1:1, 1, 1, 1]), 1) |
| 62 | + V = BlockTensorKit.oplus(oneunit(S), right_virtualspace(Q′), oneunit(S)) |
| 63 | + end |
| 64 | + H[i] = JordanMPOTensor(codomain(W) ← physicalspace(W) ⊗ V, Q1, W.B, Q2, W.D) |
| 65 | + end |
| 66 | + |
| 67 | + # absorb into next site |
| 68 | + W′ = H[i + 1] |
| 69 | + |
| 70 | + if size(W′, 4) > 1 && dim(R) != 0 |
| 71 | + @plansor A′[l p; p' r] := R[l; r'] * W′.A[r' p; p' r] |
| 72 | + else |
| 73 | + A′ = similar(W′.A, right_virtualspace(H[i].A) ⊗ physicalspace(W′) ← domain(W′.A)) |
| 74 | + end |
| 75 | + |
| 76 | + if size(W′, 4) > 1 |
| 77 | + @plansor C′[l p; p' r] := t[l; r'] * W′.A[r' p; p' r] |
| 78 | + C′ = add!(removeunit(C′, 1), W′.C) |
| 79 | + else |
| 80 | + C′ = W′.C # empty |
| 81 | + end |
| 82 | + |
| 83 | + if dim(R) != 0 |
| 84 | + @plansor B′[l p; p'] := R[l; r] * W′.B[r p; p'] |
| 85 | + else |
| 86 | + B′ = similar(W′.B, right_virtualspace(H[i].A) ⊗ physicalspace(W′) ← domain(W′.B)) |
| 87 | + end |
| 88 | + |
| 89 | + @plansor D′[l p; p'] := t[l; r] * W′.B[r p; p'] |
| 90 | + D′ = add!(removeunit(D′, 1), W′.D) |
| 91 | + |
| 92 | + H[i + 1] = JordanMPOTensor( |
| 93 | + right_virtualspace(H[i]) ⊗ physicalspace(W′) ← domain(W′), |
| 94 | + A′, B′, C′, D′ |
| 95 | + ) |
| 96 | + return H |
| 97 | +end |
| 98 | + |
| 99 | +function right_canonicalize!( |
| 100 | + H::FiniteMPOHamiltonian, i::Int; |
| 101 | + alg = LQpos(), trscheme::TruncationScheme = notrunc() |
| 102 | + ) |
| 103 | + 1 < i ≤ length(H) || throw(ArgumentError("Bounds error in canonicalize")) |
| 104 | + |
| 105 | + W = H[i] |
| 106 | + S = spacetype(W) |
| 107 | + d = sqrt(dim(physicalspace(W))) |
| 108 | + |
| 109 | + # orthogonalize second row against last |
| 110 | + WI = removeunit(W[end, 1, 1, end], 4) |
| 111 | + @plansor t[l; r] := conj(WI[r p; p']) * W.B[l p; p'] |
| 112 | + # TODO: the following is currently broken due to a TensorKit bug |
| 113 | + # @plansor B′[l p; p'] := W.B[l p; p'] - WI[r p; p'] * t[l; r] |
| 114 | + @plansor B′[l p; p'] := -WI[r p; p'] * t[l; r] |
| 115 | + add!(B′, W.B) |
| 116 | + |
| 117 | + # LQ of second row |
| 118 | + if size(W, 4) == 1 |
| 119 | + tmp = transpose(B′, ((1,), (3, 2))) |
| 120 | + if trscheme == notrunc() |
| 121 | + R, Q = rightorth!(tmp; alg) |
| 122 | + else |
| 123 | + @assert alg == SVD() || alg == SDD() |
| 124 | + U, Σ, Q = tsvd!(tmp; alg, trunc = trscheme) |
| 125 | + R = U * Σ |
| 126 | + end |
| 127 | + |
| 128 | + if dim(R) == 0 |
| 129 | + V = BlockTensorKit.oplus(oneunit(S), oneunit(S)) |
| 130 | + Q1 = typeof(W.A)(undef, SumSpace{S}() ⊗ physicalspace(W) ← physicalspace(W) ⊗ SumSpace{S}()) |
| 131 | + Q2 = typeof(W.B)(undef, SumSpace{S}() ⊗ physicalspace(W) ← physicalspace(W)) |
| 132 | + else |
| 133 | + V = BlockTensorKit.oplus(oneunit(S), space(Q, 1), oneunit(S)) |
| 134 | + scale!(Q, d) |
| 135 | + scale!(R, inv(d)) |
| 136 | + Q1 = typeof(W.A)(undef, space(Q, 1) ⊗ physicalspace(W) ← physicalspace(W) ⊗ SumSpace{S}()) |
| 137 | + Q2 = transpose(Q, ((1, 3), (2,))) |
| 138 | + end |
| 139 | + H[i] = JordanMPOTensor(V ⊗ physicalspace(W) ← domain(W), Q1, Q2, W.C, W.D) |
| 140 | + else |
| 141 | + tmp = transpose(cat(insertleftunit(B′, 4), W.A; dims = 4), ((1,), (3, 4, 2))) |
| 142 | + if trscheme == notrunc() |
| 143 | + R, Q = rightorth!(tmp; alg) |
| 144 | + else |
| 145 | + @assert alg == SVD() || alg == SDD() |
| 146 | + U, Σ, Q = tsvd!(tmp; alg, trunc = trscheme) |
| 147 | + R = U * Σ |
| 148 | + end |
| 149 | + if dim(R) == 0 |
| 150 | + V = BlockTensorKit.oplus(oneunit(S), oneunit(S)) |
| 151 | + Q1 = typeof(W.A)(undef, SumSpace{S}() ⊗ physicalspace(W) ← physicalspace(W) ⊗ SumSpace{S}()) |
| 152 | + Q2 = typeof(W.B)(undef, SumSpace{S}() ⊗ physicalspace(W) ← physicalspace(W)) |
| 153 | + else |
| 154 | + scale!(Q, d) |
| 155 | + scale!(R, inv(d)) |
| 156 | + Q′ = transpose(Q, ((1, 4), (2, 3))) |
| 157 | + Q1 = SparseBlockTensorMap(Q′[1, 1, 1, 2:end]) |
| 158 | + Q2 = removeunit(SparseBlockTensorMap(Q′[1, 1, 1, 1:1]), 4) |
| 159 | + V = BlockTensorKit.oplus(oneunit(S), left_virtualspace(Q′), oneunit(S)) |
| 160 | + end |
| 161 | + H[i] = JordanMPOTensor(V ⊗ physicalspace(W) ← domain(W), Q1, Q2, W.C, W.D) |
| 162 | + end |
| 163 | + |
| 164 | + # absorb into previous site |
| 165 | + W′ = H[i - 1] |
| 166 | + |
| 167 | + if size(W′, 1) > 1 && dim(R) != 0 |
| 168 | + @plansor A′[l p; p' r] := W′.A[l p; p' r'] * R[r'; r] |
| 169 | + else |
| 170 | + A′ = similar(W′.A, codomain(W′.A) ← physicalspace(W′.A) ⊗ left_virtualspace(H[i].A)) |
| 171 | + end |
| 172 | + |
| 173 | + if size(W′, 1) > 1 |
| 174 | + @plansor B′[l p; p' r] := W′.A[l p; p' r'] * t[r'; r] |
| 175 | + B′ = add!(removeunit(B′, 4), W′.B) |
| 176 | + else |
| 177 | + B′ = W′.B |
| 178 | + end |
| 179 | + |
| 180 | + if dim(R) != 0 |
| 181 | + @plansor C′[p; p' r] := W′.C[p; p' r'] * R[r'; r] |
| 182 | + else |
| 183 | + C′ = similar(W′.C, codomain(W′.C) ← physicalspace(W′) ⊗ left_virtualspace(H[i].A)) |
| 184 | + end |
| 185 | + |
| 186 | + @plansor D′[p; p' r] := W′.C[p; p' r'] * t[r'; r] |
| 187 | + D′ = add!(removeunit(D′, 3), W′.D) |
| 188 | + H[i - 1] = JordanMPOTensor(codomain(W′) ← physicalspace(W′) ⊗ V, A′, B′, C′, D′) |
| 189 | + return H |
| 190 | +end |
0 commit comments