@@ -6,10 +6,10 @@ using ITensors: dir
66using NamedGraphs. PartitionedGraphs:
77 PartitionedGraphs,
88 PartitionedGraph,
9- PartitionVertex ,
10- boundary_partitionedges ,
11- partitionvertices ,
12- partitionedges ,
9+ QuotientVertex ,
10+ boundary_quotientedges ,
11+ quotientvertices ,
12+ quotientedges ,
1313 unpartitioned_graph
1414using SimpleTraits: SimpleTraits, Not, @traitfn
1515using NamedGraphs. SimilarType: SimilarType
@@ -25,7 +25,8 @@ function data_graph_type(bpc::AbstractBeliefPropagationCache)
2525end
2626data_graph (bpc:: AbstractBeliefPropagationCache ) = data_graph (tensornetwork (bpc))
2727
28- # TODO : Take `dot` without precontracting the messages to allow scaling to more complex messages
28+ # TODO : Take `dot` without precontracting the messages to allow scaling to more complex
29+ # messages
2930function message_diff (message_a:: Vector{ITensor} , message_b:: Vector{ITensor} )
3031 lhs, rhs = contract (message_a), contract (message_b)
3132 f = abs2 (dot (lhs / norm (lhs), rhs / norm (rhs)))
5253partitioned_tensornetwork (bpc:: AbstractBeliefPropagationCache ) = not_implemented ()
5354messages (bpc:: AbstractBeliefPropagationCache ) = not_implemented ()
5455function default_message (
55- bpc:: AbstractBeliefPropagationCache , edge:: PartitionEdge ; kwargs...
56+ bpc:: AbstractBeliefPropagationCache , edge:: QuotientEdge ; kwargs...
5657 )
5758 return not_implemented ()
5859end
6667function environment (bpc:: AbstractBeliefPropagationCache , verts:: Vector ; kwargs... )
6768 return not_implemented ()
6869end
69- function region_scalar (bpc:: AbstractBeliefPropagationCache , pv:: PartitionVertex ; kwargs... )
70+ function region_scalar (bpc:: AbstractBeliefPropagationCache , pv:: QuotientVertex ; kwargs... )
7071 return not_implemented ()
7172end
72- function region_scalar (bpc:: AbstractBeliefPropagationCache , pe:: PartitionEdge ; kwargs... )
73+ function region_scalar (bpc:: AbstractBeliefPropagationCache , pe:: QuotientEdge ; kwargs... )
7374 return not_implemented ()
7475end
7576partitions (bpc:: AbstractBeliefPropagationCache ) = not_implemented ()
76- PartitionedGraphs. partitionedges (bpc:: AbstractBeliefPropagationCache ) = not_implemented ()
77+ PartitionedGraphs. quotientedges (bpc:: AbstractBeliefPropagationCache ) = not_implemented ()
78+ function PartitionedGraphs. partitioned_vertices (bpc:: AbstractBeliefPropagationCache )
79+ return not_implemented ()
80+ end
7781
7882default_bp_edge_sequence (bpc:: AbstractBeliefPropagationCache ) = not_implemented ()
7983default_bp_maxiter (bpc:: AbstractBeliefPropagationCache ) = not_implemented ()
@@ -87,21 +91,23 @@ function factors(bpc::AbstractBeliefPropagationCache, verts::Vector)
8791end
8892
8993function factors (
90- bpc:: AbstractBeliefPropagationCache , partition_verts:: Vector{<:PartitionVertex }
94+ bpc:: AbstractBeliefPropagationCache , partition_verts:: Vector{<:QuotientVertex }
9195 )
9296 return factors (bpc, vertices (bpc, partition_verts))
9397end
9498
95- function factors (bpc:: AbstractBeliefPropagationCache , partition_vertex:: PartitionVertex )
99+ function factors (bpc:: AbstractBeliefPropagationCache , partition_vertex:: QuotientVertex )
96100 return factors (bpc, [partition_vertex])
97101end
98102
99- function vertex_scalars (bpc:: AbstractBeliefPropagationCache , pvs = partitions (bpc); kwargs... )
103+ function vertex_scalars (
104+ bpc:: AbstractBeliefPropagationCache , pvs = partitions (bpc); kwargs...
105+ )
100106 return map (pv -> region_scalar (bpc, pv; kwargs... ), pvs)
101107end
102108
103109function edge_scalars (
104- bpc:: AbstractBeliefPropagationCache , pes = partitionedges (bpc); kwargs...
110+ bpc:: AbstractBeliefPropagationCache , pes = quotientedges (bpc); kwargs...
105111 )
106112 return map (pe -> region_scalar (bpc, pe; kwargs... ), pes)
107113end
@@ -112,16 +118,16 @@ end
112118
113119function incoming_messages (
114120 bpc:: AbstractBeliefPropagationCache ,
115- partition_vertices:: Vector{<:PartitionVertex } ;
121+ partition_vertices:: Vector{<:QuotientVertex } ;
116122 ignore_edges = (),
117123 )
118- bpes = boundary_partitionedges (bpc, partition_vertices; dir = :in )
124+ bpes = boundary_quotientedges (bpc, partition_vertices; dir = :in )
119125 ms = messages (bpc, setdiff (bpes, ignore_edges))
120126 return reduce (vcat, ms; init = ITensor[])
121127end
122128
123129function incoming_messages (
124- bpc:: AbstractBeliefPropagationCache , partition_vertex:: PartitionVertex ; kwargs...
130+ bpc:: AbstractBeliefPropagationCache , partition_vertex:: QuotientVertex ; kwargs...
125131 )
126132 return incoming_messages (bpc, [partition_vertex]; kwargs... )
127133end
@@ -157,21 +163,40 @@ function Adapt.adapt_structure(to, bpc::AbstractBeliefPropagationCache)
157163end
158164
159165# Forward from partitioned graph
160- for f in [
161- :(PartitionedGraphs. partitionedge),
162- :(PartitionedGraphs. partitionvertices),
163- :(PartitionedGraphs. partitions_graph),
164- :(PartitionedGraphs. vertices),
165- :(PartitionedGraphs. boundary_partitionedges),
166- ]
167- @eval begin
168- function $f (bpc:: AbstractBeliefPropagationCache , args... ; kwargs... )
169- return $ f (partitioned_tensornetwork (bpc), args... ; kwargs... )
170- end
171- end
166+ using Graphs: Graphs, vertices
167+ function Graphs. vertices (bpc:: AbstractBeliefPropagationCache )
168+ return vertices (partitioned_tensornetwork (bpc))
169+ end
170+ function PartitionedGraphs. quotient_graph (bpc:: AbstractBeliefPropagationCache )
171+ return PartitionedGraphs. quotient_graph (partitioned_tensornetwork (bpc))
172+ end
173+ function PartitionedGraphs. quotientedge (
174+ bpc:: AbstractBeliefPropagationCache , edge:: AbstractEdge
175+ )
176+ return PartitionedGraphs. quotientedge (partitioned_tensornetwork (bpc), edge)
177+ end
178+ function PartitionedGraphs. quotientvertices (bpc:: AbstractBeliefPropagationCache )
179+ return PartitionedGraphs. quotientvertices (partitioned_tensornetwork (bpc))
180+ end
181+ function PartitionedGraphs. quotientvertices (bpc:: AbstractBeliefPropagationCache , vs)
182+ return PartitionedGraphs. quotientvertices (partitioned_tensornetwork (bpc), vs)
183+ end
184+ function PartitionedGraphs. boundary_quotientedges (
185+ bpc:: AbstractBeliefPropagationCache , quotientvertices; kwargs...
186+ )
187+ return PartitionedGraphs. boundary_quotientedges (
188+ partitioned_tensornetwork (bpc), quotientvertices; kwargs...
189+ )
190+ end
191+ function PartitionedGraphs. boundary_quotientedges (
192+ bpc:: AbstractBeliefPropagationCache , quotientvertex:: QuotientVertex ; kwargs...
193+ )
194+ return PartitionedGraphs. boundary_quotientedges (
195+ partitioned_tensornetwork (bpc), quotientvertex; kwargs...
196+ )
172197end
173198
174- function linkinds (bpc:: AbstractBeliefPropagationCache , pe:: PartitionEdge )
199+ function linkinds (bpc:: AbstractBeliefPropagationCache , pe:: QuotientEdge )
175200 return linkinds (partitioned_tensornetwork (bpc), pe)
176201end
177202
@@ -195,62 +220,64 @@ function update_factor(bpc, vertex, factor)
195220 return bpc
196221end
197222
198- function message (bpc:: AbstractBeliefPropagationCache , edge:: PartitionEdge ; kwargs... )
223+ function message (bpc:: AbstractBeliefPropagationCache , edge:: QuotientEdge ; kwargs... )
199224 mts = messages (bpc)
200225 return get (() -> default_message (bpc, edge; kwargs... ), mts, edge)
201226end
202227function messages (bpc:: AbstractBeliefPropagationCache , edges; kwargs... )
203228 return map (edge -> message (bpc, edge; kwargs... ), edges)
204229end
205- function set_messages! (bpc:: AbstractBeliefPropagationCache , partitionedges_messages )
230+ function set_messages! (bpc:: AbstractBeliefPropagationCache , quotientedges_messages )
206231 ms = messages (bpc)
207- for pe in eachindex (partitionedges_messages )
232+ for pe in eachindex (quotientedges_messages )
208233 # TODO : Add a check that this preserves the graph structure.
209- set! (ms, pe, partitionedges_messages [pe])
234+ set! (ms, pe, quotientedges_messages [pe])
210235 end
211236 return bpc
212237end
213- function set_message! (bpc:: AbstractBeliefPropagationCache , pe:: PartitionEdge , message)
238+ function set_message! (bpc:: AbstractBeliefPropagationCache , pe:: QuotientEdge , message)
214239 ms = messages (bpc)
215240 set! (ms, pe, message)
216241 return bpc
217242end
218243
219- function set_messages (bpc:: AbstractBeliefPropagationCache , partitionedges_messages )
244+ function set_messages (bpc:: AbstractBeliefPropagationCache , quotientedges_messages )
220245 bpc = copy (bpc)
221- return set_messages! (bpc, partitionedges_messages )
246+ return set_messages! (bpc, quotientedges_messages )
222247end
223- function set_message (bpc:: AbstractBeliefPropagationCache , pe:: PartitionEdge , message)
248+ function set_message (bpc:: AbstractBeliefPropagationCache , pe:: QuotientEdge , message)
224249 bpc = copy (bpc)
225250 return set_message! (bpc, pe, message)
226251end
227252function delete_messages! (
228- bpc:: AbstractBeliefPropagationCache , pes:: Vector{<:PartitionEdge} = keys (messages (bpc))
253+ bpc:: AbstractBeliefPropagationCache ,
254+ pes:: Vector{<:QuotientEdge} = keys (messages (bpc)),
229255 )
230256 ms = messages (bpc)
231257 for pe in pes
232258 delete! (ms, pe)
233259 end
234260 return bpc
235261end
236- function delete_message! (bpc:: AbstractBeliefPropagationCache , pe:: PartitionEdge )
262+ function delete_message! (bpc:: AbstractBeliefPropagationCache , pe:: QuotientEdge )
237263 return delete_messages! (bpc, [pe])
238264end
239265function delete_messages (
240- bpc:: AbstractBeliefPropagationCache , pes:: Vector{<:PartitionEdge} = keys (messages (bpc))
266+ bpc:: AbstractBeliefPropagationCache ,
267+ pes:: Vector{<:QuotientEdge} = keys (messages (bpc)),
241268 )
242269 bpc = copy (bpc)
243270 return delete_messages! (bpc, pes)
244271end
245- function delete_message (bpc:: AbstractBeliefPropagationCache , pe:: PartitionEdge )
272+ function delete_message (bpc:: AbstractBeliefPropagationCache , pe:: QuotientEdge )
246273 return delete_messages (bpc, [pe])
247274end
248275
249276function updated_message (
250- alg:: Algorithm"contract" , bpc:: AbstractBeliefPropagationCache , edge:: PartitionEdge
277+ alg:: Algorithm"contract" , bpc:: AbstractBeliefPropagationCache , edge:: QuotientEdge
251278 )
252279 vertex = src (edge)
253- incoming_ms = incoming_messages (bpc, vertex; ignore_edges = PartitionEdge [reverse (edge)])
280+ incoming_ms = incoming_messages (bpc, vertex; ignore_edges = QuotientEdge [reverse (edge)])
254281 state = factors (bpc, vertex)
255282 contract_list = ITensor[incoming_ms; state]
256283 sequence = contraction_sequence (contract_list; alg = alg. kwargs. sequence_alg)
@@ -263,10 +290,10 @@ function updated_message(
263290end
264291
265292function updated_message (
266- alg:: Algorithm"adapt_update" , bpc:: AbstractBeliefPropagationCache , edge:: PartitionEdge
293+ alg:: Algorithm"adapt_update" , bpc:: AbstractBeliefPropagationCache , edge:: QuotientEdge
267294 )
268295 incoming_pes = setdiff (
269- boundary_partitionedges (bpc, [src (edge)]; dir = :in ), [reverse (edge)]
296+ boundary_quotientedges (bpc, [src (edge)]; dir = :in ), [reverse (edge)]
270297 )
271298 adapted_bpc = adapt_messages (alg. kwargs. adapt, bpc, incoming_pes)
272299 adapted_bpc = adapt_factors (alg. kwargs. adapt, bpc, vertices (bpc, src (edge)))
@@ -277,15 +304,15 @@ end
277304
278305function updated_message (
279306 bpc:: AbstractBeliefPropagationCache ,
280- edge:: PartitionEdge ;
307+ edge:: QuotientEdge ;
281308 alg = default_message_update_alg (bpc),
282309 kwargs... ,
283310 )
284311 return updated_message (set_default_kwargs (Algorithm (alg; kwargs... )), bpc, edge)
285312end
286313
287314function update_message (
288- message_update_alg:: Algorithm , bpc:: AbstractBeliefPropagationCache , edge:: PartitionEdge
315+ message_update_alg:: Algorithm , bpc:: AbstractBeliefPropagationCache , edge:: QuotientEdge
289316 )
290317 return set_message (bpc, edge, updated_message (message_update_alg, bpc, edge))
291318end
@@ -318,7 +345,7 @@ mts relevant to that group.
318345function update_iteration (
319346 alg:: Algorithm"bp" ,
320347 bpc:: AbstractBeliefPropagationCache ,
321- edge_groups:: Vector{<:Vector{<:PartitionEdge }} ;
348+ edge_groups:: Vector{<:Vector{<:QuotientEdge }} ;
322349 (update_diff!) = nothing ,
323350 )
324351 new_mts = empty (messages (bpc))
@@ -357,13 +384,13 @@ function update(bpc::AbstractBeliefPropagationCache; alg = default_update_alg(bp
357384end
358385
359386function rescale_messages (
360- bp_cache:: AbstractBeliefPropagationCache , partitionedge :: PartitionEdge
387+ bp_cache:: AbstractBeliefPropagationCache , quotientedge :: QuotientEdge
361388 )
362- return rescale_messages (bp_cache, [partitionedge ])
389+ return rescale_messages (bp_cache, [quotientedge ])
363390end
364391
365392function rescale_messages (bp_cache:: AbstractBeliefPropagationCache )
366- return rescale_messages (bp_cache, partitionedges (bp_cache))
393+ return rescale_messages (bp_cache, quotientedges (bp_cache))
367394end
368395
369396function rescale_partitions (
0 commit comments