Skip to content

Commit

Permalink
New File forScheduling and defaults for edge sequencing
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyT1994 committed Nov 9, 2023
1 parent a196c87 commit 045adc3
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 248 deletions.
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

0 comments on commit 045adc3

Please sign in to comment.