Skip to content

Commit bb50d44

Browse files
author
qyli
committed
Merge branch 'main' of github.com:Qiaoyi-Li/FiniteMPS.jl
2 parents 56f8ce9 + df23ce5 commit bb50d44

File tree

2 files changed

+37
-25
lines changed

2 files changed

+37
-25
lines changed

src/IntrTree/IntrIterator.jl

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
"""
2-
abstract type AbstractInteractionIterator{L}
3-
The abstract type for the iterator of interaction terms. All the concrete subtypes should implement the `iterate` method so that the following usages are both valid where
1+
"""
2+
abstract type AbstractInteractionIterator{L}
3+
The abstract type for the iterator of interaction terms. All the concrete subtypes should implement the `iterate` method so that the following usages are both valid where
44
`Ops` is an instance of `AbstractInteractionIterator`.
55
```julia
66
for O in Ops
77
# the i-th loop will give the i-th LocalOperator
88
end
99
10-
collect(Ops) # return the vector of all LocalOperators
10+
collect(Ops) # return the vector of all LocalOperators
1111
```
1212
"""
1313
abstract type AbstractInteractionIterator{L} end
@@ -21,14 +21,14 @@ length(::AbstractInteractionIterator{L}) where L = L
2121
Op::AbstractLocalOperator
2222
Z::T
2323
end
24-
24+
2525
The iterator for on-site terms such as bosonic `n_i` or fermionic `c_i` together with its Jordan-Wigner string`Z_{i+1} Z_{i+2} ... Z_{L}`.
2626
2727
# Fields
2828
Op::AbstractLocalOperator
2929
The local operator which tells both the operator and its site index.
3030
31-
Z::Nothing
31+
Z::Nothing
3232
For bosonic operators.
3333
Z::AbstractTensorMap
3434
For fermionic operators. Assume all sites are fermionic therefore each site after `Op` will give `Z` operator.
@@ -44,7 +44,7 @@ Direct constructor.
4444
si::Int64;
4545
swap::Bool=false,
4646
Z=nothing)
47-
Generate the `LocalOperator` object with `Op`, `name`, `si` and kwarg `swap`, details please see the constructors of `LocalOperator`.
47+
Generate the `LocalOperator` object with `Op`, `name`, `si` and kwarg `swap`, details please see the constructors of `LocalOperator`.
4848
"""
4949
struct OnSiteInteractionIterator{L, T} <: AbstractInteractionIterator{L}
5050
Op::AbstractLocalOperator
@@ -66,7 +66,7 @@ struct OnSiteInteractionIterator{L, T} <: AbstractInteractionIterator{L}
6666
return OnSiteInteractionIterator{L}(LocalOperator(Op, name, si, !isnothing(Z); swap=swap), Z)
6767
end
6868
end
69-
function iterate(iter::OnSiteInteractionIterator{L, Nothing}, i::Int64 = 1) where {L}
69+
function iterate(iter::OnSiteInteractionIterator{L, Nothing}, i::Int64 = 1) where {L}
7070
i > L && return nothing
7171
if i == iter.Op.si
7272
Op_wrap = iter.Op
@@ -76,7 +76,7 @@ function iterate(iter::OnSiteInteractionIterator{L, Nothing}, i::Int64 = 1) wher
7676
end
7777
return Op_wrap, i + 1
7878
end
79-
function iterate(iter::OnSiteInteractionIterator{L, <:AbstractTensorMap}, i::Int64 = 1) where {L}
79+
function iterate(iter::OnSiteInteractionIterator{L, <:AbstractTensorMap}, i::Int64 = 1) where {L}
8080
i > L && return nothing
8181
if i == iter.Op.si
8282
Op_wrap = iter.Op
@@ -111,7 +111,7 @@ end
111111
end
112112
113113
The iterator for two-site terms such as bosonic `n_i n_j` or fermionic `c_i c_j` together with its Jordan-Wigner string `Z_{i+1} Z_{i+2} ... Z_{j}`.
114-
114+
115115
Note the two site indices can be in both ascending and descending order but should not be the same. For the latter case, please use `OnSiteInteractionIterator` to get an on-site term instead.
116116
117117
# Fields
@@ -123,7 +123,7 @@ The local operators.
123123
For bosonic operators.
124124
Z::AbstractTensorMap
125125
For fermionic operators. Note we assume both `O₁` and `O₂` are fermionic operators if `Z ≠ nothing`.
126-
Z::AbstractVector
126+
Z::AbstractVector{<:AbstractTensorMap}
127127
Directly give the `Z` operator for each site to deal with the systems mixed with bosons and fermions.
128128
129129
# Constructors
@@ -135,7 +135,7 @@ Direct constructor.
135135
si::NTuple{2, Int64};
136136
convertRight::Bool=false,
137137
Z=nothing)
138-
Generate the `LocalOperator` objects with 2-tuples `Op`, `name` and `si`. If `convertRight == true`, convert the the second operator (with larger site index, can be `O₁` or `O₂`) to a right one (i.e. only have left horizontal leg), which is used to uniquely determine the contraction when calculating ITP.
138+
Generate the `LocalOperator` objects with 2-tuples `Op`, `name` and `si`. If `convertRight == true`, convert the the second operator (with larger site index, can be `O₁` or `O₂`) to a right one (i.e. only have left horizontal leg), which is used to uniquely determine the contraction when calculating ITP.
139139
"""
140140
struct TwoSiteInteractionIterator{L, T} <: AbstractInteractionIterator{L}
141141
O₁::AbstractLocalOperator
@@ -157,7 +157,7 @@ struct TwoSiteInteractionIterator{L, T} <: AbstractInteractionIterator{L}
157157
Z=nothing
158158
) where {L}
159159
@assert 1 si[1] L && 1 si[2] L && si[1] si[2]
160-
160+
161161
Zflag = !isnothing(Z)
162162

163163
O₁ = LocalOperator(Op[1], name[1], si[1], Zflag)
@@ -175,28 +175,28 @@ struct TwoSiteInteractionIterator{L, T} <: AbstractInteractionIterator{L}
175175
return TwoSiteInteractionIterator{L}(O₁, O₂, Z)
176176
end
177177
end
178-
function iterate(iter::TwoSiteInteractionIterator{L, Nothing}, st::Tuple{Int64, VectorSpace} = (1, getLeftSpace(iter.O₁))) where {L}
178+
function iterate(iter::TwoSiteInteractionIterator{L, Nothing}, st::Tuple{Int64, VectorSpace} = (1, getLeftSpace(iter.O₁))) where {L}
179179
i, aspace = st
180180
i > L && return nothing
181181
if i == iter.O₁.si
182182
Op_wrap = iter.O₁
183183
elseif i == iter.O₂.si
184184
Op_wrap = iter.O₂
185185
else
186-
# deduce pspace
186+
# deduce pspace
187187
pspace = domain(iter.O₁)[1]
188188
Op_wrap = IdentityOperator(pspace, aspace, i)
189189
end
190190
return Op_wrap, (i + 1, getRightSpace(Op_wrap))
191191
end
192-
function iterate(iter::TwoSiteInteractionIterator{L, <:AbstractTensorMap}, st::Tuple{Int64, VectorSpace} = (1, getLeftSpace(iter.O₁))) where {L}
192+
function iterate(iter::TwoSiteInteractionIterator{L, <:AbstractTensorMap}, st::Tuple{Int64, VectorSpace} = (1, getLeftSpace(iter.O₁))) where {L}
193193
i, aspace = st
194194
i > L && return nothing
195195
if i == iter.O₁.si
196196
Op_wrap = iter.O₁
197197
elseif i == iter.O₂.si
198-
# add Z here
199-
Op_wrap = _addZ!(iter.O₂, iter.Z)
198+
# add Z here
199+
Op_wrap = _addZ!(iter.O₂, iter.Z)
200200
elseif i > iter.O₁.si && i < iter.O₂.si
201201
Op_wrap = LocalOperator(iter.Z, :Z, i, false; aspace = (aspace, aspace))
202202
else
@@ -233,21 +233,21 @@ end
233233
pspace::Union{Nothing, VectorSpace, Vector{<:VectorSpace}}
234234
end
235235
236-
The iterator for an arbitrary interaction term.
236+
The iterator for an arbitrary interaction term.
237237
238238
# Fields
239239
Ops::Vector{<:AbstractLocalOperator}
240240
A vector to store the local operators, `length(Ops) == N` means a `N`-site interaction term.
241241
242242
Z::Union{Nothing, AbstractTensorMap, AbstractVector}
243243
pspace::Union{Nothing, VectorSpace, Vector{<:VectorSpace}}
244-
Provide the fermion parity operator `Z` and the local physical space `pspace`. Assume a site-independent `Z` or `pspace` if a single object is provided, otherwise, a length-`L` vector is expected to deal with the site-dependent cases.
244+
Provide the fermion parity operator `Z` and the local physical space `pspace`. Assume a site-independent `Z` or `pspace` if a single object is provided, otherwise, a length-`L` vector is expected to deal with the site-dependent cases.
245245
246246
# Constructors
247247
ArbitraryInteractionIterator{L}(Ops::Vector{<:AbstractLocalOperator},
248248
Z::Union{Nothing, AbstractTensorMap, AbstractVector},
249249
pspace::Union{Nothing, VectorSpace, Vector{<:VectorSpace}} = nothing)
250-
The direct constructor.
250+
The direct constructor.
251251
"""
252252
struct ArbitraryInteractionIterator{L} <: AbstractInteractionIterator{L}
253253
Ops::Vector{<:AbstractLocalOperator}
@@ -266,18 +266,18 @@ function iterate(iter::ArbitraryInteractionIterator{L}, st::Tuple{Int64, Int64,
266266
end
267267
else
268268
Op_i = deepcopy(iter.Ops[idx])
269-
# add Z if necessary
269+
# add Z if necessary
270270
flag && _addZ!(Op_i, _getZ(iter.Z, i))
271271
return Op_i, (i + 1, idx + 1, xor(flag, isfermionic(Op_i)), getRightSpace(Op_i))
272272
end
273273
end
274274

275275
_getZ(::Nothing, ::Int64) = nothing
276276
_getZ(Z::AbstractTensorMap, ::Int64) = Z
277-
_getZ(Z::Vector, i::Int64) = Z[i]
277+
_getZ(Z::Vector{<:AbstractTensorMap}, i::Int64) = Z[i]
278278
_getpspace(::Nothing, ::Int64) = nothing
279279
_getpspace(pspace::VectorSpace, ::Int64) = pspace
280-
_getpspace(pspace::AbstractVector{<:VectorSpace}, i::Int64) = pspace[i]
280+
_getpspace(pspace::Vector{<:VectorSpace}, i::Int64) = pspace[i]
281281

282282
_addZ!(O::LocalOperator, ::Nothing) = O
283283
function _addZ!(OR::LocalOperator{1, 1}, Z::AbstractTensorMap)
@@ -318,4 +318,3 @@ function _addZ!(OR::LocalOperator{2, 2}, Z::AbstractTensorMap)
318318
end
319319
return OR
320320
end
321-

src/LocalSpace/Spin.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ const S₋₊ = let
7777
S₋, S₊
7878
end
7979

80+
const S₊₊₋₋ = let
81+
A = S₊₋[1]
82+
B = S₊₋[1]
83+
aspace_A = Rep[U₁](1 => 1)
84+
aspace_B = Rep[U₁](1 => 1)
85+
aspace2 = Rep[U₁](2 => 1)
86+
iso = isometry(aspace_A aspace_B, aspace2)
87+
@tensor B[d a; b e] := B[a b c] * iso[d c e]
88+
C = permute(B', ((2, 1), (4, 3)))
89+
D = permute(A', ((2, 1), (3,)))
90+
A, B, C, D
91+
end
92+
8093
end
8194

8295
const U1Spin = U₁Spin

0 commit comments

Comments
 (0)