Skip to content

Commit 13c9a38

Browse files
committed
Reorganize trotter and apply_gate code
1 parent b56a5fb commit 13c9a38

File tree

8 files changed

+699
-699
lines changed

8 files changed

+699
-699
lines changed

src/PEPSKit.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ include("algorithms/truncation/truncationschemes.jl")
104104
include("algorithms/truncation/fullenv_truncation.jl")
105105
include("algorithms/truncation/bond_truncation.jl")
106106

107-
include("algorithms/time_evolution/evoltools.jl")
107+
include("algorithms/time_evolution/trotter_gate.jl")
108+
include("algorithms/time_evolution/trotter_mpo.jl")
109+
include("algorithms/time_evolution/apply_gate.jl")
110+
include("algorithms/time_evolution/apply_mpo.jl")
108111
include("algorithms/time_evolution/time_evolve.jl")
109112
include("algorithms/time_evolution/simpleupdate.jl")
110113
include("algorithms/time_evolution/simpleupdate3site.jl")
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
"""
2+
$(SIGNATURES)
3+
4+
Use QR decomposition on two tensors `A`, `B` connected by a bond to get the reduced tensors.
5+
When `A`, `B` are PEPSTensors,
6+
```
7+
2 1 1
8+
| | |
9+
5 -A/B- 3 ====> 4 - X ← 2 1 ← a - 3 1 - b → 3 4 → Y - 2
10+
| ↘ | ↘ ↘ |
11+
4 1 3 2 2 3
12+
```
13+
When `A`, `B` are PEPOTensors,
14+
- If `gate_ax = 1`
15+
```
16+
2 3 1 2 1 2
17+
↘ | ↘ | ↘ |
18+
6 -A/B- 4 ====> 5 - X ← 3 1 ← a - 3 1 - b → 3 5 → Y - 3
19+
| ↘ | ↘ ↘ |
20+
5 1 4 2 2 4
21+
```
22+
- If `gate_ax = 2`
23+
```
24+
2 3 2 2 2 2
25+
↘ | | ↘ ↘ |
26+
6 -A/B- 4 ====> 5 - X ← 3 1 ← a - 3 1 - b → 3 5 → Y - 3
27+
| ↘ | ↘ | ↘
28+
5 1 4 1 4 1
29+
```
30+
"""
31+
function _qr_bond(A::PT, B::PT; gate_ax::Int = 1) where {PT <: Union{PEPSTensor, PEPOTensor}}
32+
@assert 1 <= gate_ax <= numout(A)
33+
permA, permB, permX, permY = if A isa PEPSTensor
34+
((2, 4, 5), (1, 3)), ((2, 3, 4), (1, 5)), (1, 4, 2, 3), Tuple(1:4)
35+
else
36+
if gate_ax == 1
37+
((2, 3, 5, 6), (1, 4)), ((2, 3, 4, 5), (1, 6)), (1, 2, 5, 3, 4), Tuple(1:5)
38+
else
39+
((1, 3, 5, 6), (2, 4)), ((1, 3, 4, 5), (2, 6)), (1, 2, 5, 3, 4), Tuple(1:5)
40+
end
41+
end
42+
X, a = left_orth(permute(A, permA); positive = true)
43+
Y, b = left_orth(permute(B, permB); positive = true)
44+
# no longer needed after TensorKit 0.15
45+
# @assert !isdual(space(a, 1))
46+
# @assert !isdual(space(b, 1))
47+
X, Y = permute(X, permX), permute(Y, permY)
48+
b = permute(b, ((3, 2), (1,)))
49+
return X, a, b, Y
50+
end
51+
52+
"""
53+
$(SIGNATURES)
54+
55+
Reconstruct the tensors connected by a bond from their `_qr_bond` results.
56+
For PEPSTensors,
57+
```
58+
-2 -2
59+
| |
60+
-5- X - 1 - a - -3 -5 - b - 1 - Y - -3
61+
| ↘ ↘ |
62+
-4 -1 -1 -4
63+
```
64+
For PEPOTensors
65+
```
66+
-2 -3 -2 -3
67+
↘ | ↘ |
68+
-6- X - 1 - a - -4 -6 - b - 1 - Y - -4
69+
| ↘ ↘ |
70+
-5 -1 -1 -5
71+
72+
-3 -2 -2 -3
73+
| ↘ ↘ |
74+
-6- X - 1 - a - -4 -6 - b - 1 - Y - -4
75+
| ↘ | ↘
76+
-5 -1 -5 -1
77+
```
78+
"""
79+
function _qr_bond_undo(X::PEPSOrth, a::AbstractTensorMap, b::AbstractTensorMap, Y::PEPSOrth)
80+
@tensor A[-1; -2 -3 -4 -5] := X[-2 1 -4 -5] * a[1 -1 -3]
81+
@tensor B[-1; -2 -3 -4 -5] := b[-5 -1 1] * Y[-2 -3 -4 1]
82+
return A, B
83+
end
84+
function _qr_bond_undo(X::PEPOOrth, a::AbstractTensorMap, b::AbstractTensorMap, Y::PEPOOrth)
85+
if !isdual(space(a, 2))
86+
@tensor A[-1 -2; -3 -4 -5 -6] := X[-2 -3 1 -5 -6] * a[1 -1 -4]
87+
@tensor B[-1 -2; -3 -4 -5 -6] := b[-6 -1 1] * Y[-2 -3 -4 -5 1]
88+
else
89+
@tensor A[-1 -2; -3 -4 -5 -6] := X[-1 -3 1 -5 -6] * a[1 -2 -4]
90+
@tensor B[-1 -2; -3 -4 -5 -6] := b[-6 -2 1] * Y[-1 -3 -4 -5 1]
91+
end
92+
return A, B
93+
end
94+
95+
"""
96+
$(SIGNATURES)
97+
98+
Apply 2-site `gate` on the reduced matrices `a`, `b`
99+
```
100+
-1← a --- 3 --- b ← -4 -2 -3
101+
↓ ↓ ↓ ↓
102+
1 2 |----gate---|
103+
↓ ↓ or ↓ ↓
104+
|----gate---| 1 2
105+
↓ ↓ ↓ ↓
106+
-2 -3 -1← a --- 3 --- b ← -4
107+
```
108+
"""
109+
function _apply_gate(
110+
a::AbstractTensorMap, b::AbstractTensorMap,
111+
gate::AbstractTensorMap{T, S, 2, 2}, trunc::TruncationStrategy
112+
) where {T <: Number, S <: ElementarySpace}
113+
V = space(b, 1)
114+
need_flip = isdual(V)
115+
if isdual(space(a, 2))
116+
@tensor a2b2[-1 -2; -3 -4] := gate[1 2; -2 -3] * a[-1 1 3] * b[3 2 -4]
117+
else
118+
@tensor a2b2[-1 -2; -3 -4] := gate[-2 -3; 1 2] * a[-1 1 3] * b[3 2 -4]
119+
end
120+
trunc = if trunc isa FixedSpaceTruncation
121+
need_flip ? truncspace(flip(V)) : truncspace(V)
122+
else
123+
trunc
124+
end
125+
a, s, b, ϵ = svd_trunc!(a2b2; trunc, alg = LAPACK_QRIteration())
126+
a, b = absorb_s(a, s, b)
127+
if need_flip
128+
a, s, b = flip(a, numind(a)), _fliptwist_s(s), flip(b, 1)
129+
end
130+
return a, s, b, ϵ
131+
end

0 commit comments

Comments
 (0)