Skip to content

Move test-only helpers (random_tensornetwork, random_ttn, random_mps, ModelHamiltonians) out of src/#339

Merged
mtfishman merged 4 commits intomainfrom
mf/move-test-helpers
Apr 25, 2026
Merged

Move test-only helpers (random_tensornetwork, random_ttn, random_mps, ModelHamiltonians) out of src/#339
mtfishman merged 4 commits intomainfrom
mf/move-test-helpers

Conversation

@mtfishman
Copy link
Copy Markdown
Member

@mtfishman mtfishman commented Apr 25, 2026

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: deltasrc/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.

…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>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.50%. Comparing base (31bb354) to head (6b1ebef).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #339      +/-   ##
==========================================
+ Coverage   71.07%   72.50%   +1.43%     
==========================================
  Files          70       67       -3     
  Lines        3360     3179     -181     
==========================================
- Hits         2388     2305      -83     
+ Misses        972      874      -98     
Flag Coverage Δ
docs 46.24% <ø> (+2.22%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

mtfishman and others added 3 commits April 25, 2026 11:10
…ctor

Switch the `@setup` / `@example` blocks in `docs/src/computing_properties.md`
and `docs/src/solvers.md` from the function-callback `ITensorNetwork(s; link_space, kwargs...) do v ... end`
form to an explicit construction:

  1. build a `Dict{Edge, Index}` of link indices over `edges(g)` (mirrored
     under `reverse(e)`),
  2. build an `ITensor` for each vertex from the site index plus the link
     indices on that vertex's incident edges,
  3. wrap with the basic `ITensorNetwork(::Dict{V, ITensor})` constructor.

Mirrors the construction pattern used in the ITensorNetworksNext.jl tests
and avoids leaning on the `do v ... end` higher-level constructor that we
intend to phase out.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ctor

Replace the two base implementations of `random_tensornetwork` (the
`randn`-based one and the `Distribution`-based one) so they use the
explicit construction pattern instead of the higher-level
`ITensorNetwork(s; link_space, kwargs...) do v ... end` callback form.

The new private `_random_tensornetwork(s, build_tensor; link_space)`
helper:

  1. builds a `Dict{Edge, Index}` of fresh link indices over `edges(s)`
     (mirrored under `reverse(e)`),
  2. for each vertex, gathers the site indices from `vertex_data(s)[v]`
     (or empty if `v` has no entry — necessary for IndsNetworks built
     from a bare graph) plus the link indices on incident edges,
  3. lets the caller-supplied `build_tensor` produce the per-vertex
     `ITensor`,
  4. wraps with the basic `ITensorNetwork(::Dict{V, ITensor})`
     constructor.

This is the same pattern used in the docs setup blocks and in the
ITensorNetworksNext.jl tests, and it stops `random_tensornetwork` from
depending on the higher-level `ITensorNetwork(::IndsNetwork; link_space, kwargs...) do v ... end`
constructor we intend to remove. The 12 user-facing
`random_tensornetwork` method specializations and their `IsUnderlyingGraph`
trait wrappers are unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mtfishman mtfishman enabled auto-merge (squash) April 25, 2026 15:49
@mtfishman mtfishman merged commit 6e3c3b3 into main Apr 25, 2026
17 checks passed
@mtfishman mtfishman deleted the mf/move-test-helpers branch April 25, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant