Algorithms
Some high level algorithms based on MPS and MPO.
DMRG
Density matrix renormalization group.
FiniteMPS.BondInfo
— Type struct BondInfo
D::Int64
DD::Int64
TrunErr::Float64
SE::Float64
end
Type for storing the information of a bond.
Constructors
BondInfo(s::AbstractTensorMap, ϵ::Float64 = 0.0)
Outer constructor via giving the s
tensor and ϵ
form tsvd
.
BondInfo(A::AbstractTensorMap, direction::Symbol)
BondInfo(A::MPSTensor, direction::Symbol)
Outer constructor via giving a tensor A
and direction = :L
or :R
. We cannot get truncation error and singular values hence TrunErr
and SE
are set to 0.0
and NaN
, respectively.
FiniteMPS.DMRGInfo
— Type struct DMRGInfo
Eg::Float64
Lanczos::LanczosInfo
Bond::BondInfo
end
Information of each DMRG update.
FiniteMPS.LanczosGS
— FunctionLanczosGS(f::Function, x₀, args...;
K::Int64 = 32,
tol::Real = 1e-8,
callback::Union{Nothing, Function} = nothing,
verbose = false
) -> ϵg::Number, xg::AbstractVector, info::Dict{Symbol, Any}
Solve the ground state problem for a hermitian map x -> f(x, args...)
using the Lanczos algorithm. f
can be any function as if it acts on x
like an hermitian operator and preserves the type of x
.
Required methods
x
can be any type as if it behaves like a vector in Hilbert space, i.e. the following methods are implemented:
normalize!(x)
In-place normalize x
according to the inner-induced norm.
norm(x)
Return the inner-induced norm.
inner(x, y)
Return the inner product ⟨x, y⟩
.
add!(y, x, α)
In-place add y -> y + αx
.
rmul!(x, α)
In-place multiply x -> αx
.
Kwargs
K::Int64 = 32
Krylov space dimension.
tol::Real = 1e-8
Convergence tolerance.
callback::Union{Nothing, Function} = nothing
A in-placed callback function, applied to x after each iteration.
verbose::Bool = false
If true
, print convergence information.
FiniteMPS.DMRGSweep2!
— Function DMRGSweep2!(Env::SparseEnvironment{L,3,T}, ::SweepDirection; kwargs...)
-> info::Vector{DMRGInfo}, Timer::TimerOutput
2-site DMRG sweep from left to right or sweep back from right to left.
Kwargs
K::Int64 = 16
Krylov space dimension.
tol::Real = 1e-8
Tolerance for eagerly break in Lanczos iteration.
trunc::TruncationScheme = truncbelow(MPSDefault.tol) & truncdim(MPSDefault.D)
Control the truncation in svd after each 2-site update. Details see tsvd
.
GCstep::Bool = false
GC.gc()
manually after each step if true
.
GCsweep::Bool = false
GC.gc()
manually after each (left to right or right to left) sweep if true
.
verbose::Int64 = 0
Print the TimerOutput
after each sweep or each local update if verbose = 1
or 2
, respectively.
noise::Real = 0
Add noise to the 2-site local tensor after each update via applying a random gate to the physical indices. Note this is only a naive implementation, and may not work well for some cases.
FiniteMPS.DMRGSweep1!
— Function DMRGSweep1!(Env::SparseEnvironment{L,3,T}, ::SweepDirection; kwargs...)
-> info::Vector{DMRGInfo}, Timer::TimerOutput
1-site DMRG sweep from left to right or sweep back from right to left.
Kwargs
K::Int64 = 16
Krylov space dimension.
tol::Real = 1e-8
Tolerance for eagerly break in Lanczos iteration.
GCstep::Bool = false
GC.gc()
manually after each step if true
.
GCsweep::Bool = false
GC.gc()
manually after each (left to right or right to left) sweep if true
.
verbose::Int64 = 0
Print the TimerOutput
after each sweep or each local update if verbose = 1
or 2
, respectively.
CBEAlg::CBEAlgorithm = NoCBE()
CBE algorithm for 1-DMRG.
trunc::TruncationScheme = notrunc()
Control the truncation after each update, only used together with CBE. Details see tsvd
.
noise::NTuple{2, Float64} = (0.1, 0.0)
Add noise to the 1-site local tensor after each Lanczos update via expanding the bond and add a random tensor (normal distribution) to it. The first element is the ratio of additional bond dimension (≤ 1.0)
, the second element is the noise strength.
TDVP
Time-dependent variational principle for both MPS and MPO (viewed as a MPS via Choi isomorphism).
Note the local projective Hamiltonian action in TDVPSweep2!
has not been updated to newest implementation. Using 1-TDVP equipped with controlled bond expansion (CBE) is preferred.
FiniteMPS.TDVPInfo
— Type struct TDVPInfo{N,T}
dt::T
Lanczos::LanczosInfo
Bond::BondInfo
end
Information of each N
-site TDVP update.
Constructors
TDVPInfo{N}(dt::Number, Lanczos::LanczosInfo, Bond::BondInfo)
FiniteMPS.LanczosExp
— FunctionLanczosExp(f::Function, x₀, t::Number, args...;
K::Int64 = 32,
tol::Real = 1e-8,
callback::Union{Nothing, Function} = nothing,
verbose = false
) -> exp(At)*x, info::Dict{Symbol, Any}
Compute exp(At)x₀
for a hermitian map A: x -> f(x, args...)
using the Lanczos algorithm. f
can be any function as if it acts on x
like an hermitian operator and preserves the type of x
.
Required methods
x
can be any type as if it behaves like a vector in Hilbert space, i.e. the following methods are implemented:
eltype(x)
Return the element type of x
, e.g. Float64
or ComplexF64
.
normalize!(x)
In-place normalize x
according to the inner-induced norm.
norm(x)
Return the inner-induced norm.
inner(x, y)
Return the inner product ⟨x, y⟩
.
add!(y, x, α)
In-place add y -> y + αx
.
rmul!(x, α)
In-place multiply x -> αx
.
Kwargs
K::Int64 = 32
Krylov space dimension.
tol::Real = 1e-8
Convergence tolerance.
callback::Union{Nothing, Function} = nothing
A in-placed callback function, applied to x after each iteration.
verbose::Bool = false
If true
, print convergence information.
FiniteMPS.TDVPSweep2!
— Function TDVPSweep2!(Env::SparseEnvironment{L,3,T},
dt::Number,
direction::SweepDirection;
kwargs...) -> info, TimerSweep
Apply left-to-right or right-to-left 2-site TDVP[https://doi.org/10.1103/PhysRevB.94.165116]
sweep to perform time evolution for DenseMPS
(both MPS and MPO) with step length dt
. Env
is the 3-layer environment ⟨Ψ|H|Ψ⟩
.
TDVPSweep2!(Env::SparseEnvironment{L,3,T}, dt::Number; kwargs...)
Wrap TDVPSweep2!
with a symmetric integrator, i.e., sweeping from left to right and then from right to left with the same step length dt / 2
.
Kwargs
krylovalg::KrylovKit.KrylovAlgorithm = TDVPDefaultLanczos
trunc::TruncationType = truncbelow(MPSDefault.tol) & truncdim(MPSDefault.D)
GCstep::Bool = false
GCsweep::Bool = false
verbose::Int64 = 0
E_shift::Float64 = 0.0
Apply exp(dt(H - E_shift))
to avoid possible Inf
in imaginary time evolution. This energy shift is different from E₀
in projective Hamiltonian, the later will give back the shifted energy thus not altering the final result. Note this is a temporary approach, we intend to store log(norm)
in MPS to avoid this divergence in the future.
FiniteMPS.TDVPSweep1!
— Function TDVPSweep1!(Env::SparseEnvironment{L,3,T},
dt::Number,
direction::SweepDirection;
kwargs...) -> info, TimerSweep
Apply 1-site TDVP[https://doi.org/10.1103/PhysRevB.94.165116]
sweep to perform time evolution for DenseMPS
(both MPS and MPO) with step length dt
. Env
is the 3-layer environment ⟨Ψ|H|Ψ⟩
.
TDVPSweep1!(Env::SparseEnvironment{L,3,T}, dt::Number; kwargs...)
Wrap TDVPSweep1!
with a symmetric integrator, i.e., sweeping from left to right and then from right to left with the same step length dt / 2
.
Kwargs
K::Int64 = 32
tol::Float64 = 1e-8
The maximum Krylov dimension and tolerance in Lanczos exponential method.
trunc::TruncationType = notrunc()
GCstep::Bool = false
GCsweep::Bool = false
verbose::Int64 = 0
CBEAlg::CBEAlgorithm = NoCBE()
E_shift::Float64 = 0.0
Apply exp(dt(H - E_shift))
to avoid possible Inf
in imaginary time evolution. This energy shift is different from E₀
in projective Hamiltonian, the later will give back the shifted energy thus not altering the final result. Note this is a temporary approach, we intend to store log(norm)
in MPS to avoid this divergence in the future.
FiniteMPS.TDVPIntegrator
— Type struct TDVPIntegrator{N}
dt::NTuple{N, Float64}
direction::NTuple{N, SweepDirection}
end
Type of TDVP integrators using composition methods. Note dt
is relative, thus sum(dt) == 1
.
Constructors
TDVPIntegrator(dt::NTuple{N, Rational}, direction::NTuple{N, SweepDirection})
Standard constructor with checking dt
and direction
.
TDVPIntegrator(dt::Number...)
Assume direction is repeated as L-R-L-R-..., thus length(dt)
must be even.
FiniteMPS.SymmetricIntegrator
— Function SymmetricIntegrator(p::Int64) -> TDVPIntegrator
Construct predefined symmetric integrators with p
-th order. Only p = 2, 3, 4
are supported.
SETTN
Series-expansion thermal tensor network.
FiniteMPS.SETTN
— Function SETTN(H::SparseMPO, β::Number; kwargs...) -> ρ::MPO, lsF::Vector{Float64}
Use series-expansion thermal tensor network (SETTN)[https://doi.org/10.1103/PhysRevB.95.161104]
method to initialize a high-temperature MPO ρ = e^(-βH/2)
. Note ρ
is unnormalized. The list of free energy F = -lnTr[ρρ^†]/β
with different expansion orders is also returned.
Kwargs
trunc::TruncationScheme = truncdim(D) (this keyword argument is necessary!)
disk::Bool = false
maxorder::Int64 = 4
tol::Float64 = 1e-8
bspace::VectorSpace (details please see identityMPO)
compress::Float64 = 1e-16 (finally compress ρ with `tol = compress`)
ρ₀::MPO (initial MPO, default = Id)
Note we use mul!
and axpby!
to implement H^n -> H^(n+1)
and ρ -> ρ + (-βH/2)^n / n!
, respectively. All kwargs of these two functions are valid and will be propagated to them appropriately.
CBE
Controlled bond expansion (CBE). In the current version only a modified (based on rsvd, instead of shrewd selection) CBE is implemented, which is compatible with multi-threading.
FiniteMPS.CBEAlgorithm
— Type abstract type CBEAlgorithm{T <: SweepDirection}
Abstract type of all (controlled bond expansion) CBE algorithms.
FiniteMPS.NoCBE
— Type struct NoCBE{T <: SweepDirection} <: CBEAlgorithm{T}
FiniteMPS.FullCBE
— Type struct FullCBE{T <: SweepDirection} <: CBEAlgorithm{T}
check::Bool
end
Special case of CBE algorithm, directly keep the full bond space, usually used near boundary.
Constructor
FullCBE(direction::SweepDirection = AnyDirection(); check::Bool = false)
FiniteMPS.NaiveCBE
— Type struct NaiveCBE{T<:SweepDirection} <: CBEAlgorithm{T}
D::Int64
tol::Float64
rsvd::Bool
check::Bool
end
An naive implementation of CBE, where we directly contract the 2-site environment and then perform svd. Note the svd is O(D^3d^3) or O(D^3d^6) for MPS or MPO, respectively, which becomes the bottleneck of the algorithm. Therefore, a random svd is used to reduce the svd cost to O(D^3d) or O(D^3d^2).
Constructor
NaiveCBE(D::Int64,
tol::Float64,
direction::SweepDirection = AnyDirection();
rsvd::Bool = false,
check::Bool = false)
FiniteMPS.CBEInfo
— Type struct CBEInfo{N}
Alg::CBEAlgorithm
info::NTuple{N, BondInfo}
D₀::NTuple{2, Int64}
D::NTuple{2, Int64}
ϵp::Float64
ϵ::Float64
end
Information of CBE. Alg
is the algorithm used. info
contain the truncation info of N
times svd. D₀
and D
are the initial and final bond dimension, respectively. ϵp
is the estimated projection error. ϵ = |Al*Ar - Al_ex*Ar_ex|
if calculated (otherwise NaN
).
FiniteMPS.CBE
— Function CBE(Al::MPSTensor, Ar::MPSTensor,
El::SparseLeftTensor, Er::SparseRightTensor,
Hl::SparseMPOTensor, Hr::SparseMPOTensor,
Alg::CBEAlgorithm
) -> Al_ex::MPSTensor, Ar_ex::MPSTensor, info::CBEInfo, TO::TimerOutput
Return the two expanded local tensors Al_ex
and Ar_ex
after CBE.
FiniteMPS.LeftOrthComplement
— Typestruct LeftOrthComplement{N}
El::Vector{AbstractTensorMap}
Al::Vector{AbstractTensorMap}
Al_c::AbstractTensorMap
end
A concrete type to deal with the left half of the orthogonal complement projector of 1-site tangent space in the 2-site variational space.
Constructors
LeftOrthComplement(El_i::SparseLeftTensor,
Al_c::MPSTensor{R},
Hl::SparseMPOTensor,
Al_i::MPSTensor = Al_c)
Construct the object via providing the initial left environment tensor El_i
, the left canonical MPS tensor Al_c
, the Hamiltonian MPO tensor Hl
, and the initial local tensor at the left site. The initialization process will automatically generate the temporary tensors El
and Al
that are used in the CBE algorithm.
FiniteMPS.RightOrthComplement
— Typestruct RightOrthComplement{N}
Er::Vector{AbstractTensorMap}
Ar::Vector{AbstractTensorMap}
Ar_c::AbstractTensorMap
end
A concrete type to deal with the right half of the orthogonal complement projector of 1-site tangent space in the 2-site variational space.
Constructors
RightOrthComplement(Er_i::SparseRightTensor,
Ar_c::MPSTensor{R},
Hr::SparseMPOTensor,
Ar_i::MPSTensor{R} = Ar_c)
Construct the object via providing the initial right environment tensor Er_i
, the right canonical MPS tensor Ar_c
, the Hamiltonian MPO tensor Hr
, and the initial local tensor at the right site. The initialization process will automatically generate the temporary tensors Er
and Ar
that are used in the CBE algorithm.