Skip to content

Commit

Permalink
Bugfix similar(::FiniteMPS)
Browse files Browse the repository at this point in the history
  • Loading branch information
lkdvos committed Dec 1, 2023
1 parent 5acd494 commit 9b661d8
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/states/finitemps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@ struct FiniteMPS{A<:GenericMPSTensor,B<:MPSBondTensor} <: AbstractFiniteMPS
ARs::Vector{Union{Missing,A}}
ACs::Vector{Union{Missing,A}}
CLs::Vector{Union{Missing,B}}

function FiniteMPS{A,B}(
ALs::Vector{Union{Missing,A}},
ARs::Vector{Union{Missing,A}},
ACs::Vector{Union{Missing,A}},
CLs::Vector{Union{Missing,B}},
) where {A<:GenericMPSTensor,B<:MPSBondTensor}
return new{A,B}(ALs, ARs, ACs, CLs)
end
function FiniteMPS(
ALs::Vector{Union{Missing,A}},
ARs::Vector{Union{Missing,A}},
Expand Down Expand Up @@ -257,8 +264,8 @@ Base.size(Ψ::FiniteMPS, args...) = size(Ψ.ALs, args...)
Base.length::FiniteMPS) = length.ALs)
Base.eltype(Ψtype::Type{<:FiniteMPS}) = site_type(Ψtype) # this might not be true
Base.copy::FiniteMPS) = FiniteMPS(copy.ALs), copy.ARs), copy.ACs), copy.CLs))
function Base.similar::FiniteMPS)
return FiniteMPS(similar.ALs), similar.ARs), similar.ACs), similar.CLs))
function Base.similar::FiniteMPS{A,B}) where {A,B}
return FiniteMPS{A,B}(similar.ALs), similar.ARs), similar.ACs), similar.CLs))
end

function Base.convert(TType::Type{<:AbstractTensorMap}, Ψ::FiniteMPS)
Expand All @@ -270,6 +277,7 @@ end

site_type(::Type{<:FiniteMPS{A}}) where {A} = A
bond_type(::Type{<:FiniteMPS{<:Any,B}}) where {B} = B
TensorKit.storagetype(::Union{MPS,Type{MPS}}) where {A,MPS<:FiniteMPS{A}} = storagetype(A)

function left_virtualspace::FiniteMPS, n::Integer)
if n > 0 && !ismissing.ALs[n])
Expand Down Expand Up @@ -435,7 +443,7 @@ function Base.:+(Ψ₁::MPS, Ψ₂::MPS) where {MPS<:FiniteMPS}
fill!.ARs, missing)
fill!.ACs, missing)
fill!.CLs, missing)

halfN = div(length(Ψ), 2)

# left half
Expand All @@ -455,13 +463,13 @@ function Base.:+(Ψ₁::MPS, Ψ₂::MPS) where {MPS<:FiniteMPS}
AL₂ = _transpose_front(F₂ * _transpose_tail(Ψ₂.AL[i]))

F₁ = isometry(
storagetype(Ψ), _lastspace(AL₁) _lastspace(Ψ₂.AL[i]), _lastspace(AL₁)
storagetype(Ψ), (_lastspace(AL₁) _lastspace(Ψ₂.AL[i]))', _lastspace(AL₁)'
)
F₂ = leftnull(F₁)
@assert _lastspace(F₂) == (_lastspace(Ψ₂.AL[i]))
@assert _lastspace(F₂) == _lastspace(Ψ₂.AL[i])

AL = _transpose_front(R * _transpose_tail(AL₁ * F₁' + AL₂ * F₂'))
Ψ.ALs[i], R = leftorth!(AL)
Ψ.ALs[i], R = leftorth!(AL)
end

C₁ = F₁ * Ψ₁.CR[halfN]
Expand Down

0 comments on commit 9b661d8

Please sign in to comment.