Skip to content

Commit

Permalink
bugfixes + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DaanMaertens committed Jul 13, 2023
1 parent 0473aaf commit e6ae6d6
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 155 deletions.
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,3 @@ docs/build
Manifest.toml
.vscode
.DS_Store
timedepenv_old.jl
Testfile.jl
tdvp_old.jl
timedeptdvp_old.jl
derivatives_old.jl
timedep.jl
2 changes: 0 additions & 2 deletions src/MPSKit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ end
include("utility/periodicarray.jl")
include("utility/utility.jl") #random utility functions
include("utility/plotting.jl")
#include("utility/linearcombination.jl")

#maybe we should introduce an abstract state type
include("states/window.jl")
Expand Down Expand Up @@ -103,7 +102,6 @@ include("environments/mpohaminfenv.jl")
include("environments/multipleenv.jl")
include("environments/qpenv.jl")
include("environments/idmrgenv.jl")
#include("environments/lazylincocache.jl")

abstract type Algorithm end

Expand Down
4 changes: 1 addition & 3 deletions src/algorithms/expval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,9 @@ end

expectation_value(state::FiniteQP,opp) = expectation_value(convert(FiniteMPS,state),opp)

# ignore time-dependence by default
expectation_value(Ψ,op,t::Number,args...) = expectation_value(Ψ,op,args...)

# define expectation_value for MultipliedOperator as scalar multiplication of the non-multiplied result, instead of multiplying the operator itself
expectation_value(Ψ,op::TimedOperator,t::Number,args...) = op.f(t)*expectation_value(Ψ,op.op,args...)
expectation_value(Ψ,op::UntimedOperator,t::Number,args...) = expectation_value(Ψ,op::UntimedOperator,args...)
expectation_value(Ψ,op::UntimedOperator,args...) = op.f*expectation_value(Ψ,op.op,args...)

# define expectation_value for SumOfOperators
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/timestep/tdvp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function timestep!(Ψ::AbstractFiniteMPS, H, t::Number, dt::Number, alg::TDVP2,
end

# time-independent version
timestep(Ψ, H, dt, alg, env; kwargs...) = timestep(Ψ, H, 0., dt, alg, env; kwargs...)
timestep(Ψ, H, dt, alg, env=environments(Ψ, H); kwargs...) = timestep(Ψ, H, 0., dt, alg, env; kwargs...)

#copying version
function timestep::AbstractFiniteMPS, H, time ,timestep, alg::Union{TDVP,TDVP2},
Expand Down
12 changes: 6 additions & 6 deletions src/algorithms/timestep/windowtdvp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ function rightexpand(st::WindowMPS,H::Union{<:MultipliedOperator,<:SumOfOperator
end
rightexpand(st::WindowMPS,H::Union{MPOHamiltonian,DenseMPO,SparseMPO},t::Number,Envs; kwargs...) = rightexpand(st,UntimedOperator(H),t,Envs; kwargs...)

Check warning on line 83 in src/algorithms/timestep/windowtdvp.jl

View check run for this annotation

Codecov / codecov/patch

src/algorithms/timestep/windowtdvp.jl#L83

Added line #L83 was not covered by tests

function timestep!::WindowMPS, H::Window, t::Number, dt::Number,alg::TDVP,env::Window=environments(Ψ,H))
function timestep!::WindowMPS, H::Window, t::Number, dt::Number,alg::TDVP,env::Window=environments(Ψ,H); leftevolve=true, rightevolve=true)

#first evolve left state
if !isnothing(H.left)
if leftevolve
nleft, _ = timestep.left_gs, H.left, t, dt, alg, env.left; leftorthflag = true) #env gets updated in place
_update_leftEnv!(nleft, env)
else
Expand Down Expand Up @@ -113,7 +113,7 @@ function timestep!(Ψ::WindowMPS, H::Window, t::Number, dt::Number,alg::TDVP,env
converged == 0 &&
@info "time evolving ac($(length(Ψ))) failed $(convhist.normres)"

if !isnothing(H.right)
if rightevolve
nright, _ = timestep.right_gs, H.right, t, dt, alg, env.right, leftorthflag = false) #env gets updated in place
_update_rightEnv!(nright, env)
else
Expand Down Expand Up @@ -141,11 +141,11 @@ function timestep!(Ψ::WindowMPS, H::Window, t::Number, dt::Number,alg::TDVP,env
return WindowMPS(nleft,Ψ.window,nright),env
end

function timestep!::WindowMPS, H::Window, t::Number, dt::Number,alg::TDVP2,env::Window=environments(Ψ,H); kwargs...)
function timestep!::WindowMPS, H::Window, t::Number, dt::Number,alg::TDVP2,env::Window=environments(Ψ,H); leftevolve=false, rightevolve = false, kwargs...)
singleTDVPalg = TDVP(integrator=alg.integrator,tolgauge=alg.tolgauge,maxiter=alg.maxiter)

Check warning on line 145 in src/algorithms/timestep/windowtdvp.jl

View check run for this annotation

Codecov / codecov/patch

src/algorithms/timestep/windowtdvp.jl#L144-L145

Added lines #L144 - L145 were not covered by tests

#first evolve left state
if !isnothing(H.left)
if leftevolve

Check warning on line 148 in src/algorithms/timestep/windowtdvp.jl

View check run for this annotation

Codecov / codecov/patch

src/algorithms/timestep/windowtdvp.jl#L148

Added line #L148 was not covered by tests
# expand the bond dimension using changebonds
nleft,_ = leftexpand(Ψ,H.left,t,env.left; kwargs...)

Check warning on line 150 in src/algorithms/timestep/windowtdvp.jl

View check run for this annotation

Codecov / codecov/patch

src/algorithms/timestep/windowtdvp.jl#L150

Added line #L150 was not covered by tests
# fill it by doing regular TDVP
Expand Down Expand Up @@ -175,7 +175,7 @@ function timestep!(Ψ::WindowMPS, H::Window, t::Number, dt::Number,alg::TDVP2,en
end
end

Check warning on line 176 in src/algorithms/timestep/windowtdvp.jl

View check run for this annotation

Codecov / codecov/patch

src/algorithms/timestep/windowtdvp.jl#L176

Added line #L176 was not covered by tests

if !isnothing(H.right)
if rightevolve

Check warning on line 178 in src/algorithms/timestep/windowtdvp.jl

View check run for this annotation

Codecov / codecov/patch

src/algorithms/timestep/windowtdvp.jl#L178

Added line #L178 was not covered by tests
# expand the bond dimension using changebonds
nright,_ = rightexpand(Ψ,H.right,t,env.right; kwargs...)

Check warning on line 180 in src/algorithms/timestep/windowtdvp.jl

View check run for this annotation

Codecov / codecov/patch

src/algorithms/timestep/windowtdvp.jl#L180

Added line #L180 was not covered by tests
# fill it by doing regular TDVP
Expand Down
10 changes: 4 additions & 6 deletions src/environments/multipleenv.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# should this just be a alias for AbstractVector{C} where C <: Cache ?
# const MultipleEnvironments = AbstractVector{C} where C <: Cache

struct MultipleEnvironments{C}
struct MultipleEnvironments{O,C} <: Cache
opp::O
envs::Vector{C}
end

Expand All @@ -13,10 +11,10 @@ Base.iterate(x::MultipleEnvironments) = iterate(x.envs)
Base.iterate(x::MultipleEnvironments,i) = iterate(x.envs,i)

# we need constructor, agnostic of particular MPS
environments(st,ham::SumOfOperators) = MultipleEnvironments( map(op->environments(st,op),ham.ops) )
environments(st,ham::SumOfOperators) = MultipleEnvironments(ham, map(op->environments(st,op),ham.ops) )

environments(st::WindowMPS,ham::SumOfOperators;lenvs=environments(st.left_gs,ham),renvs=environments(st.right_gs,ham)) =
MultipleEnvironments( map( (op,sublenv,subrenv)->environments(st,op;lenvs=sublenv,renvs=subrenv),ham.ops,lenvs,renvs) )
MultipleEnvironments(ham, map( (op,sublenv,subrenv)->environments(st,op;lenvs=sublenv,renvs=subrenv),ham.ops,lenvs,renvs) )

# we need to define how to recalculate
"""
Expand Down
5 changes: 1 addition & 4 deletions src/operators/multipliedoperator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ function Base.:*(op::TimedOperator, b::Number)
end
Base.:*(b::Number, op::MultipliedOperator) = op * b

Check warning on line 42 in src/operators/multipliedoperator.jl

View check run for this annotation

Codecov / codecov/patch

src/operators/multipliedoperator.jl#L42

Added line #L42 was not covered by tests

#do we need to define * for two TimedOperators?

Base.convert(::Type{MultipliedOperator},x::Union{MPOHamiltonian,DenseMPO,SparseMPO}) = UntimedOperator(x)
#Base.convert(::Type{TimedOperator},x::Union{MPOHamiltonian,DenseMPO,SparseMPO}) = TimedOperator(x)
(x::UntimedOperator)() = x.f*x.op

#ignore time-dependence by default
(x::MultipliedOperator)(t::Number) = x
Expand Down
9 changes: 6 additions & 3 deletions src/operators/sumofoperators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ Base.length(x::SumOfOperators) = prod(size(x))
# singleton constructor
SumOfOperators(x) = SumOfOperators([x])

Check warning on line 16 in src/operators/sumofoperators.jl

View check run for this annotation

Codecov / codecov/patch

src/operators/sumofoperators.jl#L16

Added line #L16 was not covered by tests

# handy constructor for SumOfOperators{TimedOperator} and backwards compatibility for LinearCombination
LinearCombination(ops::Union{AbstractVector,Tuple},fs::Union{AbstractVector,Tuple}) = SumOfOperators( collect(map( (op,f)->MultipliedOperator(op,f),ops,fs)) )
# handy constructor for SumOfOperators{MultipliedOperator} and backwards compatibility for LinearCombination
SumOfOperators(ops::AbstractVector,fs::AbstractVector) = SumOfOperators( map( (op,f)->MultipliedOperator(op,f),ops,fs))
LinearCombination(ops::Tuple,fs::Tuple) = SumOfOperators( collect(ops), collect(fs))


# we can add operators to SumOfOperators by using +
Base.:+(op1::MultipliedOperator{O,F},op2::MultipliedOperator{O,F}) where {O,F} = SumOfOperators([op1,op2])
Base.:+(op1::MultipliedOperator{O,F},op2::MultipliedOperator{O,G}) where {O,F,G} = SumOfOperators([op1,op2])

# this we can also do with promote
Base.:+(op1::TimedOperator{O},op2::Union{O,UntimedOperator{O}}) where O = SumOfOperators(TimedOperator{O}[op1, TimedOperator(op2) ])
Expand All @@ -36,6 +37,8 @@ Base.:+(SumOfOps1::SumOfOperators{O},SumOfOps2::SumOfOperators{O}) where {O} = S
Base.:+(SumOfOps::SumOfOperators{T},op::O) where {O,T<:MultipliedOperator{O}} = SumOfOps + SumOfOperators(UntimedOperator(op))
Base.:+(op::O,SumOfOps::SumOfOperators{T}) where {O,T<:MultipliedOperator{O}} = SumOfOperators(UntimedOperator(op)) + SumOfOps

Check warning on line 38 in src/operators/sumofoperators.jl

View check run for this annotation

Codecov / codecov/patch

src/operators/sumofoperators.jl#L37-L38

Added lines #L37 - L38 were not covered by tests

(x::SumOfOperators{<: UntimedOperator})() = sum(op->op(),x)

#ignore time-dependence by default
(x::SumOfOperators)(t::Number) = x

Expand Down
26 changes: 15 additions & 11 deletions src/states/windowmps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ mutable struct WindowMPS{A<:GenericMPSTensor,B<:MPSBondTensor} <: AbstractFinite
window::FiniteMPS{A,B}
right_gs::InfiniteMPS{A,B}

function WindowMPS(Ψₗ::InfiniteMPS{A,B}, Ψₘ::FiniteMPS{A,B},
Ψᵣ::InfiniteMPS{A,B}=copy(Ψₗ)) where {A<:GenericMPSTensor,B<:MPSBondTensor}
left_virtualspace(Ψₗ, 0) == left_virtualspace(Ψₘ, 0) &&
right_virtualspace(Ψₘ, length(Ψₘ)) == right_virtualspace(Ψᵣ, length(Ψₘ)) ||
function WindowMPS{A,B}(Ψₗ::InfiniteMPS{A,B}, Ψₘ::FiniteMPS{A,B},
Ψᵣ::InfiniteMPS{A,B}=Ψₗ) where {A<:GenericMPSTensor,B<:MPSBondTensor}
right_virtualspace(Ψₗ, 0) == left_virtualspace(Ψₘ, 0) &&
right_virtualspace(Ψₘ, length(Ψₘ)) == left_virtualspace(Ψᵣ, 0) ||
throw(SpaceMismatch("Mismatch between window and environment virtual spaces"))
return new{A,B}(Ψₗ, Ψₘ, Ψᵣ)
end
Expand All @@ -53,34 +53,38 @@ end
Constructors
===========================================================================================#
# here i would like an outer constructor that copies the left and right inf environments
function WindowMPS(Ψₗ::InfiniteMPS{A,B},Ψₘ::FiniteMPS{A,B},
Ψᵣ::InfiniteMPS{A,B}=Ψₗ; docopy = true) where {A<:GenericMPSTensor,B<:MPSBondTensor}
return WindowMPS{A,B}(docopy ? copy(Ψₗ) : Ψₗ, Ψₘ, docopy ? copy(Ψᵣ) : Ψᵣ)
end

function WindowMPS(Ψₗ::InfiniteMPS, site_tensors::AbstractVector{<:GenericMPSTensor},
Ψᵣ::InfiniteMPS=copy(Ψₗ))
Ψᵣ::InfiniteMPS=Ψₗ)
return WindowMPS(Ψₗ, FiniteMPS(site_tensors), Ψᵣ)
end

function WindowMPS(f, elt, physspaces::Vector{<:Union{S,CompositeSpace{S}}},
maxvirtspace::S, Ψₗ::InfiniteMPS,
Ψᵣ::InfiniteMPS=copy(Ψₗ)) where {S<:ElementarySpace}
Ψᵣ::InfiniteMPS=Ψₗ) where {S<:ElementarySpace}
Ψₘ = FiniteMPS(f, elt, physspaces, maxvirtspace; left=left_virtualspace(Ψₗ, 0),
right=right_virtualspace(Ψᵣ, length(physspaces)))
return WindowMPS(Ψₗ, Ψₘ, Ψᵣ)
end
function WindowMPS(physspaces::Vector{<:Union{S,CompositeSpace{S}}},

Check warning on line 73 in src/states/windowmps.jl

View check run for this annotation

Codecov / codecov/patch

src/states/windowmps.jl#L73

Added line #L73 was not covered by tests
maxvirtspace::S, Ψₗ::InfiniteMPS,
Ψᵣ::InfiniteMPS=copy(Ψₗ)) where {S<:ElementarySpace}
Ψᵣ::InfiniteMPS=Ψₗ) where {S<:ElementarySpace}
return WindowMPS(rand, Defaults.eltype, physspaces, maxvirtspace, Ψₗ, Ψᵣ)

Check warning on line 76 in src/states/windowmps.jl

View check run for this annotation

Codecov / codecov/patch

src/states/windowmps.jl#L76

Added line #L76 was not covered by tests
end

function WindowMPS(f, elt, physspaces::Vector{<:Union{S,CompositeSpace{S}}},

Check warning on line 79 in src/states/windowmps.jl

View check run for this annotation

Codecov / codecov/patch

src/states/windowmps.jl#L79

Added line #L79 was not covered by tests
virtspaces::Vector{S}, Ψₗ::InfiniteMPS,
Ψᵣ::InfiniteMPS=copy(Ψₗ)) where {S<:ElementarySpace}
Ψᵣ::InfiniteMPS=Ψₗ) where {S<:ElementarySpace}
Ψₘ = FiniteMPS(f, elt, physspaces, virtspaces)
return WindowMPS(Ψₗ, Ψₘ, Ψᵣ)

Check warning on line 83 in src/states/windowmps.jl

View check run for this annotation

Codecov / codecov/patch

src/states/windowmps.jl#L82-L83

Added lines #L82 - L83 were not covered by tests
end
function WindowMPS(physspaces::Vector{<:Union{S,CompositeSpace{S}}},

Check warning on line 85 in src/states/windowmps.jl

View check run for this annotation

Codecov / codecov/patch

src/states/windowmps.jl#L85

Added line #L85 was not covered by tests
virtspaces::Vector{S}, Ψₗ::InfiniteMPS,
Ψᵣ::InfiniteMPS=copy(Ψₗ)) where {S<:ElementarySpace}
Ψᵣ::InfiniteMPS=Ψₗ) where {S<:ElementarySpace}
return WindowMPS(rand, Defaults.eltype, physspaces, virtspaces, Ψₗ, Ψᵣ)

Check warning on line 88 in src/states/windowmps.jl

View check run for this annotation

Codecov / codecov/patch

src/states/windowmps.jl#L88

Added line #L88 was not covered by tests
end

Expand Down Expand Up @@ -109,15 +113,15 @@ function WindowMPS(Ψ::InfiniteMPS{A,B}, L::Int) where {A,B}
ACs .= Ψ.AC[1:L]
CLs .= Ψ.CR[0:L]

return WindowMPS(copy(Ψ), FiniteMPS(ALs, ARs, ACs, CLs), copy(Ψ))
return WindowMPS(Ψ, FiniteMPS(ALs, ARs, ACs, CLs), Ψ)
end

#===========================================================================================
Utility
===========================================================================================#

function Base.copy::WindowMPS)
return WindowMPS(copy(Ψ.left_gs), copy.window), copy(Ψ.right_gs))
return WindowMPS.left_gs, copy.window), Ψ.right_gs)
end

# not sure about the underlying methods...
Expand Down
96 changes: 16 additions & 80 deletions test/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ println("------------------------------------")
ψ₀ = InfiniteMPS([𝔹^2], [𝔹^10])
v₀ = variance(ψ₀, H)

end

@testset "timestep" verbose = true begin
dt = 0.1
algs = [TDVP(), TDVP2()]
Expand Down Expand Up @@ -47,11 +49,11 @@ println("------------------------------------")

Ht = TimedOperator(H,f)
(ψt, envst) = timestep(ψ₀, Ht, t, dt, alg)
Et = expectation_value(ψt, Ht, 0., envst)
Et = expectation_value(ψt, Ht, t, envst)

Hunt = Ht(t)
(ψ, envs) = timestep(ψ₀, Hunt, dt, alg)
Euntt = expectation_value(ψ, Hunt, envs)
Eunt = expectation_value(ψ, Hunt, envs)

Hmult = f(t)*H
(ψ, envs) = timestep(ψ₀, Hmult, dt, alg)
Expand All @@ -72,12 +74,12 @@ println("------------------------------------")
@test sum(E₀) sum(E) atol = 1e-2
end

@testset "Finite Trivial TimedOperator TDVP" begin
ψ, envs = timestep(ψ₀, H, dt, alg)
@testset "Finite Trivial TimedOperator TDVP" begin
ψ, envs = timestep(ψ₀, H, dt, algs[1])
E = expectation_value(ψ, H, envs)

Ht = TimedOperator(H)
(ψt, envst) = timestep(ψ₀, Ht, 0., dt, alg)
(ψt, envst) = timestep(ψ₀, Ht, 0., dt, algs[1])
Et = expectation_value(ψt, Ht, 0., envst)

@test sum(E) sum(Et) atol = 1e-10
Expand All @@ -87,15 +89,15 @@ println("------------------------------------")
f(t) = 3cos(t); t = 1.

Ht = TimedOperator(H,f)
(ψt, envst) = timestep(ψ₀, Ht, t, dt, alg)
Et = expectation_value(ψt, Ht, 0., envst)
(ψt, envst) = timestep(ψ₀, Ht, t, dt, algs[1])
Et = expectation_value(ψt, Ht, t, envst)

Hunt = Ht(t)
(ψ, envs) = timestep(ψ₀, Hunt, dt, alg)
Euntt = expectation_value(ψ, Hunt, envs)
(ψ, envs) = timestep(ψ₀, Hunt, dt, algs[1])
Eunt = expectation_value(ψ, Hunt, envs)

Hmult = f(t)*H
(ψ, envs) = timestep(ψ₀, Hmult, dt, alg)
(ψ, envs) = timestep(ψ₀, Hmult, dt, algs[1])
Emult = expectation_value(ψ, Hmult, envs)

@test sum(Eunt) sum(Et) atol = 1e-2
Expand All @@ -108,7 +110,7 @@ end

@testset "time evolution windowMPS" begin

simpleH = xxx(; spin=1 // 2)
simpleH = heisenberg_XXX(; spin=1 // 2)
alg = TDVP()

# with regular MPOHamiltonian
Expand Down Expand Up @@ -147,75 +149,9 @@ end
timevolvedwindow_t,WindEnvs_t = timestep(Ψwindow,Hwindow_t,0.,0.1,alg,WindEnvs_t);

@test timevolvedwindow_t.left_gs timevolvedwindow_0.left_gs atol = 1e-10
@test timevolvedwindow_t.window timevolvedwindow_0.window atol = 1e-12
@test timevolvedwindow_t.right_gs timevolvedwindow_0.right_gs atol = 1e-12
@test timevolvedwindow_t.window timevolvedwindow_0.window atol = 1e-10
@test timevolvedwindow_t.right_gs timevolvedwindow_0.right_gs atol = 1e-10

end

@timedtestset "leading_boundary $(ind)" for (ind, alg) in
enumerate([VUMPS(; tol_galerkin=1e-5,
verbose=false)
GradientGrassmann(; verbosity=0)])
mpo = force_planar(nonsym_ising_mpo())
state = InfiniteMPS([𝔹^2], [𝔹^10])
(state, envs) = leading_boundary(state, mpo, alg)
(state, envs) = changebonds(state, mpo, OptimalExpand(; trscheme=truncdim(3)), envs)
(state, envs) = leading_boundary(state, mpo, alg)

@test dim(space(state.AL[1, 1], 1)) == 13
@test expectation_value(state, envs)[1, 1] 2.5337 atol = 1e-3
end

@timedtestset "quasiparticle_excitation" begin
@timedtestset "infinite (ham)" begin
th = repeat(force_planar(xxx()), 2)
ts = InfiniteMPS([𝔹^3, 𝔹^3], [𝔹^48, 𝔹^48])
ts, envs, _ = find_groundstate(ts, th; maxiter=400, verbose=false)
energies, Bs = excitations(th, QuasiparticleAnsatz(), Float64(pi), ts, envs)
@test energies[1] 0.41047925 atol = 1e-4
@test variance(Bs[1], th) < 1e-8
end

finite_algs = [DMRG(; verbose=verbosity > 0),
DMRG2(; verbose=verbosity > 0, trscheme=truncdim(10)),
GradientGrassmann(; verbosity=verbosity)]

@testset "Finite $i" for (i, alg) in enumerate(finite_algs)
ψ₀ = FiniteMPS(rand, ComplexF64, 10, 𝔹^2, 𝔹^10)
H = force_planar(transverse_field_ising(; g=1.1))

v₀ = variance(ψ₀, H)
ψ, envs, δ = find_groundstate(ψ₀, H, alg)
v = variance(ψ, H, envs)

@test sum(δ) < 100 * tol
@test v₀ > v && v < 1e-2 # energy variance should be low
end
end

@testset "timestep" verbose = true begin
dt = 0.1
algs = [TDVP(), TDVP2()]

H = force_planar(heisenberg_XXX(; spin=1 // 2))
ψ₀ = FiniteMPS(fill(TensorMap(rand, ComplexF64, 𝔹^1 * 𝔹^2, 𝔹^1), 5))
E₀ = expectation_value(ψ₀, H)

@testset "Finite $(alg isa TDVP ? "TDVP" : "TDVP2")" for alg in algs
ψ, envs = timestep(ψ₀, H, dt, alg)
E = expectation_value(ψ, H, envs)
@test sum(E₀) sum(E) atol = 1e-2
end

H = force_planar(heisenberg_XXX(InfiniteChain(2); spin=1))
ψ₀ = InfiniteMPS([𝔹^3, 𝔹^3], [𝔹^50, 𝔹^50])
E₀ = expectation_value(ψ₀, H)

@testset "Infinite TDVP" begin
ψ, envs = timestep(ψ₀, H, dt, TDVP())
E = expectation_value(ψ, H, envs)
@test sum(E₀) sum(E) atol = 1e-2
end
end

@testset "leading_boundary" verbose = true begin
Expand Down Expand Up @@ -373,7 +309,7 @@ end
@testset "Dynamical DMRG" verbose = true begin
ham = force_planar(-1.0 * MPOHamiltonian(σᶻᶻ()) + MPOHamiltonian(σˣ()) * 4.0)
gs, = find_groundstate(InfiniteMPS([𝔹^2], [𝔹^10]), ham, VUMPS(; verbose=false))
window = MPSComoving(gs, copy.([gs.AC[1]; [gs.AR[i] for i in 2:10]]), gs)
window = WindowMPS(gs, copy.([gs.AC[1]; [gs.AR[i] for i in 2:10]]), gs)

szd = force_planar(S_z())
@test expectation_value(gs, szd)[1] expectation_value(window, szd)[1] atol = 1e-10
Expand Down
Loading

0 comments on commit e6ae6d6

Please sign in to comment.