Skip to content

Commit 31ab17c

Browse files
author
qyli
committed
support fermion-spin coupled systems
1 parent 4ae0b62 commit 31ab17c

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

src/IntrTree/IntrIterator.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The local operator which tells both the operator and its site index.
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.
35-
Z::AbstractVector{<:AbstractTensorMap}
35+
Z::AbstractVector
3636
Directly give the `Z` operator for each site to deal with the systems mixed with bosons and fermions.
3737
3838
# Constructors
@@ -51,8 +51,8 @@ struct OnSiteInteractionIterator{L, T} <: AbstractInteractionIterator{L}
5151
Z::T
5252
function OnSiteInteractionIterator{L}(Op::AbstractLocalOperator,
5353
Z::T) where {L, T}
54-
@assert T <: Union{Nothing, AbstractTensorMap, AbstractVector{<:AbstractTensorMap}}
55-
if T <: AbstractVector{<:AbstractTensorMap}
54+
@assert T <: Union{Nothing, AbstractTensorMap, AbstractVector}
55+
if T <: AbstractVector
5656
@assert length(Z) == L
5757
end
5858
return new{L, T}(Op, Z)
@@ -109,7 +109,7 @@ The local operators.
109109
For bosonic operators.
110110
Z::AbstractTensorMap
111111
For fermionic operators. Note we assume both `O₁` and `O₂` are fermionic operators if `Z ≠ nothing`.
112-
Z::AbstractVector{<:AbstractTensorMap}
112+
Z::AbstractVector
113113
Directly give the `Z` operator for each site to deal with the systems mixed with bosons and fermions.
114114
115115
# Constructors
@@ -130,8 +130,8 @@ struct TwoSiteInteractionIterator{L, T} <: AbstractInteractionIterator{L}
130130
function TwoSiteInteractionIterator{L}(O₁::AbstractLocalOperator,
131131
O₂::AbstractLocalOperator,
132132
Z::T) where {L, T}
133-
@assert T <: Union{Nothing, AbstractTensorMap, AbstractVector{<:AbstractTensorMap}}
134-
if T <: AbstractVector{<:AbstractTensorMap}
133+
@assert T <: Union{Nothing, AbstractTensorMap, AbstractVector}
134+
if T <: AbstractVector
135135
@assert length(Z) == L
136136
end
137137
return new{L, T}(O₁, O₂, Z)
@@ -196,7 +196,7 @@ end
196196
"""
197197
ArbitraryInteractionIterator{L} <: AbstractInteractionIterator{L}
198198
Ops::Vector{<:AbstractLocalOperator}
199-
Z::Union{Nothing, AbstractTensorMap, AbstractVector{<:AbstractTensorMap}}
199+
Z::Union{Nothing, AbstractTensorMap, AbstractVector}
200200
pspace::Union{Nothing, VectorSpace, Vector{<:VectorSpace}}
201201
end
202202
@@ -206,27 +206,27 @@ The iterator for an arbitrary interaction term.
206206
Ops::Vector{<:AbstractLocalOperator}
207207
A vector to store the local operators, `length(Ops) == N` means a `N`-site interaction term.
208208
209-
Z::Union{Nothing, AbstractTensorMap, AbstractVector{<:AbstractTensorMap}}
209+
Z::Union{Nothing, AbstractTensorMap, AbstractVector}
210210
pspace::Union{Nothing, VectorSpace, Vector{<:VectorSpace}}
211211
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.
212212
213213
# Constructors
214214
ArbitraryInteractionIterator{L}(Ops::Vector{<:AbstractLocalOperator},
215-
Z::Union{Nothing, AbstractTensorMap, AbstractVector{<:AbstractTensorMap}},
215+
Z::Union{Nothing, AbstractTensorMap, AbstractVector},
216216
pspace::Union{Nothing, VectorSpace, Vector{<:VectorSpace}} = nothing)
217217
The direct constructor.
218218
"""
219219
struct ArbitraryInteractionIterator{L} <: AbstractInteractionIterator{L}
220220
Ops::Vector{<:AbstractLocalOperator}
221-
Z::Union{Nothing, AbstractTensorMap, AbstractVector{<:AbstractTensorMap}}
221+
Z::Union{Nothing, AbstractTensorMap, AbstractVector}
222222
pspace::Union{Nothing, VectorSpace, Vector{<:VectorSpace}}
223223
end
224224
function iterate(iter::ArbitraryInteractionIterator{L}, st::Tuple{Int64, Int64, Bool, VectorSpace} = (1, 1, false, getLeftSpace(iter.Ops[1]))) where {L}
225225
i, idx, flag, aspace = st
226226
i > L && return nothing
227227

228228
if idx > length(iter.Ops) || i < iter.Ops[idx].si
229-
if flag
229+
if flag && !isnothing(_getZ(iter.Z, i))
230230
return LocalOperator(_getZ(iter.Z, i), :Z, i, false; aspace = (aspace, aspace)), (i + 1, idx, flag, aspace)
231231
else
232232
return IdentityOperator(_getpspace(iter.pspace, i), aspace, i), (i + 1, idx, flag, aspace)
@@ -241,10 +241,10 @@ end
241241

242242
_getZ(::Nothing, ::Int64) = nothing
243243
_getZ(Z::AbstractTensorMap, ::Int64) = Z
244-
_getZ(Z::Vector{AbstractTensorMap}, i::Int64) = Z[i]
244+
_getZ(Z::Vector, i::Int64) = Z[i]
245245
_getpspace(::Nothing, ::Int64) = nothing
246246
_getpspace(pspace::VectorSpace, ::Int64) = pspace
247-
_getpspace(pspace::Vector{VectorSpace}, i::Int64) = pspace[i]
247+
_getpspace(pspace::AbstractVector{<:VectorSpace}, i::Int64) = pspace[i]
248248

249249
_addZ!(O::LocalOperator, ::Nothing) = O
250250
function _addZ!(OR::LocalOperator{1, 1}, Z::AbstractTensorMap)

src/IntrTree/addIntr.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
Add an interaction characterized by `N` local operators at `si = (i, j, ...)` sites. `fermionic` indicates whether each operator is fermionic or not.
1414
1515
# Kwargs
16-
Z::Union{Nothing, AbstractTensorMap, Vector{<:AbstractTensorMap}}
17-
Provide the parity operator to deal with the fermionic anti-commutation relations.If `Z == nothing`, assume all operators are bosonic. Otherwise, a uniform (single operator) `Z::AbstractTensorMap` or site-dependent (length `L` vector) `Z::Vector{<:AbstractTensorMap}` should be given.
16+
Z::Union{Nothing, AbstractTensorMap, AbstractVector}
17+
Provide the parity operator to deal with the fermionic anti-commutation relations.If `Z == nothing`, assume all operators are bosonic. Otherwise, a uniform (single operator) `Z::AbstractTensorMap` or site-dependent (length `L` vector) `Z::AbstractVector` should be given.
1818
1919
pspace::Union{Nothing, VectorSpace, Vector{<:VectorSpace}}
2020
Provide the local Hilbert space (`VectorSpace` in `TensorKit.jl`). This is not required in generating Hamiltonian, so the default value is set as `nothing`. But some processes like generating an identity MPO require this information. In such cases, a uniform or site-dependent (length `L` vector) `pspace` should be given.
@@ -30,7 +30,7 @@ function addIntr!(Tree::InteractionTree{L},
3030
si::NTuple{N, Int64},
3131
fermionic::NTuple{N, Bool},
3232
strength::Number;
33-
Z::Union{Nothing, AbstractTensorMap, Vector{<:AbstractTensorMap}} = nothing,
33+
Z::Union{Nothing, AbstractTensorMap, AbstractVector} = nothing,
3434
pspace::Union{Nothing, VectorSpace, Vector{<:VectorSpace}} = nothing,
3535
name::NTuple{N, Union{Symbol, String}} = _default_IntrName(N),
3636
IntrName::Union{Symbol, String} = prod(string.(name)),
@@ -93,7 +93,7 @@ end
9393

9494
function addIntr!(Tree::InteractionTree{L},
9595
S::StringOperator,
96-
Z::Union{Nothing, AbstractTensorMap, Vector{<:AbstractTensorMap}},
96+
Z::Union{Nothing, AbstractTensorMap, AbstractVector},
9797
ref::Ref;
9898
pspace::Union{Nothing, VectorSpace, Vector{<:VectorSpace}} = nothing,
9999
) where L

src/Observables/addObs.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
Add an `N`-site observable to `Tree`, where the observable is characterized by `N`-tuples `Op`, `si` and `fermionic`. The implementation and usage is similar to `addIntr!`, except for the logic to deal with same operator which is added twice.
1313
1414
# Kwargs
15-
Z::Union{Nothing, AbstractTensorMap, Vector{<:AbstractTensorMap}}
16-
Provide the parity operator to deal with the fermionic anti-commutation relations.If `Z == nothing`, assume all operators are bosonic. Otherwise, a uniform (single operator) `Z::AbstractTensorMap` or site-dependent (length `L` vector) `Z::Vector{<:AbstractTensorMap}` should be given.
15+
Z::Union{Nothing, AbstractTensorMap, AbstractVector}
16+
Provide the parity operator to deal with the fermionic anti-commutation relations.If `Z == nothing`, assume all operators are bosonic. Otherwise, a uniform (single operator) `Z::AbstractTensorMap` or site-dependent (length `L` vector) `Z::AbstractVector` should be given.
1717
1818
pspace::Union{Nothing, VectorSpace, Vector{<:VectorSpace}}
1919
Provide the local Hilbert space (`VectorSpace` in `TensorKit.jl`). This is not required in generating Hamiltonian, so the default value is set as `nothing`. But some processes like generating an identity MPO require this information. In such cases, a uniform or site-dependent (length `L` vector) `pspace` should be given.
@@ -28,7 +28,7 @@ function addObs!(Tree::ObservableTree{L},
2828
Op::NTuple{N, AbstractTensorMap},
2929
si::NTuple{N, Int64},
3030
fermionic::NTuple{N, Bool};
31-
Z::Union{Nothing, AbstractTensorMap, Vector{<:AbstractTensorMap}} = nothing,
31+
Z::Union{Nothing, AbstractTensorMap, AbstractVector} = nothing,
3232
pspace::Union{Nothing, VectorSpace, Vector{<:VectorSpace}} = nothing,
3333
name::NTuple{N, Union{Symbol, String}} = _default_IntrName(N),
3434
IntrName::Union{Symbol, String} = prod(string.(name)),
@@ -78,7 +78,7 @@ end
7878

7979
function addObs!(Tree::ObservableTree{L},
8080
S::StringOperator,
81-
Z::Union{Nothing, AbstractTensorMap, Vector{<:AbstractTensorMap}},
81+
Z::Union{Nothing, AbstractTensorMap, AbstractVector},
8282
ref::Ref;
8383
pspace::Union{Nothing, VectorSpace, Vector{<:VectorSpace}} = nothing,
8484
) where L

0 commit comments

Comments
 (0)