Skip to content

Commit

Permalink
[Bugfix] Ensure that projection environments have correct above (#204)
Browse files Browse the repository at this point in the history
* Fix an issue with unequal above and below states

* Add twosite DMRG excitations to tests
  • Loading branch information
lkdvos authored Dec 11, 2024
1 parent 35472e2 commit c20d382
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/environments/FinEnv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ function MPSKit.environments(below::FiniteMPS{S}, O::DenseMPO, above=nothing) wh
N = length(below)
leftstart = isomorphism(storagetype(S),
left_virtualspace(below, 0) space(O[1], 1)'
left_virtualspace(below, 0))
left_virtualspace(something(above, below), 0))
rightstart = isomorphism(storagetype(S),
right_virtualspace(below, N) space(O[N], 4)'
right_virtualspace(something(above, below), N)
space(O[N], 4)'
right_virtualspace(below, length(below)))
return environments(below, O, above, leftstart, rightstart)
end
Expand All @@ -101,7 +102,7 @@ end
function environments(state::Union{FiniteMPS,WindowMPS}, opp::ProjectionOperator)
@plansor leftstart[-1; -2 -3 -4] := l_LL(opp.ket)[-3; -4] * l_LL(opp.ket)[-1; -2]
@plansor rightstart[-1; -2 -3 -4] := r_RR(opp.ket)[-1; -2] * r_RR(opp.ket)[-3; -4]
return environments(state, fill(nothing, length(state)), state, leftstart, rightstart)
return environments(state, fill(nothing, length(state)), opp.ket, leftstart, rightstart)
end

#notify the cache that we updated in-place, so it should invalidate the dependencies
Expand Down
14 changes: 7 additions & 7 deletions test/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -426,16 +426,16 @@ end
ψ = FiniteMPS(rand, ComplexF64, len, ℙ^2, ℙ^15)
(ψ, envs, _) = find_groundstate(ψ, H; verbosity)

#find energy with quasiparticle ansatz
# find energy with quasiparticle ansatz
energies_QP, ϕs = excitations(H, QuasiparticleAnsatz(), ψ, envs)
@test variance(ϕs[1], H) < 1e-6

#find energy with normal dmrg
energies_dm, _ = excitations(H,
FiniteExcited(;
gsalg=DMRG(; verbosity,
tol=1e-6)), ψ)
@test energies_dm[1] energies_QP[1] + expectation_value(ψ, H, envs) atol = 1e-4
# find energy with normal dmrg
for gsalg in (DMRG(; verbosity, tol=1e-6),
DMRG2(; verbosity, tol=1e-6, trscheme=truncbelow(1e-4)))
energies_dm, _ = excitations(H, FiniteExcited(; gsalg), ψ)
@test energies_dm[1] energies_QP[1] + expectation_value(ψ, H, envs) atol = 1e-4
end

# find energy with Chepiga ansatz
energies_ch, _ = excitations(H, ChepigaAnsatz(), ψ, envs)
Expand Down

0 comments on commit c20d382

Please sign in to comment.