Skip to content

Commit 29d78fa

Browse files
authored
Rename TensorNetwork to ITensorNetwork and adopt the v0.10 next-generation stack (#125)
## Summary Renames the `TensorNetwork` type to `ITensorNetwork`, along with `AbstractTensorNetwork` and the `TensorNetworkGenerators` submodule, to match the package name and the naming used across the next-generation stack. Moves the package onto the v0.10 next-generation stack: ITensorBase v0.7, TensorAlgebra v0.10, and GradedArrays v0.10. Factorization call sites move to the namespaces where ITensorBase defines its named-tensor methods (MatrixAlgebraKit for `qr_compact` and `svd_trunc`, `TensorAlgebra.MatrixAlgebra` for the Gram factorizations), and the named-axis helpers follow ITensorBase's v0.7 renames. This is a breaking release (`0.7.0`).
1 parent dd886af commit 29d78fa

20 files changed

Lines changed: 159 additions & 150 deletions

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ITensorNetworksNext"
22
uuid = "302f2e75-49f0-4526-aef7-d8ba550cb06c"
3-
version = "0.6.1"
3+
version = "0.7.0"
44
authors = ["ITensor developers <support@itensor.org> and contributors"]
55

66
[workspace]
@@ -30,13 +30,13 @@ Combinatorics = "1"
3030
DataGraphs = "0.4"
3131
Dictionaries = "0.4.5"
3232
Graphs = "1.13.1"
33-
ITensorBase = "0.6.3"
33+
ITensorBase = "0.7"
3434
LinearAlgebra = "1.10"
3535
MacroTools = "0.5.16"
3636
MatrixAlgebraKit = "0.6"
3737
NamedGraphs = "0.11"
3838
Random = "1.10"
3939
SimpleTraits = "0.9.5"
4040
SplitApplyCombine = "1.2.3"
41-
TensorAlgebra = "0.9.7"
41+
TensorAlgebra = "0.10"
4242
julia = "1.10"

docs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ path = ".."
1010
[compat]
1111
Documenter = "1"
1212
ITensorFormatter = "0.2.27"
13-
ITensorNetworksNext = "0.6"
13+
ITensorNetworksNext = "0.7"
1414
Literate = "2"

docs/src/reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Reference
22

33
```@autodocs
4-
Modules = [ITensorNetworksNext, ITensorNetworksNext.TensorNetworkGenerators]
4+
Modules = [ITensorNetworksNext, ITensorNetworksNext.ITensorNetworkGenerators]
55
```

examples/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ ITensorNetworksNext = "302f2e75-49f0-4526-aef7-d8ba550cb06c"
55
path = ".."
66

77
[compat]
8-
ITensorNetworksNext = "0.6"
8+
ITensorNetworksNext = "0.7"

src/TensorNetworkGenerators/TensorNetworkGenerators.jl renamed to src/ITensorNetworkGenerators/ITensorNetworkGenerators.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module TensorNetworkGenerators
1+
module ITensorNetworkGenerators
22

33
export delta_network, ising_network
44

src/TensorNetworkGenerators/delta_network.jl renamed to src/ITensorNetworkGenerators/delta_network.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using ..ITensorNetworksNext: TensorNetwork
1+
using ..ITensorNetworksNext: ITensorNetwork
22
using Graphs: AbstractGraph
3-
using ITensorBase: NamedUnitRange, denamed, name, nameddims
3+
using ITensorBase: NamedUnitRange, name, nameddims, unnamed
44
using NamedGraphs.GraphsExtensions: incident_edges
55

66
diaglength(a::AbstractArray) = minimum(size(a))
@@ -29,20 +29,20 @@ function diagonaltensor(
2929
diag::AbstractVector,
3030
is::Tuple{NamedUnitRange, Vararg{NamedUnitRange}}
3131
)
32-
return nameddims(diagonaltensor(diag, denamed.(is)), name.(is))
32+
return nameddims(diagonaltensor(diag, unnamed.(is)), name.(is))
3333
end
3434

35-
delta(elt::Type, is) = diagonaltensor(ones(elt, minimum(length denamed, is)), is)
35+
delta(elt::Type, is) = diagonaltensor(ones(elt, minimum(length, is)), is)
3636

3737
"""
3838
delta_network(f, elt::Type = Float64, g::AbstractGraph)
3939
40-
Construct a TensorNetwork on the graph `g` with element type `elt` that has delta tensors
40+
Construct a ITensorNetwork on the graph `g` with element type `elt` that has delta tensors
4141
on each vertex. Link dimensions are defined using the function `f(e)` that should take an
4242
edge `e` as an input and should output the link index on that edge.
4343
"""
4444
function delta_network(f, elt::Type, g::AbstractGraph)
45-
return tn = TensorNetwork(g) do v
45+
return tn = ITensorNetwork(g) do v
4646
is = Tuple(f.(incident_edges(g, v)))
4747
return delta(elt, is)
4848
end

src/TensorNetworkGenerators/ising_network.jl renamed to src/ITensorNetworkGenerators/ising_network.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ end
1818
"""
1919
ising_network(f, β::Number, g::AbstractGraph)
2020
21-
Construct a TensorNetwork on the graph `g` with inverse temperature `β` that has Ising
21+
Construct a ITensorNetwork on the graph `g` with inverse temperature `β` that has Ising
2222
partition function tensors on each vertex. Link dimensions are defined using the function
2323
`f(e)` that should take an edge `e` as an input and should output the link index on that
2424
edge.

src/ITensorNetworksNext.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ include("select_algorithm.jl")
1212
include("AlgorithmsInterfaceExtensions/AlgorithmsInterfaceExtensions.jl")
1313
include("abstracttensornetwork.jl")
1414
include("tensornetwork.jl")
15-
include("TensorNetworkGenerators/TensorNetworkGenerators.jl")
15+
include("ITensorNetworkGenerators/ITensorNetworkGenerators.jl")
1616
include("contract_network.jl")
1717

1818
include("beliefpropagation/messagecache.jl")

src/abstracttensornetwork.jl

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ using NamedGraphs.GraphsExtensions: directed_graph, incident_edges, rem_edges!,
1111
using NamedGraphs.OrdinalIndexing: OrdinalSuffixedInteger
1212
using NamedGraphs: NamedGraphs, NamedGraph, not_implemented, similar_graph
1313

14-
abstract type AbstractTensorNetwork{V, VD} <: AbstractDataGraph{V, VD, Nothing} end
14+
abstract type AbstractITensorNetwork{V, VD} <: AbstractDataGraph{V, VD, Nothing} end
1515

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

1919
# Graphs.jl overloads
20-
function Graphs.weights(graph::AbstractTensorNetwork)
20+
function Graphs.weights(graph::AbstractITensorNetwork)
2121
V = vertextype(graph)
2222
es = Tuple.(edges(graph))
2323
ws = Dictionary{Tuple{V, V}, Float64}(es, undef)
@@ -29,28 +29,28 @@ function Graphs.weights(graph::AbstractTensorNetwork)
2929
end
3030

3131
# Copy
32-
Base.copy(::AbstractTensorNetwork) = not_implemented()
32+
Base.copy(::AbstractITensorNetwork) = not_implemented()
3333

3434
# Iteration
35-
Base.iterate(tn::AbstractTensorNetwork, args...) = iterate(vertex_data(tn), args...)
36-
Base.keys(tn::AbstractTensorNetwork) = vertices(tn)
35+
Base.iterate(tn::AbstractITensorNetwork, args...) = iterate(vertex_data(tn), args...)
36+
Base.keys(tn::AbstractITensorNetwork) = vertices(tn)
3737

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

4242
# Overload if needed
43-
Graphs.is_directed(::Type{<:AbstractTensorNetwork}) = false
43+
Graphs.is_directed(::Type{<:AbstractITensorNetwork}) = false
4444

45-
DataGraphs.underlying_graph(::AbstractTensorNetwork) = not_implemented()
46-
function NamedGraphs.vertex_positions(tn::AbstractTensorNetwork)
45+
DataGraphs.underlying_graph(::AbstractITensorNetwork) = not_implemented()
46+
function NamedGraphs.vertex_positions(tn::AbstractITensorNetwork)
4747
return NamedGraphs.vertex_positions(underlying_graph(tn))
4848
end
49-
function NamedGraphs.ordered_vertices(tn::AbstractTensorNetwork)
49+
function NamedGraphs.ordered_vertices(tn::AbstractITensorNetwork)
5050
return NamedGraphs.ordered_vertices(underlying_graph(tn))
5151
end
5252

53-
function Adapt.adapt_structure(to, tn::AbstractTensorNetwork)
53+
function Adapt.adapt_structure(to, tn::AbstractITensorNetwork)
5454
# TODO: Define and use:
5555
#
5656
# @preserve_graph map_vertex_data(adapt(to), tn)
@@ -135,14 +135,14 @@ macro preserve_graph(expr)
135135
return :(setindex_preserve_graph!($(esc(array)), $(esc(value)), $(esc.(indices)...)))
136136
end
137137

138-
# Update the graph of the TensorNetwork `tn` to include
138+
# Update the graph of the ITensorNetwork `tn` to include
139139
# edges that should exist based on the tensor connectivity.
140140
function add_missing_edges!(tn::AbstractGraph)
141141
foreach(v -> add_missing_edges!(tn, v), vertices(tn))
142142
return tn
143143
end
144144

145-
# Update the graph of the TensorNetwork `tn` to include
145+
# Update the graph of the ITensorNetwork `tn` to include
146146
# edges that should be incident to the vertex `v`
147147
# based on the tensor connectivity.
148148
function add_missing_edges!(tn::AbstractGraph, v)
@@ -157,13 +157,13 @@ function add_missing_edges!(tn::AbstractGraph, v)
157157
return tn
158158
end
159159

160-
# Fix the edges of the TensorNetwork `tn` to match
160+
# Fix the edges of the ITensorNetwork `tn` to match
161161
# the tensor connectivity.
162162
function fix_edges!(tn::AbstractGraph)
163163
foreach(v -> fix_edges!(tn, v), vertices(tn))
164164
return tn
165165
end
166-
# Fix the edges of the TensorNetwork `tn` to match
166+
# Fix the edges of the ITensorNetwork `tn` to match
167167
# the tensor connectivity at vertex `v`.
168168
function fix_edges!(tn::AbstractGraph, v)
169169
for e in incident_edges(tn, v)
@@ -176,12 +176,12 @@ function fix_edges!(tn::AbstractGraph, v)
176176
return tn
177177
end
178178

179-
using ITensorBase: denamedtype, named, nametype, uniquename
179+
using ITensorBase: named, nametype, uniquename, unnamedtype
180180
using TensorAlgebra: trivialrange
181181
function insertlink!(tn, e)
182182
add_edge!(tn, e)
183183
T = eltype(inds(tn[src(e)]))
184-
l = named(trivialrange(denamedtype(T)), uniquename(nametype(T)))
184+
l = named(trivialrange(unnamedtype(T)), uniquename(nametype(T)))
185185
x = fill!(similar(tn[src(e)], (l,)), one(eltype(tn[src(e)])))
186186
@preserve_graph tn[src(e)] = tn[src(e)] * x
187187
@preserve_graph tn[dst(e)] = tn[dst(e)] * conj(x)
@@ -202,28 +202,32 @@ function randlinknames(tn)
202202
return new_tn
203203
end
204204

205-
function Base.setindex!(tn::AbstractTensorNetwork, value, v)
205+
function Base.setindex!(tn::AbstractITensorNetwork, value, v)
206206
@preserve_graph tn[v] = value
207207
fix_edges!(tn, v)
208208
return tn
209209
end
210210
# Fix ambiguity error.
211-
function Base.setindex!(graph::AbstractTensorNetwork, value, vertex::OrdinalSuffixedInteger)
211+
function Base.setindex!(
212+
graph::AbstractITensorNetwork,
213+
value,
214+
vertex::OrdinalSuffixedInteger
215+
)
212216
graph[vertices(graph)[vertex]] = value
213217
return graph
214218
end
215-
Base.setindex!(tn::AbstractTensorNetwork, value, edge::AbstractEdge) = not_implemented()
216-
Base.setindex!(tn::AbstractTensorNetwork, value, edge::Pair) = not_implemented()
219+
Base.setindex!(tn::AbstractITensorNetwork, value, edge::AbstractEdge) = not_implemented()
220+
Base.setindex!(tn::AbstractITensorNetwork, value, edge::Pair) = not_implemented()
217221
# Fix ambiguity error.
218222
function Base.setindex!(
219-
tn::AbstractTensorNetwork,
223+
tn::AbstractITensorNetwork,
220224
value,
221225
edge::Pair{<:OrdinalSuffixedInteger, <:OrdinalSuffixedInteger}
222226
)
223227
return not_implemented()
224228
end
225229

226-
function Base.show(io::IO, mime::MIME"text/plain", graph::AbstractTensorNetwork)
230+
function Base.show(io::IO, mime::MIME"text/plain", graph::AbstractITensorNetwork)
227231
println(io, "$(typeof(graph)) with $(nv(graph)) vertices:")
228232
show(io, mime, vertices(graph))
229233
println(io, "\n")
@@ -238,4 +242,4 @@ function Base.show(io::IO, mime::MIME"text/plain", graph::AbstractTensorNetwork)
238242
return nothing
239243
end
240244

241-
Base.show(io::IO, graph::AbstractTensorNetwork) = show(io, MIME"text/plain"(), graph)
245+
Base.show(io::IO, graph::AbstractITensorNetwork) = show(io, MIME"text/plain"(), graph)

src/apply/apply_operators.jl

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ using Graphs: dst, src, vertices
55
using ITensorBase:
66
ITensorBase as ITB, AbstractITensor, dimnames, domainnames, operator, replacedimnames
77
using LinearAlgebra: norm
8+
using MatrixAlgebraKit: qr_compact, svd_trunc
89
using NamedGraphs.GraphsExtensions: all_edges, boundary_edges
9-
using TensorAlgebra: TensorAlgebra as TA, gram_eigh_full, gram_eigh_full_with_pinv
10+
using TensorAlgebra.MatrixAlgebra: gram_eigh_full, gram_eigh_full_with_pinv
1011

1112
# === Top-level user entry point ===
1213

@@ -15,7 +16,7 @@ using TensorAlgebra: TensorAlgebra as TA, gram_eigh_full, gram_eigh_full_with_pi
1516
1617
Apply each operator in `operators` (a sequence of single-tensor or two-tensor
1718
operators) to `state` in turn, updating `env` to reflect each application.
18-
`state` is an `AbstractTensorNetwork`, `env` is a per-edge environment cache
19+
`state` is an `AbstractITensorNetwork`, `env` is a per-edge environment cache
1920
(typically built by `identity_norm_message_env(state)` or one of the related
2021
`*_norm_message_env` constructors), and the returned `(state, env)` pair has
2122
the operators applied. `kwargs` are forwarded to the per-operator algorithm
@@ -205,8 +206,8 @@ end
205206
# === BP simple-update implementation ===
206207

207208
function apply_gate_bp!(
208-
dest::AbstractTensorNetwork, op::AbstractITensor,
209-
state::AbstractTensorNetwork, env; kwargs...
209+
dest::AbstractITensorNetwork, op::AbstractITensor,
210+
state::AbstractITensorNetwork, env; kwargs...
210211
)
211212
op_in = domainnames(op)
212213
vs = [v for v in vertices(state) if !isempty(intersect(op_in, sitenames(state, v)))]
@@ -217,15 +218,15 @@ function apply_gate_bp!(
217218
end
218219

219220
function apply_gate_bp_nsite!(
220-
::Val{N}, dest::AbstractTensorNetwork, op::AbstractITensor,
221-
state::AbstractTensorNetwork, env, vs; kwargs...
221+
::Val{N}, dest::AbstractITensorNetwork, op::AbstractITensor,
222+
state::AbstractITensorNetwork, env, vs; kwargs...
222223
) where {N}
223224
return throw(ArgumentError("$N-site gate decomposition not implemented"))
224225
end
225226

226227
function apply_gate_bp_nsite!(
227-
::Val{1}, dest::AbstractTensorNetwork, op::AbstractITensor,
228-
state::AbstractTensorNetwork, env, vs;
228+
::Val{1}, dest::AbstractITensorNetwork, op::AbstractITensor,
229+
state::AbstractITensorNetwork, env, vs;
229230
normalize, kwargs...
230231
)
231232
v = only(vs)
@@ -242,8 +243,8 @@ function apply_gate_bp_nsite!(
242243
end
243244

244245
function apply_gate_bp_nsite!(
245-
::Val{2}, dest::AbstractTensorNetwork, op::AbstractITensor,
246-
state::AbstractTensorNetwork, env, vs;
246+
::Val{2}, dest::AbstractITensorNetwork, op::AbstractITensor,
247+
state::AbstractITensorNetwork, env, vs;
247248
trunc, normalize
248249
)
249250
v1, v2 = vs
@@ -258,10 +259,10 @@ function apply_gate_bp_nsite!(
258259
ψ_v1 = prod([[state[v1]]; gauges_v1])
259260
ψ_v2 = prod([[state[v2]]; gauges_v2])
260261

261-
Q_v1, R_v1 = TA.qr(ψ_v1, setdiff(dimnames(ψ_v1), dimnames(ψ_v2), dimnames(op)))
262-
Q_v2, R_v2 = TA.qr(ψ_v2, setdiff(dimnames(ψ_v2), dimnames(ψ_v1), dimnames(op)))
262+
Q_v1, R_v1 = qr_compact(ψ_v1, setdiff(dimnames(ψ_v1), dimnames(ψ_v2), dimnames(op)))
263+
Q_v2, R_v2 = qr_compact(ψ_v2, setdiff(dimnames(ψ_v2), dimnames(ψ_v1), dimnames(op)))
263264
op_R_v1v2 = ITB.apply(op, R_v1 * R_v2)
264-
U_v1, S, U_v2 = TA.svd(op_R_v1v2, setdiff(dimnames(R_v1), dimnames(R_v2)); trunc)
265+
U_v1, S, U_v2 = svd_trunc(op_R_v1v2, setdiff(dimnames(R_v1), dimnames(R_v2)); trunc)
265266
if normalize
266267
S = S / norm(S)
267268
end

0 commit comments

Comments
 (0)