Skip to content

Commit

Permalink
Merge pull request #60 from iitis/lp/identities
Browse files Browse the repository at this point in the history
Introduce the concpept of identity MPS and MPO
  • Loading branch information
bartekGardas committed Feb 9, 2021
2 parents 63f8f67 + 7833f48 commit 56b120c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/SpinGlassPEPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module SpinGlassPEPS
include("utils.jl")
include("compressions.jl")
include("contractions.jl")
include("identities.jl")
include("lattice.jl")
#include("graphs/chimera.jl")
#include("graphs/lattice.jl")
Expand Down
3 changes: 2 additions & 1 deletion src/contractions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ function LinearAlgebra.dot(ϕ::AbstractMPS, O::Union{Vector, NTuple}, ψ::Abstra
end


function LinearAlgebra.dot(O::AbstractMPO, ψ::T) where {T <: AbstractMPS}
function LinearAlgebra.dot(O::AbstractMPO, ψ::AbstractMPS)
L = length(ψ)
S = promote_type(eltype(ψ), eltype(O))
T = typeof(ψ)
ϕ = T.name.wrapper(S, L)

for i 1:L
Expand Down
26 changes: 26 additions & 0 deletions src/identities.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export IdentityMPO, IdentityMPS
struct IdentityMPS{T <: Number} <: AbstractMPS{T} end
struct IdentityMPO{T <: Number} <: AbstractMPO{T} end

@inline Base.getindex(::IdentityMPS{T}, ::Int) where {T} = ones(T, 1, 1, 1)
@inline Base.getindex(::IdentityMPO{T}, ::Int) where {T} = ones(T, 1, 1, 1, 1)

MPS(::UniformScaling{T}) where {T} = IdentityMPS{T}()
MPO(::UniformScaling{T}) where {T} = IdentityMPO{T}()

LinearAlgebra.dot(O::AbstractMPO, ::IdentityMPO) = O
LinearAlgebra.dot(::IdentityMPO, O::AbstractMPO) = O

function LinearAlgebra.dot(O::AbstractMPO, ::IdentityMPS)
L = length(O)
T = eltype(O)
ψ = MPS(T, L)
for i eachindex(ψ)
B = O[i]
@reduce A[x, σ, y] |= sum(η) B[x, σ, y, η]
ψ[i] = A
end
ψ
end

LinearAlgebra.dot(::IdentityMPO, ψ::AbstractMPS) = ψ
21 changes: 21 additions & 0 deletions test/identities.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@testset "multiplication of identities" begin
ψ = randn(MPS{Float64}, 4, 3, 2)
O = randn(MPO{Float64}, 4, 3, 2)

IMPS = MPS(I)
IMPO = MPO(I)

@test IMPO * ψ == ψ
@test IMPO * O == O

ϕ = O * IMPS

@test typeof(ϕ) == MPS{Float64}
@test length(ϕ) == length(O)

for i eachindex(O)
@test ϕ[i] == dropdims(sum(O[i], dims=4), dims=4)
end

@test IMPO === MPO(I)
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ push!(my_tests,
"utils.jl",
"contractions.jl",
"compressions.jl",
"identities.jl",
"ising.jl",
"indexing.jl",
"searchMPS.jl",
Expand Down

0 comments on commit 56b120c

Please sign in to comment.