Skip to content

[BREAKING] Drop IndsNetwork/graph ITensorNetwork ctors and ttn/mps generic ctors#356

Merged
mtfishman merged 7 commits into
mainfrom
mf/drop-indsnetwork-ctors
May 9, 2026
Merged

[BREAKING] Drop IndsNetwork/graph ITensorNetwork ctors and ttn/mps generic ctors#356
mtfishman merged 7 commits into
mainfrom
mf/drop-indsnetwork-ctors

Conversation

@mtfishman
Copy link
Copy Markdown
Member

@mtfishman mtfishman commented May 7, 2026

Summary

Continues the post-#355 cleanup. Drops the rest of the higher-level
ITensorNetwork and ttn / mps constructor surface that wrapped the old
IndsNetwork-based code paths, plus the ttn(::OpSum, ::IndsNetwork) and
ttn(::ITensor, ::IndsNetwork) dispatches (canonical name is now
TreeTensorNetwork; mpo continues to dispatch through to it). Surviving
construction surface: ITensorNetwork(tensors),
ITensorNetwork(tensors, graph), and
TreeTensorNetwork(::OpSum / ::ITensor / ::ITensorNetwork, ...).

Adds factorize_edge! and Graphs.add_edge! on AbstractITensorNetwork.
Internal callers that built ITensorNetwork(::IndsNetwork) placeholders now
build ITensorNetwork(tensors, graph) directly. Folds in two bug fixes
(missing trivial_space import; _siteinds returning Tuple instead of
Vector{Index}).

test/utils.jl substantially simplified (~261 → ~75 effective lines):
surviving helpers are random_tensornetwork, productstate, and
ModelHamiltonians; Distributions dep dropped. Docs updated to the
canonical construction. Project.toml bumped 0.21 → 0.22.0-DEV (breaking;
accumulator pattern — a strip-suffix PR will release 0.22.0 once v0.22
cleanups are batched).

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

codecov Bot commented May 7, 2026

Codecov Report

❌ Patch coverage is 65.30612% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.14%. Comparing base (9a4c4a7) to head (c114cd3).

Files with missing lines Patch % Lines
src/abstractitensornetwork.jl 35.00% 13 Missing ⚠️
...rc/treetensornetworks/opsum_to_ttn/opsum_to_ttn.jl 50.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #356      +/-   ##
==========================================
- Coverage   74.65%   74.14%   -0.51%     
==========================================
  Files          63       63              
  Lines        3101     3036      -65     
==========================================
- Hits         2315     2251      -64     
+ Misses        786      785       -1     
Flag Coverage Δ
docs 48.25% <61.22%> (+0.01%) ⬆️

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 4 commits May 7, 2026 20:07
Follow-up to the IndsNetwork/graph ctor removal in the same branch.

Drop the `ttn` / `mps` short-name surface entirely (rather than narrowing it):
the surviving constructors keep the canonical `TreeTensorNetwork` name. This
covers `ttn(::OpSum, ::IndsNetwork)` (and its `eltype`-leading variant) and
`ttn(::ITensor, ::IndsNetwork)`. `mpo` continues to dispatch through to
`TreeTensorNetwork(::OpSum, ::IndsNetwork)`.

Docs: drop `ttn` / `mps` from `using ITensorNetworks` in `docs/make.jl` and
the `mps`-specific section from `tree_tensor_networks.md`; rewrite the
constructor examples in `itensor_networks.md` and `tree_tensor_networks.md`
to build link inds explicitly with `random_itensor` so they don't fall back
to `EmptyNumber` placeholders that fail the downstream `add` / `qr` /
`directsum` examples; rename `ttn` callsites to `TreeTensorNetwork` in
`solvers.md` and `experimental_methods.md`. Fixes the docs build failure
on PR #356.

`src/abstractitensornetwork.jl`: `_siteinds` now `collect`s the inds before
iterating, so the return type is a `Vector{Index}` rather than a `Tuple`.
The `IndsNetwork` `vertex_data` setter expects a vector, and the previous
behaviour produced a `Tuple` whenever a vertex's tensor had no shared
neighbour inds. Also rename `truncate(ttn) → truncate(tn)` in a docstring.

`test/utils.jl`: substantial simplification (~261 → ~75 effective lines).
Drop `random_mps`, `random_ttn`, `Op`-handling, the `generic_state` machinery,
and the `@traitfn` indirection. Surviving surface: `random_tensornetwork`
(graph or `IndsNetwork` input, eltype + distribution variants), `productstate`
(renamed from `tensornetworkstate`, since it only builds product states;
routed through `insert_linkinds` so the default `link_space` follows
`trivial_space` and stays QN-aware), and the `ModelHamiltonians` submodule.
Test callsites updated: `ttn(state, s) → TreeTensorNetwork(productstate(state, s))`,
`ttn(os, s) → TreeTensorNetwork(os, s)`, `ttn(A, is; cutoff) → TreeTensorNetwork(A, is; cutoff)`,
and `tensornetworkstate → productstate`.

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

Further simplification of `test/utils.jl`:

- Delete the `random_tensornetwork(rng, ::Distribution, ...)` overload (and the
  one-line testset that exercised it). It was the sole consumer of `Distributions`
  in this package, so drop the dep from `Project.toml` and `test/Project.toml`,
  and drop `using Distributions: Uniform` from `test_itensornetwork.jl`.

- Inline the `_build_tensornetwork` and `_graph_and_sites` helpers into a
  two-method `random_tensornetwork(rng, eltype, ::IndsNetwork; link_space)`
  core, with `random_tensornetwork(rng, eltype, ::AbstractGraph; ...)` thin
  delegating through `IndsNetwork(g)`. The closure-passing through a
  `tensor_at(v, site_inds, link_inds)` callback was the only thing the
  helpers gave us, and it's no longer needed once the distribution variant
  is gone.

- Make `productstate(elt::Type, state, ::IndsNetwork; ...)` the workhorse
  and have `productstate(state, ::IndsNetwork; ...) = productstate(Float64,
  state, ...)` instead of the previous direction (no-eltype builds Float64,
  eltype builds + post-converts). Same default behaviour, simpler chain.

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

Define `factorize_edge!(f, tn, edge)` and `Graphs.add_edge!(tn, edge)` (graph
edge + QR-threaded link) on AbstractITensorNetwork. Migrate the 7 existing
internal `add_edge!(tn, ...)` call sites to `add_edge!(data_graph(tn), ...)`
since they already share inds and want graph-only behavior.

Rewrite `productstate` in test/utils.jl: build a site-only TN from an edgeless
graph, then thread one link per edge. Use a local `_add_edge!` (onehot into
both endpoints with `trivial_space(tn)`) rather than the new QR-based
`add_edge!` so on-site QN flux stays on sites — the QR variant pushes flux
into links and BP's default_message returns empty BlockSparse for non-trivial
QN sectors.
… productstate

random_tensornetwork's core method now takes (rng, eltype, graph::AbstractGraph,
siteinds; link_space). The IndsNetwork variant extracts siteinds via a per-vertex
dict; the plain-graph variant supplies empty siteinds. Symmetrize the link
dictionary with merge(l, Dict(reverse(e) => l[e])) so incident_edges lookup
doesn't need a reverse-key fallback. Rename `sites_or_graph` to `sites` in the
default-RNG/eltype wrappers.

productstate drops the g_full/g_empty pair and iterates s's vertices and edges
directly.
Comment thread Project.toml Outdated
@mtfishman mtfishman merged commit a3509ff into main May 9, 2026
16 of 18 checks passed
@mtfishman mtfishman deleted the mf/drop-indsnetwork-ctors branch May 9, 2026 01:06
mtfishman added a commit that referenced this pull request May 11, 2026
- Drop the `_ITensorCollection` Union from the `ITensorNetwork` constructor
  signatures and the in-file comments referencing the long-removed
  function-callback ctor's dispatch loop (those constructors went away in
  #356). The `Vector{ITensor}` / `Dict{V, ITensor}` / `Dictionary{V, ITensor}`
  shapes still flow through the same body via duck-typed `keys` /
  `keytype` / `tensors[v]`.
- Use `LinearAlgebra.qr` directly inside `qr!` (instead of
  `factorize(...; ortho = "left")`), and reorder the residual contraction
  to `R * tn[dst(edge)]` so the expression reads left-to-right as
  "absorb the residual into the destination tensor". Drop the now-unused
  `factorize` import.
- Refresh the stale `gauge` entry in `docs/src/experimental_methods.md` —
  the `alg::Algorithm` positional and `kwargs...` were dropped from
  `gauge` earlier in this PR.
mtfishman added a commit that referenced this pull request May 12, 2026
## Summary

- Drops the two `mpo(::OpSum, ...)` overloads in
`src/treetensornetworks/opsum_to_ttn/opsum_to_ttn.jl`. Both were trivial
wrappers forwarding to `TreeTensorNetwork(os,
path_indsnetwork(external_inds))` and `TreeTensorNetwork(os, s)`. Zero
callers in `src/`, `test/`, Tennis.jl, ITensorNetworksNext.jl, or
TensorNetworkQuantumSimulator.jl. Continuation of
[#356](#356
direction of dropping short-name dispatches in favor of explicit
`TreeTensorNetwork(::OpSum, ...)` constructors.
- Drops `path_indsnetwork` (two overloads in `src/indsnetwork.jl`) —
only consumer was the deleted `mpo(::OpSum, ::Vector)` form, so it's
orphaned.
- Removes the matching doc blocks from
`docs/src/experimental_methods.md`.

No version bump — substantive change accumulates against the existing
`0.22.0-DEV` prerelease.
mtfishman added a commit that referenced this pull request May 13, 2026
## Summary

Doc-only cleanup: remove references in
`docs/src/experimental_methods.md` and `docs/src/developer_methods.md`
to methods that no longer exist in src/.

- **`visualize(is::IndsNetwork, args...; kwargs...)`** — removed from
`src/indsnetwork.jl` in
[#356](#356) along
with the `IndsNetwork`-based `ITensorNetwork` constructor family. The
doc entry was missed.
- **`data_graph_type`** — was an accessor for the
pre-[#365](#365)
`DataGraph`-based storage layout. After #365 inlined storage into
`NamedGraph + Dictionary` fields, no implementation remains in src/, but
the docs still listed it for `AbstractFormNetwork`,
`QuadraticFormNetwork`, `AbstractBeliefPropagationCache`, `AbstractTTN`
(as a prose label), and `TreeTensorNetwork`. Drop all of those entries.
- **`edge_data_eltype(::Type{<:AbstractIndsNetwork})`** — misnamed; the
actual function is `DataGraphs.edge_data_type`. Fix the name.
- **`setindex!(bpc, factor, vertex)`** — documented for both
`AbstractBeliefPropagationCache` and `BeliefPropagationCache`, but
neither type has a corresponding method in src/. Drop both entries.

No version bump — substantive change accumulates against the existing
`0.22.0-DEV` prerelease.
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