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

BP Efficiency Improvement #194

Merged
merged 8 commits into from
Sep 3, 2024
Merged
Changes from 7 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
14 changes: 8 additions & 6 deletions src/caches/beliefpropagationcache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ end

function message(bp_cache::BeliefPropagationCache, edge::PartitionEdge)
mts = messages(bp_cache)
return get(mts, edge, default_message(bp_cache, edge))
haskey(mts, edge) && return mts[edge]
return default_message(bp_cache, edge)
JoeyT1994 marked this conversation as resolved.
Show resolved Hide resolved
end
function messages(bp_cache::BeliefPropagationCache, edges; kwargs...)
return map(edge -> message(bp_cache, edge; kwargs...), edges)
Expand Down Expand Up @@ -152,15 +153,16 @@ end
function environment(bp_cache::BeliefPropagationCache, verts::Vector)
partition_verts = partitionvertices(bp_cache, verts)
messages = environment(bp_cache, partition_verts)
central_tensors = ITensor[
tensornetwork(bp_cache)[v] for v in setdiff(vertices(bp_cache, partition_verts), verts)
]
central_tensors = factors(bp_cache, setdiff(vertices(bp_cache, partition_verts), verts))
return vcat(messages, central_tensors)
end

function factors(bp_cache::BeliefPropagationCache, verts::Vector)
return ITensor[tensornetwork(bp_cache)[v] for v in verts]
end

function factor(bp_cache::BeliefPropagationCache, vertex::PartitionVertex)
ptn = partitioned_tensornetwork(bp_cache)
return collect(eachtensor(subgraph(ptn, vertex)))
return factors(bp_cache, vertices(bp_cache, vertex))
end

"""
Expand Down
Loading