Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Belief propagation cache #139

Merged
merged 16 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
7 changes: 4 additions & 3 deletions src/ITensorNetworks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ include("opsum.jl")
include("sitetype.jl")
include("abstractitensornetwork.jl")
include("contraction_sequences.jl")
include("apply.jl")
include("expect.jl")
include("models.jl")
include("tebd.jl")
Expand All @@ -95,13 +94,15 @@ include("contract.jl")
include("utility.jl")
include("specialitensornetworks.jl")
include("boundarymps.jl")
include(joinpath("beliefpropagation", "beliefpropagation.jl"))
include(joinpath("beliefpropagation", "beliefpropagation_schedule.jl"))
include("partitioneditensornetwork.jl")
include("edge_sequences.jl")
include(joinpath("formnetworks", "abstractformnetwork.jl"))
include(joinpath("formnetworks", "bilinearformnetwork.jl"))
include(joinpath("formnetworks", "quadraticformnetwork.jl"))
include(joinpath("caches", "beliefpropagationcache.jl"))
include("contraction_tree_to_graph.jl")
include("gauging.jl")
include("apply.jl")
include("utils.jl")
include("tensornetworkoperators.jl")
include(joinpath("ITensorsExt", "itensorutils.jl"))
Expand Down
46 changes: 21 additions & 25 deletions src/apply.jl
Original file line number Diff line number Diff line change
Expand Up @@ -298,33 +298,29 @@ end
"""Apply() function for an ITN in the Vidal Gauge. Hence the bond tensors are required.
Gate does not necessarily need to be passed. Can supply an edge to do an identity update instead. Uses Simple Update procedure assuming gate is two-site"""
function vidal_apply(
JoeyT1994 marked this conversation as resolved.
Show resolved Hide resolved
o::Union{ITensor,NamedEdge},
ψ::AbstractITensorNetwork,
bond_tensors::DataGraph;
normalize=false,
apply_kwargs...,
o::Union{ITensor,NamedEdge}, ψv::VidalITensorNetwork; normalize=false, apply_kwargs...
JoeyT1994 marked this conversation as resolved.
Show resolved Hide resolved
)
ψ = copy(ψ)
bond_tensors = copy(bond_tensors)
v⃗ = _gate_vertices(o, ψ)
updated_ψ = copy(itensornetwork(ψv))
updated_bond_tensors = copy(bond_tensors(ψv))
v⃗ = _gate_vertices(o, ψv)
if length(v⃗) == 2
e = NamedEdge(v⃗[1] => v⃗[2])
ψv1, ψv2 = ψ[src(e)], ψ[dst(e)]
ψv1, ψv2 = ψv[src(e)], ψv[dst(e)]
e_ind = commonind(ψv1, ψv2)

for vn in neighbors(ψ, src(e))
for vn in neighbors(ψv, src(e))
if (vn != dst(e))
ψv1 = noprime(ψv1 * bond_tensors[vn => src(e)])
ψv1 = noprime(ψv1 * bond_tensor(ψv, vn => src(e)))
end
end

for vn in neighbors(ψ, dst(e))
for vn in neighbors(ψv, dst(e))
if (vn != src(e))
ψv2 = noprime(ψv2 * bond_tensors[vn => dst(e)])
ψv2 = noprime(ψv2 * bond_tensor(ψv, vn => dst(e)))
end
end

Qᵥ₁, Rᵥ₁, Qᵥ₂, Rᵥ₂, theta = _contract_gate(o, ψv1, bond_tensors[e], ψv2)
Qᵥ₁, Rᵥ₁, Qᵥ₂, Rᵥ₂, theta = _contract_gate(o, ψv1, bond_tensor(ψv, e), ψv2)

U, S, V = ITensors.svd(
theta,
Expand All @@ -339,34 +335,34 @@ function vidal_apply(
S = replaceind(S, ind_to_replace => ind_to_replace_with')
V = replaceind(V, ind_to_replace => ind_to_replace_with)

ψv1, bond_tensors[e], ψv2 = U * Qᵥ₁, S, V * Qᵥ₂
ψv1, updated_bond_tensors[e], ψv2 = U * Qᵥ₁, S, V * Qᵥ₂

for vn in neighbors(ψ, src(e))
for vn in neighbors(ψv, src(e))
if (vn != dst(e))
ψv1 = noprime(ψv1 * inv_diag(bond_tensors[vn => src(e)]))
ψv1 = noprime(ψv1 * inv_diag(bond_tensor(ψv, vn => src(e))))
end
end

for vn in neighbors(ψ, dst(e))
for vn in neighbors(ψv, dst(e))
if (vn != src(e))
ψv2 = noprime(ψv2 * inv_diag(bond_tensors[vn => dst(e)]))
ψv2 = noprime(ψv2 * inv_diag(bond_tensor(ψv, vn => dst(e))))
end
end

if normalize
ψv1 /= norm(ψv1)
ψv2 /= norm(ψv2)
normalize!(bond_tensors[e])
normalize!(updated_bond_tensors[e])
JoeyT1994 marked this conversation as resolved.
Show resolved Hide resolved
end

setindex_preserve_graph!(ψ, ψv1, src(e))
setindex_preserve_graph!(ψ, ψv2, dst(e))
setindex_preserve_graph!(updated_ψ, ψv1, src(e))
setindex_preserve_graph!(updated_ψ, ψv2, dst(e))

return ψ, bond_tensors
return VidalITensorNetwork(updated_ψ, updated_bond_tensors)

else
ψ = ITensors.apply(o, ψ; normalize)
return ψ, bond_tensors
updated_ψ = ITensors.apply(o, updated_ψ; normalize)
return VidalITensorNetwork(ψ, updated_bond_tensors)
end
end

Expand Down
143 changes: 0 additions & 143 deletions src/beliefpropagation/beliefpropagation.jl

This file was deleted.

Loading
Loading