diff --git a/src/Tensors/linearalgebra.jl b/src/Tensors/linearalgebra.jl index 80ed2cee09..0e1a7aab39 100644 --- a/src/Tensors/linearalgebra.jl +++ b/src/Tensors/linearalgebra.jl @@ -60,14 +60,38 @@ svd of an order-2 DenseTensor """ function LinearAlgebra.svd(T::DenseTensor{ElT,2,IndsT}; kwargs...) where {ElT,IndsT} + # Keyword argument deprecations + use_absolute_cutoff = false + if haskey(kwargs, :absoluteCutoff) + @warn "In svd, keyword argument absoluteCutoff is deprecated in favor of use_absolute_cutoff" + use_absolute_cutoff = get(kwargs, + :absoluteCutoff, + use_absolute_cutoff) + end + use_relative_cutoff = true + if haskey(kwargs, :doRelCutoff) + @warn "In svd, keyword argument doRelCutoff is deprecated in favor of use_relative_cutoff" + use_relative_cutoff = get(kwargs, + :doRelCutoff, + use_relative_cutoff) + end + if haskey(kwargs, :fastSVD) + @warn "In svd, keyword argument fastSVD is deprecated in favor of fastsvd" + fastsvd = get(kwargs, :fastsvd, true) + end + maxdim::Int = get(kwargs,:maxdim,minimum(dims(T))) mindim::Int = get(kwargs,:mindim,1) cutoff::Float64 = get(kwargs,:cutoff,0.0) - absoluteCutoff::Bool = get(kwargs,:absoluteCutoff,false) - doRelCutoff::Bool = get(kwargs,:doRelCutoff,true) - fastSVD::Bool = get(kwargs,:fastSVD,false) + use_absolute_cutoff::Bool = get(kwargs, + :use_absolute_cutoff, + use_absolute_cutoff) + use_relative_cutoff::Bool = get(kwargs, + :use_relative_cutoff, + use_relative_cutoff) + fastsvd::Bool = get(kwargs,:fastsvd,false) - if fastSVD + if fastsvd MU,MS,MV = svd(matrix(T)) else MU,MS,MV = svd_recursive(matrix(T)) @@ -78,8 +102,8 @@ function LinearAlgebra.svd(T::DenseTensor{ElT,2,IndsT}; truncerr,_ = truncate!(P;mindim=mindim, maxdim=maxdim, cutoff=cutoff, - absoluteCutoff=absoluteCutoff, - doRelCutoff=doRelCutoff) + use_absolute_cutoff=use_absolute_cutoff, + use_relative_cutoff=use_relative_cutoff) spec = Spectrum(P,truncerr) dS = length(P) if dS < length(MS) @@ -102,12 +126,32 @@ end function LinearAlgebra.eigen(T::Hermitian{ElT,<:DenseTensor{ElT,2,IndsT}}; kwargs...) where {ElT<:Union{Real,Complex},IndsT} + # Keyword argument deprecations + use_absolute_cutoff = false + if haskey(kwargs, :absoluteCutoff) + @warn "In svd, keyword argument absoluteCutoff is deprecated in favor of use_absolute_cutoff" + use_absolute_cutoff = get(kwargs, + :absoluteCutoff, + use_absolute_cutoff) + end + use_relative_cutoff = true + if haskey(kwargs, :doRelCutoff) + @warn "In svd, keyword argument doRelCutoff is deprecated in favor of use_relative_cutoff" + use_relative_cutoff = get(kwargs, + :doRelCutoff, + use_relative_cutoff) + end + truncate = haskey(kwargs,:maxdim) || haskey(kwargs,:cutoff) maxdim::Int = get(kwargs,:maxdim,minimum(dims(T))) mindim::Int = get(kwargs,:mindim,1) cutoff::Float64 = get(kwargs,:cutoff,0.0) - absoluteCutoff::Bool = get(kwargs,:absoluteCutoff,false) - doRelCutoff::Bool = get(kwargs,:doRelCutoff,true) + use_absolute_cutoff::Bool = get(kwargs, + :use_absolute_cutoff, + use_absolute_cutoff) + use_relative_cutoff::Bool = get(kwargs, + :use_relative_cutoff, + use_relative_cutoff) DM,UM = eigen(matrix(T)) @@ -119,8 +163,8 @@ function LinearAlgebra.eigen(T::Hermitian{ElT,<:DenseTensor{ElT,2,IndsT}}; if truncate truncerr,_ = truncate!(DM;maxdim=maxdim, cutoff=cutoff, - absoluteCutoff=absoluteCutoff, - doRelCutoff=doRelCutoff) + use_absolute_cutoff=use_absolute_cutoff, + use_relative_cutoff=use_relative_cutoff) dD = length(DM) if dD < size(UM,2) UM = UM[:,1:dD] @@ -156,7 +200,6 @@ function LinearAlgebra.eigen(T::DenseTensor{ElT,2,IndsT}; return U,D end - function qr_positive(M::AbstractMatrix) sparseQ,R = qr(M) Q = convert(Matrix,sparseQ) @@ -172,14 +215,32 @@ end function LinearAlgebra.eigen(T::DenseTensor{ElT,2,IndsT}; kwargs...) where {ElT<:Union{Real,Complex},IndsT} - #ispossemidef::Bool = get(kwargs,:ispossemidef,false) + # Keyword argument deprecations + use_absolute_cutoff = false + if haskey(kwargs, :absoluteCutoff) + @warn "In svd, keyword argument absoluteCutoff is deprecated in favor of use_absolute_cutoff" + use_absolute_cutoff = get(kwargs, + :absoluteCutoff, + use_absolute_cutoff) + end + use_relative_cutoff = true + if haskey(kwargs, :doRelCutoff) + @warn "In svd, keyword argument doRelCutoff is deprecated in favor of use_relative_cutoff" + use_relative_cutoff = get(kwargs, + :doRelCutoff, + use_relative_cutoff) + end truncate = haskey(kwargs,:maxdim) || haskey(kwargs,:cutoff) maxdim::Int = get(kwargs,:maxdim,minimum(dims(T))) mindim::Int = get(kwargs,:mindim,1) cutoff::Float64 = get(kwargs,:cutoff,0.0) - absoluteCutoff::Bool = get(kwargs,:absoluteCutoff,false) - doRelCutoff::Bool = get(kwargs,:doRelCutoff,true) + use_absolute_cutoff::Bool = get(kwargs, + :use_absolute_cutoff, + use_absolute_cutoff) + use_relative_cutoff::Bool = get(kwargs, + :use_relative_cutoff, + use_relative_cutoff) DM,UM = eigen(matrix(T)) @@ -191,8 +252,8 @@ function LinearAlgebra.eigen(T::DenseTensor{ElT,2,IndsT}; if truncate truncerr,_ = truncate!(DM;maxdim=maxdim, cutoff=cutoff, - absoluteCutoff=absoluteCutoff, - doRelCutoff=doRelCutoff) + use_absolute_cutoff=use_absolute_cutoff, + use_relative_cutoff=use_relative_cutoff) dD = length(DM) if dD < size(UM,2) UM = UM[:,1:dD] diff --git a/src/Tensors/truncate.jl b/src/Tensors/truncate.jl index a0ca6ca678..c799b7ddbe 100644 --- a/src/Tensors/truncate.jl +++ b/src/Tensors/truncate.jl @@ -2,11 +2,31 @@ export truncate! function truncate!(P::Vector{Float64}; kwargs...)::Tuple{Float64,Float64} + # Keyword argument deprecations + use_absolute_cutoff = false + if haskey(kwargs, :absoluteCutoff) + @warn "In truncate!, keyword argument absoluteCutoff is deprecated in favor of use_absolute_cutoff" + use_absolute_cutoff = get(kwargs, + :absoluteCutoff, + use_absolute_cutoff) + end + use_relative_cutoff = true + if haskey(kwargs, :doRelCutoff) + @warn "In truncate!, keyword argument doRelCutoff is deprecated in favor of use_relative_cutoff" + use_relative_cutoff = get(kwargs, + :doRelCutoff, + use_relative_cutoff) + end + maxdim::Int = min(get(kwargs,:maxdim,length(P)), length(P)) mindim::Int = max(get(kwargs,:mindim,1), 1) cutoff::Float64 = max(get(kwargs,:cutoff,0.0), 0.0) - absoluteCutoff::Bool = get(kwargs,:absoluteCutoff,false) - doRelCutoff::Bool = get(kwargs,:doRelCutoff,true) + use_absolute_cutoff::Bool = get(kwargs, + :use_absolute_cutoff, + use_absolute_cutoff) + use_relative_cutoff::Bool = get(kwargs, + :use_relative_cutoff, + use_relative_cutoff) origm = length(P) docut = 0.0 @@ -35,7 +55,7 @@ function truncate!(P::Vector{Float64}; n -= 1 end - if absoluteCutoff + if use_absolute_cutoff #Test if individual prob. weights fall below cutoff #rather than using *sum* of discarded weights while P[n] <= cutoff && n > mindim @@ -44,7 +64,7 @@ function truncate!(P::Vector{Float64}; end else scale = 1.0 - if doRelCutoff + if use_relative_cutoff scale = sum(P) (scale==0.0) && (scale = 1.0) end diff --git a/src/decomp.jl b/src/decomp.jl index afeb159154..f75a68b181 100644 --- a/src/decomp.jl +++ b/src/decomp.jl @@ -43,8 +43,8 @@ arguments provided. The following keyword arguments are recognized: * `maxdim` [Int] * `mindim` [Int] * `cutoff` [Float64] -* `absoluteCutoff` [Bool] Default value: false. -* `doRelCutoff` [Bool] Default value: true. +* `use_absolute_cutoff` [Bool] Default value: false. +* `use_relative_cutoff` [Bool] Default value: true. * `utags` [String] Default value: "Link,u". * `vtags` [String] Default value: "Link,v". * `fastSVD` [Bool] Defaut value: false. diff --git a/src/mps/mpo.jl b/src/mps/mpo.jl index cdca58fdc7..46c037e693 100644 --- a/src/mps/mpo.jl +++ b/src/mps/mpo.jl @@ -1,8 +1,8 @@ export MPO, randomMPO, - applyMPO, - multMPO, - errorMPOprod, + applympo, + multmpo, + error_mpoprod, maxlinkdim, orthogonalize!, truncate!, @@ -89,7 +89,7 @@ function randomMPO(sites, m::Int=1) end Base.length(m::MPO) = m.N_ -tensors(m::MPO) = m.A_ +Tensors.store(m::MPO) = m.A_ leftlim(m::MPO) = m.llim_ rightlim(m::MPO) = m.rlim_ @@ -101,21 +101,21 @@ function set_rightlim!(m::MPO,new_rl::Int) m.rlim_ = new_rl end -Base.getindex(m::MPO, n::Integer) = getindex(tensors(m), n) +Base.getindex(m::MPO, n::Integer) = getindex(store(m), n) function Base.setindex!(M::MPO,T::ITensor,n::Integer) (n <= leftlim(M)) && set_leftlim!(M,n-1) (n >= rightlim(M)) && set_rightlim!(M,n+1) - setindex!(tensors(M),T,n) + setindex!(store(M),T,n) end -Base.copy(m::MPO) = MPO(m.N_, copy(tensors(m))) -Base.similar(m::MPO) = MPO(m.N_, similar(tensors(m)), 0, m.N_) +Base.copy(m::MPO) = MPO(m.N_, copy(store(m))) +Base.similar(m::MPO) = MPO(m.N_, similar(store(m)), 0, m.N_) function Base.deepcopy(m::T) where {T <: Union{MPO,MPS}} res = similar(m) # otherwise we will end up modifying the elements of A! - res.A_ = deepcopy(tensors(m)) + res.A_ = deepcopy(store(m)) return res end @@ -195,7 +195,7 @@ end function Base.show(io::IO, W::MPO) print(io,"MPO") (length(W) > 0) && print(io,"\n") - for (i, A) ∈ enumerate(tensors(W)) + for (i, A) ∈ enumerate(store(W)) if order(A) != 0 println(io,"[$i] $(inds(A))") else @@ -216,13 +216,14 @@ end """ +dot(y::MPS, A::MPO, x::MPS) inner(y::MPS, A::MPO, x::MPS) Compute """ -function inner(y::MPS, - A::MPO, - x::MPS)::Number +function LinearAlgebra.dot(y::MPS, + A::MPO, + x::MPS)::Number N = length(A) if length(y) != N || length(x) != N throw(DimensionMismatch("inner: mismatched lengths $N and $(length(x)) or $(length(y))")) @@ -239,14 +240,15 @@ function inner(y::MPS, end """ +dot(B::MPO, y::MPS, A::MPO, x::MPS) inner(B::MPO, y::MPS, A::MPO, x::MPS) Compute """ -function inner(B::MPO, - y::MPS, - A::MPO, - x::MPS)::Number +function LinearAlgebra.dot(B::MPO, + y::MPS, + A::MPO, + x::MPS)::Number N = length(B) if length(y) != N || length(x) != N || length(A) != N throw(DimensionMismatch("inner: mismatched lengths $N and $(length(x)) or $(length(y)) or $(length(A))")) @@ -278,12 +280,12 @@ end """ -errorMPOprod(y::MPS, A::MPO, x::MPS) +error_mpoprod(y::MPS, A::MPO, x::MPS) Compute the distance between A|x> and an approximation MPS y: | |y> - A|x> |/| A|x> | = √(1 + ( - 2*real())/) """ -function errorMPOprod(y::MPS, A::MPO, x::MPS) +function error_mpoprod(y::MPS, A::MPO, x::MPS) N = length(A) if length(y) != N || length(x) != N throw(DimensionMismatch("inner: mismatched lengths $N and $(length(x)) or $(length(y))")) @@ -360,17 +362,21 @@ function Base.sum(A::Vector{T}; kwargs...) where {T <: Union{MPS, MPO}} return sum(newterms; kwargs...) end -function applyMPO(A::MPO, psi::MPS; kwargs...)::MPS - method = get(kwargs, :method, "DensityMatrix") - if method == "DensityMatrix" || method == "densitymatrix" - return densityMatrixApplyMPO(A, psi; kwargs...) +function applympo(A::MPO, psi::MPS; kwargs...)::MPS + method = get(kwargs, :method, "densitymatrix") + if method == "DensityMatrix" + @warn "In applympo, method DensityMatrix is deprecated in favor of densitymatrix" + method = "densitymatrix" + end + if method == "densitymatrix" + return applympo_densitymatrix(A, psi; kwargs...) elseif method == "naive" || method == "Naive" - return naiveApplyMPO(A, psi; kwargs...) + return applympo_naive(A, psi; kwargs...) end throw(ArgumentError("Method $method not supported")) end -function densityMatrixApplyMPO(A::MPO, psi::MPS; kwargs...)::MPS +function applympo_densitymatrix(A::MPO, psi::MPS; kwargs...)::MPS n = length(A) n != length(psi) && throw(DimensionMismatch("lengths of MPO ($n) and MPS ($(length(psi))) do not match")) psi_out = similar(psi) @@ -379,7 +385,7 @@ function densityMatrixApplyMPO(A::MPO, psi::MPS; kwargs...)::MPS maxdim::Int = get(kwargs,:maxdim,maxlinkdim(psi)) mindim::Int = max(get(kwargs,:mindim,1), 1) normalize::Bool = get(kwargs, :normalize, false) - all(x -> x != Index(), [siteindex(A, psi, j) for j in 1:n]) || throw(ErrorException("MPS and MPO have different site indices in applyMPO method 'DensityMatrix'")) + all(x -> x != Index(), [siteindex(A, psi, j) for j in 1:n]) || throw(ErrorException("MPS and MPO have different site indices in applympo method 'DensityMatrix'")) rand_plev = 14741 psi_c = dag(copy(psi)) @@ -429,7 +435,7 @@ function densityMatrixApplyMPO(A::MPO, psi::MPS; kwargs...)::MPS return psi_out end -function naiveApplyMPO(A::MPO, psi::MPS; kwargs...)::MPS +function applympo_naive(A::MPO, psi::MPS; kwargs...)::MPS truncate = get(kwargs,:truncate,true) N = length(A) @@ -457,7 +463,7 @@ function naiveApplyMPO(A::MPO, psi::MPS; kwargs...)::MPS return psi_out end -function multMPO(A::MPO, B::MPO; kwargs...)::MPO +function multmpo(A::MPO, B::MPO; kwargs...)::MPO cutoff::Float64 = get(kwargs, :cutoff, 1e-14) resp_degen::Bool = get(kwargs, :respect_degenerate, true) maxdim::Int = get(kwargs,:maxdim,maxlinkdim(A)*maxlinkdim(B)) @@ -487,7 +493,7 @@ function multMPO(A::MPO, B::MPO; kwargs...)::MPO end sites_A = Index[] sites_B = Index[] - @inbounds for (AA, BB) in zip(tensors(A_), tensors(B_)) + @inbounds for (AA, BB) in zip(store(A_), store(B_)) sda = setdiff(inds(AA, "Site"), inds(BB, "Site")) sdb = setdiff(inds(BB, "Site"), inds(AA, "Site")) sda_ind = setprime(sda[1], 0) == sdb[1] ? plev(sda[1]) == 1 ? sda[1] : setprime(sda[1], 1) : setprime(sda[1], 0) @@ -634,3 +640,13 @@ Perform a truncation of all bonds of an MPO, using the truncation parameters (cutoff,maxdim, etc.) provided as keyword arguments. """ truncate! + +@deprecate applyMPO(args...; kwargs...) applympo(args...; kwargs...) +@deprecate errorMPOprod(args...; kwargs...) error_mpoprod(args...; kwargs...) +@deprecate densityMatrixApplyMPO(args...; kwargs...) applympo_densitymatrix(args...; kwargs...) +@deprecate naiveApplyMPO(args...; kwargs...) applympo_naive(args...; kwargs...) +@deprecate multMPO(args...; kwargs...) multmpo(args...; kwargs...) +@deprecate set_leftlim!(args...; kwargs...) setleftlim!(args...; kwargs...) +@deprecate set_rightlim!(args...; kwargs...) setrightlim!(args...; kwargs...) +@deprecate tensors(args...; kwargs...) store(args...; kwargs...) + diff --git a/src/mps/mps.jl b/src/mps/mps.jl index 9883e7481e..e92fdeefca 100644 --- a/src/mps/mps.jl +++ b/src/mps/mps.jl @@ -55,8 +55,7 @@ MPS(sites) = MPS(Float64,sites) Base.length(m::MPS) = m.N_ -# TODO: make this vec? -tensors(m::MPS) = m.A_ +Tensors.store(m::MPS) = m.A_ leftlim(m::MPS) = m.llim_ rightlim(m::MPS) = m.rlim_ @@ -71,28 +70,28 @@ end isortho(m::MPS) = (leftlim(m)+1 == rightlim(m)-1) -function orthoCenter(m::MPS) +function orthocenter(m::MPS) !isortho(m) && error("MPS has no well-defined orthogonality center") return leftlim(m)+1 end -Base.getindex(M::MPS, n::Integer) = getindex(tensors(M),n) +Base.getindex(M::MPS, n::Integer) = getindex(store(M),n) function Base.setindex!(M::MPS,T::ITensor,n::Integer) (n <= leftlim(M)) && set_leftlim!(M,n-1) (n >= rightlim(M)) && set_rightlim!(M,n+1) - setindex!(tensors(M),T,n) + setindex!(store(M),T,n) end -Base.copy(m::MPS) = MPS(m.N_,copy(tensors(m)),m.llim_,m.rlim_) -Base.similar(m::MPS) = MPS(m.N_, similar(tensors(m)), 0, m.N_) +Base.copy(m::MPS) = MPS(m.N_,copy(store(m)),m.llim_,m.rlim_) +Base.similar(m::MPS) = MPS(m.N_, similar(store(m)), 0, m.N_) Base.eachindex(m::MPS) = 1:length(m) function Base.show(io::IO, M::MPS) print(io,"MPS") (length(M) > 0) && print(io,"\n") - for (i, A) ∈ enumerate(tensors(M)) + for (i, A) ∈ enumerate(store(M)) if order(A) != 0 println(io,"[$i] $(inds(A))") else @@ -182,11 +181,12 @@ function replacesites!(M::MPS,sites) end """ +dot(psi::MPS, phi::MPS) inner(psi::MPS, phi::MPS) Compute """ -function inner(M1::MPS, M2::MPS)::Number +function LinearAlgebra.dot(M1::MPS, M2::MPS)::Number N = length(M1) if length(M2) != N throw(DimensionMismatch("inner: mismatched lengths $N and $(length(M2))")) @@ -200,6 +200,8 @@ function inner(M1::MPS, M2::MPS)::Number return O[] end +const inner = dot + function replacebond!(M::MPS, b::Int, phi::ITensor; @@ -251,7 +253,7 @@ end """ sample(m::MPS) -Given a normalized MPS m with `orthoCenter(m)==1`, +Given a normalized MPS m with `orthocenter(m)==1`, returns a `Vector{Int}` of `length(m)` corresponding to one sample of the probability distribution defined by @@ -261,8 +263,8 @@ that the MPS represents function sample(m::MPS) N = length(m) - if orthoCenter(m) != 1 - error("sample: MPS m must have orthoCenter(m)==1") + if orthocenter(m) != 1 + error("sample: MPS m must have orthocenter(m)==1") end if abs(1.0-norm(m[1])) > 1E-8 error("sample: MPS is not normalized, norm=$(norm(m[1]))") @@ -302,3 +304,6 @@ function sample(m::MPS) end return result end + +@deprecate orthoCenter(args...; kwargs...) orthocenter(args...; kwargs...) + diff --git a/src/tagset.jl b/src/tagset.jl index 1f1bb1441f..27d67b9f9c 100644 --- a/src/tagset.jl +++ b/src/tagset.jl @@ -97,10 +97,10 @@ end Base.convert(::Type{TagSet}, str::String) = TagSet(str) -tags(T::TagSet) = T.tags +Tensors.store(T::TagSet) = T.tags Base.length(T::TagSet) = T.length -Base.getindex(T::TagSet,n::Int) = Tag(getindex(tags(T),n)) -Base.copy(ts::TagSet) = TagSet(tags(ts),length(ts)) +Base.getindex(T::TagSet,n::Int) = Tag(getindex(store(T),n)) +Base.copy(ts::TagSet) = TagSet(store(ts),length(ts)) # Cast SVector of IntTag of length 4 to SVector of UInt128 of length 2 # This is to make TagSet comparison a little bit faster @@ -110,7 +110,7 @@ end function Base.:(==)(ts1::TagSet,ts2::TagSet) # Block the bits together to make the comparison faster - return cast_to_uint128(tags(ts1)) == cast_to_uint128(tags(ts2)) + return cast_to_uint128(store(ts1)) == cast_to_uint128(store(ts2)) end function hastag(ts::TagSet, tag) @@ -138,7 +138,7 @@ function addtags(ts::TagSet, tagsadd) throw(ErrorException("Cannot add tag: TagSet already maximum size")) end tsadd = TagSet(tagsadd) - res_ts = MVector(tags(ts)) + res_ts = MVector(store(ts)) ntags = length(ts) for n = 1:length(tsadd) @inbounds ntags = _addtag_ordered!(res_ts, ntags,IntSmallString(tsadd[n])) @@ -162,7 +162,7 @@ end #TODO: optimize this function function removetags(ts::TagSet, tagsremove) tsremove = TagSet(tagsremove) - res_ts = MVector(tags(ts)) + res_ts = MVector(store(ts)) ntags = length(ts) for n=1:length(tsremove) @inbounds ntags = _removetag!(res_ts, ntags, tsremove[n]) @@ -174,7 +174,7 @@ end function replacetags(ts::TagSet, tagsremove, tagsadd) tsremove = TagSet(tagsremove) tsadd = TagSet(tagsadd) - res_ts = MVector(tags(ts)) + res_ts = MVector(store(ts)) ntags = length(ts) # The TagSet must have the tags to be replaced !hastags(ts,tsremove) && return ts @@ -247,3 +247,6 @@ function HDF5.read(parent::Union{HDF5File,HDF5Group}, tstring = read(g,"tags") return TagSet(tstring) end + +@deprecate tags(t::TagSet) store(t::TagSet) + diff --git a/test/decomp.jl b/test/decomp.jl index ed360118d5..0020f3d8b5 100644 --- a/test/decomp.jl +++ b/test/decomp.jl @@ -5,7 +5,9 @@ a = [-0.1, -0.12] @test ITensors.truncate!(a) == (0., 0.) @test length(a) == 1 a = [0.1, 0.01, 1e-13] -@test ITensors.truncate!(a,absoluteCutoff=true,cutoff=1e-5) == (1e-13, (0.01 + 1e-13)/2) +@test ITensors.truncate!(a, + use_absolute_cutoff=true, + cutoff=1e-5) == (1e-13, (0.01 + 1e-13)/2) @test length(a) == 2 i = Index(2,"i") diff --git a/test/mpo.jl b/test/mpo.jl index ab65fabb7c..3effad6171 100644 --- a/test/mpo.jl +++ b/test/mpo.jl @@ -34,7 +34,7 @@ end @test hasind(P[1],prime(sites[1])) # test constructor from Vector{ITensor} K = randomMPO(sites) - @test ITensors.tensors(MPO(copy(ITensors.tensors(K)))) == ITensors.tensors(K) + @test ITensors.store(MPO(copy(ITensors.store(K)))) == ITensors.store(K) @testset "orthogonalize" begin phi = randomMPS(sites) @@ -138,7 +138,7 @@ end @test_throws DimensionMismatch inner(J,phi,K,badpsi) end - @testset "errorMPOprod" begin + @testset "error_mpoprod" begin phi = makeRandomMPS(sites) K = makeRandomMPO(sites,chi=2) @@ -146,30 +146,30 @@ end dist = sqrt(abs(1 + (inner(phi,phi) - 2*real(inner(phi,K,psi))) /inner(K,psi,K,psi))) - @test dist ≈ errorMPOprod(phi,K,psi) + @test dist ≈ error_mpoprod(phi,K,psi) badsites = [Index(2,"Site") for n=1:N+1] badpsi = randomMPS(badsites) - # Apply K to phi and check that errorMPOprod is close to 0. - Kphi = applyMPO(K,phi;method="naive", cutoff=1E-8) - @test errorMPOprod(Kphi, K, phi) ≈ 0. atol=1e-4 + # Apply K to phi and check that error_mpoprod is close to 0. + Kphi = applympo(K,phi;method="naive", cutoff=1E-8) + @test error_mpoprod(Kphi, K, phi) ≈ 0. atol=1e-4 - @test_throws DimensionMismatch applyMPO(K,badpsi;method="naive", cutoff=1E-8) - @test_throws DimensionMismatch errorMPOprod(phi,K,badpsi) + @test_throws DimensionMismatch applympo(K,badpsi;method="naive", cutoff=1E-8) + @test_throws DimensionMismatch error_mpoprod(phi,K,badpsi) end - @testset "applyMPO" begin + @testset "applympo" begin phi = randomMPS(sites) K = randomMPO(sites) @test maxlinkdim(K) == 1 psi = randomMPS(sites) - psi_out = applyMPO(K, psi,maxdim=1) + psi_out = applympo(K, psi,maxdim=1) @test inner(phi,psi_out) ≈ inner(phi,K,psi) - @test_throws ArgumentError applyMPO(K, psi, method="fakemethod") + @test_throws ArgumentError applympo(K, psi, method="fakemethod") badsites = [Index(2,"Site") for n=1:N+1] badpsi = randomMPS(badsites) - @test_throws DimensionMismatch applyMPO(K,badpsi) + @test_throws DimensionMismatch applympo(K,badpsi) # make bigger random MPO... for link_dim in 2:5 @@ -195,7 +195,7 @@ end orthogonalize!(psi, 1; maxdim=link_dim) orthogonalize!(K, 1; maxdim=link_dim) orthogonalize!(phi, 1; normalize=true, maxdim=link_dim) - psi_out = applyMPO(deepcopy(K), deepcopy(psi); maxdim=10*link_dim, cutoff=0.0) + psi_out = applympo(deepcopy(K), deepcopy(psi); maxdim=10*link_dim, cutoff=0.0) @test inner(phi, psi_out) ≈ inner(phi, K, psi) end end @@ -206,8 +206,8 @@ end M = sum(K, L) @test length(M) == N psi = randomMPS(shsites) - k_psi = applyMPO(K, psi, maxdim=1) - l_psi = applyMPO(L, psi, maxdim=1) + k_psi = applympo(K, psi, maxdim=1) + l_psi = applympo(L, psi, maxdim=1) @test inner(psi, sum(k_psi, l_psi)) ≈ inner(psi, M, psi) atol=5e-3 @test inner(psi, sum([k_psi, l_psi])) ≈ inner(psi, M, psi) atol=5e-3 for dim in 2:4 @@ -217,26 +217,26 @@ end M = sum(K, L) @test length(M) == N psi = randomMPS(shsites) - k_psi = applyMPO(K, psi) - l_psi = applyMPO(L, psi) + k_psi = applympo(K, psi) + l_psi = applympo(L, psi) @test inner(psi, sum(k_psi, l_psi)) ≈ inner(psi, M, psi) atol=5e-3 @test inner(psi, sum([k_psi, l_psi])) ≈ inner(psi, M, psi) atol=5e-3 psi = randomMPS(shsites) M = sum(K, L; cutoff=1E-9) - k_psi = applyMPO(K, psi) - l_psi = applyMPO(L, psi) + k_psi = applympo(K, psi) + l_psi = applympo(L, psi) @test inner(psi, sum(k_psi, l_psi)) ≈ inner(psi, M, psi) atol=5e-3 end end - @testset "multMPO" begin + @testset "multmpo" begin psi = randomMPS(sites) K = randomMPO(sites) L = randomMPO(sites) @test maxlinkdim(K) == 1 @test maxlinkdim(L) == 1 - KL = multMPO(K, L, maxdim=1) - psi_kl_out = applyMPO(K, applyMPO(L, psi, maxdim=1), maxdim=1) + KL = multmpo(K, L, maxdim=1) + psi_kl_out = applympo(K, applympo(L, psi, maxdim=1), maxdim=1) @test inner(psi,KL,psi) ≈ inner(psi, psi_kl_out) atol=5e-3 # where both K and L have differently labelled sites @@ -248,15 +248,15 @@ end replaceind!(K[ii], sites[ii]', othersitesk[ii]) replaceind!(L[ii], sites[ii]', othersitesl[ii]) end - KL = multMPO(K, L, maxdim=1) + KL = multmpo(K, L, maxdim=1) psik = randomMPS(othersitesk) psil = randomMPS(othersitesl) - psi_kl_out = applyMPO(K, applyMPO(L, psil, maxdim=1), maxdim=1) + psi_kl_out = applympo(K, applympo(L, psil, maxdim=1), maxdim=1) @test inner(psik,KL,psil) ≈ inner(psik, psi_kl_out) atol=5e-3 badsites = [Index(2,"Site") for n=1:N+1] badL = randomMPO(badsites) - @test_throws DimensionMismatch multMPO(K,badL) + @test_throws DimensionMismatch multmpo(K,badL) end sites = siteinds("S=1/2",N)