Skip to content

Commit

Permalink
Remove c_tensor_network in favour of const_tensornetwork
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyT1994 committed Apr 9, 2024
1 parent e92bc88 commit f81cad5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
13 changes: 7 additions & 6 deletions src/itensornetworks_elementary_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ default_k_value() = 1.0
default_nterms() = 20
default_dimension() = 1

"""Construct the product state representation of the function f(x) = const."""
"""Build a representation of the function f(x,y,z,...) = c, with flexible choice of linkdim"""
function const_itensornetwork(
s::IndsNetwork, bit_map; c::Union{Float64,ComplexF64}=default_c_value()
s::IndsNetwork, bit_map; c::Union{Float64,ComplexF64}=default_c_value(), linkdim::Int64=1
)
ψ = copy_tensor_network(s)
ψ = random_tensornetwork(s; link_space=linkdim)
inv_L = Float64(1.0 / nv(s))
for v in vertices(ψ)
ψ[v] *= c^inv_L
virt_inds = setdiff(inds(ψ[v]), Index[only(s[v])])
ψ[v] = c^inv_L * c_tensor(only(s[v]), virt_inds)
end

return ITensorNetworkFunction(ψ, bit_map)
Expand Down Expand Up @@ -216,7 +217,7 @@ function polynomial_itensornetwork(
root_vertices_dim = filter(v -> v dimension_vertices, leaf_vertices(s_tree))
@assert !isempty(root_vertices_dim)
root_vertex = first(root_vertices_dim)
ψ = copy_tensor_network(s_tree; linkdim=n + 1)
ψ = const_itensornetwork(s_tree, bit_map; linkdim=n + 1)
#Place the Q_n tensors, making sure we get the right index pointing towards the root
for v in dimension_vertices
siteindex = s_tree[v][]
Expand Down Expand Up @@ -245,7 +246,7 @@ function polynomial_itensornetwork(
end
end

return ITensorNetworkFunction(ψ, bit_map)
return ψ
end

function random_itensornetwork(s::IndsNetwork, bit_map; kwargs...)
Expand Down
14 changes: 2 additions & 12 deletions src/itensornetworksutils.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using ITensors: Index, dim, inds
using ITensorNetworks: random_tensornetwork, IndsNetwork

"""Build the order L tensor corresponding to fx(x): x ∈ [0,1]."""
"""Build the order L tensor corresponding to fx(x): x ∈ [0,1], default decomposition is binary"""
function build_full_rank_tensor(L::Int64, fx::Function; base::Int64=2)
inds = [Index(base, "$i") for i in 1:L]
dims = Tuple([base for i in 1:L])
Expand All @@ -15,10 +15,10 @@ function build_full_rank_tensor(L::Int64, fx::Function; base::Int64=2)
return ITensor(array, inds)
end

"""Build the tensor C such that C_{phys_ind, virt_inds...} = delta_{virt_inds...}"""
function c_tensor(phys_ind::Index, virt_inds::Vector)
inds = vcat(phys_ind, virt_inds)
@assert allequal(dim.(virt_inds))
#Build tensor to be delta on inds and independent of phys_ind
T = ITensor(0.0, inds...)
for i in 1:dim(phys_ind)
for j in 1:dim(first(virt_inds))
Expand All @@ -29,13 +29,3 @@ function c_tensor(phys_ind::Index, virt_inds::Vector)

return T
end

function copy_tensor_network(s::IndsNetwork; linkdim::Int64=1)
tn = random_tensornetwork(s; link_space=linkdim)
for v in vertices(tn)
virt_inds = setdiff(inds(tn[v]), Index[only(s[v])])
tn[v] = c_tensor(only(s[v]), virt_inds)
end

return tn
end

0 comments on commit f81cad5

Please sign in to comment.