From 18321b681217f86f45ac65708d9fac0dd3a75a06 Mon Sep 17 00:00:00 2001 From: Joseph Tindall Date: Mon, 20 Nov 2023 17:05:30 -0500 Subject: [PATCH] Fixed NamedGraph type for certain operations --- examples/gauging/gauging_itns.jl | 8 ++++---- .../beliefpropagation_schedule.jl | 17 ++++++++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/examples/gauging/gauging_itns.jl b/examples/gauging/gauging_itns.jl index 0246e443..7463d54a 100644 --- a/examples/gauging/gauging_itns.jl +++ b/examples/gauging/gauging_itns.jl @@ -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", ) @@ -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") @@ -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 @@ -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 diff --git a/src/beliefpropagation/beliefpropagation_schedule.jl b/src/beliefpropagation/beliefpropagation_schedule.jl index fb79d011..7cda8325 100644 --- a/src/beliefpropagation/beliefpropagation_schedule.jl +++ b/src/beliefpropagation/beliefpropagation_schedule.jl @@ -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(