Skip to content

Commit

Permalink
find and replace MPOMultiline with MultilineMPO
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorVanthilt committed Dec 16, 2024
1 parent 9606248 commit ce46097
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 82 deletions.
4 changes: 2 additions & 2 deletions src/MPSKit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export braille
export AbstractMPO
export MPO, FiniteMPO, InfiniteMPO
export MPOHamiltonian, FiniteMPOHamiltonian, InfiniteMPOHamiltonian
export SparseMPO, DenseMPO, MPOMultiline
export SparseMPO, DenseMPO, MultilineMPO
export UntimedOperator, TimedOperator, MultipliedOperator, LazySum

export ∂C, ∂AC, ∂AC2, environments, expectation_value, effective_excitation_hamiltonian
Expand Down Expand Up @@ -93,7 +93,7 @@ include("states/ortho.jl")
include("operators/abstractmpo.jl")
include("operators/mpo.jl")
include("operators/mpohamiltonian.jl") # the mpohamiltonian objects
include("operators/mpomultiline.jl")
include("operators/multilinempo.jl")
include("operators/projection.jl")
include("operators/timedependence.jl")
include("operators/multipliedoperator.jl")
Expand Down
4 changes: 2 additions & 2 deletions src/algorithms/approximate/idmrg.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function approximate(ost::MultilineMPS, toapprox::Tuple{<:MPOMultiline,<:MultilineMPS},
function approximate(ost::MultilineMPS, toapprox::Tuple{<:MultilineMPO,<:MultilineMPS},
alg::IDMRG1, oenvs=environments(ost, toapprox))
ψ = copy(ost)
mpo, above = toapprox
Expand Down Expand Up @@ -57,7 +57,7 @@ function approximate(ost::MultilineMPS, toapprox::Tuple{<:MPOMultiline,<:Multili
return nst, nenvs, ϵ
end

function approximate(ost::MultilineMPS, toapprox::Tuple{<:MPOMultiline,<:MultilineMPS},
function approximate(ost::MultilineMPS, toapprox::Tuple{<:MultilineMPO,<:MultilineMPS},
alg::IDMRG2, oenvs=environments(ost, toapprox))
length(ost) < 2 && throw(ArgumentError("unit cell should be >= 2"))
mpo, above = toapprox
Expand Down
6 changes: 3 additions & 3 deletions src/algorithms/approximate/vomps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ function approximate(ψ::InfiniteMPS,
envs=environments(ψ, toapprox))
# PeriodicMPO's always act on MultilineMPS's. To avoid code duplication, define everything in terms of MultilineMPS's.
multi, envs = approximate(convert(MultilineMPS, ψ),
(convert(MPOMultiline, toapprox[1]),
(convert(MultilineMPO, toapprox[1]),
convert(MultilineMPS, toapprox[2])), algorithm, envs)
ψ = convert(InfiniteMPS, multi)
return ψ, envs
end

Base.@deprecate(approximate::MultilineMPS, toapprox::Tuple{<:MPOMultiline,<:MultilineMPS},
Base.@deprecate(approximate::MultilineMPS, toapprox::Tuple{<:MultilineMPO,<:MultilineMPS},
alg::VUMPS, envs...; kwargs...),
approximate(ψ, toapprox,
VOMPS(; alg.tol, alg.maxiter, alg.finalize,
alg.verbosity, alg.alg_gauge, alg.alg_environments),
envs...; kwargs...))

function approximate::MultilineMPS, toapprox::Tuple{<:MPOMultiline,<:MultilineMPS},
function approximate::MultilineMPS, toapprox::Tuple{<:MultilineMPO,<:MultilineMPS},
alg::VOMPS, envs=environments(ψ, toapprox))
ϵ::Float64 = calc_galerkin(ψ, envs)
temp_ACs = similar.(ψ.AC)
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/changebonds/optimalexpand.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ end

function changebonds::InfiniteMPS, H::DenseMPO, alg::OptimalExpand,
envs=environments(ψ, H))
(nmψ, envs) = changebonds(convert(MultilineMPS, ψ), convert(MPOMultiline, H), alg, envs)
(nmψ, envs) = changebonds(convert(MultilineMPS, ψ), convert(MultilineMPO, H), alg, envs)
return (convert(InfiniteMPS, nmψ), envs)
end

Expand Down
4 changes: 2 additions & 2 deletions src/algorithms/changebonds/svdcut.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ end
function changebonds::InfiniteMPO, alg::SvdCut)
return convert(InfiniteMPO, changebonds(convert(InfiniteMPS, ψ), alg))
end
function changebonds::MPOMultiline, alg::SvdCut)
return convert(MPOMultiline, changebonds(convert(MultilineMPS, ψ), alg))
function changebonds::MultilineMPO, alg::SvdCut)
return convert(MultilineMPO, changebonds(convert(MultilineMPS, ψ), alg))
end
function changebonds::MultilineMPS, alg::SvdCut)
return Multiline(map(x -> changebonds(x, alg), ψ.data))
Expand Down
12 changes: 6 additions & 6 deletions src/algorithms/derivatives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ Base.:*(h::Union{MPO_∂∂C,MPO_∂∂AC,MPO_∂∂AC2}, v) = h(v);
function ∂∂C(pos::Int, mps, operator::AbstractMPO, cache)
return MPO_∂∂C(leftenv(cache, pos + 1, mps), rightenv(cache, pos, mps))
end
function ∂∂C(col::Int, mps, operator::MPOMultiline, envs)
function ∂∂C(col::Int, mps, operator::MultilineMPO, envs)
return MPO_∂∂C(leftenv(envs, col + 1, mps), rightenv(envs, col, mps))
end
function ∂∂C(row::Int, col::Int, mps, operator::MPOMultiline, envs)
function ∂∂C(row::Int, col::Int, mps, operator::MultilineMPO, envs)
return MPO_∂∂C(leftenv(envs, row, col + 1, mps), rightenv(envs, row, col, mps))
end

function ∂∂AC(pos::Int, mps, operator::AbstractMPO, cache)
return MPO_∂∂AC(operator[pos], leftenv(cache, pos, mps), rightenv(cache, pos, mps))
end
function ∂∂AC(row::Int, col::Int, mps, operator::MPOMultiline, envs)
function ∂∂AC(row::Int, col::Int, mps, operator::MultilineMPO, envs)
return MPO_∂∂AC(operator[row, col], leftenv(envs, row, col, mps),
rightenv(envs, row, col, mps))
end
function ∂∂AC(col::Int, mps, operator::MPOMultiline, envs)
function ∂∂AC(col::Int, mps, operator::MultilineMPO, envs)
return MPO_∂∂AC(envs.operator[:, col], leftenv(envs, col, mps),
rightenv(envs, col, mps))
end;
Expand All @@ -57,11 +57,11 @@ function ∂∂AC2(pos::Int, mps, operator::AbstractMPO, cache)
return MPO_∂∂AC2(operator[pos], operator[pos + 1], leftenv(cache, pos, mps),
rightenv(cache, pos + 1, mps))
end;
function ∂∂AC2(col::Int, mps, operator::MPOMultiline, envs)
function ∂∂AC2(col::Int, mps, operator::MultilineMPO, envs)
return MPO_∂∂AC2(operator[:, col], operator[:, col + 1], leftenv(envs, col, mps),
rightenv(envs, col + 1, mps))
end
function ∂∂AC2(row::Int, col::Int, mps, operator::MPOMultiline, envs)
function ∂∂AC2(row::Int, col::Int, mps, operator::MultilineMPO, envs)
return MPO_∂∂AC2(operator[row, col], operator[row, col + 1],
leftenv(envs, row, col, mps), rightenv(envs, row, col + 1, mps))
end
Expand Down
14 changes: 7 additions & 7 deletions src/algorithms/excitation/quasiparticleexcitation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ end
# Statmech Excitations #
################################################################################

function excitations(H::MPOMultiline, alg::QuasiparticleAnsatz, ϕ₀::Multiline{<:InfiniteQP},
function excitations(H::MultilineMPO, alg::QuasiparticleAnsatz, ϕ₀::Multiline{<:InfiniteQP},
lenvs, renvs; num=1, solver=Defaults.linearsolver)
qp_envs(ϕ) = environments(ϕ, H, lenvs, renvs; solver)
function H_eff(ϕ′)
Expand All @@ -194,13 +194,13 @@ function excitations(H::InfiniteMPO, alg::QuasiparticleAnsatz, ϕ₀::InfiniteQP
return Es, ϕs
end

function excitations(H::MPOMultiline, alg::QuasiparticleAnsatz, ϕ₀::Multiline{<:InfiniteQP},
function excitations(H::MultilineMPO, alg::QuasiparticleAnsatz, ϕ₀::Multiline{<:InfiniteQP},
lenvs; num=1, solver=Defaults.linearsolver)
# Infer `renvs` in function body as it depends on `solver`.
renvs = ϕ₀.trivial ? lenvs : environments(ϕ₀.right_gs, H; solver)
return excitations(H, alg, ϕ₀, lenvs, renvs; num, solver)
end
function excitations(H::MPOMultiline, alg::QuasiparticleAnsatz, ϕ₀::Multiline{<:InfiniteQP};
function excitations(H::MultilineMPO, alg::QuasiparticleAnsatz, ϕ₀::Multiline{<:InfiniteQP};
num=1, solver=Defaults.linearsolver)
# Infer `lenvs` in function body as it depends on `solver`.
lenvs = environments(ϕ₀.left_gs, H; solver)
Expand All @@ -214,16 +214,16 @@ function excitations(H::DenseMPO, alg::QuasiparticleAnsatz, momentum::Real,
sector=one(sectortype(lmps)), num=1, solver=Defaults.linearsolver)
multiline_lmps = convert(MultilineMPS, lmps)
if lmps === rmps
excitations(convert(MPOMultiline, H), alg, momentum, multiline_lmps, lenvs,
excitations(convert(MultilineMPO, H), alg, momentum, multiline_lmps, lenvs,
multiline_lmps,
lenvs; sector, num, solver)
else
excitations(convert(MPOMultiline, H), alg, momentum, multiline_lmps, lenvs,
excitations(convert(MultilineMPO, H), alg, momentum, multiline_lmps, lenvs,
convert(MultilineMPS, rmps), renvs; sector, num, solver)
end
end

function excitations(H::MPOMultiline, alg::QuasiparticleAnsatz, momentum::Real,
function excitations(H::MultilineMPO, alg::QuasiparticleAnsatz, momentum::Real,
lmps::MultilineMPS,
lenvs=environments(lmps, H), rmps=lmps,
renvs=lmps === rmps ? lenvs : environments(rmps, H);
Expand Down Expand Up @@ -263,7 +263,7 @@ function effective_excitation_hamiltonian(H::Union{InfiniteMPOHamiltonian,
return ϕ′
end

function effective_excitation_hamiltonian(H::MPOMultiline, ϕ::Multiline{<:InfiniteQP},
function effective_excitation_hamiltonian(H::MultilineMPO, ϕ::Multiline{<:InfiniteQP},
envs=environments(ϕ, H))
ϕ′ = Multiline(similar.(ϕ.data))
left_gs = ϕ.left_gs
Expand Down
6 changes: 3 additions & 3 deletions src/algorithms/expval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ function expectation_value(ψ::FiniteQP, mpo::FiniteMPO)
return expectation_value(convert(FiniteMPS, ψ), mpo)
end
function expectation_value::InfiniteMPS, mpo::InfiniteMPO, envs...)
return expectation_value(convert(MultilineMPS, ψ), convert(MPOMultiline, mpo), envs...)
return expectation_value(convert(MultilineMPS, ψ), convert(MultilineMPO, mpo), envs...)
end
function expectation_value::MultilineMPS, O::MPOMultiline{<:Union{DenseMPO,SparseMPO}},
function expectation_value::MultilineMPS, O::MultilineMPO{<:Union{DenseMPO,SparseMPO}},
envs::InfiniteMPOEnvironments=environments(ψ, O))
return prod(product(1:size(ψ, 1), 1:size(ψ, 2))) do (i, j)
GL = leftenv(envs, i, j, ψ)
Expand All @@ -130,7 +130,7 @@ function expectation_value(ψ::MultilineMPS, O::MPOMultiline{<:Union{DenseMPO,Sp
conj.AC[i + 1, j][1 4; 8])
end
end
function expectation_value::MultilineMPS, mpo::MPOMultiline, envs...)
function expectation_value::MultilineMPS, mpo::MultilineMPO, envs...)
# TODO: fix environments
return prod(x -> expectation_value(x...), zip(parent(ψ), parent(mpo)))
end
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/statmech/gradient_grassmann.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function leading_boundary(state::InfiniteMPS, H::DenseMPO, alg::GradientGrassmann,
envs=environments(state, H))
(multi, envs, err) = leading_boundary(convert(MultilineMPS, state),
convert(MPOMultiline, H), alg, envs)
convert(MultilineMPO, H), alg, envs)
state = convert(InfiniteMPS, multi)
return (state, envs, err)
end
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/statmech/vomps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Power method algorithm for infinite MPS.
alg_environments = Defaults.alg_environments()
end

function leading_boundary::MultilineMPS, O::MPOMultiline, alg::VOMPS,
function leading_boundary::MultilineMPS, O::MultilineMPO, alg::VOMPS,
envs=environments(ψ, O))
ϵ::Float64 = calc_galerkin(ψ, envs)
temp_ACs = similar.(ψ.AC)
Expand Down
12 changes: 6 additions & 6 deletions src/environments/infinitempo_envs.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
InfiniteMPOEnvironments{O<:MPOMultiline,V,S<:MultilineMPS,A} <: AbstractMPSEnvironments
InfiniteMPOEnvironments{O<:MultilineMPO,V,S<:MultilineMPS,A} <: AbstractMPSEnvironments
Environment manager for `InfiniteMPO` and its `Multiline` version.
"""
Expand All @@ -23,30 +23,30 @@ end
# Constructors
# ------------
function environments(state::InfiniteMPS, O::InfiniteMPO; kwargs...)
return environments(convert(MultilineMPS, state), convert(MPOMultiline, O); kwargs...)
return environments(convert(MultilineMPS, state), convert(MultilineMPO, O); kwargs...)
end
function environments(below::InfiniteMPS,
(mpo, above)::Tuple{<:InfiniteMPO,<:InfiniteMPS}; kwargs...)
return environments(convert(MultilineMPS, below),
(convert(MPOMultiline, mpo), convert(MultilineMPS, above));
(convert(MultilineMPO, mpo), convert(MultilineMPS, above));
kwargs...)
end

function environments(state::MultilineMPS, mpo::MPOMultiline; solver=Defaults.eigsolver)
function environments(state::MultilineMPS, mpo::MultilineMPO; solver=Defaults.eigsolver)
GL, GR = initialize_environments(state, mpo, state)
envs = InfiniteMPOEnvironments(nothing, mpo, state, solver, GL, GR)
return recalculate!(envs, state)
end

function environments(below::MultilineMPS,
(mpo, above)::Tuple{<:MPOMultiline,<:MultilineMPS};
(mpo, above)::Tuple{<:MultilineMPO,<:MultilineMPS};
solver=Defaults.eigsolver)
GL, GR = initialize_environments(above, mpo, below)
envs = InfiniteMPOEnvironments(above, mpo, below, solver, GL, GR)
return recalculate!(envs, below)
end

function initialize_environments(ket::MultilineMPS, operator::MPOMultiline,
function initialize_environments(ket::MultilineMPS, operator::MultilineMPO,
bra::MultilineMPS=ket)
# allocate
GL = PeriodicArray([allocate_GL(bra[row], operator[row], ket[row], col)
Expand Down
2 changes: 1 addition & 1 deletion src/environments/qp_envs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ function environments(exci::FiniteQP,
end

function environments(exci::Multiline{<:InfiniteQP},
ham::MPOMultiline,
ham::MultilineMPO,
lenvs,
renvs;
solver=Defaults.linearsolver)
Expand Down
45 changes: 0 additions & 45 deletions src/operators/mpomultiline.jl

This file was deleted.

45 changes: 45 additions & 0 deletions src/operators/multilinempo.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# MultilineMPO
# ------------
"""
const MultilineMPO = Multiline{<:Union{SparseMPO,DenseMPO}}
Type that represents multiple lines of `MPO` objects.
# Constructors
MultilineMPO(mpos::AbstractVector{<:Union{SparseMPO,DenseMPO}})
MultilineMPO(Os::AbstractMatrix{<:MPOTensor})
See also: [`Multiline`](@ref), [`SparseMPO`](@ref), [`DenseMPO`](@ref)
"""
const MultilineMPO = Multiline{<:AbstractMPO}

function MultilineMPO(Os::AbstractMatrix{T}) where {T<:MPOTensor}
return MultilineMPO(map(FiniteMPO, eachrow(Os)))
end
function MultilineMPO(Os::PeriodicMatrix{T}) where {T<:MPOTensor}
return MultilineMPO(map(InfiniteMPO, eachrow(Os)))
end
MultilineMPO(mpos::AbstractVector{<:AbstractMPO}) = Multiline(mpos)
MultilineMPO(t::MPOTensor) = MultilineMPO(PeriodicMatrix(fill(t, 1, 1)))

# allow indexing with two indices
Base.getindex(t::MultilineMPO, ::Colon, j::Int) = Base.getindex.(t.data, j)
Base.getindex(t::MultilineMPO, i::Int, j) = Base.getindex(t[i], j)
Base.getindex(t::MultilineMPO, I::CartesianIndex{2}) = t[I.I...]

# converters
Base.convert(::Type{MultilineMPO}, t::AbstractMPO) = Multiline([t])
Base.convert(::Type{DenseMPO}, t::MultilineMPO{<:DenseMPO}) = only(t)
Base.convert(::Type{SparseMPO}, t::MultilineMPO{<:SparseMPO}) = only(t)
Base.convert(::Type{FiniteMPO}, t::MultilineMPO{<:FiniteMPO}) = only(t)
Base.convert(::Type{InfiniteMPO}, t::MultilineMPO{<:InfiniteMPO}) = only(t)

function Base.:*(mpo::MultilineMPO, st::MultilineMPS)
size(mpo) == size(st) || throw(ArgumentError("dimension mismatch"))
return Multiline(map(*, zip(mpo, st)))
end

function Base.:*(mpo1::MultilineMPO, mpo2::MultilineMPO)
size(mpo1) == size(mpo2) || throw(ArgumentError("dimension mismatch"))
return Multiline(map(*, zip(mpo1, mpo2)))
end
2 changes: 1 addition & 1 deletion src/utility/multiline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ multiple lines of `InfiniteMPS` (`MultilineMPS`) or MPO (`Multiline{<:AbstractMP
# Fields
- `data::PeriodicArray{T,1}`: the data of the multiline object
See also: [`MultilineMPS`](@ref) and [`MPOMultiline`](@ref)
See also: [`MultilineMPS`](@ref) and [`MultilineMPO`](@ref)
"""
struct Multiline{T}
data::PeriodicArray{T,1}
Expand Down
2 changes: 1 addition & 1 deletion test/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ end

@testset "MultilineMPS" begin
o = rand(ComplexF64, pspace * pspace, pspace * pspace)
mpo = MPOMultiline(o)
mpo = MultilineMPO(o)

t = rand(ComplexF64, Dspace * pspace, Dspace)
state = MultilineMPS(fill(t, 1, 1))
Expand Down

0 comments on commit ce46097

Please sign in to comment.