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 1 commit
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
4 changes: 2 additions & 2 deletions examples/belief_propagation/bpexample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function main()
ψψ; subgraph_vertices=collect(values(group(v -> v[1], vertices(ψψ))))
)

mts = belief_propagation(ψψ, mts; contract_kwargs=(; alg="exact"))
mts = belief_propagation(ψψ, mts; contract_kwargs=(; alg="exact"), niters=20)

numerator_network = approx_network_region(
ψψ, mts, [(v, 1)]; verts_tn=ITensorNetwork([apply(op("Sz", s[v]), ψ[v])])
Expand All @@ -54,7 +54,7 @@ function main()
)
Zpp = partition(ψψ; subgraph_vertices=nested_graph_leaf_vertices(Zp))
mts = message_tensors(Zpp)
mts = belief_propagation(ψψ, mts; contract_kwargs=(; alg="exact"))
mts = belief_propagation(ψψ, mts; contract_kwargs=(; alg="exact"), niters=20)
numerator_network = approx_network_region(
ψψ, mts, [(v, 1)]; verts_tn=ITensorNetwork([apply(op("Sz", s[v]), ψ[v])])
)
Expand Down
250 changes: 62 additions & 188 deletions examples/belief_propagation/bpsequences.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,196 +12,70 @@ using ITensorNetworks:
approx_network_region,
contract_inner,
message_tensors,
nested_graph_leaf_vertices
nested_graph_leaf_vertices,
edge_sequence

function main()
g = named_comb_tree((6, 6))
s = siteinds("S=1/2", g)
χ = 4

Random.seed!(5467)

ψ = randomITensorNetwork(s; link_space=χ)
ψψ = ψ ⊗ prime(dag(ψ); sites=[])

#Initial message tensors for BP
mts_init = message_tensors(
ψψ; subgraph_vertices=collect(values(group(v -> v[1], vertices(ψψ))))
)

println("\nFirst testing out a comb tree. Random network with bond dim $χ")

#Now test out various sequences
print("Parallel updates (sequence is irrelevant): ")
belief_propagation(
ψψ,
mts_init;
contract_kwargs=(; alg="exact"),
target_precision=1e-10,
niters=100,
edges=[[e] for e in edges(mts_init)],
verbose=true,
)
print("Sequential updates (sequence is default edge list of the message tensors): ")
belief_propagation(
ψψ,
mts_init;
contract_kwargs=(; alg="exact"),
target_precision=1e-10,
niters=100,
edges=[e for e in edges(mts_init)],
verbose=true,
)
print("Sequential updates (sequence is our custom sequence finder): ")
belief_propagation(
ψψ,
mts_init;
contract_kwargs=(; alg="exact"),
target_precision=1e-10,
niters=100,
verbose=true,
)

g = NamedGraph(Graphs.random_regular_graph(100, 3))
s = siteinds("S=1/2", g)
χ = 4

Random.seed!(5467)

ψ = randomITensorNetwork(s; link_space=χ)
ψψ = ψ ⊗ prime(dag(ψ); sites=[])

#Initial message tensors for BP
mts_init = message_tensors(
ψψ; subgraph_vertices=collect(values(group(v -> v[1], vertices(ψψ))))
)

println("\nNow testing out a z = 3 random regular graph. Random network with bond dim $χ")

#Now test out various sequences
print("Parallel updates (sequence is irrelevant): ")
belief_propagation(
ψψ,
mts_init;
contract_kwargs=(; alg="exact"),
target_precision=1e-10,
niters=100,
edges=[[e] for e in edges(mts_init)],
verbose=true,
)
print("Sequential updates (sequence is default edge list of the message tensors): ")
belief_propagation(
ψψ,
mts_init;
contract_kwargs=(; alg="exact"),
target_precision=1e-10,
niters=100,
edges=[e for e in edges(mts_init)],
verbose=true,
)
print("Sequential updates (sequence is our custom sequence finder): ")
belief_propagation(
ψψ,
mts_init;
contract_kwargs=(; alg="exact"),
target_precision=1e-10,
niters=100,
verbose=true,
)

g = named_grid((6, 6))
s = siteinds("S=1/2", g)
χ = 2

Random.seed!(5467)

ψ = randomITensorNetwork(s; link_space=χ)
ψψ = ψ ⊗ prime(dag(ψ); sites=[])

#Initial message tensors for BP
mts_init = message_tensors(
ψψ; subgraph_vertices=collect(values(group(v -> v[1], vertices(ψψ))))
)

println("\nNow testing out a 6x6 grid. Random network with bond dim $χ")

#Now test out various sequences
print("Parallel updates (sequence is irrelevant): ")
belief_propagation(
ψψ,
mts_init;
contract_kwargs=(; alg="exact"),
target_precision=1e-10,
niters=100,
edges=[[e] for e in edges(mts_init)],
verbose=true,
)
print("Sequential updates (sequence is default edge list of the message tensors): ")
belief_propagation(
ψψ,
mts_init;
contract_kwargs=(; alg="exact"),
target_precision=1e-10,
niters=100,
edges=[e for e in edges(mts_init)],
verbose=true,
)
print("Sequential updates (sequence is our custom sequence finder): ")
belief_propagation(
ψψ,
mts_init;
contract_kwargs=(; alg="exact"),
target_precision=1e-10,
niters=100,
verbose=true,
)

g = NamedGraphs.hexagonal_lattice_graph(4, 4)
s = siteinds("S=1/2", g)
χ = 3

Random.seed!(5467)

ψ = randomITensorNetwork(s; link_space=χ)
ψψ = ψ ⊗ prime(dag(ψ); sites=[])

#Initial message tensors for BP
mts_init = message_tensors(
ψψ; subgraph_vertices=collect(values(group(v -> v[1], vertices(ψψ))))
)

println("\nNow testing out a 4 x 4 hexagonal lattice. Random network with bond dim $χ")

#Now test out various sequences
print("Parallel updates (sequence is irrelevant): ")
belief_propagation(
ψψ,
mts_init;
contract_kwargs=(; alg="exact"),
target_precision=1e-10,
niters=100,
edges=[[e] for e in edges(mts_init)],
verbose=true,
)
print("Sequential updates (sequence is default edge list of the message tensors): ")
belief_propagation(
ψψ,
mts_init;
contract_kwargs=(; alg="exact"),
target_precision=1e-10,
niters=100,
edges=[e for e in edges(mts_init)],
verbose=true,
)
print("Sequential updates (sequence is our custom sequence finder): ")
return belief_propagation(
ψψ,
mts_init;
contract_kwargs=(; alg="exact"),
target_precision=1e-10,
niters=100,
verbose=true,
)
g_labels = [
"Comb Tree",
"100 Site Random Regular Graph z = 3",
"6x6 Square Grid",
"4x4 Hexagonal Lattice",
]
gs = [
named_comb_tree((6, 6)),
NamedGraph(Graphs.random_regular_graph(100, 3)),
named_grid((6, 6)),
NamedGraphs.hexagonal_lattice_graph(4, 4),
]
χs = [4, 4, 2, 3]

for (i, g) in enumerate(gs)
Random.seed!(5467)
g_label = g_labels[i]
χ = χs[i]
s = siteinds("S=1/2", g)
ψ = randomITensorNetwork(s; link_space=χ)
ψψ = ψ ⊗ prime(dag(ψ); sites=[])

#Initial message tensors for BP
mts_init = message_tensors(
ψψ; subgraph_vertices=collect(values(group(v -> v[1], vertices(ψψ))))
)

println("\nFirst testing out a $g_label. Random network with bond dim $χ")

#Now test out various sequences
print("Parallel updates (sequence is irrelevant): ")
belief_propagation(
ψψ,
mts_init;
contract_kwargs=(; alg="exact"),
target_precision=1e-10,
niters=100,
edges=edge_sequence(mts_init; alg=ITensorNetworks.Parallel()),
verbose=true,
)
print("Sequential updates (sequence is default edge list of the message tensors): ")
belief_propagation(
ψψ,
mts_init;
contract_kwargs=(; alg="exact"),
target_precision=1e-10,
niters=100,
edges=[e for e in edges(mts_init)],
verbose=true,
)
print("Sequential updates (sequence is our custom sequence finder): ")
belief_propagation(
ψψ,
mts_init;
contract_kwargs=(; alg="exact"),
target_precision=1e-10,
niters=100,
verbose=true,
)
end
end

main()
5 changes: 4 additions & 1 deletion examples/gauging/gauging_itns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ function benchmark_state_gauging(
)
else
times_iters[i] = @elapsed mts, _ = belief_propagation_iteration(
ψψ, mts; contract_kwargs=(; alg="exact"), edges=[[e] for e in edges(mts)]
ψψ,
mts;
contract_kwargs=(; alg="exact"),
edges=edge_sequence(mts; alg=ITensorNetworks.Parallel()),
)
end

Expand Down
1 change: 1 addition & 0 deletions src/ITensorNetworks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ include("specialitensornetworks.jl")
include("renameitensornetwork.jl")
include("boundarymps.jl")
include(joinpath("beliefpropagation", "beliefpropagation.jl"))
include(joinpath("beliefpropagation", "beliefpropagation_schedule.jl"))
include(joinpath("beliefpropagation", "sqrt_beliefpropagation.jl"))
include("contraction_tree_to_graph.jl")
include("gauging.jl")
Expand Down
Loading
Loading