Skip to content

Commit

Permalink
Fixed NamedGraph type for certain operations
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyT1994 committed Nov 20, 2023
1 parent c82f92f commit 18321b6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
8 changes: 4 additions & 4 deletions examples/gauging/gauging_itns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ end
"""Bring an ITN into the Vidal gauge, various methods possible. Result is timed"""
function benchmark_state_gauging(
ψ::ITensorNetwork;
mode="BeliefPropagation",
mode="belief_propagation",
no_iterations=50,
BP_update_order::String="sequential",
)
Expand All @@ -68,7 +68,7 @@ function benchmark_state_gauging(
for i in 1:no_iterations
println("On Iteration " * string(i))

if mode == "BeliefPropagation"
if mode == "belief_propagation"
if BP_update_order != "parallel"
times_iters[i] = @elapsed mts, _ = belief_propagation_iteration(
ψψ, mts; contract_kwargs=(; alg="exact")
Expand All @@ -80,7 +80,7 @@ function benchmark_state_gauging(
end

times_gauging[i] = @elapsed ψ, bond_tensors = vidal_gauge(ψinit, mts)
elseif mode == "Eager"
elseif mode == "eager"
times_iters[i] = @elapsed ψ, bond_tensors, mts = eager_gauging(ψ, bond_tensors, mts)
else
times_iters[i] = @elapsed begin
Expand Down Expand Up @@ -110,7 +110,7 @@ BPG_simulation_times, BPG_Cs = benchmark_state_gauging(
BPG_sequential_simulation_times, BPG_sequential_Cs = benchmark_state_gauging(
ψ; no_iterations
)
Eager_simulation_times, Eager_Cs = benchmark_state_gauging(ψ; mode="Eager", no_iterations)
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-10
Expand Down
17 changes: 10 additions & 7 deletions src/beliefpropagation/beliefpropagation_schedule.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
default_edge_sequence_alg() = "forest_cover"

@traitfn default_bp_niters(g::NamedGraph::(!IsDirected)) = is_tree(g) ? 1 : nothing
@traitfn undirected_default_bp_niters(g::AbstractGraph::(!IsDirected)) =
is_tree(g) ? 1 : nothing
function default_bp_niters(g::AbstractGraph)
return default_bp_niters(undirected_graph(underlying_graph(g)))
return undirected_default_bp_niters(undirected_graph(underlying_graph(g)))
end

function edge_sequence(g::NamedGraph; alg=default_edge_sequence_alg())
return edge_sequence(alg, g)
@traitfn function edge_sequence(
g::NamedGraph::(!IsDirected); alg=default_edge_sequence_alg(), kwargs...
)
return edge_sequence(Algorithm(alg), g; kwargs...)
end

function edge_sequence(g::AbstractGraph; alg=default_edge_sequence_alg())
return edge_sequence(Algorithm(alg), undirected_graph(underlying_graph(g)))
function edge_sequence(g::AbstractGraph; alg=default_edge_sequence_alg(), kwargs...)
return edge_sequence(Algorithm(alg), undirected_graph(underlying_graph(g)); kwargs...)
end

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

@traitfn function edge_sequence(
Expand Down

0 comments on commit 18321b6

Please sign in to comment.