Skip to content

Commit 429e6ce

Browse files
committed
update tests
1 parent fef41ad commit 429e6ce

File tree

4 files changed

+94
-27
lines changed

4 files changed

+94
-27
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Accessors = "0.1"
2626
Aqua = "0.8.9"
2727
BlockTensorKit = "0.1.4"
2828
Compat = "3.47, 4.10"
29+
Combinatorics = "1"
2930
DocStringExtensions = "0.9.3"
3031
HalfIntegers = "1.6.0"
3132
KrylovKit = "0.8.3, 0.9.2"
@@ -48,11 +49,12 @@ julia = "1.10"
4849

4950
[extras]
5051
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
52+
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
5153
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
5254
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
5355
TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2"
5456
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
5557
TestExtras = "5ed8adda-3752-4e41-b88a-e8b09835ee3a"
5658

5759
[targets]
58-
test = ["Aqua", "Pkg", "Test", "TestExtras", "Plots"]
60+
test = ["Aqua", "Pkg", "Test", "TestExtras", "Plots", "Combinatorics"]

src/operators/mpohamiltonian.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ function Base.getproperty(H::MPOHamiltonian, sym::Symbol)
340340
elseif sym === :C
341341
return map(h -> h[1, 1, 1, 2:(end - 1)], parent(H))
342342
elseif sym === :D
343-
return map(h -> h[1, 1, 1, end], parent(H))
343+
return map(h -> h[1:1, 1, 1, end:end], parent(H))
344344
else
345345
return getfield(H, sym)
346346
end

test/algorithms.jl

Lines changed: 80 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module TestAlgorithms
77

88
using ..TestSetup
99
using Test, TestExtras
10-
using MPSKit
10+
using MPSKit: fuse_mul_mpo
1111
using TensorKit
1212
using TensorKit:
1313

@@ -763,6 +763,85 @@ end
763763
end
764764
765765
@testset "TaylorCluster time evolution" begin
766+
L = 4
767+
dt = 0.05
768+
dτ = -im * dt
769+
770+
@testset "O(1) exact expression" begin
771+
alg = TaylorCluster(; N=1, compression=true, extension=true)
772+
for H in (transverse_field_ising(), heisenberg_XXX())
773+
# Infinite
774+
mpo = make_time_mpo(H, dt, alg)
775+
O = mpo[1]
776+
I, A, B, C, D = H[1][1], H.A[1], H.B[1], H.C[1], H.D[1]
777+
778+
@test size(O, 1) == size(D, 1)^2 + (size(D, 1) * size(B, 1))
779+
@test size(O, 4) == size(D, 4)^2 + (size(C, 4) * size(D, 4))
780+
781+
O_exact = similar(O)
782+
O_exact[1, 1, 1, 1] = I + dτ * D + dτ^2 / 2 * fuse_mul_mpo(D, D)
783+
O_exact[1, 1, 1, 2] = C + dτ * symm_mul_mpo(C, D)
784+
O_exact[2, 1, 1, 1] = dτ * (B + dτ * symm_mul_mpo(B, D))
785+
O_exact[2, 1, 1, 2] = A + dτ * (symm_mul_mpo(A, D) + symm_mul_mpo(C, B))
786+
787+
@test all(isapprox.(parent(O), parent(O_exact)))
788+
789+
# Finite
790+
H_fin = open_boundary_conditions(H, L)
791+
mpo_fin = make_time_mpo(H_fin, dt, alg)
792+
mpo_fin2 = open_boundary_conditions(mpo, L)
793+
for i in 1:L
794+
@test all(isapprox.(parent(mpo_fin[i]), parent(mpo_fin2[i])))
795+
end
796+
end
797+
end
798+
799+
@testset "O(2) exact expression" begin
800+
alg = TaylorCluster(; N=2, compression=true, extension=true)
801+
for H in (transverse_field_ising(), heisenberg_XXX())
802+
# Infinite
803+
mpo = make_time_mpo(H, dt, alg)
804+
O = mpo[1]
805+
I, A, B, C, D = H[1][1], H.A[1], H.B[1], H.C[1], H.D[1]
806+
807+
@test size(O, 1) ==
808+
size(D, 1)^3 + (size(D, 1)^2 * size(B, 1)) + (size(D, 1) * size(B, 1)^2)
809+
@test size(O, 4) ==
810+
size(D, 4)^3 + (size(C, 4) * size(D, 4)^2) + (size(D, 4) * size(C, 4)^2)
811+
812+
O_exact = similar(O)
813+
O_exact[1, 1, 1, 1] = I + dτ * D + dτ^2 / 2 * fuse_mul_mpo(D, D) +
814+
dτ^3 / 6 * fuse_mul_mpo(fuse_mul_mpo(D, D), D)
815+
O_exact[1, 1, 1, 2] = C + dτ * symm_mul_mpo(C, D) +
816+
dτ^2 / 2 * symm_mul_mpo(C, D, D)
817+
O_exact[1, 1, 1, 3] = fuse_mul_mpo(C, C) + dτ * symm_mul_mpo(C, C, D)
818+
O_exact[2, 1, 1, 1] = dτ *
819+
(B + dτ * symm_mul_mpo(B, D) +
820+
dτ^2 / 2 * symm_mul_mpo(B, D, D))
821+
O_exact[2, 1, 1, 2] = A + dτ * symm_mul_mpo(A, D) +
822+
dτ^2 / 2 * symm_mul_mpo(A, D, D) +
823+
dτ * (symm_mul_mpo(C, B) + dτ * symm_mul_mpo(C, B, D))
824+
O_exact[2, 1, 1, 3] = 2 * (symm_mul_mpo(A, C) + dτ * symm_mul_mpo(A, C, D)) +
825+
dτ * symm_mul_mpo(C, C, B)
826+
O_exact[3, 1, 1, 1] = dτ^2 / 2 *
827+
(fuse_mul_mpo(B, B) + dτ * symm_mul_mpo(B, B, D))
828+
O_exact[3, 1, 1, 2] = dτ * (symm_mul_mpo(A, B) + dτ * symm_mul_mpo(A, B, D)) +
829+
dτ^2 / 2 * symm_mul_mpo(B, B, C)
830+
O_exact[3, 1, 1, 3] = fuse_mul_mpo(A, A) + dτ * symm_mul_mpo(A, A, D) +
831+
2 * dτ * symm_mul_mpo(A, C, B)
832+
833+
@test all(isapprox.(parent(O), parent(O_exact)))
834+
835+
# Finite
836+
H_fin = open_boundary_conditions(H, L)
837+
mpo_fin = make_time_mpo(H_fin, dt, alg)
838+
mpo_fin2 = open_boundary_conditions(mpo, L)
839+
for i in 1:L
840+
@test all(isapprox.(parent(mpo_fin[i]), parent(mpo_fin2[i])))
841+
end
842+
end
843+
end
844+
766845
L = 4
767846
Hs = [transverse_field_ising(; L=L), heisenberg_XXX(; L=L)]
768847
@@ -800,28 +879,4 @@ end
800879
end
801880
end
802881
803-
@testset "TaylorCluster for non-square Hamiltonians" begin
804-
# Make a MPOHamiltonian with very non-square Tensors
805-
# Make different orders and kinds of TaylorCluster time-evolution MPOs
806-
# Check the virtual dimensions match up between the MPOs
807-
808-
chain = fill(ℂ^2, 8)
809-
O = randn(ComplexF64, ℂ^2 ← ℂ^2)
810-
811-
ops1 = fill((1, 2) => O ⊗ O, 5)
812-
ops2 = [(2, 3) => O ⊗ O ⊗ O for i in 2:(length(chain) - 1)]
813-
ops3 = [(3, 5) => O ⊗ O ⊗ O for i in 3:(length(chain) - 2)]
814-
815-
H = FiniteMPOHamiltonian(chain, ops1..., ops2..., ops3...)
816-
817-
for N in 1:3
818-
for configuration in ((false, false), (false, true), (true, false), (true, true))
819-
O = make_time_mpo(H, 0.1, TaylorCluster(N, configuration...))
820-
for i in 1:(length(chain) - 1)
821-
@test right_virtualspace(O, i) == left_virtualspace(O, i + 1)
822-
end
823-
end
824-
end
825-
end
826-
827882
end

test/setup.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ using TensorKit
88
using TensorKit: PlanarTrivial, ℙ, BraidingTensor
99
using BlockTensorKit
1010
using LinearAlgebra: Diagonal
11+
using Combinatorics: permutations
1112

1213
# exports
1314
export S_xx, S_yy, S_zz, S_x, S_y, S_z
1415
export force_planar
16+
export symm_mul_mpo
1517
export transverse_field_ising, heisenberg_XXX, bilinear_biquadratic_model
1618
export classical_ising, finite_classical_ising, sixvertex
1719

@@ -58,6 +60,14 @@ end
5860
force_planar(mpo::MPOHamiltonian) = MPOHamiltonian(map(force_planar, parent(mpo)))
5961
force_planar(mpo::MPO) = MPO(map(force_planar, parent(mpo)))
6062

63+
# sum of all permutations: {Os...}
64+
function symm_mul_mpo(Os::MPSKit.MPOTensor...)
65+
N! = factorial(length(Os))
66+
return sum(permutations(Os)) do os
67+
return foldl(MPSKit.fuse_mul_mpo, os)
68+
end / N!
69+
end
70+
6171
# Toy models
6272
# ----------------------------
6373

0 commit comments

Comments
 (0)