Skip to content

Commit 9fcd381

Browse files
committed
improve test coverage
1 parent 9208b67 commit 9fcd381

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/algorithms/expval.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,12 @@ function expectation_value(
200200
n = norm.AC[end])^2
201201
return sum(ens) / (n * length(ψ))
202202
end
203+
204+
# Density matrices
205+
# ----------------
206+
function expectation_value::FiniteMPO, args...)
207+
return expectation_value(convert(FiniteMPS, ρ), args...)
208+
end
209+
function expectation_value::InfiniteMPO, args...)
210+
return expectation_value(convert(InfiniteMPS, ρ), args...)
211+
end

test/algorithms.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -962,12 +962,15 @@ module TestAlgorithms
962962
Z_dense_2 = tr(exp(-2beta * H_dense))^(1 / L)
963963

964964
# taylor cluster
965-
rho_taylor_1 = make_time_mpo(H, -im * beta, TaylorCluster(; N = 2))
965+
rho_taylor_1 = make_time_mpo(H, beta, TaylorCluster(; N = 2); imaginary_evolution = true)
966966
Z_taylor_1 = tr(rho_taylor_1)^(1 / L)
967967
@test Z_taylor_1 Z_dense_1 atol = 1.0e-2
968968
Z_taylor_2 = real(dot(rho_taylor_1, rho_taylor_1))^(1 / L)
969969
@test Z_taylor_2 Z_dense_2 atol = 1.0e-2
970970

971+
E_x_taylor = @constinferred expectation_value(rho_taylor_1, 1 => S_x())
972+
E_xx_taylor = @constinferred expectation_value(rho_taylor_1, (1, 2) => S_xx())
973+
971974
# MPO multiplication
972975
rho_mps = convert(FiniteMPS, rho_taylor_1)
973976
rho_mps, = approximate(rho_mps, (rho_taylor_1, rho_mps), DMRG2(; trscheme, verbosity))
@@ -977,9 +980,14 @@ module TestAlgorithms
977980
# TDVP
978981
rho_0 = MPSKit.infinite_temperature_density_matrix(H)
979982
rho_0_mps = convert(FiniteMPS, rho_0)
980-
rho_mps, = timestep(rho_0_mps, H, 0.0, im * beta, TDVP2(; trscheme))
983+
rho_mps, = timestep(rho_0_mps, H, 0.0, beta, TDVP2(; trscheme); imaginary_evolution = true)
981984
Z_tdvp = real(dot(rho_mps, rho_mps))^(1 / L)
982985
@test Z_tdvp Z_dense_2 atol = 1.0e-2
986+
987+
@test expectation_value(rho_0_mps, 1 => S_x()) 0
988+
@test expectation_value(rho_0_mps, (1, 2) => S_xx()) 0
989+
@test expectation_value(rho_mps, 1 => X) E_x_taylor atol = 1.0e-2
990+
@test expectation_value(rho_mps, (1, 2) => XX) E_xx_taylor atol = 1.0e-2
983991
end
984992

985993
@testset "Sector conventions" begin

0 commit comments

Comments
 (0)