-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Benedikt Kloss
committed
Jan 24, 2024
1 parent
1f888df
commit 3aa639f
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using ITensors | ||
using ITensorNetworks | ||
using Test | ||
|
||
@testset "MPS expect comparison with ITensors" begin | ||
N = 25 | ||
s = siteinds("S=1/2", N) | ||
a = random_mps(s; internal_inds_space=100) | ||
b = MPS([a[v] for v in vertices(a)]) | ||
res_a = expect("Sz", a) | ||
res_b = expect(b, "Sz") | ||
res_a = [res_a[v] for v in vertices(a)] | ||
@test res_a ≈ res_b rtol=1e-6 | ||
Check warning on line 13 in test/test_treetensornetworks/test_expect.jl GitHub Actions / format
|
||
end | ||
|
||
@testset "TTN expect" begin | ||
tooth_lengths = fill(5, 6) | ||
Check warning on line 17 in test/test_treetensornetworks/test_expect.jl GitHub Actions / format
|
||
c = named_comb_tree(tooth_lengths) | ||
s = siteinds("S=1/2", c) | ||
d = Dict() | ||
magnetization = Dict() | ||
for (i, v) in enumerate(vertices(s)) | ||
d[v] = isodd(i) ? "Up" : "Dn" | ||
magnetization[v] = isodd(i) ? 0.5 : -0.5 | ||
end | ||
states = v -> d[v] | ||
state = TTN(s, states) | ||
res=expect("Sz", state) # just testing that this doesn't go via expect for arbitrary tensor networks. | ||
@test all([isapprox(res[v], magnetization[v],atol=1e-8) for v in vertices(s)]) | ||
end | ||
|
||
nothing |