forked from JoeyT1994/TensorNetworkQuantumSimulator.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_expect.jl
More file actions
47 lines (37 loc) · 1.32 KB
/
Copy pathtest_expect.jl
File metadata and controls
47 lines (37 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
@eval module $(gensym())
using Dictionaries: Dictionary
using ITensors: datatype
using Random
using Statistics
using TensorNetworkQuantumSimulator
using Test: @testset, @test
@testset "Test Expect" begin
nx, ny = 4, 4
χ = 2
gs = [
(named_grid((nx, 1)), "line"),
(named_hexagonal_lattice_graph(nx - 2, ny - 2), "hexagonal"),
(named_grid((nx, ny)), "square"),
]
for (g, g_str) in gs
ψ = random_tensornetworkstate(ComplexF32, g, "S=1/2"; bond_dimension = χ)
v_centre = first(center(g))
sz_exact = expect(ψ, ("Z", v_centre); alg = "exact")
sz_bp = expect(ψ, ("Z", v_centre); alg = "bp")
if is_tree(g)
@test sz_bp ≈ sz_exact
else
@test sz_bp != sz_exact
end
Rmps = 16
sz_boundarymps = expect(ψ, ("Z", v_centre); alg = "boundarymps", mps_bond_dimension = Rmps)
@test sz_boundarymps ≈ sz_exact atol = 10*eps(Float32)
if !is_tree(g)
v_centre_neighbor = first(neighbors(g, v_centre))
sz_exact = expect(ψ, ("ZZ", [v_centre, v_centre_neighbor]); alg = "exact")
sz_boundarymps = expect(ψ, ("ZZ", [v_centre, v_centre_neighbor]); alg = "boundarymps", mps_bond_dimension = Rmps)
@test sz_boundarymps ≈ sz_exact
end
end
end
end