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 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
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,11 +94,12 @@ 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("utils.jl")
Expand Down Expand Up @@ -128,6 +128,7 @@ include(joinpath("treetensornetworks", "solvers", "dmrg_x.jl"))
include(joinpath("treetensornetworks", "solvers", "contract.jl"))
include(joinpath("treetensornetworks", "solvers", "linsolve.jl"))
include(joinpath("treetensornetworks", "solvers", "tree_sweeping.jl"))
include("apply.jl")

include("exports.jl")

Expand Down
38 changes: 16 additions & 22 deletions src/apply.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function simple_update_bp(o, ψ, v⃗; envs, (observer!)=nothing, apply_kwargs..
end

function ITensors.apply(
o::ITensor,
o,
ψ::AbstractITensorNetwork;
envs=ITensor[],
normalize=false,
Expand Down Expand Up @@ -297,15 +297,9 @@ end
#In the future we will try to unify this into apply() above but currently leave it mostly as a separate function
"""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(
o::Union{ITensor,NamedEdge},
ψ::AbstractITensorNetwork,
bond_tensors::DataGraph;
normalize=false,
apply_kwargs...,
)
ψ = copy(ψ)
bond_tensors = copy(bond_tensors)
function ITensors.apply(o, ψ::VidalITensorNetwork; normalize=false, apply_kwargs...)
updated_ψ = copy(site_tensors(ψ))
updated_bond_tensors = copy(bond_tensors(ψ))
v⃗ = _gate_vertices(o, ψ)
if length(v⃗) == 2
e = NamedEdge(v⃗[1] => v⃗[2])
Expand All @@ -314,17 +308,17 @@ function vidal_apply(

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

for vn in neighbors(ψ, dst(e))
if (vn != src(e))
ψv2 = noprime(ψv2 * bond_tensors[vn => dst(e)])
ψv2 = noprime(ψv2 * bond_tensor(ψ, 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(ψ, e), ψv2)

U, S, V = ITensors.svd(
theta,
Expand All @@ -339,34 +333,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))
if (vn != dst(e))
ψv1 = noprime(ψv1 * inv_diag(bond_tensors[vn => src(e)]))
ψv1 = noprime(ψv1 * inv_diag(bond_tensor(ψ, vn => src(e))))
end
end

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

if normalize
ψv1 /= norm(ψv1)
ψv2 /= norm(ψv2)
normalize!(bond_tensors[e])
updated_bond_tensors[e] /= norm(updated_bond_tensors[e])
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