Skip to content

Commit 6357bee

Browse files
github-actions[bot]CompatHelper Juliamtfishman
authored
CompatHelper: bump compat for NamedGraphs to 0.8, (keep existing compat) (#264)
Co-authored-by: CompatHelper Julia <[email protected]> Co-authored-by: Matt Fishman <[email protected]> Co-authored-by: mtfishman <[email protected]>
1 parent afd15c3 commit 6357bee

File tree

9 files changed

+110
-82
lines changed

9 files changed

+110
-82
lines changed

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ITensorNetworks"
22
uuid = "2919e153-833c-4bdc-8836-1ea460a35fc7"
33
authors = ["Matthew Fishman <[email protected]>, Joseph Tindall <[email protected]> and contributors"]
4-
version = "0.15.2"
4+
version = "0.15.3"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
@@ -56,7 +56,7 @@ Adapt = "4"
5656
Combinatorics = "1"
5757
Compat = "3, 4"
5858
ConstructionBase = "1.6.0"
59-
DataGraphs = "0.2.3"
59+
DataGraphs = "0.2.13"
6060
DataStructures = "0.18, 0.19"
6161
Dictionaries = "0.4"
6262
Distributions = "0.25.86"
@@ -70,7 +70,7 @@ IterTools = "1.4.0"
7070
KrylovKit = "0.6, 0.7, 0.8, 0.9, 0.10"
7171
MacroTools = "0.5"
7272
NDTensors = "0.3, 0.4"
73-
NamedGraphs = "0.7.1"
73+
NamedGraphs = "0.8.2"
7474
OMEinsumContractionOrders = "0.8.3, 0.9, 1"
7575
Observers = "0.2.4"
7676
SerializedElementArrays = "0.1"

src/caches/abstractbeliefpropagationcache.jl

Lines changed: 78 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ using ITensors: dir
66
using 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
1414
using SimpleTraits: SimpleTraits, Not, @traitfn
1515
using NamedGraphs.SimilarType: SimilarType
@@ -25,7 +25,8 @@ function data_graph_type(bpc::AbstractBeliefPropagationCache)
2525
end
2626
data_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
2930
function 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)))
@@ -52,7 +53,7 @@ end
5253
partitioned_tensornetwork(bpc::AbstractBeliefPropagationCache) = not_implemented()
5354
messages(bpc::AbstractBeliefPropagationCache) = not_implemented()
5455
function default_message(
55-
bpc::AbstractBeliefPropagationCache, edge::PartitionEdge; kwargs...
56+
bpc::AbstractBeliefPropagationCache, edge::QuotientEdge; kwargs...
5657
)
5758
return not_implemented()
5859
end
@@ -66,14 +67,17 @@ end
6667
function environment(bpc::AbstractBeliefPropagationCache, verts::Vector; kwargs...)
6768
return not_implemented()
6869
end
69-
function region_scalar(bpc::AbstractBeliefPropagationCache, pv::PartitionVertex; kwargs...)
70+
function region_scalar(bpc::AbstractBeliefPropagationCache, pv::QuotientVertex; kwargs...)
7071
return not_implemented()
7172
end
72-
function region_scalar(bpc::AbstractBeliefPropagationCache, pe::PartitionEdge; kwargs...)
73+
function region_scalar(bpc::AbstractBeliefPropagationCache, pe::QuotientEdge; kwargs...)
7374
return not_implemented()
7475
end
7576
partitions(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

7882
default_bp_edge_sequence(bpc::AbstractBeliefPropagationCache) = not_implemented()
7983
default_bp_maxiter(bpc::AbstractBeliefPropagationCache) = not_implemented()
@@ -87,21 +91,23 @@ function factors(bpc::AbstractBeliefPropagationCache, verts::Vector)
8791
end
8892

8993
function factors(
90-
bpc::AbstractBeliefPropagationCache, partition_verts::Vector{<:PartitionVertex}
94+
bpc::AbstractBeliefPropagationCache, partition_verts::Vector{<:QuotientVertex}
9195
)
9296
return factors(bpc, vertices(bpc, partition_verts))
9397
end
9498

95-
function factors(bpc::AbstractBeliefPropagationCache, partition_vertex::PartitionVertex)
99+
function factors(bpc::AbstractBeliefPropagationCache, partition_vertex::QuotientVertex)
96100
return factors(bpc, [partition_vertex])
97101
end
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)
101107
end
102108

103109
function 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)
107113
end
@@ -112,16 +118,16 @@ end
112118

113119
function 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[])
121127
end
122128

123129
function 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...)
127133
end
@@ -157,21 +163,40 @@ function Adapt.adapt_structure(to, bpc::AbstractBeliefPropagationCache)
157163
end
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+
)
172197
end
173198

174-
function linkinds(bpc::AbstractBeliefPropagationCache, pe::PartitionEdge)
199+
function linkinds(bpc::AbstractBeliefPropagationCache, pe::QuotientEdge)
175200
return linkinds(partitioned_tensornetwork(bpc), pe)
176201
end
177202

@@ -195,62 +220,64 @@ function update_factor(bpc, vertex, factor)
195220
return bpc
196221
end
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)
201226
end
202227
function messages(bpc::AbstractBeliefPropagationCache, edges; kwargs...)
203228
return map(edge -> message(bpc, edge; kwargs...), edges)
204229
end
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
212237
end
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
217242
end
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)
222247
end
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)
226251
end
227252
function 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
235261
end
236-
function delete_message!(bpc::AbstractBeliefPropagationCache, pe::PartitionEdge)
262+
function delete_message!(bpc::AbstractBeliefPropagationCache, pe::QuotientEdge)
237263
return delete_messages!(bpc, [pe])
238264
end
239265
function 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)
244271
end
245-
function delete_message(bpc::AbstractBeliefPropagationCache, pe::PartitionEdge)
272+
function delete_message(bpc::AbstractBeliefPropagationCache, pe::QuotientEdge)
246273
return delete_messages(bpc, [pe])
247274
end
248275

249276
function 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(
263290
end
264291

265292
function 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

278305
function 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)
285312
end
286313

287314
function 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))
291318
end
@@ -318,7 +345,7 @@ mts relevant to that group.
318345
function 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
357384
end
358385

359386
function 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])
363390
end
364391

365392
function rescale_messages(bp_cache::AbstractBeliefPropagationCache)
366-
return rescale_messages(bp_cache, partitionedges(bp_cache))
393+
return rescale_messages(bp_cache, quotientedges(bp_cache))
367394
end
368395

369396
function rescale_partitions(

0 commit comments

Comments
 (0)