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
2 changes: 1 addition & 1 deletion examples/belief_propagation/bpsequences.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function main()
contract_kwargs=(; alg="exact"),
target_precision=1e-10,
niters=100,
edges=edge_sequence(mts_init; alg=ITensorNetworks.Parallel()),
edges=edge_sequence(mts_init; alg=ITensors.Algorithm("Parallel")),
JoeyT1994 marked this conversation as resolved.
Show resolved Hide resolved
verbose=true,
)
print("Sequential updates (sequence is default edge list of the message tensors): ")
Expand Down
5 changes: 3 additions & 2 deletions examples/gauging/gauging_itns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ using ITensorNetworks:
vidal_to_symmetric_gauge,
initialize_bond_tensors,
vidal_itn_isometries,
norm_network
norm_network,
edge_sequence

using NamedGraphs
using NamedGraphs: add_edges!, rem_vertex!, hexagonal_lattice_graph
Expand Down Expand Up @@ -77,7 +78,7 @@ function benchmark_state_gauging(
ψψ,
mts;
contract_kwargs=(; alg="exact"),
edges=edge_sequence(mts; alg=ITensorNetworks.Parallel()),
edges=edge_sequence(mts; alg=ITensors.Algorithm("Parallel")),
)
end

Expand Down
31 changes: 10 additions & 21 deletions src/beliefpropagation/beliefpropagation_schedule.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
abstract type EdgeSequenceAlgorithm end

struct ForestCover <: EdgeSequenceAlgorithm end
struct Parallel <: EdgeSequenceAlgorithm end

default_edge_sequence_alg() = ForestCover()
default_edge_sequence_alg() = Algorithm("ForestCover")

default_bp_niters(g::NamedGraph) = is_tree(g) ? 1 : nothing
function default_bp_niters(g::Union{DataGraph,AbstractITensorNetwork})
function default_bp_niters(g::AbstractGraph)
return default_bp_niters(undirected_graph(underlying_graph(g)))
end

function edge_sequence(g::NamedGraph; alg=default_edge_sequence_alg())
return edge_sequence(alg, g)
JoeyT1994 marked this conversation as resolved.
Show resolved Hide resolved
end
JoeyT1994 marked this conversation as resolved.
Show resolved Hide resolved

function edge_sequence(mts::DataGraph; alg=default_edge_sequence_alg())
return edge_sequence(alg, undirected_graph(underlying_graph(mts)))
function edge_sequence(g::AbstractGraph; alg=default_edge_sequence_alg())
return edge_sequence(alg, undirected_graph(underlying_graph(g)))
end
JoeyT1994 marked this conversation as resolved.
Show resolved Hide resolved

function edge_sequence(alg::Algorithm, g::AbstractGraph; kwargs...)
return edge_sequence(alg, g, kwargs...)
end

function edge_sequence(
::ForestCover, g::NamedGraph; root_vertex=NamedGraphs.default_root_vertex
::Algorithm"ForestCover", g::NamedGraph; root_vertex=NamedGraphs.default_root_vertex
)
JoeyT1994 marked this conversation as resolved.
Show resolved Hide resolved
@assert !is_directed(g)
forests = NamedGraphs.forest_cover(g)
Expand All @@ -35,17 +34,7 @@ function edge_sequence(
return edges
end

function edge_sequence(
::ForestCover, mts::DataGraph; root_vertex=NamedGraphs.default_root_vertex
)
return edge_sequence(ForestCover, undirected_graph(underlying_graph(mts)); root_vertex)
end

function edge_sequence(::Parallel, g::NamedGraph)
function edge_sequence(::Algorithm"Parallel", g::NamedGraph)
@assert !is_directed(g)
JoeyT1994 marked this conversation as resolved.
Show resolved Hide resolved
return [[e] for e in vcat(edges(g), reverse.(edges(g)))]
end

function edge_sequence(::Parallel, mts::DataGraph)
return edge_sequence(Parallel, undirected_graph(underlying_graph(mts)))
end
2 changes: 1 addition & 1 deletion src/beliefpropagation/sqrt_beliefpropagation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ end
function sqrt_belief_propagation(
tn::ITensorNetwork,
mts::DataGraph;
niters::Union{Int64,Nothing}=default_bp_niters(mts),
niters=default_bp_niters(mts),
edges=edge_sequence(mts),
# target_precision::Union{Float64,Nothing}=nothing,
)
Expand Down
4 changes: 2 additions & 2 deletions test/test_treetensornetworks/test_solvers/test_dmrg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ using Observers
# Compare to `ITensors.MPO` version of `dmrg`
H_mpo = MPO([H[v] for v in 1:nv(H)])
psi_mps = MPS([psi[v] for v in 1:nv(psi)])
e2, psi2 = dmrg(H_mpo, psi_mps; nsweeps, maxdim, normalize=false, outputlevel=0)
e2, psi2 = dmrg(H_mpo, psi_mps; nsweeps, maxdim, outputlevel=0)

psi = dmrg(H, psi; nsweeps, maxdim, cutoff, nsite, solver_krylovdim=3, solver_maxiter=1)
@test inner(psi', H, psi) ≈ inner(psi2', H_mpo, psi2)
Expand Down Expand Up @@ -134,7 +134,7 @@ end
sline = only.(collect(vertex_data(s)))[linear_order]
Hline = MPO(relabel_sites(os, vmap), sline)
psiline = randomMPS(sline; linkdims=20)
e2, psi2 = dmrg(Hline, psiline, sweeps; normalize=false, outputlevel=0)
e2, psi2 = dmrg(Hline, psiline, sweeps; outputlevel=0)

@test inner(psi', H, psi) ≈ inner(psi2', Hline, psi2) atol = 1e-5
end
Expand Down
Loading