From f221b709e8dda26864022879994d3294b8511bd5 Mon Sep 17 00:00:00 2001 From: Joey Date: Thu, 8 Aug 2024 12:50:47 -0400 Subject: [PATCH 1/3] Add normalzie flag in default message update --- src/caches/beliefpropagationcache.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/caches/beliefpropagationcache.jl b/src/caches/beliefpropagationcache.jl index 2ce338f3..e9a64cda 100644 --- a/src/caches/beliefpropagationcache.jl +++ b/src/caches/beliefpropagationcache.jl @@ -16,10 +16,12 @@ using SimpleTraits: SimpleTraits, Not, @traitfn default_message(inds_e) = ITensor[denseblocks(delta(i)) for i in inds_e] default_messages(ptn::PartitionedGraph) = Dictionary() default_message_norm(m::ITensor) = norm(m) -function default_message_update(contract_list::Vector{ITensor}; kwargs...) +function default_message_update(contract_list::Vector{ITensor}; normalize=true, kwargs...) sequence = optimal_contraction_sequence(contract_list) updated_messages = contract(contract_list; sequence, kwargs...) - updated_messages /= norm(updated_messages) + if normalize + updated_messages /= norm(updated_messages) + end return ITensor[updated_messages] end @traitfn default_bp_maxiter(g::::(!IsDirected)) = is_tree(g) ? 1 : nothing From b747e95d17e4d98605b955027a85e392624e78c1 Mon Sep 17 00:00:00 2001 From: Joey Date: Thu, 8 Aug 2024 13:09:03 -0400 Subject: [PATCH 2/3] Formatting --- src/caches/beliefpropagationcache.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/caches/beliefpropagationcache.jl b/src/caches/beliefpropagationcache.jl index 378fd004..bd1f0665 100644 --- a/src/caches/beliefpropagationcache.jl +++ b/src/caches/beliefpropagationcache.jl @@ -17,7 +17,7 @@ using NDTensors: NDTensors default_message(elt, inds_e) = ITensor[denseblocks(delta(elt, i)) for i in inds_e] default_messages(ptn::PartitionedGraph) = Dictionary() default_message_norm(m::ITensor) = norm(m) -function default_message_update(contract_list::Vector{ITensor}; normalize = true, kwargs...) +function default_message_update(contract_list::Vector{ITensor}; normalize=true, kwargs...) sequence = optimal_contraction_sequence(contract_list) updated_messages = contract(contract_list; sequence, kwargs...) if normalize && !iszero(norm(updated_messages)) From 3cbe1cea4723fd6b6c1442e6b5ffa2491471b51b Mon Sep 17 00:00:00 2001 From: Joey Date: Thu, 8 Aug 2024 13:45:28 -0400 Subject: [PATCH 3/3] Bug fix --- src/caches/beliefpropagationcache.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/caches/beliefpropagationcache.jl b/src/caches/beliefpropagationcache.jl index bd1f0665..7dc78413 100644 --- a/src/caches/beliefpropagationcache.jl +++ b/src/caches/beliefpropagationcache.jl @@ -16,11 +16,11 @@ using NDTensors: NDTensors default_message(elt, inds_e) = ITensor[denseblocks(delta(elt, i)) for i in inds_e] default_messages(ptn::PartitionedGraph) = Dictionary() -default_message_norm(m::ITensor) = norm(m) function default_message_update(contract_list::Vector{ITensor}; normalize=true, kwargs...) sequence = optimal_contraction_sequence(contract_list) updated_messages = contract(contract_list; sequence, kwargs...) - if normalize && !iszero(norm(updated_messages)) + message_norm = norm(updated_messages) + if normalize && !iszero(message_norm) updated_messages /= message_norm end return ITensor[updated_messages]