-
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
Mar 19, 2024
1 parent
5f03979
commit 7ee14bd
Showing
2 changed files
with
54 additions
and
32 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
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,53 @@ | ||
using ITensors | ||
using ITensors: contract | ||
using ITensorNetworks | ||
using ITensorNetworks: contract_with_BP, group | ||
using Test | ||
|
||
@testset "TTN constructor defaulting to link_space=1" begin | ||
tooth_lengths = fill(5, 6) | ||
c = named_comb_tree(tooth_lengths) | ||
s = siteinds("S=1/2", c) | ||
d = Dict() | ||
for (i, v) in enumerate(vertices(s)) | ||
d[v] = isodd(i) ? "Up" : "Dn" | ||
end | ||
states = v -> d[v] | ||
#test a few signatures | ||
state = TTN(s, states) | ||
lds = edge_data(linkdims(state)) | ||
@test all([isone(lds[k]) for k in keys(lds)]) | ||
state = TTN(s) | ||
lds = edge_data(linkdims(state)) | ||
@test all([isone(lds[k]) for k in keys(lds)]) | ||
end | ||
|
||
@testset "Inner products for TTN via BP" begin | ||
Random.seed!(1234) | ||
Lx, Ly = 3, 3 | ||
χ = 2 | ||
g = named_comb_tree((Lx, Ly)) | ||
s = siteinds("S=1/2", g) | ||
y = TTN(randomITensorNetwork(ComplexF64, s; link_space=χ)) | ||
x = TTN(randomITensorNetwork(ComplexF64, s; link_space=χ)) | ||
|
||
A = TTN(ITensorNetworks.heisenberg(s), s) | ||
#First lets do it with the flattened version of the network | ||
xy = inner_network(x, y; combine_linkinds=true) | ||
xy_scalar = contract(xy)[] | ||
xy_scalar_bp = contract_with_BP(xy) | ||
|
||
@test_broken xy_scalar ≈ xy_scalar_bp | ||
|
||
#Now lets keep it unflattened and do Block BP to keep the partitioned graph as a tree | ||
xy = inner_network(x, y; combine_linkinds=false) | ||
xy_scalar = contract(xy)[] | ||
xy_scalar_bp = contract_with_BP(xy; partitioning=group(v -> first(v), vertices(xy))) | ||
|
||
@test xy_scalar ≈ xy_scalar_bp | ||
# test contraction of three layers for expectation values | ||
# for TTN inner with this signature passes via contract_with_BP | ||
@test inner(prime(x), A, y) ≈ | ||
inner(x, apply(A, y; nsweeps=10, maxdim=16, cutoff=1e-10, init=y)) rtol = 1e-6 | ||
end | ||
nothing |