Skip to content

Commit

Permalink
Fix more namespace issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman committed Oct 26, 2024
1 parent cd6afc4 commit 3345413
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
8 changes: 4 additions & 4 deletions src/infinitecanonicalmps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function infsiteinds(
return infsiteinds(s, translator)
end

function ITensors.linkinds::InfiniteMPS)
function ITensorMPS.linkinds::InfiniteMPS)
N = nsites(ψ)
return CelledVector([linkinds(ψ, (n, n + 1)) for n in 1:N], translator(ψ))
end
Expand Down Expand Up @@ -266,14 +266,14 @@ function finite_mps(ψ::InfiniteCanonicalMPS, range::AbstractRange)
set_ortho_lims!(ψ_finite, (N + 1):(N + 1))
return ψ_finite
end
function ITensors.expect::InfiniteCanonicalMPS, o::String, n::Int)
function ITensorMPS.expect::InfiniteCanonicalMPS, o::String, n::Int)
s = siteinds(only, ψ.AL)
O = op(o, s[n])
ϕ = ψ.AL[n] * ψ.C[n]
return inner(ϕ, apply(O, ϕ))
end

function ITensors.expect::InfiniteCanonicalMPS, h::MPO)
function ITensorMPS.expect::InfiniteCanonicalMPS, h::MPO)
l = linkinds(ITensorInfiniteMPS.only, ψ.AL)
r = linkinds(ITensorInfiniteMPS.only, ψ.AR)
s = siteinds(ITensorInfiniteMPS.only, ψ)
Expand All @@ -298,6 +298,6 @@ function ITensors.expect(ψ::InfiniteCanonicalMPS, h::MPO)
return temp_O[]
end

function ITensors.expect::InfiniteCanonicalMPS, h::InfiniteSum)
function ITensorMPS.expect::InfiniteCanonicalMPS, h::InfiniteSum)
return [expect(ψ, h[j]) for j in 1:nsites(ψ)]
end
38 changes: 19 additions & 19 deletions src/infinitemps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ function ITensors.dag(ψ::InfiniteCanonicalMPS, args...; kwargs...)
return fmap(x -> dag(x, args...; kwargs...), ψ)
end

ITensors.siteinds(f::typeof(only), ψ::InfiniteCanonicalMPS) = siteinds(f, ψ.AL)
ITensorMPS.siteinds(f::typeof(only), ψ::InfiniteCanonicalMPS) = siteinds(f, ψ.AL)

getcell(i::Index) = ITensorInfiniteMPS.getcell(tags(i))
getsite(i::Index) = getsite(tags(i))

#Before, for a two site Hamiltonian, findsites(ψ, H[3]) would return [1, 2]
#Appeared unsafe for index purpose
function ITensors.findfirstsiteind::InfiniteMPS, i::Index)
function ITensorMPS.findfirstsiteind::InfiniteMPS, i::Index)
c = ITensorInfiniteMPS.getcell(i)
n1 = getsite(i)
# if translator(ψ) == translatecelltags
Expand Down Expand Up @@ -95,28 +95,28 @@ function ITensors.findfirstsiteind(ψ::InfiniteMPS, i::Index)
# return 0
# end
end
function ITensors.findfirstsiteind::InfiniteCanonicalMPS, i::Index)
return ITensors.findfirstsiteind.AL, i)
function ITensorMPS.findfirstsiteind::InfiniteCanonicalMPS, i::Index)
return ITensorMPS.findfirstsiteind.AL, i)
end

function ITensors.findsites::InfiniteCanonicalMPS, is::Union{<:Tuple,<:Vector})
function ITensorMPS.findsites::InfiniteCanonicalMPS, is::Union{<:Tuple,<:Vector})
return sort([ITensors.findfirstsiteind(ψ, i) for i in is])
end
function ITensors.findsites::InfiniteMPS, is::Union{<:Tuple,<:Vector})
function ITensorMPS.findsites::InfiniteMPS, is::Union{<:Tuple,<:Vector})
return sort([ITensors.findfirstsiteind(ψ, i) for i in is])
end
function ITensors.findsites::InfiniteMPS, T::MPO)
function ITensorMPS.findsites::InfiniteMPS, T::MPO)
s = [noprime(filterinds(T[x]; plev=1)[1]) for x in 1:length(T)]
return sort([ITensors.findfirstsiteind(ψ, i) for i in s])
end
ITensors.findsites::InfiniteCanonicalMPS, T::MPO) = findsites.AL, T)
ITensorMPS.findsites::InfiniteCanonicalMPS, T::MPO) = findsites.AL, T)

#Kept for historical reason
function ITensors.findsites::InfiniteMPS, T::ITensor)
function ITensorMPS.findsites::InfiniteMPS, T::ITensor)
s = filterinds(T; plev=0)
return sort([ITensors.findfirstsiteind(ψ, i) for i in s])
end
ITensors.findsites::InfiniteCanonicalMPS, T::ITensor) = findsites.AL, T)
ITensorMPS.findsites::InfiniteCanonicalMPS, T::ITensor) = findsites.AL, T)

# For now, only represents nearest neighbor interactions
# on a linear chain
Expand Down Expand Up @@ -193,20 +193,20 @@ function nrange(h::MPO; ncell=1)
return ns[end] - ns[1] + 1
end

ITensors.findsites(h::InfiniteSum) = [findsites(h, n) for n in 1:nsites(h)]
ITensors.findsites(h::InfiniteSum, n::Int64) = findsites(h.data[n]; ncell=nsites(h))
#ITensors.findsites(h::InfiniteSum, is::Union{<:Tuple,<:Vector}) = [findsites(h.data[n], is) for n in 1:nsites(h)]
#ITensors.findsites(h::InfiniteSum, i::Index) = [findsites(h.data[n], i) for n in 1:nsites(h)]
ITensorMPS.findsites(h::InfiniteSum) = [findsites(h, n) for n in 1:nsites(h)]
ITensorMPS.findsites(h::InfiniteSum, n::Int64) = findsites(h.data[n]; ncell=nsites(h))
#ITensorMPS.findsites(h::InfiniteSum, is::Union{<:Tuple,<:Vector}) = [findsites(h.data[n], is) for n in 1:nsites(h)]
#ITensorMPS.findsites(h::InfiniteSum, i::Index) = [findsites(h.data[n], i) for n in 1:nsites(h)]
#TODO improve the findsites routines for Infinite Sum

function ITensors.findfirstsiteind(i::Index, ncell::Int64)
function ITensorMPS.findfirstsiteind(i::Index, ncell::Int64)
c = ITensorInfiniteMPS.getcell(i)
n1 = getsite(i)
return (c - 1) * ncell + n1
end
function ITensors.findsites(h::MPO; ncell::Int64=1)
function ITensorMPS.findsites(h::MPO; ncell::Int64=1)
s = [filterinds(h[x]; plev=1)[1] for x in 1:length(h)]
return sort([ITensors.findfirstsiteind(i, ncell) for i in s])
return sort([ITensorMPS.findfirstsiteind(i, ncell) for i in s])
end

#Kept for historical reasons
Expand All @@ -223,12 +223,12 @@ function nrange(ψ::InfiniteCanonicalMPS, h::MPO)
return ns[end] - ns[1] + 1
end

function ITensors.findfirstsiteind(h::ITensor, i::Index, ncell::Int64)
function ITensorMPS.findfirstsiteind(h::ITensor, i::Index, ncell::Int64)
c = getcell(i)
n1 = getsite(i)
return (c - 1) * ncell + n1
end
function ITensors.findsites(h::ITensor; ncell::Int64=1)
function ITensorMPS.findsites(h::ITensor; ncell::Int64=1)
s = filterinds(h; plev=0)
return sort([ITensors.findfirstsiteind(h, i, ncell) for i in s])
end
Expand Down

0 comments on commit 3345413

Please sign in to comment.