Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 80 additions & 3 deletions src/states/abstractmps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const MPSTensor{S} = GenericMPSTensor{S, 2} # the usual mps tensors on which we

"""
MPSTensor([f, eltype], d::Int, left_D::Int, [right_D]::Int])
MPSTensor([f, eltype], physicalspace::Union{S,CompositeSpace{S}},
MPSTensor([f, eltype], physicalspace::Union{S,CompositeSpace{S}},
left_virtualspace::S, [right_virtualspace]::S) where {S<:ElementarySpace}

Construct an `MPSTensor` with given physical and virtual spaces.
Expand Down Expand Up @@ -164,6 +164,8 @@ If this hasn't been computed before, this can be computed as:
- `kind=:ALAC` : AL[i] * AC[i+1]
""" AC2

AC2(psi::AbstractMPS, site::Int; kwargs...) = AC2(GeometryStyle(psi), psi, site; kwargs...)

#===========================================================================================
MPS types
===========================================================================================#
Expand Down Expand Up @@ -202,7 +204,7 @@ TensorKit.sectortype(ψtype::Type{<:AbstractMPS}) = sectortype(site_type(ψtype)

"""
left_virtualspace(ψ::AbstractMPS, [pos=1:length(ψ)])

Return the virtual space of the bond to the left of sites `pos`.

!!! warning
Expand Down Expand Up @@ -245,4 +247,79 @@ physicalspace(ψ::AbstractMPS) = map(Base.Fix1(physicalspace, ψ), eachsite(ψ))

Return an iterator over the sites of the MPS `state`.
"""
eachsite(ψ::AbstractMPS) = eachindex(ψ)
eachsite(ψ::AbstractMPS) = eachsite(GeometryStyle(ψ), ψ)

eachsite(::GeometryStyle, ψ::AbstractMPS) = eachindex(ψ)

# TensorKit utility
# -----------------

function TensorKit.dot(ψ₁::AbstractMPS, ψ₂::AbstractMPS; kwargs...)
geometry_style = GeometryStyle(ψ₁) & GeometryStyle(ψ₂)
return TensorKit.dot(geometry_style, ψ₁, ψ₂; kwargs...)
end
function Base.isapprox(ψ₁::AbstractMPS, ψ₂::AbstractMPS; kwargs...)
return isapprox(dot(ψ₁, ψ₂), 1; kwargs...)
end
TensorKit.norm(ψ::AbstractMPS) = TensorKit.norm(GeometryStyle(ψ), ψ)
TensorKit.normalize!(ψ::AbstractMPS) = TensorKit.normalize!(GeometryStyle(ψ), ψ)
TensorKit.normalize(ψ::AbstractMPS) = normalize!(copy(ψ))
#===========================================================================================
Fixedpoints
===========================================================================================#

"""
l_RR(ψ, location)

Left dominant eigenvector of the `AR`-`AR` transfermatrix.
"""
l_RR(ψ::AbstractMPS, loc::Int = 1) = l_RR(GeometryStyle(ψ), ψ, loc)

"""
l_RL(ψ, location)

Left dominant eigenvector of the `AR`-`AL` transfermatrix.
"""
l_RL(ψ::AbstractMPS, loc::Int = 1) = l_RL(GeometryStyle(ψ), ψ, loc)

"""
l_LR(ψ, location)

Left dominant eigenvector of the `AL`-`AR` transfermatrix.
"""
l_LR(ψ::AbstractMPS, loc::Int = 1) = l_LR(GeometryStyle(ψ), ψ, loc)

"""
l_LL(ψ, location)

Left dominant eigenvector of the `AL`-`AL` transfermatrix.
"""
l_LL(ψ::AbstractMPS, loc::Int = 1) = l_LL(GeometryStyle(ψ), ψ, loc)

"""
r_RR(ψ, location)

Right dominant eigenvector of the `AR`-`AR` transfermatrix.
"""
r_RR(ψ::AbstractMPS, loc::Int = length(ψ)) = r_RR(GeometryStyle(ψ), ψ, loc)

"""
r_RL(ψ, location)

Right dominant eigenvector of the `AR`-`AL` transfermatrix.
"""
r_RL(ψ::AbstractMPS, loc::Int = length(ψ)) = r_RL(GeometryStyle(ψ), ψ, loc)

"""
r_LR(ψ, location)

Right dominant eigenvector of the `AL`-`AR` transfermatrix.
"""
r_LR(ψ::AbstractMPS, loc::Int = length(ψ)) = r_LR(GeometryStyle(ψ), ψ, loc)

"""
r_LL(ψ, location)

Right dominant eigenvector of the `AL`-`AL` transfermatrix.
"""
r_LL(ψ::AbstractMPS, loc::Int = length(ψ)) = r_LL(GeometryStyle(ψ), ψ, loc)
12 changes: 12 additions & 0 deletions src/utility/styles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Trait to describe the operator behavior of the input `x` or type `T`, which can
abstract type OperatorStyle end
OperatorStyle(x) = OperatorStyle(typeof(x))
OperatorStyle(T::Type) = throw(MethodError(OperatorStyle, T)) # avoid stackoverflow if not defined
OperatorStyle(x::OperatorStyle) = x

OperatorStyle(x, y) = OperatorStyle(OperatorStyle(x)::OperatorStyle, OperatorStyle(y)::OperatorStyle)
OperatorStyle(::T, ::T) where {T <: OperatorStyle} = T()
OperatorStyle(x::OperatorStyle, y::OperatorStyle) = error("Unknown combination of operator styles $x and $y")
@inline OperatorStyle(x, y, zs...) = OperatorStyle(OperatorStyle(x, y), zs...)

struct MPOStyle <: OperatorStyle end
struct HamiltonianStyle <: OperatorStyle end
Expand All @@ -29,6 +35,12 @@ Trait to describe the geometry of the input `x` or type `T`, which can be either
abstract type GeometryStyle end
GeometryStyle(x) = GeometryStyle(typeof(x))
GeometryStyle(T::Type) = throw(MethodError(GeometryStyle, T)) # avoid stackoverflow if not defined
GeometryStyle(x::GeometryStyle) = x

GeometryStyle(x, y) = GeometryStyle(GeometryStyle(x)::GeometryStyle, GeometryStyle(y)::GeometryStyle)
GeometryStyle(::T, ::T) where {T <: GeometryStyle} = T()
GeometryStyle(x::GeometryStyle, y::GeometryStyle) = error("Unknown combination of geometry styles $x and $y")
@inline GeometryStyle(x, y, zs...) = GeometryStyle(GeometryStyle(x, y), zs...)

struct FiniteChainStyle <: GeometryStyle end
struct InfiniteChainStyle <: GeometryStyle end
Expand Down
5 changes: 5 additions & 0 deletions test/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ module TestOperators
mps₁ = FiniteMPS(ψ₁)
mps₂ = FiniteMPS(ψ₂)

@test @constinferred GeometryStyle(mps₁, mpo₁, mps₁) == GeometryStyle(mps₁)

@test convert(TensorMap, mpo₁ * mps₁) ≈ O₁ * ψ₁
@test mpo₁ * ψ₁ ≈ O₁ * ψ₁
@test convert(TensorMap, mpo₃ * mps₁) ≈ O₃ * ψ₁
Expand Down Expand Up @@ -140,6 +142,7 @@ module TestOperators
@test GeometryStyle(H) == FiniteChainStyle()
@test OperatorStyle(typeof(H)) == HamiltonianStyle()
@test OperatorStyle(H) == HamiltonianStyle()
@test OperatorStyle(H, H′) == OperatorStyle(H)

# Infinite
Ws = [Wmid]
Expand Down Expand Up @@ -410,6 +413,8 @@ module TestOperators
ψ = InfiniteMPS([pspace], [ou ⊕ pspace])

W = MPSKit.DenseMPO(make_time_mpo(ham, 1im * 0.5, WII()))

@test GeometryStyle(ψ, W) == GeometryStyle(ψ)
@test W * (W * ψ) ≈ (W * W) * ψ atol = 1.0e-2 # TODO: there is a normalization issue here
end

Expand Down
9 changes: 9 additions & 0 deletions test/other.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ module TestMiscellaneous

@test OperatorStyle(MPO) == MPOStyle()
@test OperatorStyle(InfiniteMPO) == MPOStyle()
@test OperatorStyle(HamiltonianStyle()) == HamiltonianStyle()
@test @constinferred OperatorStyle(MPO, InfiniteMPO, MPO) == MPOStyle()
@test_throws ErrorException OperatorStyle(MPO, HamiltonianStyle())

@test GeometryStyle(FiniteMPOHamiltonian) == FiniteChainStyle()
@test GeometryStyle(InfiniteMPS) == InfiniteChainStyle()
Expand All @@ -120,5 +123,11 @@ module TestMiscellaneous
@test GeometryStyle(FiniteMPOHamiltonian) == FiniteChainStyle()
@test GeometryStyle(InfiniteMPO) == InfiniteChainStyle()
@test GeometryStyle(InfiniteMPOHamiltonian) == InfiniteChainStyle()

@test GeometryStyle(GeometryStyle(FiniteMPS)) == GeometryStyle(FiniteMPS)
@test GeometryStyle(FiniteMPS, FiniteMPO) == FiniteChainStyle()
@test_throws ErrorException GeometryStyle(FiniteMPS, InfiniteMPO)
@test @constinferred GeometryStyle(InfiniteMPS, InfiniteMPO, InfiniteMPS) == InfiniteChainStyle()
@test_throws ErrorException GeometryStyle(FiniteMPS, FiniteMPO, InfiniteMPS)
end
end
Loading