Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions src/algorithms/changebonds/changebonds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,15 @@
changebonds(ψ::AbstractMPS, alg) -> ψ′

Change the bond dimension of `ψ` using the algorithm `alg`, and return the new `ψ` and the new `envs`.
For AbstractInfiniteMPS, changebonds returns new environments without modifying the one provided.
changedbonds! can modifiy both the provided state and environments, depending on the algorithm.
For FiniteMPS, changebonds also modifies the environments.

See also: [`SvdCut`](@ref), [`RandExpand`](@ref), [`VUMPSSvdCut`](@ref), [`OptimalExpand`](@ref)
"""
function changebonds end
function changebonds! end

# write in terms of MultilineMPS
function changebonds(
ψ::InfiniteMPS, operator::InfiniteMPO, alg, envs = environments(ψ, operator)
)
ψ′, envs′ = changebonds(
convert(MultilineMPS, ψ), convert(MultilineMPO, operator), alg, Multiline([envs])
)
return convert(InfiniteMPS, ψ′), envs
end

_expand(ψ, AL′, AR′) = _expand!(copy(ψ), AL′, AR′)
function _expand!(ψ::InfiniteMPS, AL′::PeriodicVector, AR′::PeriodicVector)
for i in 1:length(ψ)
Expand Down
18 changes: 16 additions & 2 deletions src/algorithms/changebonds/optimalexpand.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ An algorithm that expands the given mps as described in
[Zauner-Stauber et al. Phys. Rev. B 97 (2018)](@cite zauner-stauber2018), by selecting the
dominant contributions of a two-site updated MPS tensor, orthogonal to the original ψ.

!!! note
[`changebonds!`](@ref) is only defined for `FiniteMPS`, and modifies both the state and its environment.

## Fields

$(TYPEDFIELDS)
Expand All @@ -17,6 +20,16 @@ $(TYPEDFIELDS)
trscheme::TruncationStrategy
end

# Simple wrapper to convert between diffrent type of InifniteMPS.
function changebonds(
ψ::InfiniteMPS, operator::InfiniteMPO, alg::OptimalExpand, envs = environments(ψ, operator)
)
ψ′, envs′ = changebonds(
convert(MultilineMPS, ψ), convert(MultilineMPO, operator), alg, Multiline([envs])
)
return convert(InfiniteMPS, ψ′), only(parent(envs′))
end

function changebonds(
ψ::InfiniteMPS, H::InfiniteMPOHamiltonian, alg::OptimalExpand,
envs = environments(ψ, H)
Expand All @@ -39,7 +52,7 @@ function changebonds(
end

newψ = _expand(ψ, AL′, AR′)
recalculate!(envs, newψ, H)
envs = environments(newψ, H)
Comment thread
lkdvos marked this conversation as resolved.
return newψ, envs
end

Expand All @@ -64,13 +77,14 @@ function changebonds(ψ::MultilineMPS, H, alg::OptimalExpand, envs = environment
end

newψ = _expand(ψ, AL′, AR′)
recalculate!(envs, newψ, H)
envs = environments(newψ, H) # recalculate!(envs, newψ, H)
Comment thread
lkdvos marked this conversation as resolved.
return newψ, envs
end

function changebonds(ψ::AbstractFiniteMPS, H, alg::OptimalExpand, envs = environments(ψ, H))
return changebonds!(copy(ψ), H, alg, envs)
end

function changebonds!(ψ::AbstractFiniteMPS, H, alg::OptimalExpand, envs = environments(ψ, H))
#inspired by the infinite mps algorithm, alternative is to use https://arxiv.org/pdf/1501.05504.pdf

Expand Down
17 changes: 17 additions & 0 deletions src/algorithms/changebonds/randexpand.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ parallel, and therefore the expansion will never go beyond the local two-site su
The truncation strategy dictates the number of expanded states, by generating uniformly
distributed weights for each state in the two-site space and truncating that.

!!! note
The environments are not used here, but [`changebonds!`](@ref) modifies both the state
and environment so they remain consistent.

## Fields

$(TYPEDFIELDS)
Expand Down Expand Up @@ -50,6 +54,19 @@ end
changebonds(ψ::AbstractMPS, alg::RandExpand) = changebonds!(copy(ψ), alg)
changebonds(ψ::MultilineMPS, alg::RandExpand) = changebonds!(copy(ψ), alg)

function changebonds(ψ, H, alg::RandExpand, envs)
newψ = changebonds(ψ, alg)
return newψ, environments(newψ, H)
end


function changebonds!(ψ, H, alg::RandExpand, envs)
ψ = changebonds!(ψ, alg)
recalculate!(envs, ψ, H)
return ψ, envs
end


function changebonds!(ψ::AbstractFiniteMPS, alg::RandExpand)
for i in 1:(length(ψ) - 1)
AC2 = randomize!(_transpose_front(ψ.AC[i]) * _transpose_tail(ψ.AR[i + 1]))
Expand Down
13 changes: 11 additions & 2 deletions src/algorithms/changebonds/svdcut.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ $(TYPEDEF)
An algorithm that uses truncated SVD to change the bond dimension of a state or operator.
This is achieved by a sweeping algorithm that locally performs (optimal) truncations in a gauged basis.

changedbonds! is only defined for FiniteMPS and FiniteMPO.

See also [`changebonds(!)`](@ref changebonds)

## Fields
Expand Down Expand Up @@ -36,6 +38,12 @@ function changebonds!(ψ::AbstractFiniteMPS, alg::SvdCut; normalize::Bool = true
return normalize ? normalize!(ψ) : ψ
end

function changebonds!(ψ::AbstractFiniteMPS, H, alg::SvdCut, envs)
ψ = changebonds!(ψ, alg)
recalculate!(envs, ψ, H)
return ψ, envs
end

# Note: it might be better to go to an MPS representation first
# such that the SVD cut happens in a canonical form;
# this would still not be the correct norm, so we will ignore this for now.
Expand Down Expand Up @@ -108,8 +116,9 @@ function changebonds(ψ::InfiniteMPS, alg::SvdCut)
return normalize!(ψ)
end

function changebonds(ψ, H, alg::SvdCut, envs = environments(ψ, H))
return changebonds(ψ, alg), envs
function changebonds(ψ, H, alg::SvdCut, envs)
newψ = changebonds(ψ, alg)
return newψ, environments(newψ, H)
end

changebonds(mpo::FiniteMPOHamiltonian, alg::SvdCut) = changebonds!(copy(mpo), alg)
Expand Down
8 changes: 5 additions & 3 deletions src/algorithms/changebonds/vumpssvd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ $(TYPEDEF)

An algorithm that uses a two-site update step to change the bond dimension of a state.

!!! note
[`changebonds!`](@ref) is not defined.

## Fields

$(TYPEDFIELDS)
Expand Down Expand Up @@ -44,9 +47,8 @@ function changebonds_1(
collapsed = InfiniteMPS(
[nstate.AL[1]], nstate.C[1]; alg.alg_gauge.tol, alg.alg_gauge.maxiter
)
recalculate!(envs, collapsed, H, collapsed)

return collapsed, envs
return collapsed, environments(collapsed, H)
end

function changebonds_n(state::InfiniteMPS, H, alg::VUMPSSvdCut, envs = environments(state, H))
Expand Down Expand Up @@ -75,7 +77,7 @@ function changebonds_n(state::InfiniteMPS, H, alg::VUMPSSvdCut, envs = environme
copied[loc] = AL1
copied[loc + 1] = AL2
state = InfiniteMPS(copied; alg.alg_gauge.tol, alg.alg_gauge.maxiter)
recalculate!(envs, state, H, state)
envs = environments(state, H)
end
return state, envs
end
Expand Down
9 changes: 9 additions & 0 deletions src/states/finitemps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,15 @@ function FiniteMPS(
return FiniteMPS(rand, Defaults.eltype, Pspaces, maxVspaces; kwargs...)
end


function FiniteMPS(
elt::Type, Pspaces::Vector{<:Union{S, CompositeSpace{S}}}, maxVspaces::Union{S, Vector{S}};
kwargs...
) where {S <: ElementarySpace}
return FiniteMPS(rand, elt, Pspaces, maxVspaces; kwargs...)
end


# Also accept single physical space and length
function FiniteMPS(N::Int, V::VectorSpace, args...; kwargs...)
return FiniteMPS(fill(V, N), args...; kwargs...)
Expand Down
Loading