Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
./samples/
Manifest.toml
samples/
.DS_Store
26 changes: 26 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,45 @@ authors = ["Ryo Watanabe <https://github.com/Ryo-wtnb11>"]
version = "0.1.0"

[deps]
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
DataGraphs = "b5a273c3-7e6c-41f6-98bd-8d7f1525a36a"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
GraphTikZ = "cef0280d-a2bf-4776-a511-cf6253a7debc"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
ITensorNetworks = "2919e153-833c-4bdc-8836-1ea460a35fc7"
ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5"
NPZ = "15e1cf62-19b3-5cfa-8e77-841668bca605"
NamedGraphs = "678767b0-92e7-4007-89e4-4527a8725b19"
QuanticsGrids = "634c7f73-3e90-4749-a1bd-001b8efc642d"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
SimpleTensorNetworks = "3075f829-f72e-4896-a859-7fe0a9cabb9b"
SparseIR = "4fe2279e-80f0-4adb-8463-ee114ff56b7d"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
T4ARegistrator = "52e3f0f8-52ab-4798-a033-7b9fb81451b4"
TensorCrossInterpolation = "b261b2ec-6378-4871-b32e-9173bb050604"

[compat]
Combinatorics = "1.0.3"
DataGraphs = "0.2.5"
DataStructures = "0.18.22"
Distributions = "0.25.120"
Flux = "0.16.4"
GraphTikZ = "0.1.0"
Graphs = "1.12.0"
ITensorNetworks = "0.14.1"
ITensors = "0.9.11"
NPZ = "0.4.3"
NamedGraphs = "0.6.4"
QuanticsGrids = "0.6.0"
Random = "1.10"
Revise = "3.9.0"
SimpleTensorNetworks = "0.1.0"
SparseIR = "1.1.4"
Statistics = "1.11.1"
T4ARegistrator = "0.2.1"
TensorCrossInterpolation = "0.9.13"

[extras]
Expand Down
65 changes: 65 additions & 0 deletions samples/1d_tightbinding_model.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using Random
using LinearAlgebra
using TreeTCI: crossinterpolate, crossinterpolate_with_structuralsearch, crossinterpolate_with_3site_swapping
using NamedGraphs: NamedGraph, add_edge!, edges, src, dst
using QuanticsGrids
const QG = QuanticsGrids
using SparseIR
using ITensorNetworks
using TreeTCI: ttnopt
const ITN = ITensorNetworks
using ITensors
using NPZ
include("utils.jl")
include("graphs.jl")


ε(k) = 2*cos(k) + cos(5*k) + 2*cos(20*k)

gk(m::Int, kx::Float64; β::Float64=10.0) = begin
m = 2 * m + 1
ν = FermionicFreq(m)
iν = SparseIR.valueim(ν, β)
return 1 / (iν - ε(kx))
end

function gkb(b::Vector{Int}, n_m::Int, n_kx::Int; mu::Float64=0.0, β::Float64=10.0, layout::Symbol=:block)
@assert length(b) == n_m + n_kx
parts = split_bits(b; group_bits=[n_m, n_kx], layout=layout)
mb, kxb = parts
mbit = length(mb)
kxbit = length(kxb)
Nm = 2^mbit
Nkx = 2^kxbit
im = frombins(mb)
ikx = frombins(kxb)
@assert im ≤ Nm
@assert ikx ≤ Nkx
kx = 2π * (ikx - 1)/Nkx
m = (im - 1)
return gk(m, kx; mu=mu, β=β)
end

function main()
nkx_bit = 10
nm_bit = 10
localdims = fill(2, nkx_bit + nm_bit)
f(v) = gkb(v, nm_bit, nkx_bit; layout=:interleave)
g = graph_TT(nkx_bit + nm_bit)
maxbonddim = 200
kwargs = (maxbonddim = maxbonddim, maxiter = 100, tolerance = 1e-13)
center_vertex = (nkx_bit + nm_bit) ÷ 2
# center_vertex = 1

ttn, ranks, errors = crossinterpolate(ComplexF64, f, localdims, g; center_vertex = center_vertex, kwargs...)
@show last(ranks)


g_tmp, original_entanglements, entanglements = ttnopt(ttn; ortho_vertex = center_vertex, max_degree = 2)
ttn_, ranks, errors = crossinterpolate(ComplexF64, f, localdims, g_tmp; center_vertex = center_vertex, kwargs...)
@show last(ranks)

return 0
end

main()
92 changes: 92 additions & 0 deletions samples/2d_model.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using Random
using LinearAlgebra
using TreeTCI: crossinterpolate, crossinterpolate_with_structuralsearch, crossinterpolate_with_3site_swapping
using NamedGraphs: NamedGraph, add_edge!, edges, src, dst
using QuanticsGrids
const QG = QuanticsGrids
using SparseIR
using ITensorNetworks
using TreeTCI: ttnopt
const ITN = ITensorNetworks
using ITensors
using NPZ
include("utils.jl")
include("graphs.jl")


ε(kx, ky) = -2*cos(kx) - 2*cos(ky)

gk(kx::Float64, ky::Float64; mu::Float64=0.0, β::Float64=10.0) = begin
m = 1
ν = FermionicFreq(m)
iν = SparseIR.valueim(ν, β)
return 1 / (iν - ε(kx, ky) + mu)
end

function gkb(b::Vector{Int}, n_kx::Int, n_ky; mu::Float64=0.0, β::Float64=10.0, layout::Symbol=:block)
@assert length(b) == n_kx + n_ky
parts = split_bits(b; group_bits=[n_kx, n_ky], layout=layout)
kxb, kyb = parts
kxbit = length(kxb)
kybit = length(kyb)
Nkx = 2^kxbit
Nky = 2^kybit
iky = frombins(kyb)
ikx = frombins(kxb)
@assert ikx ≤ Nkx
@assert iky ≤ Nky
kx = 2π * (ikx - 1)/Nkx
ky = 2π * (iky - 1)/Nky
return gk(kx, ky; mu=mu, β=β)
end


function calculate_entanglements(entanglements)
ee = 0.0
edges = []
edge_vals = []
for (key, value) in entanglements
ee += value
push!(edges, key)
push!(edge_vals, value)
end
@show ee / length(edges)
@show edges
@show edge_vals
end

function main()
nkx_bit = 10
nky_bit = 10
localdims = fill(2, nkx_bit + nky_bit)
f(v) = gkb(v, nky_bit, nkx_bit; layout=:interleave, mu=-1.0, β=10.0)
g = graph_TT(nkx_bit + nky_bit)
maxbonddim = 200
kwargs = (maxbonddim = maxbonddim, maxiter = 100, tolerance = 1e-13)
center_vertex = (nkx_bit + nky_bit) ÷ 2

ttn, ranks, errors = crossinterpolate(ComplexF64, f, localdims, g; center_vertex = center_vertex, kwargs...)

g_tmp, original_entanglements, entanglements = ttnopt(ttn; ortho_vertex = center_vertex, max_degree = 1)
ttn_, ranks, errors = crossinterpolate(ComplexF64, f, localdims, g_tmp; center_vertex = center_vertex, kwargs...)
println("original_entanglements")
calculate_entanglements(original_entanglements)
@show last(ranks)

println("--------------------------------")
println("ΔG = 2")
calculate_entanglements(entanglements)
@show last(ranks)

g_tmp, original_entanglements, entanglements = ttnopt(ttn; ortho_vertex = center_vertex, max_degree = 2)
ttn_, ranks, errors = crossinterpolate(ComplexF64, f, localdims, g_tmp; center_vertex = center_vertex, kwargs...)

println("--------------------------------")
println("ΔG = 3")
calculate_entanglements(entanglements)
@show last(ranks)

return 0
end

main()
9 changes: 9 additions & 0 deletions samples/graphs.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using NamedGraphs: NamedGraph, add_edge!

function graph_TT(R::Int)
g = NamedGraph(R)
for i in 1:R-1
add_edge!(g, i, i+1)
end
return g
end
49 changes: 49 additions & 0 deletions samples/sample_strucuralsearch.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Random
using LinearAlgebra
using TreeTCI: crossinterpolate_with_3site_swapping
using Statistics
using Distributions
using NamedGraphs: NamedGraph, add_edge!, edges
using QuanticsGrids
const QG = QuanticsGrids


function build_problem()
Random.seed!(1234)
R = 4
μ = zeros(3)
Σ = rand(LKJ(3, 50.0))
dist = MvNormal(μ, Hermitian(Σ))
f(x,y,z) = pdf(dist, [x,y,z])

grid = QG.DiscretizedGrid{3}(R, (-5,-5,-5), (5,5,5); unfoldingscheme=:interleaved)
fq = QG.quanticsfunction(Float64, grid, f)

nsites = 3R
g = NamedGraph(nsites)
for i in 1:(nsites-1)
add_edge!(g, i, i+1)
end
localdims = fill(grid.base, nsites)

return fq, localdims, g
end

function main()

fq, localdims, g = build_problem()

kwargs = (
maxbonddim = 10,
tolerance = 1e-10,
maxiter = 100,
)

tci = crossinterpolate_with_3site_swapping(Float64, fq, localdims, g; kwargs...)

ttn = TreeTensorNetwork(tci.g, tci.sitetensors)

return tci
end

main()
27 changes: 27 additions & 0 deletions samples/sample_treetci.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Test
using TreeTCI
import NamedGraphs: NamedGraph, NamedEdge, add_edge!, vertices, edges, has_edge

function main()
# make graph
g = NamedGraph(10)
add_edge!(g, 1, 3)
add_edge!(g, 2, 3)
add_edge!(g, 3, 5)

add_edge!(g, 4, 5)
add_edge!(g, 5, 7)
add_edge!(g, 6, 7)
add_edge!(g, 7, 8)
add_edge!(g, 8, 9)
add_edge!(g, 8, 10)

localdims = fill(2, length(vertices(g)))
f(v) = 1 / (1 + v' * v)
kwargs = (maxbonddim = 20, maxiter = 10)
ttn, ranks, errors = TreeTCI.crossinterpolate(Float64, f, localdims, g; kwargs...)
@show ttn([1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), f([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
@show ttn([1, 2, 1, 2, 1, 2, 1, 2, 1, 2]), f([1, 2, 1, 2, 1, 2, 1, 2, 1, 2])
end

main()
32 changes: 32 additions & 0 deletions samples/sample_treetci2.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Test
using TreeTCI
import NamedGraphs: NamedGraph, NamedEdge, add_edge!, vertices, edges, has_edge

function f_pairwise(v::Vector{Int})
s = 0.0
for i in 1:2:length(v)-1
s += v[i] * v[i+1]
end
return 1 / (1+s)
end


function main()
# make graph
g = NamedGraph(8)
add_edge!(g, 1, 2)
add_edge!(g, 2, 3)
add_edge!(g, 3, 4)
add_edge!(g, 4, 5)
add_edge!(g, 5, 6)
add_edge!(g, 6, 7)
add_edge!(g, 7, 8)

localdims = fill(8, length(vertices(g)))
f(v) = f_pairwise(v)
kwargs = (maxbonddim = 64, maxiter = 10)
ttn, ranks, errors = TreeTCI.crossinterpolate(Float64, f, localdims, g; kwargs...)

end

main()
Loading
Loading