Skip to content

Commit e0dd1bb

Browse files
mtfishmanclaude
andcommitted
[BREAKING] Drop IndsNetwork/graph ITensorNetwork ctors and ttn/mps generic ctors
Remove the IndsNetwork-, AbstractNamedGraph-, and AbstractSimpleGraph-based ITensorNetwork constructor families (state/value, function-callback, undef, plain-graph variants), the broken-stub ITensorNetwork{V}(g::NamedGraph), and the generic ttn(args...)/mps(args...)/mps(f, ::Vector{<:Index})/ mps(::Vector{<:Index}) wrappers that delegated to them. Also remove visualize(::IndsNetwork). Internal callers that built `ITensorNetwork(::IndsNetwork)`-style placeholders now build `ITensorNetwork(tensors, graph::NamedGraph)` directly: bilinearform- network, the directsum branch in abstracttreetensornetwork, opsum_to_ttn, and ttn(::ITensor, ::IndsNetwork). set_ortho_region and the QR/SVD-decomposition ttn use TreeTensorNetwork(tn) instead of ttn(tn::ITensorNetwork). Bug fix: trivial_space was used in abstractindsnetwork.jl and abstractitensornetwork.jl without being imported from ITensorsExtensions — imports added. test/utils.jl: rename state_tensornetwork → tensornetworkstate, drop default_tensornetwork (callers use random_tensornetwork for structural setups), and switch tensornetworkstate / random_tensornetwork to construct via ITensorNetwork(tensors, graph) so graph edge order is preserved. Test files rewritten to use the new helpers and the surviving ctor surface; the exhaustive parameterised "Product state constructors" testset (which covered the deleted state-arg ctor surface) is dropped. Docs updated: itensor_networks.md and tree_tensor_networks.md show the canonical (tensors, graph) construction; deprecated_methods.md entries for the removed ctors are removed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent e1e7ed9 commit e0dd1bb

28 files changed

Lines changed: 258 additions & 510 deletions

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ITensorNetworks"
22
uuid = "2919e153-833c-4bdc-8836-1ea460a35fc7"
3-
version = "0.21.0"
3+
version = "0.22.0"
44
authors = ["Matthew Fishman <mfishman@flatironinstitute.org>, Joseph Tindall <jtindall@flatironinstitute.org> and contributors"]
55

66
[workspace]

docs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ path = ".."
1616
Documenter = "1.10"
1717
Graphs = "1"
1818
ITensorFormatter = "0.2.27"
19-
ITensorNetworks = "0.21"
19+
ITensorNetworks = "0.22"
2020
ITensors = "0.9"
2121
Literate = "2.20.1"
2222
NamedGraphs = "0.11"

docs/src/computing_properties.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
```@setup main
44
using Graphs: edges, vertices
5-
using ITensorNetworks: ITensorNetwork, expect, inner, loginner, normalize, siteinds, ttn
5+
using ITensorNetworks:
6+
ITensorNetwork, TreeTensorNetwork, expect, inner, loginner, normalize, siteinds
67
using ITensors: Index, random_itensor
78
using LinearAlgebra: norm
89
using NamedGraphs.GraphsExtensions: incident_edges
@@ -20,10 +21,10 @@ end
2021
2122
g = named_grid((4,))
2223
s = siteinds("S=1/2", g)
23-
phi = normalize(ttn(random_state(g, s; link_space = 2)))
24-
psi = normalize(ttn(random_state(g, s; link_space = 2)))
25-
x = normalize(ttn(random_state(g, s; link_space = 2)))
26-
y = normalize(ttn(random_state(g, s; link_space = 2)))
24+
phi = normalize(TreeTensorNetwork(random_state(g, s; link_space = 2)))
25+
psi = normalize(TreeTensorNetwork(random_state(g, s; link_space = 2)))
26+
x = normalize(TreeTensorNetwork(random_state(g, s; link_space = 2)))
27+
y = normalize(TreeTensorNetwork(random_state(g, s; link_space = 2)))
2728
v = first(vertices(psi))
2829
```
2930

docs/src/deprecated_methods.md

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,6 @@
22

33
Suggestions of methods which could be deleted.
44

5-
## ITensorNetwork Methods
6-
7-
#### ITensorNetwork Constructors
8-
9-
* From a named graph, forwards to construction from `IndsNetwork` (`itensornetwork.jl`):
10-
```julia
11-
ITensorNetwork{V}(g::NamedGraph)
12-
ITensorNetwork(eltype::Type, undef::UndefInitializer, graph::AbstractNamedGraph; kws...)
13-
ITensorNetwork(f, graph::AbstractNamedGraph; kwargs...)
14-
ITensorNetwork(graph::AbstractNamedGraph; kwargs...)
15-
```
16-
17-
* From a simple graph, forwards to construction from `IndsNetwork` (`itensornetwork.jl`):
18-
```julia
19-
ITensorNetwork(eltype::Type, undef::UndefInitializer, graph::AbstractSimpleGraph; kws...)
20-
ITensorNetwork(f, graph::AbstractSimpleGraph; kwargs...)
21-
ITensorNetwork(graph::AbstractSimpleGraph; kwargs...)
22-
```
23-
24-
* From a function over vertices or from a "value" (e.g. a string like `"Up"`,
25-
an `Op`, an array, or a per-vertex dict/array) that is converted to a callable and used
26-
to initialize each vertex tensor (`itensornetwork.jl`):
27-
```julia
28-
ITensorNetwork(value, is::IndsNetwork; kwargs...)
29-
ITensorNetwork(elt::Type, f, is::IndsNetwork; link_space = trivial_space(is), kws...)
30-
ITensorNetwork(itensor_constructor::Function, is::IndsNetwork; link_space = trivial_space(is), kwargs...)
31-
```
32-
33-
* Construct an `ITensorNetwork` from an `IndsNetwork`. Initializes ITensors with `undef` storage on each vertex
34-
of the `IndsNetwork` with the corresponding indices (`itensornetwork.jl`):
35-
```julia
36-
ITensorNetwork(eltype::Type, undef::UndefInitializer, is::IndsNetwork; kwargs...)
37-
ITensorNetwork(eltype::Type, is::IndsNetwork; kwargs...)
38-
ITensorNetwork(undef::UndefInitializer, is::IndsNetwork; kwargs...)
39-
ITensorNetwork(is::IndsNetwork; kwargs...)
40-
```
41-
425
## Global Operations on ITensorNetworks
436

447

docs/src/interface_methods.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ Recommended methods for building applications on top of ITensorNetworks.
66

77
These ITensorNetwork constructor interfaces are foundational to other constructors:
88

9-
* From dictionary-like objects, including other `ITensorNetwork` objects, or a `Dict`
10-
from vertices to `ITensor`. The `tensors` can be a collection of `ITensor`s in which case
11-
the vertex labels are auto-assigned to `eachindex(tensors)` and edges are inferred
12-
from shared indices between the `ITensor`s.
9+
* From a collection of `ITensor`s indexed by vertex (a `Dict`, `Dictionary`, or
10+
`Vector{ITensor}` with linear-index vertex labels). Edges are inferred from shared
11+
`Index` objects between the tensors.
1312
```julia
1413
# `keys(tensors)` are vertices, `values(tensors)` are tensors on those vertices
1514
ITensorNetwork(tensors)
1615
ITensorNetwork{V}(tensors)
1716
```
1817

19-
* From collections of vertices and tensors. E.g. a `Vector{Int}` and a `Vector{ITensor}`.
18+
* From a collection of `ITensor`s placed at the vertices of a given `NamedGraph`. No
19+
edge inference; the graph's edges are used as-is.
2020
```julia
21-
ITensorNetwork(vertices, tensors)
22-
ITensorNetwork{V}(vertices, tensors)
21+
ITensorNetwork(tensors, graph::NamedGraph)
22+
ITensorNetwork{V}(tensors, graph::NamedGraph)
2323
```
2424

2525

docs/src/itensor_networks.md

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,49 +11,44 @@ Key facts:
1111
- The underlying graph is a [`NamedGraph`](https://github.com/ITensor/NamedGraphs.jl), so
1212
vertices can be any hashable Julia value: integers, tuples, strings, etc.
1313
- Each vertex holds exactly one `ITensor`.
14-
- Edges and link indices are either inferred from shared `Index` objects (when constructing
15-
from a collection of `ITensor`s) or inserted automatically (when constructing from an
16-
`IndsNetwork`).
14+
- Edges are either inferred from shared `Index` objects (when constructing from a
15+
collection of `ITensor`s) or taken from a graph passed explicitly alongside the tensors.
1716

1817
## Construction
1918

20-
The most common entry point is an `IndsNetwork` — a graph whose vertices and edges carry
21-
`Index` objects. Generate site indices with the `siteinds` function which takes a site
22-
type string (such as "S=1/2" or "Electron") and a NamedGraph. The NamedGraph can be
23-
generated from functions such as `named_grid`, `named_comb_tree`, etc. from the NamedGraphs.jl
24-
`NamedGraphGenerators` module:
19+
When you already have `ITensor`s in hand, edges are inferred automatically from shared
20+
indices:
2521

2622
```@example main
2723
using Graphs: edges, ne, neighbors, nv, vertices
2824
using ITensorNetworks: ITensorNetwork, add, linkinds, siteinds
2925
using ITensors: Index, ITensor
3026
using NamedGraphs.NamedGraphGenerators: named_grid
3127
32-
# 3×3 square-lattice tensor network
33-
g = named_grid((3, 3))
34-
s = siteinds("S=1/2", g) # one spin-½ Index per vertex
35-
36-
# Zero-initialized, bond dimension 2
37-
ψ = ITensorNetwork(s; link_space = 2)
38-
39-
# Product state — every site in the |↑⟩ state
40-
ψ = ITensorNetwork("Up", s)
28+
i, j, k = Index(2, "i"), Index(2, "j"), Index(2, "k")
29+
A, B, C = ITensor(i, j), ITensor(j, k), ITensor(k)
4130
42-
# Staggered initialization with a vertex-dependent function
43-
ψ = ITensorNetwork(v -> isodd(sum(v)) ? "Up" : "Dn", s)
31+
tn = ITensorNetwork([A, B, C]) # integer vertices 1, 2, 3
32+
tn = ITensorNetwork(Dict("A" => A, "B" => B, "C" => C)) # named vertices via a Dict
4433
```
4534

46-
When you already have `ITensor`s in hand, edges are inferred automatically from shared
47-
indices:
35+
If you want to control edges directly — for example to build an empty network on a
36+
prescribed lattice and fill in tensors later — pass a `NamedGraph` along with a
37+
collection of `ITensor`s indexed by vertex:
4838

4939
```@example main
50-
i, j, k = Index(2, "i"), Index(2, "j"), Index(2, "k")
51-
A, B, C = ITensor(i, j), ITensor(j, k), ITensor(k)
40+
g = named_grid((3, 3))
41+
s = siteinds("S=1/2", g) # one spin-½ Index per vertex
5242
53-
tn = ITensorNetwork([A, B, C]) # integer vertices 1, 2, 3
54-
tn = ITensorNetwork(Dict("A" => A, "B" => B, "C" => C)) # named vertices via a Dict
43+
# Build site tensors on the 3×3 lattice with one (placeholder) site index each
44+
tensors = Dict(v => ITensor(s[v]...) for v in vertices(g))
45+
ψ = ITensorNetwork(tensors, g)
5546
```
5647

48+
Higher-level construction routines (random networks, product states, OpSum-derived
49+
TTNs, etc.) are provided by sibling functions like `ttn(opsum, sites)` and the test-only
50+
helpers in `test/utils.jl`.
51+
5752
```@docs; canonical=false
5853
ITensorNetworks.ITensorNetwork
5954
```

docs/src/solvers.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ variational sweep algorithm.
1717

1818
```@example main
1919
using Graphs: vertices
20-
using ITensorNetworks: ITensorNetwork, dmrg, dst, edges, normalize, siteinds, src, ttn
20+
using ITensorNetworks:
21+
ITensorNetwork, TreeTensorNetwork, dmrg, dst, edges, normalize, siteinds, src, ttn
2122
using ITensors: Index, OpSum, random_itensor
2223
using NamedGraphs.GraphsExtensions: incident_edges
2324
using NamedGraphs.NamedGraphGenerators: named_comb_tree
@@ -45,7 +46,7 @@ H = let h = OpSum()
4546
end
4647
4748
# Random initial state (normalise first!)
48-
psi0 = normalize(ttn(random_state(g, s; link_space = 2)))
49+
psi0 = normalize(TreeTensorNetwork(random_state(g, s; link_space = 2)))
4950
5051
# Run DMRG
5152
energy, psi = dmrg(H, psi0;

docs/src/tree_tensor_networks.md

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,49 @@ records which vertices currently form the orthogonality center of the network. A
1111
update this field as the gauge changes.
1212

1313
**MPS** (matrix product states) are the special case of a `TreeTensorNetwork` on a
14-
1D path graph. The [`mps`](@ref ITensorNetworks.mps) constructor enforces this topology
15-
and provides a convenient interface for 1D calculations.
14+
1D path graph.
1615

1716
## Construction
1817

19-
### From an `IndsNetwork` or graph
18+
### From an `OpSum` (Hamiltonian)
19+
20+
A common way to obtain a Hamiltonian-shaped TTN is to convert an `OpSum` over an
21+
`IndsNetwork` of site indices.
22+
23+
```@docs; canonical=false
24+
ITensorNetworks.ttn(::ITensors.Ops.OpSum, ::ITensorNetworks.IndsNetwork)
25+
```
26+
27+
### From an existing `ITensorNetwork`
28+
29+
The `TreeTensorNetwork` struct wraps an `ITensorNetwork` and records the current
30+
orthogonality region. Use the `TreeTensorNetwork` constructor to convert a plain
31+
`ITensorNetwork` with tree topology into a `TTN`, and `ITensorNetwork` to strip the
32+
gauge metadata when you need a plain network again.
2033

2134
```@example main
2235
using Graphs: vertices
23-
using ITensorNetworks: ITensorNetwork, TreeTensorNetwork, mps, ortho_region, orthogonalize,
36+
using ITensorNetworks: ITensorNetwork, TreeTensorNetwork, ortho_region, orthogonalize,
2437
siteinds, ttn
25-
using ITensors: ITensors
38+
using ITensors: ITensors, ITensor
2639
using LinearAlgebra: norm
40+
using NamedGraphs: NamedGraph
2741
using NamedGraphs.NamedGraphGenerators: named_comb_tree
2842
2943
# Comb-tree TTN (a popular tree topology for 2D-like systems)
3044
g = named_comb_tree((3, 2))
3145
sites = siteinds("S=1/2", g)
3246
33-
psi = ttn(sites) # zero-initialised
34-
psi = ttn(v -> "Up", sites) # product state
35-
36-
# 1D MPS
37-
s1d = siteinds("S=1/2", 6)
38-
mps_state = mps(v -> "Up", s1d) # product MPS
47+
# Build an `ITensorNetwork` from explicit per-vertex tensors and wrap as a TTN
48+
tensors = Dict(v => ITensor(sites[v]...) for v in vertices(g))
49+
itn = ITensorNetwork(tensors, NamedGraph(g))
50+
psi = TreeTensorNetwork(itn)
3951
```
4052

41-
```@docs; canonical=false
42-
ITensorNetworks.ttn
43-
ITensorNetworks.mps
44-
```
45-
46-
### The `TreeTensorNetwork` type and conversion
47-
48-
The `TreeTensorNetwork` struct wraps an `ITensorNetwork` and records the current
49-
orthogonality region. Use the `TreeTensorNetwork` constructor to convert a plain
50-
`ITensorNetwork` with tree topology into a `TTN`, and `ITensorNetwork` to strip the
51-
gauge metadata when you need a plain network again.
53+
To strip the gauge metadata back to a plain `ITensorNetwork`:
5254

5355
```@example main
54-
itn = ITensorNetwork(psi) # TTN → ITensorNetwork
55-
psi = TreeTensorNetwork(itn) # ITensorNetwork → TTN
56+
itn_again = ITensorNetwork(psi) # TTN → ITensorNetwork
5657
```
5758

5859
```@docs; canonical=false

examples/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ ITensorNetworks = "2919e153-833c-4bdc-8836-1ea460a35fc7"
55
path = ".."
66

77
[compat]
8-
ITensorNetworks = "0.21"
8+
ITensorNetworks = "0.22"

src/abstractindsnetwork.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using .ITensorsExtensions: ITensorsExtensions, promote_indtype
1+
using .ITensorsExtensions: ITensorsExtensions, promote_indtype, trivial_space
22
using DataGraphs: DataGraphs, AbstractDataGraph, DataGraph, IsUnderlyingGraph, edge_data,
33
get_edge_data, get_vertex_data, is_edge_assigned, is_vertex_assigned, map_data,
44
set_edge_data!, set_vertex_data!, underlying_graph_type, vertex_data

0 commit comments

Comments
 (0)