Commit 6e3c3b3
Move test-only helpers (random_tensornetwork, random_ttn, random_mps, ModelHamiltonians) out of src/ (#339)
## Summary
Pull non-basic constructors that are only used by tests out of `src/`
and into a new `test/utils.jl`. 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 to `test/utils.jl`:**
- `random_tensornetwork` (12 method specializations, including the
`Distribution`- and `IsUnderlyingGraph`-based variants) — moved from
`src/specialitensornetworks.jl`.
- `random_ttn` and `random_mps` — moved from
`src/treetensornetworks/treetensornetwork.jl`. These thin wrappers
around `random_tensornetwork` had no real `src/` consumers (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/` into
a `ModelHamiltonians` submodule of `test/utils.jl`. Test sites continue
to call them as `ModelHamiltonians.ising(...)` etc.
**What was deleted entirely (no consumers):**
- `delta_network` (and the rest of `src/specialitensornetworks.jl`) —
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 and was
dropped.
- `random_ttn` / `random_mps` jldoctest examples in `src/normalize.jl`,
`src/expect.jl`, `src/treetensornetworks/abstracttreetensornetwork.jl`,
plus `[ref]` links in `See also:` lists. Consistent with not having doc
examples that depend on functions being removed.
**Construction pattern**
The `random_tensornetwork` helpers in `test/utils.jl` are factored
through a private `_random_tensornetwork(s::IndsNetwork, build_tensor;
link_space)` that uses the explicit Dict-of-ITensor pattern: build a
`Dict{Edge, Index}` of fresh link indices over `edges(s)` (mirrored
under `reverse(e)`); for each vertex, gather the site indices from
`vertex_data(s)[v]` (or empty if `v` has no entry) plus the link indices
on incident edges; let the caller-supplied `build_tensor` produce the
per-vertex `ITensor`; wrap with the basic `ITensorNetwork(::Dict{V,
ITensor})` constructor. The 12 user-facing `random_tensornetwork` method
specializations and their `IsUnderlyingGraph` trait wrappers route
through this helper.
**Documentation**
- `docs/src/{computing_properties,solvers}.md` setup blocks now build a
small inline `random_state(g, s; link_space)` helper using the same
Dict-of-ITensor pattern, instead of calling `random_ttn`. `link_space`
is required (no default), passed explicitly at the call sites.
- `docs/src/tree_tensor_networks.md` drops the `random_ttn` /
`random_mps` constructor examples and autodoc entries.
- `docs/src/reference.md`'s `@autodocs` listing trimmed to just
`ITensorNetworks` (no longer pulling in the removed `ModelNetworks` /
`ModelHamiltonians` submodules).
**Incidental import cleanups**
A few imports were previously available inside `ITensorNetworks` as a
side effect of the deleted files' `using` clauses; now imported
directly:
- `ITensors: delta` — `src/formnetworks/bilinearformnetwork.jl`,
`src/caches/abstractbeliefpropagationcache.jl`
**Version + test deps**
- Bump to `0.19.0` (pre-1.0 minor bump = breaking, public API removed).
- Update pinned `ITensorNetworks` compat in `test/`, `docs/`,
`examples/` Project.toml.
- Add `SimpleTraits` to `test/Project.toml` so `test/utils.jl` can use
`@traitfn` / `IsUnderlyingGraph`.
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 31bb354 commit 6e3c3b3
33 files changed
Lines changed: 291 additions & 496 deletions
File tree
- docs
- src
- examples
- src
- caches
- formnetworks
- lib
- ModelHamiltonians/src
- ModelNetworks/src
- treetensornetworks
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
6 | 7 | | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
9 | 21 | | |
10 | 22 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
15 | 27 | | |
16 | 28 | | |
17 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
| 3 | + | |
5 | 4 | | |
6 | 5 | | |
7 | | - | |
| 6 | + | |
8 | 7 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
23 | 35 | | |
24 | 36 | | |
25 | 37 | | |
| |||
33 | 45 | | |
34 | 46 | | |
35 | 47 | | |
36 | | - | |
| 48 | + | |
37 | 49 | | |
38 | 50 | | |
39 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | 36 | | |
40 | 37 | | |
41 | 38 | | |
42 | | - | |
43 | 39 | | |
44 | 40 | | |
45 | 41 | | |
46 | 42 | | |
47 | 43 | | |
48 | | - | |
49 | | - | |
50 | 44 | | |
51 | 45 | | |
52 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | 17 | | |
19 | 18 | | |
20 | 19 | | |
| |||
63 | 62 | | |
64 | 63 | | |
65 | 64 | | |
66 | | - | |
67 | | - | |
68 | 65 | | |
69 | 66 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | 100 | | |
118 | 101 | | |
119 | 102 | | |
| |||
0 commit comments