Skip to content

Commit 0431eb2

Browse files
authored
Add files via upload
1 parent 2bb4dbb commit 0431eb2

18 files changed

+3038
-0
lines changed

ABCD1.png

4.19 KB
Loading

ABCD2.png

10.6 KB
Loading

Manifest.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This file is machine-generated - editing it directly is not advised
2+
3+
[[Libdl]]
4+
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
5+
6+
[[LinearAlgebra]]
7+
deps = ["Libdl"]
8+
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

Project.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name = "SweepContractor"
2+
uuid = "75a5deae-e917-4509-af32-a989148c8d5f"
3+
authors = ["Christopher Chubb <[email protected]>"]
4+
version = "0.1.0"
5+
6+
[deps]
7+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

example_2d_open.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Pkg; Pkg.add(url="https://github.com/chubbc/SweepContractor.jl")
2+
using SweepContractor
3+
4+
L=16; d=2
5+
6+
LTN = LabelledTensorNetwork{Tuple{Int,Int}}()
7+
for i1:L, j1:L
8+
adj=Tuple{Int,Int}[];
9+
i>1 && push!(adj,(i-1,j))
10+
j>1 && push!(adj,(i,j-1))
11+
i<L && push!(adj,(i+1,j))
12+
j<L && push!(adj,(i,j+1))
13+
LTN[i,j] = Tensor(adj, randn(d*ones(Int,length(adj))...), i, j)
14+
end
15+
16+
println("example_2d_open")
17+
for χ d.^(4:9)
18+
sweep = sweep_contract(LTN, χ, 2*χ; fast=true)
19+
println("χ=:\t", ldexp(sweep...))
20+
end

example_2d_periodic.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Pkg; Pkg.add(url="https://github.com/chubbc/SweepContractor.jl")
2+
using SweepContractor
3+
4+
L=6; d=2
5+
6+
LTN = LabelledTensorNetwork{Tuple{Int,Int}}()
7+
for i1:L, j1:L
8+
adj=[
9+
(mod1(i-1,L),mod1(j,L)),
10+
(mod1(i+1,L),mod1(j,L)),
11+
(mod1(i,L),mod1(j-1,L)),
12+
(mod1(i,L),mod1(j+1,L))
13+
]
14+
LTN[i,j] = Tensor(adj, randn(d,d,d,d), i+0.01*rand(), j+0.01*rand())
15+
end
16+
17+
println("example_2d_periodic")
18+
for χ d.^(4:9)
19+
sweep = sweep_contract(LTN,χ, 2*χ)
20+
println("χ=:\t",ldexp(sweep...))
21+
end

example_3d.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Pkg; Pkg.add(url="https://github.com/chubbc/SweepContractor.jl")
2+
using SweepContractor
3+
4+
L=3; d=2
5+
6+
LTN = LabelledTensorNetwork{Tuple{Int,Int,Int}}()
7+
for i1:L, j1:L, k1:L
8+
adj=Tuple{Int,Int,Int}[];
9+
i>1 && push!(adj,(i-1,j,k))
10+
i<L && push!(adj,(i+1,j,k))
11+
j>1 && push!(adj,(i,j-1,k))
12+
j<L && push!(adj,(i,j+1,k))
13+
k>1 && push!(adj,(i,j,k-1))
14+
k<L && push!(adj,(i,j,k+1))
15+
LTN[i,j,k] = Tensor(
16+
adj,
17+
randn(d*ones(Int,length(adj))...),
18+
i+0.01*randn(),
19+
j+0.01*randn()
20+
)
21+
end
22+
23+
println("example_3d")
24+
for χd.^(4:9)
25+
sweep=sweep_contract(LTN, χ, 2*χ)
26+
println("χ=:\t",ldexp(sweep...))
27+
end

example_ABCD.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Pkg; Pkg.add(url="https://github.com/chubbc/SweepContractor.jl")
2+
using SweepContractor
3+
4+
LTN = LabelledTensorNetwork{Char}()
5+
LTN['A'] = Tensor(['D','B'], [i^2-2j for i=0:2, j=0:2], 0, 1)
6+
LTN['B'] = Tensor(['A','D','C'], [-3^i*j+k for i=0:2, j=0:2, k=0:2], 0, 0)
7+
LTN['C'] = Tensor(['B','D'], [j for i=0:2, j=0:2], 1, 0)
8+
LTN['D'] = Tensor(['A','B','C'], [i*j*k for i=0:2, j=0:2, k=0:2], 1, 1)
9+
10+
brute = 0.0
11+
for ab=1:3, ad=1:3, bc=1:3, bd=1:3, cd=1:3
12+
global brute += LTN['A'].arr[ad,ab] * LTN['B'].arr[ab,bd,bc] * LTN['C'].arr[bc,cd] *
13+
LTN['D'].arr[ad,bd,cd]
14+
end
15+
16+
sweep = sweep_contract(LTN, 2, 4; fast=true)
17+
18+
println("example_ABCD")
19+
println("brute = $brute")
20+
println("sweep = $(ldexp(sweep...))")

example_rand.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Pkg; Pkg.add(url="https://github.com/chubbc/SweepContractor.jl")
2+
using SweepContractor
3+
4+
n=8; d=2
5+
6+
TN=TensorNetwork(undef,n)
7+
for i=1:n
8+
TN[i]=Tensor(
9+
setdiff(1:n,i),
10+
randn(d*ones(Int,n-1)...),
11+
randn(),
12+
randn()
13+
)
14+
end
15+
16+
println("example_rand")
17+
for χd.^(4:9)
18+
sweep=sweep_contract(TN,χ,2*χ;connected=false)
19+
println("χ=:\t",ldexp(sweep...))
20+
end

src/SweepContractor.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module SweepContractor
2+
import Base: show, print, summary
3+
export Tensor, TensorNetwork, LabelledTensorNetwork
4+
# Define the types
5+
include("tensor_network.jl")
6+
7+
import Base: By, Lt, Ordering, Forward, ForwardOrdering, ReverseOrdering, lt
8+
include("sorted_data_structs/data_structures.jl")
9+
include("sorted_data_structs/balanced_tree.jl")
10+
include("sorted_data_structs/avl_tree.jl")
11+
include("sorted_data_structs/sorted_dict.jl")
12+
include("sorted_data_structs/priorityqueue.jl")
13+
import LinearAlgebra
14+
import Base: issorted, sortperm, sort!, isless, intersect
15+
# Utilities to make sure networks are suitably formatted for sweep contraction
16+
include("tn_utilities.jl")
17+
18+
export sweep_contract!, sweep_contract
19+
# The sweep contraction algorithm
20+
include("sweep_contract.jl")
21+
end

0 commit comments

Comments
 (0)