Skip to content

Commit 174cb4d

Browse files
authored
BP Efficiency Improvement (#194)
1 parent 806d897 commit 174cb4d

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/caches/beliefpropagationcache.jl

+7-6
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ end
106106

107107
function message(bp_cache::BeliefPropagationCache, edge::PartitionEdge)
108108
mts = messages(bp_cache)
109-
return get(mts, edge, default_message(bp_cache, edge))
109+
return get(() -> default_message(bp_cache, edge), mts, edge)
110110
end
111111
function messages(bp_cache::BeliefPropagationCache, edges; kwargs...)
112112
return map(edge -> message(bp_cache, edge; kwargs...), edges)
@@ -152,15 +152,16 @@ end
152152
function environment(bp_cache::BeliefPropagationCache, verts::Vector)
153153
partition_verts = partitionvertices(bp_cache, verts)
154154
messages = environment(bp_cache, partition_verts)
155-
central_tensors = ITensor[
156-
tensornetwork(bp_cache)[v] for v in setdiff(vertices(bp_cache, partition_verts), verts)
157-
]
155+
central_tensors = factors(bp_cache, setdiff(vertices(bp_cache, partition_verts), verts))
158156
return vcat(messages, central_tensors)
159157
end
160158

159+
function factors(bp_cache::BeliefPropagationCache, verts::Vector)
160+
return ITensor[tensornetwork(bp_cache)[v] for v in verts]
161+
end
162+
161163
function factor(bp_cache::BeliefPropagationCache, vertex::PartitionVertex)
162-
ptn = partitioned_tensornetwork(bp_cache)
163-
return collect(eachtensor(subgraph(ptn, vertex)))
164+
return factors(bp_cache, vertices(bp_cache, vertex))
164165
end
165166

166167
"""

0 commit comments

Comments
 (0)