Skip to content

Commit ae7018a

Browse files
mtfishmanclaude
andcommitted
Move random_tensornetwork, random_ttn, random_mps, ModelHamiltonians to test/utils.jl
Pull non-basic constructors that are only used by tests out of `src/` and into a new `test/utils.jl` helper file. Each test that needs them does `include("utils.jl")` inside its gensym module. The file is intentionally named `utils.jl` so the `ITensorPkgSkeleton.runtests` runner does not auto-pick it up (the runner only globs `test_*.jl`). What moved: - `random_tensornetwork` (12 method specializations, including the `Distribution`- and `IsUnderlyingGraph`-based variants) — moved from `src/specialitensornetworks.jl` to `test/utils.jl`. - `random_ttn` and `random_mps` — moved from `src/treetensornetworks/treetensornetwork.jl` to `test/utils.jl`. These thin wrappers around `random_tensornetwork` had no real consumers in `src/` (only docstring examples) and a single test reference. - `ModelHamiltonians.tight_binding`, `heisenberg`, `ising`, plus the internal helpers `to_callable`, `nth_nearest_neighbors`, `next_nearest_neighbors` — moved from `src/lib/ModelHamiltonians/` to a `ModelHamiltonians` submodule in `test/utils.jl`. Test sites continue to call them as `ModelHamiltonians.ising(...)` etc. What was deleted outright: - `delta_network` (and the entire `src/specialitensornetworks.jl`) — the only consumer was `ModelNetworks.ising_network`, which itself had no consumers. - `ModelHamiltonians.hubbard` — no consumers. - `src/lib/ModelNetworks/` (`ising_network`, `ising_network_state`) — no consumers; the lone `using ITensorNetworks.ModelNetworks: ModelNetworks` in `test/test_belief_propagation.jl` was an unused import. - `random_ttn` / `random_mps` jldoctest examples in `src/normalize.jl`, `src/expect.jl`, `src/treetensornetworks/abstracttreetensornetwork.jl` (per the rule that doc examples should not depend on functions being removed). The `[`random_ttn`](@ref)` / `[`random_mps`](@ref)` references in `See also:` lists were dropped as well. `docs/src/computing_properties.md`, `tree_tensor_networks.md`, and `solvers.md` were updated to drop their `random_ttn` / `random_mps` calls; the `@autodocs` listing in `docs/src/reference.md` was trimmed to just `ITensorNetworks` (no longer pulling in the removed `ModelNetworks` / `ModelHamiltonians` submodules). A few imports that were previously available inside `ITensorNetworks` as a side effect of the deleted files' `using` clauses are now imported directly by the files that actually use them: - `ITensors: delta` — `src/formnetworks/bilinearformnetwork.jl`, `src/caches/abstractbeliefpropagationcache.jl` Bump to 0.19.0 (breaking, pre-1.0 minor bump) and update pinned `ITensorNetworks` compat in `test/`, `docs/`, and `examples/` Project.toml. Also add `SimpleTraits` to `test/Project.toml` so `test/utils.jl` can use the `@traitfn` macro. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 31bb354 commit ae7018a

33 files changed

Lines changed: 256 additions & 495 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.18.1"
3+
version = "0.19.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.18"
19+
ITensorNetworks = "0.19"
2020
ITensors = "0.9"
2121
Literate = "2.20.1"
2222
NamedGraphs = "0.8.2"

docs/src/computing_properties.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@
22

33
```@setup main
44
using Graphs: vertices
5-
using ITensorNetworks: expect, inner, loginner, normalize, random_ttn, siteinds
5+
using ITensorNetworks: ITensorNetwork, expect, inner, loginner, normalize, siteinds, ttn
6+
using ITensors: itensor
7+
using ITensors.NDTensors: dim
68
using LinearAlgebra: norm
79
using NamedGraphs.NamedGraphGenerators: named_grid
810
11+
random_state(s) = ITensorNetwork(s; link_space = 2) do v
12+
return inds -> itensor(randn(Float64, dim.(inds)...), inds)
13+
end
14+
915
g = named_grid((4,))
1016
s = siteinds("S=1/2", g)
11-
phi = normalize(random_ttn(s; link_space = 2))
12-
psi = normalize(random_ttn(s; link_space = 2))
13-
x = normalize(random_ttn(s; link_space = 2))
14-
y = normalize(random_ttn(s; link_space = 2))
17+
phi = normalize(ttn(random_state(s)))
18+
psi = normalize(ttn(random_state(s)))
19+
x = normalize(ttn(random_state(s)))
20+
y = normalize(ttn(random_state(s)))
1521
v = first(vertices(psi))
1622
```
1723

docs/src/reference.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# API Reference
22

3-
Complete listing of all documented public functions and types in ITensorNetworks.jl,
4-
ITensorNetworks.ModelNetworks, and ITensorNetworks.ModelHamiltonians.
3+
Complete listing of all documented public functions and types in ITensorNetworks.jl.
54

65
```@autodocs
7-
Modules = [ITensorNetworks, ITensorNetworks.ModelNetworks, ITensorNetworks.ModelHamiltonians]
6+
Modules = [ITensorNetworks]
87
```

docs/src/solvers.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ variational sweep algorithm.
1616
[`dmrg`](@ref ITensorNetworks.dmrg) is an alias for `eigsolve`.
1717

1818
```@example main
19-
using ITensorNetworks: dmrg, dst, edges, normalize, random_ttn, siteinds, src, ttn
20-
using ITensors: OpSum
19+
using ITensorNetworks: ITensorNetwork, dmrg, dst, edges, normalize, siteinds, src, ttn
20+
using ITensors: OpSum, itensor
21+
using ITensors.NDTensors: dim
2122
using NamedGraphs.NamedGraphGenerators: named_comb_tree
2223
24+
random_state(s) = ITensorNetwork(s; link_space = 2) do v
25+
return inds -> itensor(randn(Float64, dim.(inds)...), inds)
26+
end
27+
2328
# Build a Heisenberg Hamiltonian on a comb tree
2429
g = named_comb_tree((3, 2))
2530
s = siteinds("S=1/2", g)
@@ -33,7 +38,7 @@ H = let h = OpSum()
3338
end
3439
3540
# Random initial state (normalise first!)
36-
psi0 = normalize(random_ttn(s; link_space = 2))
41+
psi0 = normalize(ttn(random_state(s)))
3742
3843
# Run DMRG
3944
energy, psi = dmrg(H, psi0;

docs/src/tree_tensor_networks.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ and provides a convenient interface for 1D calculations.
2121
```@example main
2222
using Graphs: vertices
2323
using ITensorNetworks: ITensorNetwork, TreeTensorNetwork, mps, ortho_region, orthogonalize,
24-
random_mps, random_ttn, siteinds, ttn
24+
siteinds, ttn
2525
using ITensors: ITensors
2626
using LinearAlgebra: norm
2727
using NamedGraphs.NamedGraphGenerators: named_comb_tree
@@ -33,20 +33,14 @@ sites = siteinds("S=1/2", g)
3333
psi = ttn(sites) # zero-initialised
3434
psi = ttn(v -> "Up", sites) # product state
3535
36-
# Random TTN
37-
psi = random_ttn(sites; link_space = 2)
38-
3936
# 1D MPS
4037
s1d = siteinds("S=1/2", 6)
4138
mps_state = mps(v -> "Up", s1d) # product MPS
42-
mps_state = random_mps(s1d; link_space = 2)
4339
```
4440

4541
```@docs; canonical=false
4642
ITensorNetworks.ttn
4743
ITensorNetworks.mps
48-
ITensorNetworks.random_ttn
49-
ITensorNetworks.random_mps
5044
```
5145

5246
### The `TreeTensorNetwork` type and conversion

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.18"
8+
ITensorNetworks = "0.19"

src/ITensorNetworks.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ include("contraction_sequences.jl")
1414
include("tebd.jl")
1515
include("itensornetwork.jl")
1616
include("contract.jl")
17-
include("specialitensornetworks.jl")
1817
include("partitioneditensornetwork.jl")
1918
include("edge_sequences.jl")
2019
include("caches/abstractbeliefpropagationcache.jl")
@@ -63,7 +62,5 @@ include("normalize.jl")
6362
include("expect.jl")
6463
include("environment.jl")
6564
include("exports.jl")
66-
include("lib/ModelHamiltonians/src/ModelHamiltonians.jl")
67-
include("lib/ModelNetworks/src/ModelNetworks.jl")
6865

6966
end

src/caches/abstractbeliefpropagationcache.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Adapt: Adapt, adapt, adapt_structure
22
using Graphs: Graphs, IsDirected
3-
using ITensors: dir
3+
using ITensors: delta, dir
44
using LinearAlgebra: diag, dot
55
using NDTensors: NDTensors
66
using NamedGraphs.PartitionedGraphs: PartitionedGraph, PartitionedGraphs, QuotientVertex,

src/expect.jl

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,23 +97,6 @@ vertex of `ψ`.
9797
9898
A `Dictionary` mapping each vertex of `ψ` to its expectation value.
9999
100-
# Example
101-
102-
```jldoctest
103-
julia> using NamedGraphs.NamedGraphGenerators: named_grid
104-
105-
julia> g = named_grid((4,));
106-
107-
julia> s = siteinds("S=1/2", g);
108-
109-
julia> psi = random_ttn(s; link_space = 2);
110-
111-
julia> sz = expect(psi, "Sz");
112-
113-
julia> sz_exact = expect(psi, "Sz"; alg = "exact");
114-
115-
```
116-
117100
See also: [`expect(ψ, op::String, vertices)`](@ref),
118101
[`expect(operator, state::AbstractTreeTensorNetwork)`](@ref).
119102
"""

0 commit comments

Comments
 (0)