Skip to content
Open
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
19 changes: 17 additions & 2 deletions src/algorithms/changebonds/optimalexpand.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ 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 ψ.

changedbonds! is only defined for FiniteMPS, and modify its environment.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
changedbonds! is only defined for FiniteMPS, and modify its environment.
!!! note
`changebonds!` is only defined for `FiniteMPS`, and modifies its environment.


## Fields

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

##= This is only useful for OptimalExpand
Comment thread
lkdvos marked this conversation as resolved.
### 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 +53,7 @@ function changebonds(
end

newψ = _expand(ψ, AL′, AR′)
recalculate!(envs, newψ, H)
envs = environments(newψ, H)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely following this change. Is it not possible to overwrite the old environments?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I think I see now what you intended: is it that the non-bang (!) functions shouldn't modify their inputs?
I can see that being a good choice, I think it is mostly that the envs are always kind of treated as a special thing that is modified everywhere.
I'm happy either way, I think you have a better feeling of what is convenient/efficient.

return newψ, envs
end

Expand All @@ -64,13 +78,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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here

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
16 changes: 16 additions & 0 deletions src/algorithms/changebonds/randexpand.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ 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.

The environments are not used here.
changebonds! modify both the provided state and environments.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
changebonds! modify both the provided state and environments.
`changebonds!` modifies both the provided state and environments.


## Fields

$(TYPEDFIELDS)
Expand Down Expand Up @@ -50,6 +53,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
7 changes: 4 additions & 3 deletions src/algorithms/changebonds/vumpssvd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ $(TYPEDEF)

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

changedbonds! is not defined.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
changedbonds! is not defined.
!!! note
`changebonds!` is not defined.


## Fields

$(TYPEDFIELDS)
Expand Down Expand Up @@ -44,9 +46,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 +76,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