From ea154042232899872c1e0789f286ada45d264c46 Mon Sep 17 00:00:00 2001 From: Joseph Tindall Date: Mon, 6 May 2024 11:27:52 -0400 Subject: [PATCH] Make contract calls for BP do sequence finding by default --- src/caches/beliefpropagationcache.jl | 29 ++++++++++++++++++++-------- src/expect.jl | 4 +++- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/caches/beliefpropagationcache.jl b/src/caches/beliefpropagationcache.jl index 475a8e02..aa816c2b 100644 --- a/src/caches/beliefpropagationcache.jl +++ b/src/caches/beliefpropagationcache.jl @@ -267,27 +267,40 @@ function update_factor(bp_cache, vertex, factor) return update_factors(bp_cache, Dictionary([vertex], [factor])) end -function region_scalar(bp_cache::BeliefPropagationCache, pv::PartitionVertex) +function region_scalar( + bp_cache::BeliefPropagationCache, + pv::PartitionVertex; + contract_kwargs=(; sequence="automatic"), +) incoming_mts = environment(bp_cache, [pv]) local_state = factor(bp_cache, pv) - return contract(vcat(incoming_mts, local_state))[] + return contract(vcat(incoming_mts, local_state); contract_kwargs...)[] end -function region_scalar(bp_cache::BeliefPropagationCache, pe::PartitionEdge) - return contract(vcat(message(bp_cache, pe), message(bp_cache, reverse(pe))))[] +function region_scalar( + bp_cache::BeliefPropagationCache, + pe::PartitionEdge; + contract_kwargs=(; sequence="automatic"), +) + return contract( + vcat(message(bp_cache, pe), message(bp_cache, reverse(pe))); contract_kwargs... + )[] end function vertex_scalars( bp_cache::BeliefPropagationCache, - pvs=partitionvertices(partitioned_tensornetwork(bp_cache)), + pvs=partitionvertices(partitioned_tensornetwork(bp_cache)); + kwargs..., ) - return map(pv -> region_scalar(bp_cache, pv), pvs) + return map(pv -> region_scalar(bp_cache, pv; kwargs...), pvs) end function edge_scalars( - bp_cache::BeliefPropagationCache, pes=partitionedges(partitioned_tensornetwork(bp_cache)) + bp_cache::BeliefPropagationCache, + pes=partitionedges(partitioned_tensornetwork(bp_cache)); + kwargs..., ) - return map(pe -> region_scalar(bp_cache, pe), pes) + return map(pe -> region_scalar(bp_cache, pe; kwargs...), pes) end function scalar_factors_quotient(bp_cache::BeliefPropagationCache) diff --git a/src/expect.jl b/src/expect.jl index 64dc78b3..8b4b6526 100644 --- a/src/expect.jl +++ b/src/expect.jl @@ -4,7 +4,9 @@ using ITensors.ITensorMPS: ITensorMPS, expect default_expect_alg() = "bp" -function ITensorMPS.expect(ψIψ::AbstractFormNetwork, op::Op; contract_kwargs=(;), kwargs...) +function ITensorMPS.expect( + ψIψ::AbstractFormNetwork, op::Op; contract_kwargs=(; sequence="automatic"), kwargs... +) v = only(op.sites) ψIψ_v = ψIψ[operator_vertex(ψIψ, v)] s = commonind(ψIψ[ket_vertex(ψIψ, v)], ψIψ_v)