|
| 1 | +using Compat |
1 | 2 | using ITensors
|
| 3 | +using Metis |
2 | 4 | using ITensorNetworks
|
| 5 | + |
3 | 6 | using ITensorNetworks:
|
4 |
| - delta_network, |
5 |
| - formsubgraphs, |
6 |
| - partition, |
7 |
| - flatten_thicken_bonds, |
8 |
| - flattened_inner_network, |
9 | 7 | construct_initial_mts,
|
10 | 8 | update_all_mts,
|
11 |
| - get_single_site_expec, |
12 |
| - iterate_single_site_expec, |
13 |
| - contract_boundary_mps |
14 |
| -using KaHyPar |
15 |
| -using Compat |
| 9 | + get_single_site_expec |
16 | 10 |
|
17 |
| -#nxn GRID |
18 | 11 | n = 4
|
19 |
| -g = named_grid((n, n)) |
| 12 | +dims = (n, n) |
| 13 | +g = named_grid(dims) |
| 14 | +# g = named_comb_tree(dims) |
20 | 15 | s = siteinds("S=1/2", g)
|
21 |
| -chi = 3 |
| 16 | +chi = 2 |
22 | 17 |
|
23 |
| -#Random Tensor Network, Flatten it too |
24 |
| -psi = randomITensorNetwork(s; link_space=chi) |
25 |
| -psiflat, combiners = flatten_thicken_bonds(deepcopy(psi)) |
| 18 | +ψ = randomITensorNetwork(s; link_space=chi) |
26 | 19 |
|
27 |
| -v = (1, 1) |
| 20 | +ψψ = norm_sqr_network(ψ; flatten=true, map_bra_linkinds=prime) |
| 21 | +combiners = linkinds_combiners(ψψ) |
| 22 | +ψψ = combine_linkinds(ψψ, combiners) |
28 | 23 |
|
29 |
| -#Apply Sz to site v and flatten that |
30 |
| -psiflatO = flatten_thicken_bonds(psi; ops=["Sz"], vops=[v], s=s, combiners=combiners) |
| 24 | +# Apply Sz to site v |
| 25 | +v = one.(dims) |
| 26 | +Oψ = copy(ψ) |
| 27 | +Oψ[v] = apply(op("Sz", s[v]), ψ[v]) |
| 28 | +ψOψ = inner_network(ψ, Oψ; flatten=true, map_bra_linkinds=prime) |
| 29 | +ψOψ = combine_linkinds(ψOψ, combiners) |
31 | 30 |
|
32 |
| -#Get the value of sz on v via exact contraction |
33 |
| -actual_sz = ITensors.contract(psiflatO)[1] / ITensors.contract(psiflat)[1] |
| 31 | +# Get the value of sz on v via exact contraction |
| 32 | +contract_seq = contraction_sequence(ψψ) |
| 33 | +actual_sz = contract(ψOψ; sequence=contract_seq)[] / contract(ψψ; sequence=contract_seq)[] |
34 | 34 |
|
35 | 35 | println("Actual value of Sz on site " * string(v) * " is " * string(actual_sz))
|
36 | 36 |
|
37 |
| -nsites = 1 |
38 |
| -println("First " * string(nsites) * " sites form a subgraph") |
39 |
| -dg_subgraphs = formsubgraphs(g, Int(n * n / nsites)) |
40 |
| -mts = construct_initial_mts(psiflat, dg_subgraphs; init=(I...) -> allequal(I) ? 1 : 0) |
41 |
| -niters = 5 |
| 37 | +niters = 20 |
42 | 38 |
|
43 |
| -iterate_single_site_expec(psiflat, psiflatO, mts, dg_subgraphs, niters, v) |
| 39 | +nsites = 1 |
| 40 | +println("\nFirst " * string(nsites) * " sites form a subgraph") |
| 41 | +mts = construct_initial_mts(ψψ, nsites; init=(I...) -> @compat allequal(I) ? 1 : 0) |
| 42 | +@show get_single_site_expec(ψψ, mts, ψOψ, v) |
| 43 | +mts = update_all_mts(ψψ, mts, niters) |
| 44 | +@show get_single_site_expec(ψψ, mts, ψOψ, v) |
44 | 45 |
|
45 | 46 | nsites = 4
|
46 |
| -println("Now " * string(nsites) * " sites form a subgraph") |
47 |
| -dg_subgraphs = formsubgraphs(g, Int(n * n / nsites)) |
48 |
| -mts = construct_initial_mts(psiflat, dg_subgraphs; init=(I...) -> allequal(I) ? 1 : 0) |
49 |
| - |
50 |
| -iterate_single_site_expec(psiflat, psiflatO, mts, dg_subgraphs, niters, v) |
| 47 | +println("\nNow " * string(nsites) * " sites form a subgraph") |
| 48 | +mts = construct_initial_mts(ψψ, nsites; init=(I...) -> @compat allequal(I) ? 1 : 0) |
| 49 | +@show get_single_site_expec(ψψ, mts, ψOψ, v) |
| 50 | +mts = update_all_mts(ψψ, mts, niters) |
| 51 | +@show get_single_site_expec(ψψ, mts, ψOψ, v) |
0 commit comments