Skip to content

Commit b058626

Browse files
committed
Add some tests
1 parent 84273bf commit b058626

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

test/operators.jl

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,13 @@ module TestOperators
124124
@testset "Finite MPOHamiltonian" begin
125125
L = 3
126126
T = ComplexF64
127-
for V in (ℂ^2, U1Space(0 => 1, 1 => 1))
127+
for V in (ℂ^2, U1Space(-1 => 1, 0 => 1, 1 => 1))
128128
lattice = fill(V, L)
129-
O₁ = rand(T, V, V)
129+
O₁ = randn(T, V, V)
130+
O₁ += O₁'
130131
E = id(storagetype(O₁), domain(O₁))
131-
O₂ = rand(T, V^2 V^2)
132+
O₂ = randn(T, V^2 ← V^2)
133+
O₂ += O₂'
132134

133135
H1 = FiniteMPOHamiltonian(lattice, i => O₁ for i in 1:L)
134136
H2 = FiniteMPOHamiltonian(lattice, (i, i + 1) => O₂ for i in 1:(L - 1))
@@ -164,6 +166,9 @@ module TestOperators
164166
FiniteMPOHamiltonian(lattice, 3 => O₁)
165167
@test 0.8 * H1 + 0.2 * H1 H1 atol = 1.0e-6
166168
@test convert(TensorMap, H1 + H2) convert(TensorMap, H1) + convert(TensorMap, H2) atol = 1.0e-6
169+
H1_trunc = changebonds(H1, SvdCut(; trscheme=truncdim(0)))
170+
@test H1_trunc H1
171+
@test all(left_virtualspace(H1_trunc) .== left_virtualspace(H1))
167172

168173
# test dot and application
169174
state = rand(T, prod(lattice))
@@ -181,12 +186,21 @@ module TestOperators
181186
vertical_operators = Dict(
182187
(I, I + I_vertical) => O₂ for I in eachindex(IndexCartesian(), square) if I[1] < size(square, 1)
183188
)
184-
operators = merge(local_operators, vertical_operators)
189+
I_horizontal = CartesianIndex(0, 1)
190+
horizontal_operators = Dict(
191+
(I, I + I_horizontal) => O₂ for I in eachindex(IndexCartesian(), square) if I[2] < size(square, 1)
192+
)
193+
operators = merge(local_operators, vertical_operators, horizontal_operators)
185194
H4 = FiniteMPOHamiltonian(grid, operators)
186195

187196
@test H4
188197
FiniteMPOHamiltonian(grid, local_operators) +
189-
FiniteMPOHamiltonian(grid, vertical_operators)
198+
FiniteMPOHamiltonian(grid, vertical_operators) +
199+
FiniteMPOHamiltonian(grid, horizontal_operators) atol=1e-4
200+
201+
H5 = changebonds(H4 / 3 + 2H4 / 3, SvdCut(; trscheme = truncbelow(1.0e-12)))
202+
psi = FiniteMPS(physicalspace(H5), V oneunit(V))
203+
@test expectation_value(psi, H4) expectation_value(psi, H5)
190204
end
191205
end
192206

0 commit comments

Comments
 (0)