Skip to content

Commit

Permalink
CompatHelper: bump compat for ITensors to 0.7, (keep existing compat) (
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Oct 27, 2024
1 parent fc1078a commit 33c38cf
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 53 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ SplitApplyCombine = "03a91e81-4c3e-53e1-a0a4-9c0c8f19dd66"
[compat]
Compat = "3, 4"
HDF5 = "0.15, 0.16, 0.17"
ITensorMPS = "0.2.2"
ITensors = "0.6.8"
ITensorMPS = "0.3"
ITensors = "0.7"
Infinities = "0.1"
IterTools = "1"
KrylovKit = "0.5, 0.6, 0.7, 0.8"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function energy_local(ψ1, ψ2, h)
return (noprime* h) * dag(ϕ))[]
end

function ITensors.expect(ψ, o)
function ITensorMPS.expect(ψ, o)
return (noprime* op(o, filterinds(ψ, "Site")...)) * dag(ψ))[]
end

Expand Down
2 changes: 1 addition & 1 deletion examples/vumps/transfer_matrix_spectrum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function energy_local(ψ1, ψ2, h)
return inner(ϕ, apply(h, ϕ))
end

function ITensors.expect::ITensor, o::String)
function ITensorMPS.expect::ITensor, o::String)
return inner(ψ, apply(op(o, filterinds(ψ, "Site")...), ψ))
end

Expand Down
2 changes: 1 addition & 1 deletion examples/vumps/vumps_heisenberg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ energy_finite_total, ψfinite = dmrg(Hfinite, ψfinite; nsweeps, maxdim, cutoff)

energy_exact_finite = reference(model, Observable("energy"); N=Nfinite)

function ITensors.expect::ITensor, o::String)
function ITensorMPS.expect::ITensor, o::String)
return inner(ψ, apply(op(o, filterinds(ψ, "Site")...), ψ))
end

Expand Down
6 changes: 3 additions & 3 deletions examples/vumps/vumps_hubbard_extended.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ bsfinite = [(nfinite, nfinite + 1), (nfinite + 1, nfinite + 2)]
hfinite(b) = ITensor(model, [sfinite[b[1]], sfinite[b[2]]]; model_params...)
energy_finite = map(b -> expect_two_site(ψfinite, hfinite(b), b), bsfinite)

Nup_finite = ITensors.expect(ψfinite, "Nup")[nfinite:(nfinite + 1)]
Ndn_finite = ITensors.expect(ψfinite, "Ndn")[nfinite:(nfinite + 1)]
Sz_finite = ITensors.expect(ψfinite, "Sz")[nfinite:(nfinite + 1)]
Nup_finite = ITensorMPS.expect(ψfinite, "Nup")[nfinite:(nfinite + 1)]
Ndn_finite = ITensorMPS.expect(ψfinite, "Ndn")[nfinite:(nfinite + 1)]
Sz_finite = ITensorMPS.expect(ψfinite, "Sz")[nfinite:(nfinite + 1)]

energy_exact = reference(model, Observable("energy"); U=model_params.U / model_params.t)

Expand Down
2 changes: 1 addition & 1 deletion examples/vumps/vumps_ising.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ end

energy_local(ψ1, ψ2, h::MPO) = energy_local(ψ1, ψ2, prod(h))

function ITensors.expect(ψ, o)
function ITensorMPS.expect(ψ, o)
return (noprime* op(o, filterinds(ψ, "Site")...)) * dag(ψ))[]
end

Expand Down
3 changes: 2 additions & 1 deletion src/ITensorInfiniteMPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ using KrylovKit: eigsolve, linsolve, exponentiate

import Base: getindex, length, setindex!, +, -, *

import ITensors: AbstractMPS,
using ITensorMPS: AbstractMPS
import ITensors:

include("ITensors.jl")
include("ITensorNetworks.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/ITensorNetworks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ end

ITensors.inds(tn::ITensorNetwork, ij::Pair{<:Integer,<:Integer}) = inds(tn)[ij]

function ITensors.linkinds(tn::ITensorNetwork, ij::Pair{<:Integer,<:Integer})
function ITensorMPS.linkinds(tn::ITensorNetwork, ij::Pair{<:Integer,<:Integer})
i, j = ij
@assert i j
return inds(tn, ij)
Expand Down
20 changes: 10 additions & 10 deletions src/abstractinfinitemps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,26 +186,26 @@ function ITensors.dag(ψ::AbstractInfiniteMPS)
return typeof(ψ)(ψdag, translator(ψ); reverse=ψ.reverse)
end

ITensors.linkinds::AbstractInfiniteMPS, n1n2) = linkinds(ψ, Pair(n1n2...))
ITensorMPS.linkinds::AbstractInfiniteMPS, n1n2) = linkinds(ψ, Pair(n1n2...))

function ITensors.linkinds::AbstractInfiniteMPS, n1n2::Pair{<:Integer,<:Integer})
function ITensorMPS.linkinds::AbstractInfiniteMPS, n1n2::Pair{<:Integer,<:Integer})
return commoninds(ψ[n1n2[1]], ψ[n1n2[2]])
end

function ITensors.linkind::AbstractInfiniteMPS, n1n2::Pair{<:Integer,<:Integer})
function ITensorMPS.linkind::AbstractInfiniteMPS, n1n2::Pair{<:Integer,<:Integer})
return commonind(ψ[n1n2[1]], ψ[n1n2[2]])
end

function ITensors.siteind::AbstractInfiniteMPS, n::Integer)
function ITensorMPS.siteind::AbstractInfiniteMPS, n::Integer)
return uniqueind(ψ[n], ψ[n - 1], ψ[n + 1])
end

function ITensors.siteinds::AbstractInfiniteMPS, n::Integer)
function ITensorMPS.siteinds::AbstractInfiniteMPS, n::Integer)
return uniqueinds(ψ[n], ψ[n - 1], ψ[n + 1])
end

# TODO: return a Dictionary or IndexSetNetwork?
function ITensors.siteinds::AbstractInfiniteMPS, r::AbstractRange)
function ITensorMPS.siteinds::AbstractInfiniteMPS, r::AbstractRange)
return [siteind(ψ, n) for n in r]
end

Expand All @@ -216,9 +216,9 @@ function siterange(ψ::AbstractInfiniteMPS, c::Cell)
return start:stop
end

ITensors.siteinds::AbstractInfiniteMPS, c::Cell) = siteinds(ψ, siterange(ψ, c))
ITensorMPS.siteinds::AbstractInfiniteMPS, c::Cell) = siteinds(ψ, siterange(ψ, c))

function ITensors.siteinds::AbstractInfiniteMPS)
function ITensorMPS.siteinds::AbstractInfiniteMPS)
return CelledVector(siteinds(ψ, Cell(1)), translator(ψ))
end
infsiteinds::AbstractInfiniteMPS) = siteinds(ψ)
Expand All @@ -238,12 +238,12 @@ end

(::Colon)(n::Int, f::typeof(nsites)) = UnitRangeToFunction(n, f)

function ITensors.linkinds(f::typeof(only), ψ::AbstractInfiniteMPS)
function ITensorMPS.linkinds(f::typeof(only), ψ::AbstractInfiniteMPS)
N = nsites(ψ)
return CelledVector([f(commoninds(ψ[n], ψ[n + 1])) for n in 1:N], translator(ψ))
end

function ITensors.siteinds(f::typeof(only), ψ::AbstractInfiniteMPS)
function ITensorMPS.siteinds(f::typeof(only), ψ::AbstractInfiniteMPS)
N = nsites(ψ)
return CelledVector([f(uniqueinds(ψ[n], ψ[n - 1], ψ[n + 1])) for n in 1:N], translator(ψ))
end
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
48 changes: 24 additions & 24 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})
return sort([ITensors.findfirstsiteind(ψ, i) for i in is])
function ITensorMPS.findsites::InfiniteCanonicalMPS, is::Union{<:Tuple,<:Vector})
return sort([ITensorMPS.findfirstsiteind(ψ, i) for i in is])
end
function ITensors.findsites::InfiniteMPS, is::Union{<:Tuple,<:Vector})
return sort([ITensors.findfirstsiteind(ψ, i) for i in is])
function ITensorMPS.findsites::InfiniteMPS, is::Union{<:Tuple,<:Vector})
return sort([ITensorMPS.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])
return sort([ITensorMPS.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])
return sort([ITensorMPS.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,14 +223,14 @@ 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])
return sort([ITensorMPS.findfirstsiteind(h, i, ncell) for i in s])
end

## HDF5 support for the InfiniteCanonicalMPS type
Expand Down
2 changes: 1 addition & 1 deletion src/models/models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function InfiniteBlockMPO(model::Model, s::CelledVector, translator::Function; k
return mpos
end

function ITensors.MPO(model::Model, s::Vector{<:Index}; kwargs...)
function ITensorMPS.MPO(model::Model, s::Vector{<:Index}; kwargs...)
opsum = opsum_finite(model, length(s); kwargs...)
return splitblocks(linkinds, MPO(opsum, s))
end
Expand Down
2 changes: 1 addition & 1 deletion src/orthogonalize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function mixed_canonical(
return InfiniteCanonicalMPS(ψᴸ, C, ψᴿ)
end

ITensors.orthogonalize::InfiniteMPS, ::Colon; kwargs...) = mixed_canonical(ψ; kwargs...)
ITensorMPS.orthogonalize::InfiniteMPS, ::Colon; kwargs...) = mixed_canonical(ψ; kwargs...)

#TODO put these functions somewhere else
function ortho_overlap(AC, C)
Expand Down
4 changes: 2 additions & 2 deletions test/test_iMPOConversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ end
# Terminate and then call expect
# for inf ψ and finite h, which is already supported in src/infinitecanonicalmps.jl
#
function ITensors.expect::InfiniteCanonicalMPS, h::InfiniteMPO)
function ITensorMPS.expect::InfiniteCanonicalMPS, h::InfiniteMPO)
return expect(ψ, terminate(h)) #defer to src/infinitecanonicalmps.jl
end

Expand All @@ -82,7 +82,7 @@ function generate_edges(h::InfiniteBlockMPO)
return Ls, Rs
end

function ITensors.expect::InfiniteCanonicalMPS, h::InfiniteBlockMPO)
function ITensorMPS.expect::InfiniteCanonicalMPS, h::InfiniteBlockMPO)
Ncell = nsites(h)
L, R = generate_edges(h)
l = commoninds.AL[0], ψ.AL[1])
Expand Down

0 comments on commit 33c38cf

Please sign in to comment.