From 35ff6f929812ce6b117ac3510908871fcbbfd987 Mon Sep 17 00:00:00 2001 From: CompatHelper Julia Date: Thu, 13 Nov 2025 02:09:59 +0000 Subject: [PATCH 1/7] CompatHelper: bump compat for NamedGraphs to 0.8, (keep existing compat) --- Project.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 0df19b54..9a10094e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ITensorNetworks" uuid = "2919e153-833c-4bdc-8836-1ea460a35fc7" +version = "0.15.3" authors = ["Matthew Fishman , Joseph Tindall and contributors"] -version = "0.15.2" [deps] AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" @@ -70,7 +70,7 @@ IterTools = "1.4.0" KrylovKit = "0.6, 0.7, 0.8, 0.9, 0.10" MacroTools = "0.5" NDTensors = "0.3, 0.4" -NamedGraphs = "0.7.1" +NamedGraphs = "0.7.1, 0.8" OMEinsumContractionOrders = "0.8.3, 0.9, 1" Observers = "0.2.4" SerializedElementArrays = "0.1" From a4999401b270a3f77bc1385c8c049f486b6eda51 Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Fri, 21 Nov 2025 10:47:47 -0500 Subject: [PATCH 2/7] Update NamedGraphs dependency version to 0.8 --- test/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Project.toml b/test/Project.toml index aff7bb32..fe65d7a4 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -50,7 +50,7 @@ KrylovKit = "0.8, 0.9, 0.10" LinearAlgebra = "1.10" Metis = "1.5" NDTensors = "0.3, 0.4" -NamedGraphs = "0.7" +NamedGraphs = "0.8" OMEinsumContractionOrders = "0.9.5, 1" Observers = "0.2.5" OrdinaryDiffEqTsit5 = "1.1" From 9f6bfcf6ed31bf08f6110c75912516fd7ed418a8 Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Fri, 21 Nov 2025 10:48:06 -0500 Subject: [PATCH 3/7] Apply suggestion from @mtfishman --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 9a10094e..9216d164 100644 --- a/Project.toml +++ b/Project.toml @@ -70,7 +70,7 @@ IterTools = "1.4.0" KrylovKit = "0.6, 0.7, 0.8, 0.9, 0.10" MacroTools = "0.5" NDTensors = "0.3, 0.4" -NamedGraphs = "0.7.1, 0.8" +NamedGraphs = "0.8" OMEinsumContractionOrders = "0.8.3, 0.9, 1" Observers = "0.2.4" SerializedElementArrays = "0.1" From 5b4453f75ddb6cd74e63a984f3da5a2e0c9ab686 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Fri, 21 Nov 2025 11:27:27 -0500 Subject: [PATCH 4/7] Renaming --- src/caches/abstractbeliefpropagationcache.jl | 82 ++++++++++---------- src/caches/beliefpropagationcache.jl | 28 +++---- src/edge_sequences.jl | 4 +- src/gauging.jl | 6 +- src/partitioneditensornetwork.jl | 4 +- 5 files changed, 62 insertions(+), 62 deletions(-) diff --git a/src/caches/abstractbeliefpropagationcache.jl b/src/caches/abstractbeliefpropagationcache.jl index 6421b31d..bca3c0a5 100644 --- a/src/caches/abstractbeliefpropagationcache.jl +++ b/src/caches/abstractbeliefpropagationcache.jl @@ -6,10 +6,10 @@ using ITensors: dir using NamedGraphs.PartitionedGraphs: PartitionedGraphs, PartitionedGraph, - PartitionVertex, - boundary_partitionedges, - partitionvertices, - partitionedges, + QuotientVertex, + boundary_quotientedges, + quotientvertices, + quotientedges, unpartitioned_graph using SimpleTraits: SimpleTraits, Not, @traitfn using NamedGraphs.SimilarType: SimilarType @@ -52,7 +52,7 @@ end partitioned_tensornetwork(bpc::AbstractBeliefPropagationCache) = not_implemented() messages(bpc::AbstractBeliefPropagationCache) = not_implemented() function default_message( - bpc::AbstractBeliefPropagationCache, edge::PartitionEdge; kwargs... + bpc::AbstractBeliefPropagationCache, edge::QuotientEdge; kwargs... ) return not_implemented() end @@ -66,14 +66,14 @@ end function environment(bpc::AbstractBeliefPropagationCache, verts::Vector; kwargs...) return not_implemented() end -function region_scalar(bpc::AbstractBeliefPropagationCache, pv::PartitionVertex; kwargs...) +function region_scalar(bpc::AbstractBeliefPropagationCache, pv::QuotientVertex; kwargs...) return not_implemented() end -function region_scalar(bpc::AbstractBeliefPropagationCache, pe::PartitionEdge; kwargs...) +function region_scalar(bpc::AbstractBeliefPropagationCache, pe::QuotientEdge; kwargs...) return not_implemented() end partitions(bpc::AbstractBeliefPropagationCache) = not_implemented() -PartitionedGraphs.partitionedges(bpc::AbstractBeliefPropagationCache) = not_implemented() +PartitionedGraphs.quotientedges(bpc::AbstractBeliefPropagationCache) = not_implemented() default_bp_edge_sequence(bpc::AbstractBeliefPropagationCache) = not_implemented() default_bp_maxiter(bpc::AbstractBeliefPropagationCache) = not_implemented() @@ -87,12 +87,12 @@ function factors(bpc::AbstractBeliefPropagationCache, verts::Vector) end function factors( - bpc::AbstractBeliefPropagationCache, partition_verts::Vector{<:PartitionVertex} + bpc::AbstractBeliefPropagationCache, partition_verts::Vector{<:QuotientVertex} ) return factors(bpc, vertices(bpc, partition_verts)) end -function factors(bpc::AbstractBeliefPropagationCache, partition_vertex::PartitionVertex) +function factors(bpc::AbstractBeliefPropagationCache, partition_vertex::QuotientVertex) return factors(bpc, [partition_vertex]) end @@ -101,7 +101,7 @@ function vertex_scalars(bpc::AbstractBeliefPropagationCache, pvs = partitions(bp end function edge_scalars( - bpc::AbstractBeliefPropagationCache, pes = partitionedges(bpc); kwargs... + bpc::AbstractBeliefPropagationCache, pes = quotientedges(bpc); kwargs... ) return map(pe -> region_scalar(bpc, pe; kwargs...), pes) end @@ -112,16 +112,16 @@ end function incoming_messages( bpc::AbstractBeliefPropagationCache, - partition_vertices::Vector{<:PartitionVertex}; + partition_vertices::Vector{<:QuotientVertex}; ignore_edges = (), ) - bpes = boundary_partitionedges(bpc, partition_vertices; dir = :in) + bpes = boundary_quotientedges(bpc, partition_vertices; dir = :in) ms = messages(bpc, setdiff(bpes, ignore_edges)) return reduce(vcat, ms; init = ITensor[]) end function incoming_messages( - bpc::AbstractBeliefPropagationCache, partition_vertex::PartitionVertex; kwargs... + bpc::AbstractBeliefPropagationCache, partition_vertex::QuotientVertex; kwargs... ) return incoming_messages(bpc, [partition_vertex]; kwargs...) end @@ -158,11 +158,11 @@ end #Forward from partitioned graph for f in [ - :(PartitionedGraphs.partitionedge), - :(PartitionedGraphs.partitionvertices), - :(PartitionedGraphs.partitions_graph), + :(PartitionedGraphs.quotientedge), + :(PartitionedGraphs.quotientvertices), + :(PartitionedGraphs.quotient_graph), :(PartitionedGraphs.vertices), - :(PartitionedGraphs.boundary_partitionedges), + :(PartitionedGraphs.boundary_quotientedges), ] @eval begin function $f(bpc::AbstractBeliefPropagationCache, args...; kwargs...) @@ -171,7 +171,7 @@ for f in [ end end -function linkinds(bpc::AbstractBeliefPropagationCache, pe::PartitionEdge) +function linkinds(bpc::AbstractBeliefPropagationCache, pe::QuotientEdge) return linkinds(partitioned_tensornetwork(bpc), pe) end @@ -195,37 +195,37 @@ function update_factor(bpc, vertex, factor) return bpc end -function message(bpc::AbstractBeliefPropagationCache, edge::PartitionEdge; kwargs...) +function message(bpc::AbstractBeliefPropagationCache, edge::QuotientEdge; kwargs...) mts = messages(bpc) return get(() -> default_message(bpc, edge; kwargs...), mts, edge) end function messages(bpc::AbstractBeliefPropagationCache, edges; kwargs...) return map(edge -> message(bpc, edge; kwargs...), edges) end -function set_messages!(bpc::AbstractBeliefPropagationCache, partitionedges_messages) +function set_messages!(bpc::AbstractBeliefPropagationCache, quotientedges_messages) ms = messages(bpc) - for pe in eachindex(partitionedges_messages) + for pe in eachindex(quotientedges_messages) # TODO: Add a check that this preserves the graph structure. - set!(ms, pe, partitionedges_messages[pe]) + set!(ms, pe, quotientedges_messages[pe]) end return bpc end -function set_message!(bpc::AbstractBeliefPropagationCache, pe::PartitionEdge, message) +function set_message!(bpc::AbstractBeliefPropagationCache, pe::QuotientEdge, message) ms = messages(bpc) set!(ms, pe, message) return bpc end -function set_messages(bpc::AbstractBeliefPropagationCache, partitionedges_messages) +function set_messages(bpc::AbstractBeliefPropagationCache, quotientedges_messages) bpc = copy(bpc) - return set_messages!(bpc, partitionedges_messages) + return set_messages!(bpc, quotientedges_messages) end -function set_message(bpc::AbstractBeliefPropagationCache, pe::PartitionEdge, message) +function set_message(bpc::AbstractBeliefPropagationCache, pe::QuotientEdge, message) bpc = copy(bpc) return set_message!(bpc, pe, message) end function delete_messages!( - bpc::AbstractBeliefPropagationCache, pes::Vector{<:PartitionEdge} = keys(messages(bpc)) + bpc::AbstractBeliefPropagationCache, pes::Vector{<:QuotientEdge} = keys(messages(bpc)) ) ms = messages(bpc) for pe in pes @@ -233,24 +233,24 @@ function delete_messages!( end return bpc end -function delete_message!(bpc::AbstractBeliefPropagationCache, pe::PartitionEdge) +function delete_message!(bpc::AbstractBeliefPropagationCache, pe::QuotientEdge) return delete_messages!(bpc, [pe]) end function delete_messages( - bpc::AbstractBeliefPropagationCache, pes::Vector{<:PartitionEdge} = keys(messages(bpc)) + bpc::AbstractBeliefPropagationCache, pes::Vector{<:QuotientEdge} = keys(messages(bpc)) ) bpc = copy(bpc) return delete_messages!(bpc, pes) end -function delete_message(bpc::AbstractBeliefPropagationCache, pe::PartitionEdge) +function delete_message(bpc::AbstractBeliefPropagationCache, pe::QuotientEdge) return delete_messages(bpc, [pe]) end function updated_message( - alg::Algorithm"contract", bpc::AbstractBeliefPropagationCache, edge::PartitionEdge + alg::Algorithm"contract", bpc::AbstractBeliefPropagationCache, edge::QuotientEdge ) vertex = src(edge) - incoming_ms = incoming_messages(bpc, vertex; ignore_edges = PartitionEdge[reverse(edge)]) + incoming_ms = incoming_messages(bpc, vertex; ignore_edges = QuotientEdge[reverse(edge)]) state = factors(bpc, vertex) contract_list = ITensor[incoming_ms; state] sequence = contraction_sequence(contract_list; alg = alg.kwargs.sequence_alg) @@ -263,10 +263,10 @@ function updated_message( end function updated_message( - alg::Algorithm"adapt_update", bpc::AbstractBeliefPropagationCache, edge::PartitionEdge + alg::Algorithm"adapt_update", bpc::AbstractBeliefPropagationCache, edge::QuotientEdge ) incoming_pes = setdiff( - boundary_partitionedges(bpc, [src(edge)]; dir = :in), [reverse(edge)] + boundary_quotientedges(bpc, [src(edge)]; dir = :in), [reverse(edge)] ) adapted_bpc = adapt_messages(alg.kwargs.adapt, bpc, incoming_pes) adapted_bpc = adapt_factors(alg.kwargs.adapt, bpc, vertices(bpc, src(edge))) @@ -277,7 +277,7 @@ end function updated_message( bpc::AbstractBeliefPropagationCache, - edge::PartitionEdge; + edge::QuotientEdge; alg = default_message_update_alg(bpc), kwargs..., ) @@ -285,7 +285,7 @@ function updated_message( end function update_message( - message_update_alg::Algorithm, bpc::AbstractBeliefPropagationCache, edge::PartitionEdge + message_update_alg::Algorithm, bpc::AbstractBeliefPropagationCache, edge::QuotientEdge ) return set_message(bpc, edge, updated_message(message_update_alg, bpc, edge)) end @@ -318,7 +318,7 @@ mts relevant to that group. function update_iteration( alg::Algorithm"bp", bpc::AbstractBeliefPropagationCache, - edge_groups::Vector{<:Vector{<:PartitionEdge}}; + edge_groups::Vector{<:Vector{<:QuotientEdge}}; (update_diff!) = nothing, ) new_mts = empty(messages(bpc)) @@ -357,13 +357,13 @@ function update(bpc::AbstractBeliefPropagationCache; alg = default_update_alg(bp end function rescale_messages( - bp_cache::AbstractBeliefPropagationCache, partitionedge::PartitionEdge + bp_cache::AbstractBeliefPropagationCache, quotientedge::QuotientEdge ) - return rescale_messages(bp_cache, [partitionedge]) + return rescale_messages(bp_cache, [quotientedge]) end function rescale_messages(bp_cache::AbstractBeliefPropagationCache) - return rescale_messages(bp_cache, partitionedges(bp_cache)) + return rescale_messages(bp_cache, quotientedges(bp_cache)) end function rescale_partitions( diff --git a/src/caches/beliefpropagationcache.jl b/src/caches/beliefpropagationcache.jl index a431b152..73f081fd 100644 --- a/src/caches/beliefpropagationcache.jl +++ b/src/caches/beliefpropagationcache.jl @@ -6,12 +6,12 @@ using NamedGraphs.PartitionedGraphs: AbstractPartitionedGraph, PartitionedGraphs, PartitionedGraph, - PartitionVertex, - boundary_partitionedges, - partitionvertices, - partitionedges, + QuotientVertex, + boundary_quotientedges, + quotientvertices, + quotientedges, partitioned_vertices, - partitions_graph, + quotient_graph, unpartitioned_graph, which_partition using SimpleTraits: SimpleTraits, Not, @traitfn @@ -59,7 +59,7 @@ end messages(bp_cache::BeliefPropagationCache) = bp_cache.messages -function default_message(bp_cache::BeliefPropagationCache, edge::PartitionEdge) +function default_message(bp_cache::BeliefPropagationCache, edge::QuotientEdge) return default_message(datatype(bp_cache), linkinds(bp_cache, edge)) end @@ -96,26 +96,26 @@ function set_default_kwargs(alg::Algorithm"bp", bp_cache::BeliefPropagationCache end function default_bp_maxiter(bp_cache::BeliefPropagationCache) - return default_bp_maxiter(partitions_graph(bp_cache)) + return default_bp_maxiter(quotient_graph(bp_cache)) end function default_bp_edge_sequence(bp_cache::BeliefPropagationCache) return default_edge_sequence(partitioned_tensornetwork(bp_cache)) end Base.setindex!(bpc::BeliefPropagationCache, factor::ITensor, vertex) = not_implemented() -partitions(bpc::BeliefPropagationCache) = partitionvertices(partitioned_tensornetwork(bpc)) -function PartitionedGraphs.partitionedges(bpc::BeliefPropagationCache) - return partitionedges(partitioned_tensornetwork(bpc)) +partitions(bpc::BeliefPropagationCache) = quotientvertices(partitioned_tensornetwork(bpc)) +function PartitionedGraphs.quotientedges(bpc::BeliefPropagationCache) + return quotientedges(partitioned_tensornetwork(bpc)) end function environment(bpc::BeliefPropagationCache, verts::Vector; kwargs...) - partition_verts = partitionvertices(bpc, verts) + partition_verts = quotientvertices(bpc, verts) messages = incoming_messages(bpc, partition_verts; kwargs...) central_tensors = factors(bpc, setdiff(vertices(bpc, partition_verts), verts)) return vcat(messages, central_tensors) end -function region_scalar(bp_cache::BeliefPropagationCache, pv::PartitionVertex) +function region_scalar(bp_cache::BeliefPropagationCache, pv::QuotientVertex) incoming_mts = incoming_messages(bp_cache, [pv]) local_state = factors(bp_cache, pv) ts = vcat(incoming_mts, local_state) @@ -123,13 +123,13 @@ function region_scalar(bp_cache::BeliefPropagationCache, pv::PartitionVertex) return contract(ts; sequence)[] end -function region_scalar(bp_cache::BeliefPropagationCache, pe::PartitionEdge) +function region_scalar(bp_cache::BeliefPropagationCache, pe::QuotientEdge) ts = vcat(message(bp_cache, pe), message(bp_cache, reverse(pe))) sequence = contraction_sequence(ts; alg = "optimal") return contract(ts; sequence)[] end -function rescale_messages(bp_cache::BeliefPropagationCache, pes::Vector{<:PartitionEdge}) +function rescale_messages(bp_cache::BeliefPropagationCache, pes::Vector{<:QuotientEdge}) bp_cache = copy(bp_cache) mts = messages(bp_cache) for pe in pes diff --git a/src/edge_sequences.jl b/src/edge_sequences.jl index 089a5218..a1ccc0f5 100644 --- a/src/edge_sequences.jl +++ b/src/edge_sequences.jl @@ -2,12 +2,12 @@ using Graphs: IsDirected, connected_components, edges, edgetype using ITensors.NDTensors: Algorithm, @Algorithm_str using NamedGraphs: NamedGraphs using NamedGraphs.GraphsExtensions: GraphsExtensions, forest_cover, undirected_graph -using NamedGraphs.PartitionedGraphs: PartitionEdge, PartitionedGraph, partitions_graph +using NamedGraphs.PartitionedGraphs: QuotientEdge, PartitionedGraph, quotient_graph using SimpleTraits: SimpleTraits, Not, @traitfn default_edge_sequence_alg() = "forest_cover" function default_edge_sequence(pg::PartitionedGraph) - return PartitionEdge.(edge_sequence(partitions_graph(pg))) + return QuotientEdge.(edge_sequence(quotient_graph(pg))) end @traitfn function edge_sequence( diff --git a/src/gauging.jl b/src/gauging.jl index 00c200c4..f5760848 100644 --- a/src/gauging.jl +++ b/src/gauging.jl @@ -1,6 +1,6 @@ using ITensors: tags using ITensors.NDTensors: dense, scalartype -using NamedGraphs.PartitionedGraphs: partitionedge +using NamedGraphs.PartitionedGraphs: quotientedge function default_bond_tensors(ψ::ITensorNetwork) return DataGraph( @@ -49,7 +49,7 @@ function ITensorNetwork( for e in edges(ψ) vsrc, vdst = src(e), dst(e) - pe = partitionedge(bp_cache, (vsrc, "bra") => (vdst, "bra")) + pe = quotientedge(bp_cache, (vsrc, "bra") => (vdst, "bra")) set!(mts, pe, copy(ITensor[dense(bond_tensor(ψ_vidal, e))])) set!(mts, reverse(pe), copy(ITensor[dense(bond_tensor(ψ_vidal, e))])) end @@ -78,7 +78,7 @@ function vidalitensornetwork_preserve_cache( vsrc, vdst = src(e), dst(e) ψvsrc, ψvdst = ψ_vidal_site_tensors[vsrc], ψ_vidal_site_tensors[vdst] - pe = partitionedge(cache, (vsrc, "bra") => (vdst, "bra")) + pe = quotientedge(cache, (vsrc, "bra") => (vdst, "bra")) edge_ind = commoninds(ψvsrc, ψvdst) edge_ind_sim = sim(edge_ind) diff --git a/src/partitioneditensornetwork.jl b/src/partitioneditensornetwork.jl index e1bf7700..a559bcc6 100644 --- a/src/partitioneditensornetwork.jl +++ b/src/partitioneditensornetwork.jl @@ -1,9 +1,9 @@ using Graphs: dst, src using ITensors: commoninds using NamedGraphs.GraphsExtensions: subgraph -using NamedGraphs.PartitionedGraphs: PartitionedGraph, PartitionEdge +using NamedGraphs.PartitionedGraphs: PartitionedGraph, QuotientEdge -function linkinds(pitn::PartitionedGraph, edge::PartitionEdge) +function linkinds(pitn::PartitionedGraph, edge::QuotientEdge) src_e_itn = subgraph(pitn, src(edge)) dst_e_itn = subgraph(pitn, dst(edge)) return commoninds(src_e_itn, dst_e_itn) From 7da92b63080b71439414abc0dd03a26630c1bb62 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Fri, 21 Nov 2025 16:51:58 -0500 Subject: [PATCH 5/7] Fix tests --- src/caches/abstractbeliefpropagationcache.jl | 59 ++++++++++++++------ src/caches/beliefpropagationcache.jl | 12 ++-- src/partitioneditensornetwork.jl | 8 +++ test/test_apply.jl | 1 - test/test_belief_propagation.jl | 4 +- 5 files changed, 60 insertions(+), 24 deletions(-) diff --git a/src/caches/abstractbeliefpropagationcache.jl b/src/caches/abstractbeliefpropagationcache.jl index bca3c0a5..c2a62ec1 100644 --- a/src/caches/abstractbeliefpropagationcache.jl +++ b/src/caches/abstractbeliefpropagationcache.jl @@ -25,7 +25,8 @@ function data_graph_type(bpc::AbstractBeliefPropagationCache) end data_graph(bpc::AbstractBeliefPropagationCache) = data_graph(tensornetwork(bpc)) -#TODO: Take `dot` without precontracting the messages to allow scaling to more complex messages +#TODO: Take `dot` without precontracting the messages to allow scaling to more complex +# messages function message_diff(message_a::Vector{ITensor}, message_b::Vector{ITensor}) lhs, rhs = contract(message_a), contract(message_b) f = abs2(dot(lhs / norm(lhs), rhs / norm(rhs))) @@ -74,6 +75,9 @@ function region_scalar(bpc::AbstractBeliefPropagationCache, pe::QuotientEdge; kw end partitions(bpc::AbstractBeliefPropagationCache) = not_implemented() PartitionedGraphs.quotientedges(bpc::AbstractBeliefPropagationCache) = not_implemented() +function PartitionedGraphs.partitioned_vertices(bpc::AbstractBeliefPropagationCache) + return not_implemented() +end default_bp_edge_sequence(bpc::AbstractBeliefPropagationCache) = not_implemented() default_bp_maxiter(bpc::AbstractBeliefPropagationCache) = not_implemented() @@ -96,7 +100,9 @@ function factors(bpc::AbstractBeliefPropagationCache, partition_vertex::Quotient return factors(bpc, [partition_vertex]) end -function vertex_scalars(bpc::AbstractBeliefPropagationCache, pvs = partitions(bpc); kwargs...) +function vertex_scalars( + bpc::AbstractBeliefPropagationCache, pvs = partitions(bpc); kwargs... + ) return map(pv -> region_scalar(bpc, pv; kwargs...), pvs) end @@ -157,18 +163,37 @@ function Adapt.adapt_structure(to, bpc::AbstractBeliefPropagationCache) end #Forward from partitioned graph -for f in [ - :(PartitionedGraphs.quotientedge), - :(PartitionedGraphs.quotientvertices), - :(PartitionedGraphs.quotient_graph), - :(PartitionedGraphs.vertices), - :(PartitionedGraphs.boundary_quotientedges), - ] - @eval begin - function $f(bpc::AbstractBeliefPropagationCache, args...; kwargs...) - return $f(partitioned_tensornetwork(bpc), args...; kwargs...) - end - end +using Graphs: Graphs, vertices +function Graphs.vertices(bpc::AbstractBeliefPropagationCache) + return vertices(partitioned_tensornetwork(bpc)) +end +function PartitionedGraphs.quotient_graph(bpc::AbstractBeliefPropagationCache) + return PartitionedGraphs.quotient_graph(partitioned_tensornetwork(bpc)) +end +function PartitionedGraphs.quotientedge( + bpc::AbstractBeliefPropagationCache, edge::AbstractEdge + ) + return PartitionedGraphs.quotientedge(partitioned_tensornetwork(bpc), edge) +end +function PartitionedGraphs.quotientvertices(bpc::AbstractBeliefPropagationCache) + return PartitionedGraphs.quotientvertices(partitioned_tensornetwork(bpc)) +end +function PartitionedGraphs.quotientvertices(bpc::AbstractBeliefPropagationCache, vs) + return PartitionedGraphs.quotientvertices(partitioned_tensornetwork(bpc), vs) +end +function PartitionedGraphs.boundary_quotientedges( + bpc::AbstractBeliefPropagationCache, quotientvertices; kwargs... + ) + return PartitionedGraphs.boundary_quotientedges( + partitioned_tensornetwork(bpc), quotientvertices; kwargs... + ) +end +function PartitionedGraphs.boundary_quotientedges( + bpc::AbstractBeliefPropagationCache, quotientvertex::QuotientVertex; kwargs... + ) + return PartitionedGraphs.boundary_quotientedges( + partitioned_tensornetwork(bpc), quotientvertex; kwargs... + ) end function linkinds(bpc::AbstractBeliefPropagationCache, pe::QuotientEdge) @@ -225,7 +250,8 @@ function set_message(bpc::AbstractBeliefPropagationCache, pe::QuotientEdge, mess return set_message!(bpc, pe, message) end function delete_messages!( - bpc::AbstractBeliefPropagationCache, pes::Vector{<:QuotientEdge} = keys(messages(bpc)) + bpc::AbstractBeliefPropagationCache, + pes::Vector{<:QuotientEdge} = keys(messages(bpc)), ) ms = messages(bpc) for pe in pes @@ -237,7 +263,8 @@ function delete_message!(bpc::AbstractBeliefPropagationCache, pe::QuotientEdge) return delete_messages!(bpc, [pe]) end function delete_messages( - bpc::AbstractBeliefPropagationCache, pes::Vector{<:QuotientEdge} = keys(messages(bpc)) + bpc::AbstractBeliefPropagationCache, + pes::Vector{<:QuotientEdge} = keys(messages(bpc)), ) bpc = copy(bpc) return delete_messages!(bpc, pes) diff --git a/src/caches/beliefpropagationcache.jl b/src/caches/beliefpropagationcache.jl index 73f081fd..3252afa4 100644 --- a/src/caches/beliefpropagationcache.jl +++ b/src/caches/beliefpropagationcache.jl @@ -8,12 +8,11 @@ using NamedGraphs.PartitionedGraphs: PartitionedGraph, QuotientVertex, boundary_quotientedges, - quotientvertices, - quotientedges, partitioned_vertices, quotient_graph, - unpartitioned_graph, - which_partition + quotientedges, + quotientvertices, + unpartitioned_graph using SimpleTraits: SimpleTraits, Not, @traitfn using NDTensors: NDTensors, Algorithm @@ -107,6 +106,9 @@ partitions(bpc::BeliefPropagationCache) = quotientvertices(partitioned_tensornet function PartitionedGraphs.quotientedges(bpc::BeliefPropagationCache) return quotientedges(partitioned_tensornetwork(bpc)) end +function PartitionedGraphs.partitioned_vertices(bpc::BeliefPropagationCache) + return partitioned_vertices(partitioned_tensornetwork(bpc)) +end function environment(bpc::BeliefPropagationCache, verts::Vector; kwargs...) partition_verts = quotientvertices(bpc, verts) @@ -129,7 +131,7 @@ function region_scalar(bp_cache::BeliefPropagationCache, pe::QuotientEdge) return contract(ts; sequence)[] end -function rescale_messages(bp_cache::BeliefPropagationCache, pes::Vector{<:QuotientEdge}) +function rescale_messages(bp_cache::BeliefPropagationCache, pes) bp_cache = copy(bp_cache) mts = messages(bp_cache) for pe in pes diff --git a/src/partitioneditensornetwork.jl b/src/partitioneditensornetwork.jl index a559bcc6..7d9275a8 100644 --- a/src/partitioneditensornetwork.jl +++ b/src/partitioneditensornetwork.jl @@ -3,6 +3,14 @@ using ITensors: commoninds using NamedGraphs.GraphsExtensions: subgraph using NamedGraphs.PartitionedGraphs: PartitionedGraph, QuotientEdge +# TODO: Delete this once it is fixed in NamedGraphs.jl. +using Graphs: induced_subgraph +using NamedGraphs.GraphsExtensions: GraphsExtensions +using NamedGraphs.PartitionedGraphs: PartitionedGraph, QuotientVertex +function GraphsExtensions.subgraph(g::PartitionedGraph, v::QuotientVertex) + return induced_subgraph(g, v)[1].graph +end + function linkinds(pitn::PartitionedGraph, edge::QuotientEdge) src_e_itn = subgraph(pitn, src(edge)) dst_e_itn = subgraph(pitn, dst(edge)) diff --git a/test/test_apply.jl b/test/test_apply.jl index f732ce64..7bacbf22 100644 --- a/test/test_apply.jl +++ b/test/test_apply.jl @@ -13,7 +13,6 @@ using ITensorNetworks: update using ITensors: ITensors, ITensor, Algorithm, inner, op using NamedGraphs.NamedGraphGenerators: named_grid -using NamedGraphs.PartitionedGraphs: PartitionVertex using SplitApplyCombine: group using StableRNGs: StableRNG using TensorOperations: TensorOperations diff --git a/test/test_belief_propagation.jl b/test/test_belief_propagation.jl index dbc60d02..144764cb 100644 --- a/test/test_belief_propagation.jl +++ b/test/test_belief_propagation.jl @@ -32,7 +32,7 @@ using ITensors.NDTensors: array using LinearAlgebra: eigvals, tr using NamedGraphs: NamedEdge, NamedGraph using NamedGraphs.NamedGraphGenerators: named_comb_tree, named_grid -using NamedGraphs.PartitionedGraphs: PartitionVertex, partitionedges +using NamedGraphs.PartitionedGraphs: quotientedges using SplitApplyCombine: group using StableRNGs: StableRNG using TensorOperations: TensorOperations @@ -65,7 +65,7 @@ using Test: @test, @testset bpc = update(bpc; alg = "bp", maxiter = 25, tol = eps(real(elt))) #Test messages are converged - for pe in partitionedges(bpc) + for pe in quotientedges(bpc) @test message_diff(updated_message(bpc, pe), message(bpc, pe)) < 10 * eps(real(elt)) @test eltype(only(message(bpc, pe))) == elt end From 36b2c74791cb84ffccce405a2c9c904263209604 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Fri, 21 Nov 2025 21:05:48 -0500 Subject: [PATCH 6/7] Bump dep compat --- Project.toml | 4 ++-- src/partitioneditensornetwork.jl | 8 -------- test/Project.toml | 4 ++-- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/Project.toml b/Project.toml index 9216d164..e5895b04 100644 --- a/Project.toml +++ b/Project.toml @@ -56,7 +56,7 @@ Adapt = "4" Combinatorics = "1" Compat = "3, 4" ConstructionBase = "1.6.0" -DataGraphs = "0.2.3" +DataGraphs = "0.2.13" DataStructures = "0.18, 0.19" Dictionaries = "0.4" Distributions = "0.25.86" @@ -70,7 +70,7 @@ IterTools = "1.4.0" KrylovKit = "0.6, 0.7, 0.8, 0.9, 0.10" MacroTools = "0.5" NDTensors = "0.3, 0.4" -NamedGraphs = "0.8" +NamedGraphs = "0.8.2" OMEinsumContractionOrders = "0.8.3, 0.9, 1" Observers = "0.2.4" SerializedElementArrays = "0.1" diff --git a/src/partitioneditensornetwork.jl b/src/partitioneditensornetwork.jl index 7d9275a8..a559bcc6 100644 --- a/src/partitioneditensornetwork.jl +++ b/src/partitioneditensornetwork.jl @@ -3,14 +3,6 @@ using ITensors: commoninds using NamedGraphs.GraphsExtensions: subgraph using NamedGraphs.PartitionedGraphs: PartitionedGraph, QuotientEdge -# TODO: Delete this once it is fixed in NamedGraphs.jl. -using Graphs: induced_subgraph -using NamedGraphs.GraphsExtensions: GraphsExtensions -using NamedGraphs.PartitionedGraphs: PartitionedGraph, QuotientVertex -function GraphsExtensions.subgraph(g::PartitionedGraph, v::QuotientVertex) - return induced_subgraph(g, v)[1].graph -end - function linkinds(pitn::PartitionedGraph, edge::QuotientEdge) src_e_itn = subgraph(pitn, src(edge)) dst_e_itn = subgraph(pitn, dst(edge)) diff --git a/test/Project.toml b/test/Project.toml index fe65d7a4..a2d9b263 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -36,7 +36,7 @@ AbstractTrees = "0.4.5" Adapt = "4.3" Aqua = "0.8.11" Compat = "4.16" -DataGraphs = "0.2.6" +DataGraphs = "0.2.13" Dictionaries = "0.4.4" Distributions = "0.25.118" EinExprs = "0.6.8, 0.7" @@ -50,7 +50,7 @@ KrylovKit = "0.8, 0.9, 0.10" LinearAlgebra = "1.10" Metis = "1.5" NDTensors = "0.3, 0.4" -NamedGraphs = "0.8" +NamedGraphs = "0.8.2" OMEinsumContractionOrders = "0.9.5, 1" Observers = "0.2.5" OrdinaryDiffEqTsit5 = "1.1" From eb72485e4f502ad766b424728cf6b9aba5b86e7a Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Fri, 21 Nov 2025 21:16:26 -0500 Subject: [PATCH 7/7] Fix Project.toml formatting --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index e5895b04..f261c297 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ITensorNetworks" uuid = "2919e153-833c-4bdc-8836-1ea460a35fc7" -version = "0.15.3" authors = ["Matthew Fishman , Joseph Tindall and contributors"] +version = "0.15.3" [deps] AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"