Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
b4ae4d7
Working BP Commit
JoeyT1994 Oct 2, 2025
d77d063
BP Code
JoeyT1994 Oct 23, 2025
b80e36e
Express BP in terms of `SweepIterator` interface
jack-dunham Oct 28, 2025
fe44b80
Add method for `setmessages!` that allows messages from one cache to …
jack-dunham Oct 31, 2025
3ce0898
Network is now passed to `forest_cover_edge_sequence` directly.
jack-dunham Nov 10, 2025
f6e4fd0
test file formatting
jack-dunham Nov 25, 2025
63840a9
Add `DataGraphsPartitionedGraphsExt` glue for `TensorNetwork` type
jack-dunham Nov 25, 2025
ba22ab5
Make abstract tensor network interface more generic.
jack-dunham Nov 25, 2025
49b0870
BP Caching overhauls
jack-dunham Nov 25, 2025
db46c04
Remove dead deps
jack-dunham Nov 25, 2025
400e373
Fix merge
jack-dunham Nov 25, 2025
b9aafe8
Fix type inference in TensorNetwork construction
jack-dunham Nov 25, 2025
4090e61
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 25, 2025
be0750e
Remove `ITensorBase` dep
jack-dunham Nov 25, 2025
b971b89
`forest_cover_edge_sequence` now constructs a temporary `NamedGraph` …
jack-dunham Dec 1, 2025
9ebf031
[LazyNamedDimsArrays] Fix `parenttype` method
jack-dunham Jan 6, 2026
16fe303
BP Cache now uses new `DataGraphs`interface
jack-dunham Jan 6, 2026
24a4335
Adjust `default_message` to take a `message` type as its first argument
jack-dunham Jan 6, 2026
c43884e
Remove unnecessary code and fix ambiguities in `AbstractTensorNetwork`
jack-dunham Jan 6, 2026
dd6f645
`TensorNetwork` type now uses new DataGraphs interface
jack-dunham Jan 6, 2026
7bb579c
Sweeping algorithms based on AlgorithmsInterface.jl (#30)
mtfishman Dec 19, 2025
032447a
Upgrade to NamedDimsArrays.jl v0.11 (#38)
mtfishman Dec 23, 2025
b256d79
[LazyNamedDimsArrays] New `symnameddims` method that pulls out indice…
jack-dunham Jan 9, 2026
b2da9d8
The function `region_scalar` should now return a scalar, rather than …
jack-dunham Jan 9, 2026
8506e26
Fix double counting in `edge_scalars` function
jack-dunham Jan 9, 2026
938180a
Minor code formatting
jack-dunham Jan 9, 2026
4461967
Expressed belief propagation in terms of AlgorithmsInterface
jack-dunham Jan 9, 2026
d68860a
Fixes to TensorNetwork construction from tensor list
jack-dunham Jan 9, 2026
2f5c783
Minor simplifications to `contract_network` interface.
jack-dunham Jan 9, 2026
9a45a5b
Merge branch 'main' into bp
jack-dunham Feb 13, 2026
4eec9b6
Upgrade DataGraphs and NamedGraphs dependencies
jack-dunham Feb 10, 2026
202724c
[AlgorithmsInterfaceExtensions] Allowing mapping over a generic itera…
jack-dunham Feb 10, 2026
69542e3
Upgrade serial BP to use own `<:Algorithm` structs.
jack-dunham Feb 11, 2026
9925069
Simplify BP cache to only store factors
jack-dunham Feb 13, 2026
292f2fa
Upgrade to DataGraphs v0.3.1 and NamedGraphs v0.10
jack-dunham Feb 13, 2026
9d937aa
Fix compat
jack-dunham Feb 13, 2026
5432fe2
Fix broken merge
jack-dunham Feb 13, 2026
c916c84
Bug fix; upgrade tests
jack-dunham Feb 19, 2026
4a511a1
Add 2D TN test
jack-dunham Feb 24, 2026
5b97af3
Formatting
jack-dunham Feb 24, 2026
fef588d
Merge branch 'main' into bp
jack-dunham Feb 24, 2026
62dae14
Merge branch 'bp' of https://github.com/jack-dunham/ITensorNetworksNe…
jack-dunham Mar 24, 2026
951cee6
Simplify BP code
jack-dunham Mar 12, 2026
1f1920c
Add spin ice test
jack-dunham Mar 13, 2026
5f3be98
Version Bump
jack-dunham Mar 13, 2026
487683a
Use `abs2` in message diff function.
jack-dunham Mar 13, 2026
aa24243
Add method for setting intitial messages; improve spin ice tests.
jack-dunham Mar 16, 2026
9248686
Remove redundant `default_message_diff_function` function.
jack-dunham Mar 16, 2026
9d7abea
Upgrade to DataGraphs and NamedGraphs to 0.4 and 0.11
jack-dunham Mar 24, 2026
66b58c0
Formatting
jack-dunham Apr 14, 2026
1cb4dad
Upgrade to simplified `similar_graph`
jack-dunham Apr 17, 2026
4b2f8c7
Remove edge arg in `similar_graph`.
jack-dunham Apr 20, 2026
3f6c112
Inline message computation into `solve!`; use type instead of alg str…
jack-dunham Apr 20, 2026
bd6a007
Add in `PartitionedGraphs` interface methods for `TensorNetwork` and …
jack-dunham Apr 20, 2026
52d8713
Test BP with differing precisions; remove `atol` test criteria.
jack-dunham Apr 21, 2026
bfc4bf4
Use `map` instead of comprehension when returning messages.
jack-dunham Apr 22, 2026
e6ad8de
Fix `nested_algorithm` methods on iterables.
jack-dunham Apr 22, 2026
3919499
Merge branch 'bp' of https://github.com/jack-dunham/ITensorNetworksNe…
jack-dunham Apr 22, 2026
395a3cc
Cleanup `AbstractBeliefPropagationCache` interface.
jack-dunham Apr 22, 2026
e530e5f
Remove `Graphs.connected_components` method for `TensorNetwork`
jack-dunham Apr 27, 2026
6a6fb90
Remove unecessary `symnameddims` method.
jack-dunham Apr 27, 2026
27691fb
Remove confusing code comment.
jack-dunham Apr 27, 2026
86e7021
Remove `beliefpropagation_sweep` in favour of constructor call.
jack-dunham Apr 27, 2026
867ec89
Fix message type initialization failing when only factors are provided.
jack-dunham Apr 28, 2026
8a67164
Formatting.
jack-dunham Apr 28, 2026
9aba7b5
Remove `edge_data_type` method for `AbstractTensorNetwork`
jack-dunham Apr 28, 2026
ecde4fa
Add some tests for `TensorNetwork` type.
jack-dunham Apr 28, 2026
01ec54e
Bug fixes; more tests
jack-dunham Apr 28, 2026
17260f2
Using `Inf` instead of `NaN` for delta initialization in `StopWhenCon…
jack-dunham Apr 28, 2026
1f889d5
Add some basic tests for `PartitionedGraphs` interactions with `Tenso…
jack-dunham Apr 28, 2026
35e6f14
Add tests via Claude.
jack-dunham Apr 29, 2026
2872016
Refine and redistribute generated tests
jack-dunham Apr 29, 2026
0dd5169
Further BP test improvements
jack-dunham Apr 29, 2026
d75c191
Fix incomplete `sitenames` and `siteaxes` definitions.
jack-dunham Apr 29, 2026
78d9088
Remove `default_message` and other fixes.
jack-dunham Apr 29, 2026
04be71a
Fix test imports
jack-dunham Apr 29, 2026
e31be99
Formatting.
jack-dunham Apr 29, 2026
a42bd86
Fix and test tensor network graph manipulation functions.
jack-dunham Apr 29, 2026
324b5f4
Simplify `factors` and `messages` methods on `AbstractGraph`
jack-dunham May 1, 2026
45af84e
Refactor `BeliefPropagationCache` -> `MessageCache`, remove abstract …
jack-dunham Apr 30, 2026
b20868b
Allow a custom stopping criteria input into `beliefpropagation` using…
jack-dunham May 1, 2026
9eba120
Hard code edge type in `MessageCache`.
jack-dunham May 1, 2026
e8c2fd0
Merge branch 'bp' of https://github.com/jack-dunham/ITensorNetworksNe…
jack-dunham May 1, 2026
e2ecb45
Remove `MessageCache` undef initializer.
jack-dunham May 1, 2026
4dae0fa
Rename argument names to be more consistent.
jack-dunham May 1, 2026
6ad8205
Simplify `MessageCache` interface.
jack-dunham May 4, 2026
d754cbf
Merge branch 'main' into tensornetwork
jack-dunham May 7, 2026
db44abb
`TensorNetwork` type refactor with inlined `link_indices`.
jack-dunham May 13, 2026
57614ff
Use `Vertex/EdgeDataGraph` as supertypes
jack-dunham May 20, 2026
b4dd74f
Merge branch 'main' into tensornetwork
jack-dunham Jun 2, 2026
93451d5
Update to DataGraphs v0.5.0
jack-dunham Jun 2, 2026
20dcb05
Add `NormNetwork` to lazily represent the norm of a tensor network
jack-dunham Jun 8, 2026
7c51b20
Upgrade to latest `NamedDimsArrays`
jack-dunham Jun 8, 2026
9acb6e7
Merge branch 'main' into jd/tensornetwork-refactor
jack-dunham Jun 22, 2026
50b3dc2
Add interface to `NormNetwork` for providing ones own index name map.
jack-dunham Jun 17, 2026
bb7b8dc
Rename `lazy_norm` to `normnetwork`.
jack-dunham Jun 17, 2026
8df78b4
Rename `index_locations` -> `dimname_vertices`.
jack-dunham Jun 22, 2026
7095002
Add `normnetworkview.jl`, begin updating tests.
jack-dunham Jun 22, 2026
0e5fa06
Upgrade `apply` code to use new data stuctures.
jack-dunham Jun 22, 2026
37a4c81
Merge branch 'main' into jd/tensornetwork-refactor
jack-dunham Jun 23, 2026
435796c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 23, 2026
0edd3bc
Rename `TensorNetwork` and co to `ITensorNetwork`.
jack-dunham Jun 23, 2026
bc4605b
Restore some `public` symbols
jack-dunham Jun 25, 2026
b6861a9
Rename local `ind` to `name` in `rem_vertex` function.
jack-dunham Jun 25, 2026
9a3d769
Rename `has_indname` to `has_dimname`.
jack-dunham Jun 25, 2026
9b4984d
Replace `indsites` with `dimnamevertices`, now takes name as argument.
jack-dunham Jun 25, 2026
7e0bc1e
Upgrade to new `ITensorBase` and `TensorAlgebra` versions.
jack-dunham Jun 25, 2026
7759e2c
Formatting
jack-dunham Jun 25, 2026
8313bf7
Merge branch 'main' into jd/tensornetwork-refactor
jack-dunham Jun 25, 2026
8d5a166
Version bump (breaking) to 0.8.0
jack-dunham Jun 25, 2026
7dddefa
Add tests for `normnetwork.jl` and `normnetworkview.jl`; fix some bugs.
jack-dunham Jun 25, 2026
9c1a8ca
Formatting.
jack-dunham Jun 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ITensorNetworksNext"
uuid = "302f2e75-49f0-4526-aef7-d8ba550cb06c"
version = "0.7.1"
version = "0.8.0"
authors = ["ITensor developers <support@itensor.org> and contributors"]

[workspace]
Expand All @@ -27,7 +27,7 @@ TensorAlgebra = "68bd88dc-f39d-4e12-b2ca-f046b68fcc6a"
Adapt = "4.3"
AlgorithmsInterface = "0.1"
Combinatorics = "1"
DataGraphs = "0.4"
DataGraphs = "0.5"
Dictionaries = "0.4.5"
Graphs = "1.13.1"
ITensorBase = "0.8"
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ path = ".."
[compat]
Documenter = "1"
ITensorFormatter = "0.2.27"
ITensorNetworksNext = "0.7"
ITensorNetworksNext = "0.8"
Literate = "2"
2 changes: 1 addition & 1 deletion examples/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ ITensorNetworksNext = "302f2e75-49f0-4526-aef7-d8ba550cb06c"
path = ".."

[compat]
ITensorNetworksNext = "0.7"
ITensorNetworksNext = "0.8"
7 changes: 4 additions & 3 deletions src/ITensorNetworkGenerators/delta_network.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using ..ITensorNetworksNext: ITensorNetwork
using Graphs: AbstractGraph
using ..ITensorNetworksNext: tensornetwork
using Graphs: AbstractGraph, vertices
using ITensorBase: NamedUnitRange, name, nameddims, unnamed
using NamedGraphs.GraphsExtensions: incident_edges

Expand Down Expand Up @@ -42,10 +42,11 @@ on each vertex. Link dimensions are defined using the function `f(e)` that shoul
edge `e` as an input and should output the link index on that edge.
"""
function delta_network(f, elt::Type, g::AbstractGraph)
return tn = ITensorNetwork(g) do v
tn = tensornetwork(vertices(g)) do v
is = Tuple(f.(incident_edges(g, v)))
return delta(elt, is)
end
return tn
end
function delta_network(f, g::AbstractGraph)
return delta_network(f, Float64, g)
Expand Down
17 changes: 10 additions & 7 deletions src/ITensorNetworkGenerators/ising_network.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ..ITensorNetworksNext: @preserve_graph
using ..ITensorNetworksNext
using Graphs: degree, dst, edges, src
using ITensorBase: apply, name, operator, uniquename
using LinearAlgebra: Diagonal, eigen
Expand Down Expand Up @@ -29,20 +29,23 @@ function ising_network(
)
elt = typeof(β)
l̃ = Dict(e => uniquename(f(e)) for e in edges(g))
f̃(e) = get(() -> l̃[reverse(e)], l̃, e)
tn = delta_network(f̃, elt, g)

fp(e) = get(() -> l̃[reverse(e)], l̃, e)
tn = delta_network(fp, elt, g)
for v in sz_vertices
tn[v] = diagonaltensor(elt[1, -1], axes(tn[v]))
end
for e in edges(tn)

for e in edges(g)
v1 = src(e)
v2 = dst(e)
deg1 = degree(tn, v1)

deg2 = degree(tn, v2)
m = sqrt_ising_bond(β; J, h, deg1, deg2)
t = operator(m, (name((e)),), (name(f(e)),))
@preserve_graph tn[v1] = apply(t, tn[v1])
@preserve_graph tn[v2] = apply(t, tn[v2])
t = operator(m, (name(fp(e)),), (name(f(e)),))
tn[v1] = apply(t, tn[v1])
tn[v2] = apply(t, tn[v2])
end
return tn
end
4 changes: 3 additions & 1 deletion src/ITensorNetworksNext.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module ITensorNetworksNext
if VERSION >= v"1.11.0-DEV.469"
eval(
Meta.parse(
"public apply_operator, apply_operators, beliefpropagation_normnetwork, identity_norm_message_env, normnetwork, norm_message_env, ones_norm_message_env, rand_norm_message_env, randn_norm_message_env, similar_norm_message_env"
Comment thread
jack-dunham marked this conversation as resolved.
"public apply_operator, apply_operators"
)
)
end
Expand All @@ -12,6 +12,8 @@ include("select_algorithm.jl")
include("AlgorithmsInterfaceExtensions/AlgorithmsInterfaceExtensions.jl")
include("abstracttensornetwork.jl")
include("tensornetwork.jl")
include("normnetwork.jl")
include("normnetworkview.jl")
include("ITensorNetworkGenerators/ITensorNetworkGenerators.jl")
include("contract_network.jl")

Expand Down
197 changes: 43 additions & 154 deletions src/abstracttensornetwork.jl
Original file line number Diff line number Diff line change
@@ -1,66 +1,54 @@
using Adapt: Adapt, adapt
using DataGraphs: DataGraphs, AbstractDataGraph, edge_data, set_vertex_data!,
underlying_graph, underlying_graph_type, vertex_data
using DataGraphs: DataGraphs, AbstractDataGraph, AbstractVertexDataGraph, edge_data,
set_vertex_data!, underlying_graph, underlying_graph_type, vertex_data
using Dictionaries: Dictionary
using Graphs: Graphs, AbstractEdge, AbstractGraph, add_edge!, add_vertex!, dst, edges,
edgetype, ne, neighbors, nv, rem_edge!, src, vertices
using ITensorBase: dimnames, inds
using ITensorBase: dimnames, inds, name, named, nametype, prime, uniquename, unnamedtype
using LinearAlgebra: LinearAlgebra
using MacroTools: @capture
using NamedGraphs.GraphsExtensions: directed_graph, incident_edges, rem_edges!, vertextype
using NamedGraphs.OrdinalIndexing: OrdinalSuffixedInteger
using NamedGraphs: NamedGraphs, NamedGraph, not_implemented, similar_graph
using TensorAlgebra: trivialrange

abstract type AbstractITensorNetwork{T, V} <: AbstractVertexDataGraph{T, V} end

abstract type AbstractITensorNetwork{V, VD} <: AbstractDataGraph{V, VD, Nothing} end
# ====================================== Graphs.jl ======================================= #

# Need to be careful about removing edges from tensor networks in case there is a bond
Graphs.rem_edge!(::AbstractITensorNetwork, edge) = not_implemented()
Graphs.rem_edge!(::AbstractITensorNetwork, _edge) = not_implemented()

# Graphs.jl overloads
function Graphs.weights(graph::AbstractITensorNetwork)
V = vertextype(graph)
es = Tuple.(edges(graph))
ws = Dictionary{Tuple{V, V}, Float64}(es, undef)
for e in edges(graph)
w = log2(dim(commoninds(graph, e)))
w = log2(dim(linkinds(graph, e)))
ws[(src(e), dst(e))] = w
end
return ws
end

# Copy
Base.copy(::AbstractITensorNetwork) = not_implemented()

# Iteration
Base.iterate(tn::AbstractITensorNetwork, args...) = iterate(vertex_data(tn), args...)
Base.keys(tn::AbstractITensorNetwork) = vertices(tn)

# TODO: This contrasts with the `DataGraphs.AbstractDataGraph` definition,
# where it is defined as the `vertextype`. Does that cause problems or should it be changed?
Base.eltype(tn::AbstractITensorNetwork) = eltype(vertex_data(tn))

# Overload if needed
Graphs.is_directed(::Type{<:AbstractITensorNetwork}) = false

DataGraphs.underlying_graph(::AbstractITensorNetwork) = not_implemented()
function NamedGraphs.vertex_positions(tn::AbstractITensorNetwork)
return NamedGraphs.vertex_positions(underlying_graph(tn))
end
function NamedGraphs.ordered_vertices(tn::AbstractITensorNetwork)
return NamedGraphs.ordered_vertices(underlying_graph(tn))
# ==================================== NamedGraphs.jl ==================================== #

function NamedGraphs.similar_graph(::AbstractITensorNetwork, VD::Type, vertices)
return ITensorNetwork{VD}(undef, collect(vertices))
end

function Adapt.adapt_structure(to, tn::AbstractITensorNetwork)
# TODO: Define and use:
#
# @preserve_graph map_vertex_data(adapt(to), tn)
#
# or just:
#
# @preserve_graph map(adapt(to), tn)
return map_vertex_data_preserve_graph(adapt(to), tn)
# ==================================== DataGraphs.jl ===================================== #

function DataGraphs.underlying_graph(tn::AbstractITensorNetwork)
ug = NamedGraph(vertices(tn))
add_edges!(ug, edges(tn))
return ug
end

# ====================================== interface ======================================= #

linkinds(tn::AbstractGraph, edge::Pair) = linkinds(tn, edgetype(tn)(edge))
# Pick the link indices from the `src` side, identified by name match with `dst`.
# A range-strict intersection (`inds(src) ∩ inds(dst)`) would drop graded links
Expand Down Expand Up @@ -106,139 +94,40 @@ function sitenames(tn::AbstractGraph, v)
return s
end

function setindex_preserve_graph!(tn::AbstractGraph, value, vertex)
set_vertex_data!(tn, value, vertex)
return tn
end
# Return the non-link vertices associated with an dim name
function dimnamevertices(tn::AbstractGraph, name)
sites = vertextype(tn)[]

function is_setindex!_expr(expr::Expr)
return is_assignment_expr(expr) && is_getindex_expr(first(expr.args))
end
is_setindex!_expr(x) = false
is_getindex_expr(expr::Expr) = (expr.head === :ref)
is_getindex_expr(x) = false
is_assignment_expr(expr::Expr) = (expr.head === :(=))
is_assignment_expr(expr) = false

# TODO: Define this in terms of a function mapping
# preserve_graph_function(::typeof(setindex!)) = setindex!_preserve_graph
# preserve_graph_function(::typeof(map_vertex_data)) = map_vertex_data_preserve_graph
# Also allow annotating codeblocks like `@views`.
macro preserve_graph(expr)
if !is_setindex!_expr(expr)
error(
"preserve_graph must be used with setindex! syntax (as @preserve_graph a[i,j,...] = value)"
)
for v in vertices(tn)
if name ∈ dimnames(tn[v])
push!(sites, v)
end
end
@capture(expr, array_[indices__] = value_)
return :(setindex_preserve_graph!($(esc(array)), $(esc(value)), $(esc.(indices)...)))
end

# Update the graph of the ITensorNetwork `tn` to include
# edges that should exist based on the tensor connectivity.
function add_missing_edges!(tn::AbstractGraph)
foreach(v -> add_missing_edges!(tn, v), vertices(tn))
return tn
return sites
end

# Update the graph of the ITensorNetwork `tn` to include
# edges that should be incident to the vertex `v`
# based on the tensor connectivity.
function add_missing_edges!(tn::AbstractGraph, v)
for v′ in vertices(tn)
if v ≠ v′
e = v => v′
if !isempty(linknames(tn, e))
add_edge!(tn, e)
end
function has_dimname(tn::AbstractGraph, name)
for v in vertices(tn)
if name ∈ dimnames(tn[v])
return true
end
end
return tn
return false
end

# Fix the edges of the ITensorNetwork `tn` to match
# the tensor connectivity.
function fix_edges!(tn::AbstractGraph)
foreach(v -> fix_edges!(tn, v), vertices(tn))
return tn
end
# Fix the edges of the ITensorNetwork `tn` to match
# the tensor connectivity at vertex `v`.
function fix_edges!(tn::AbstractGraph, v)
for e in incident_edges(tn, v)
# Remove an edge if there is no index on that edge.
if isempty(linknames(tn, e))
rem_edge!(tn, e)
end
end
add_missing_edges!(tn, v)
return tn
end
has_ind(tn::AbstractGraph, ind) = has_dimname(tn, name(ind))

using ITensorBase: named, nametype, uniquename, unnamedtype
using TensorAlgebra: trivialrange
function insertlink!(tn, e)
add_edge!(tn, e)
function insertlink!(tn::AbstractGraph, e)
T = eltype(inds(tn[src(e)]))
l = named(trivialrange(unnamedtype(T)), uniquename(nametype(T)))
x = fill!(similar(tn[src(e)], (l,)), one(eltype(tn[src(e)])))
@preserve_graph tn[src(e)] = tn[src(e)] * x
@preserve_graph tn[dst(e)] = tn[dst(e)] * conj(x)
return tn
end

using ITensorBase: replacedimnames
function randlinknames(tn)
new_tn = copy(tn)
for e in edges(new_tn)
u, v = src(e), dst(e)
for n in intersect(dimnames(new_tn[u]), dimnames(new_tn[v]))
n′ = uniquename(n)
new_tn[u] = replacedimnames(new_tn[u], n => n′)
new_tn[v] = replacedimnames(new_tn[v], n => n′)
end
end
return new_tn
end
linkind = named(trivialrange(unnamedtype(T)), uniquename(nametype(T)))

function Base.setindex!(tn::AbstractITensorNetwork, value, v)
@preserve_graph tn[v] = value
fix_edges!(tn, v)
return tn
end
# Fix ambiguity error.
function Base.setindex!(
graph::AbstractITensorNetwork,
value,
vertex::OrdinalSuffixedInteger
)
graph[vertices(graph)[vertex]] = value
return graph
end
Base.setindex!(tn::AbstractITensorNetwork, value, edge::AbstractEdge) = not_implemented()
Base.setindex!(tn::AbstractITensorNetwork, value, edge::Pair) = not_implemented()
# Fix ambiguity error.
function Base.setindex!(
tn::AbstractITensorNetwork,
value,
edge::Pair{<:OrdinalSuffixedInteger, <:OrdinalSuffixedInteger}
)
return not_implemented()
end
x = similar(tn[src(e)], (linkind,))
fill!(x, true)

function Base.show(io::IO, mime::MIME"text/plain", graph::AbstractITensorNetwork)
println(io, "$(typeof(graph)) with $(nv(graph)) vertices:")
show(io, mime, vertices(graph))
println(io, "\n")
println(io, "and $(ne(graph)) edge(s):")
for e in edges(graph)
show(io, mime, e)
println(io)
end
println(io)
println(io, "with vertex data:")
show(io, mime, axes.(vertex_data(graph)))
return nothing
end
tn[src(e)] *= x
tn[dst(e)] *= conj(x)

Base.show(io::IO, graph::AbstractITensorNetwork) = show(io, MIME"text/plain"(), graph)
return tn
end
8 changes: 6 additions & 2 deletions src/beliefpropagation/beliefpropagation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ using DataGraphs: edge_data
using Graphs: AbstractEdge, edges, edgetype, has_edge, vertices
using ITensorBase: AbstractITensor
using LinearAlgebra: norm, normalize
using NamedGraphs.GraphsExtensions: add_edges!, boundary_edges, subgraph
using NamedGraphs.GraphsExtensions:
add_edges!, boundary_edges, forest_cover_edge_sequence, subgraph
using NamedGraphs.PartitionedGraphs: quotientvertices

# === Top-level user entry point ===
Expand Down Expand Up @@ -65,7 +66,10 @@ an explicit `AlgorithmsInterface.StoppingCriterion`.
`message_update_algorithm` controls how a single message is recomputed
from its incoming neighbours.
"""
function beliefpropagation(
function beliefpropagation(factors, messages; kwargs...)
return _beliefpropagation(factors, messages; kwargs...)
end
function _beliefpropagation(
factors, messages;
edges = default_beliefpropagation_edges(factors),
stopping_criterion = nothing,
Expand Down
Loading
Loading