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 order flexibility #111

Merged
merged 39 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d0dda47
Added option to specify order of BP updates. Also set of edges for do…
JoeyT1994 Oct 2, 2023
54604ac
Changed BP ordering to sequential for a test
JoeyT1994 Oct 2, 2023
ccc7946
No capitalisation. Fixed bug in test_belief_propagation.jl
JoeyT1994 Oct 3, 2023
6fdd8d8
es -> edges
JoeyT1994 Oct 3, 2023
6e0f152
Bug Fix
JoeyT1994 Oct 3, 2023
ff699d4
Update_order -> update_sequence
JoeyT1994 Oct 6, 2023
9ad1672
Bug Fix
JoeyT1994 Oct 6, 2023
8efe301
Working on optimal orders
JoeyT1994 Oct 23, 2023
1cf1daf
Added custom edge specification on vidal_itn_isometries
JoeyT1994 Oct 23, 2023
ffa9d5c
Added custom edge specification on vidal_gauge
JoeyT1994 Oct 23, 2023
6f8d832
New Testing for Sequences
JoeyT1994 Oct 23, 2023
be8c13d
Merge branch 'BP_Update_Order' of github.com:JoeyT1994/ITensorNetwork…
JoeyT1994 Oct 23, 2023
0832ad5
Functions for optimal edge order
JoeyT1994 Oct 23, 2023
dfec1e2
Further changes
JoeyT1994 Oct 26, 2023
1e6ec2b
Better specification of update sequence for BP
JoeyT1994 Oct 26, 2023
4c352ab
Fixed IBM processor construction to reflect row and column name swapp…
JoeyT1994 Nov 2, 2023
3ad3cbc
Forest cover for specifying edge update order. Better specification o…
JoeyT1994 Nov 2, 2023
6df26bd
Improvement
JoeyT1994 Nov 6, 2023
070996a
Merge remote-tracking branch 'upstream/main' into BP_Update_Order
JoeyT1994 Nov 6, 2023
6ba7828
Added BP sequences to test examples. Removed Sqrt_BP as already tested
JoeyT1994 Nov 6, 2023
67fef77
Update examples/gauging/gauging_itns.jl
JoeyT1994 Nov 8, 2023
57dd13f
Update src/beliefpropagation/beliefpropagation.jl
JoeyT1994 Nov 8, 2023
cedb1d6
Update src/beliefpropagation/beliefpropagation.jl
JoeyT1994 Nov 9, 2023
a8da3dc
Update src/beliefpropagation/beliefpropagation.jl
JoeyT1994 Nov 9, 2023
a5008ee
Update src/beliefpropagation/beliefpropagation.jl
JoeyT1994 Nov 9, 2023
db9a474
Update src/beliefpropagation/beliefpropagation.jl
JoeyT1994 Nov 9, 2023
f183ec7
Update src/beliefpropagation/beliefpropagation.jl
JoeyT1994 Nov 9, 2023
247f2af
Update src/beliefpropagation/beliefpropagation.jl
JoeyT1994 Nov 9, 2023
a196c87
Update src/beliefpropagation/beliefpropagation.jl
JoeyT1994 Nov 9, 2023
045adc3
New File forScheduling and defaults for edge sequencing
JoeyT1994 Nov 9, 2023
e7ccf43
Improved Schedule Code
JoeyT1994 Nov 9, 2023
2b8513a
Update src/beliefpropagation/beliefpropagation_schedule.jl
JoeyT1994 Nov 9, 2023
1b71894
Update src/beliefpropagation/beliefpropagation_schedule.jl
JoeyT1994 Nov 9, 2023
fe06b39
Update src/beliefpropagation/beliefpropagation_schedule.jl
JoeyT1994 Nov 9, 2023
b21f629
Imported Algorithmn from ITensors
JoeyT1994 Nov 9, 2023
c82f92f
Better dispatching on graph types
JoeyT1994 Nov 9, 2023
18321b6
Fixed NamedGraph type for certain operations
JoeyT1994 Nov 20, 2023
a3db9c0
Trait fns now come in pairs
JoeyT1994 Nov 21, 2023
487c43f
Type assertion removed
JoeyT1994 Nov 28, 2023
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
36 changes: 28 additions & 8 deletions examples/gauging/gauging_itns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ end

"""Bring an ITN into the Vidal gauge, various methods possible. Result is timed"""
function benchmark_state_gauging(
ψ::ITensorNetwork; mode="BeliefPropagation", no_iterations=50
ψ::ITensorNetwork;
mode="BeliefPropagation",
JoeyT1994 marked this conversation as resolved.
Show resolved Hide resolved
no_iterations=50,
BP_update_order::String="Parallel",
)
s = siteinds(ψ)

Expand All @@ -67,8 +70,9 @@ function benchmark_state_gauging(

if mode == "BeliefPropagation"
times_iters[i] = @elapsed mts, _ = belief_propagation_iteration(
ψψ, mts; contract_kwargs=(; alg="exact")
ψψ, mts; contract_kwargs=(; alg="exact"), update_order=BP_update_order
)

times_gauging[i] = @elapsed ψ, bond_tensors = vidal_gauge(ψinit, mts)
elseif mode == "Eager"
times_iters[i] = @elapsed ψ, bond_tensors, mts = eager_gauging(ψ, bond_tensors, mts)
Expand All @@ -95,22 +99,38 @@ s = siteinds("S=1/2", g)
no_iterations = 30

BPG_simulation_times, BPG_Cs = benchmark_state_gauging(ψ; no_iterations)
BPG_sequential_simulation_times, BPG_sequential_Cs = benchmark_state_gauging(
ψ; no_iterations, BP_update_order="Sequential"
)
Eager_simulation_times, Eager_Cs = benchmark_state_gauging(ψ; mode="Eager", no_iterations)
SU_simulation_times, SU_Cs = benchmark_state_gauging(ψ; mode="SU", no_iterations)

epsilon = 1e-6

println(
"Time for BPG to reach C < epsilon was " *
"Time for BPG (with parallel updates) to reach C < epsilon was " *
string(BPG_simulation_times[findfirst(x -> x < 0, BPG_Cs .- epsilon)]) *
" seconds",
" seconds. No iters was " *
string(findfirst(x -> x < 0, BPG_Cs .- epsilon)),
)
println(
"Time for Eager to reach C < epsilon was " *
"Time for BPG (with sequential updates) to reach C < epsilon was " *
string(
BPG_sequential_simulation_times[findfirst(x -> x < 0, BPG_sequential_Cs .- epsilon)]
) *
" seconds. No iters was " *
string(findfirst(x -> x < 0, BPG_sequential_Cs .- epsilon)),
)

println(
"Time for Eager Gauging to reach C < epsilon was " *
string(Eager_simulation_times[findfirst(x -> x < 0, Eager_Cs .- epsilon)]) *
" seconds",
" seconds. No iters was " *
string(findfirst(x -> x < 0, Eager_Cs .- epsilon)),
)
println(
"Time for SU to reach C < epsilon was " *
"Time for SU Gauging to reach C < epsilon was " *
string(SU_simulation_times[findfirst(x -> x < 0, SU_Cs .- epsilon)]) *
" seconds",
" seconds. No iters was " *
string(findfirst(x -> x < 0, SU_Cs .- epsilon)),
)
19 changes: 15 additions & 4 deletions src/beliefpropagation/beliefpropagation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,25 @@ function belief_propagation_iteration(
mts::DataGraph;
contract_kwargs=(; alg="density_matrix", output_structure=path_graph_structure, maxdim=1),
compute_norm=false,
update_order::String="Parallel",
JoeyT1994 marked this conversation as resolved.
Show resolved Hide resolved
es=edges(mts),
JoeyT1994 marked this conversation as resolved.
Show resolved Hide resolved
)
new_mts = copy(mts)
if update_order != "Parallel" && update_order != "Sequential"
error(
"Specified update order is not currently implemented. Choose Parallel or Sequential."
)
end
incoming_mts = update_order == "Parallel" ? mts : new_mts
c = 0
es = edges(mts)
for e in es
environment_tensornetworks = ITensorNetwork[
mts[e_in] for e_in in setdiff(boundary_edges(mts, [src(e)]; dir=:in), [reverse(e)])
incoming_mts[e_in] for
e_in in setdiff(boundary_edges(incoming_mts, [src(e)]; dir=:in), [reverse(e)])
]

new_mts[src(e) => dst(e)] = update_message_tensor(
tn, mts[src(e)], environment_tensornetworks; contract_kwargs
tn, incoming_mts[src(e)], environment_tensornetworks; contract_kwargs
)

if compute_norm
Expand All @@ -111,10 +119,13 @@ function belief_propagation(
contract_kwargs=(; alg="density_matrix", output_structure=path_graph_structure, maxdim=1),
niters=20,
target_precision::Union{Float64,Nothing}=nothing,
JoeyT1994 marked this conversation as resolved.
Show resolved Hide resolved
update_order::String="Parallel",
)
compute_norm = target_precision == nothing ? false : true
JoeyT1994 marked this conversation as resolved.
Show resolved Hide resolved
for i in 1:niters
mts, c = belief_propagation_iteration(tn, mts; contract_kwargs, compute_norm)
mts, c = belief_propagation_iteration(
tn, mts; contract_kwargs, compute_norm, update_order
)
if compute_norm && c <= target_precision
println(
"Belief Propagation finished. Reached a canonicalness of " *
Expand Down
10 changes: 9 additions & 1 deletion src/beliefpropagation/sqrt_beliefpropagation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,19 @@ end
function sqrt_belief_propagation_iteration(
tn::ITensorNetwork,
sqrt_mts::DataGraph;
update_order::String="Parallel",
es=edges(sqrt_mts),

# compute_norm=false,
)
new_sqrt_mts = copy(sqrt_mts)
if update_order != "Parallel" && update_order != "Sequential"
error(
"Specified update order is not currently implemented. Choose Parallel or Sequential."
)
end
incoming_mts = update_order == "Parallel" ? mts : new_mts
c = 0.0
es = edges(sqrt_mts)
for e in es
environment_tensornetworks = ITensorNetwork[
sqrt_mts[e_in] for
Expand Down
8 changes: 7 additions & 1 deletion test/test_belief_propagation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ ITensors.disable_warn_order()

Z = partition(ψψ; subgraph_vertices=collect(values(group(v -> v[1], vertices(ψψ)))))
mts = message_tensors(Z)
mts = belief_propagation(ψψ, mts; contract_kwargs=(; alg="exact"), target_precision=1e-8)
mts = belief_propagation(
ψψ,
mts;
contract_kwargs=(; alg="exact"),
target_precision=1e-8;
update_order="Sequential",
)

numerator_network = approx_network_region(
ψψ, mts, [(v, 1)]; verts_tn=ITensorNetwork(ITensor[apply(op("Sz", s[v]), ψ[v])])
Expand Down
Loading