[BREAKING] Drop IndsNetwork/graph ITensorNetwork ctors and ttn/mps generic ctors#356
Merged
Conversation
…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 Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
mtfishman
commented
May 9, 2026
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Continues the post-#355 cleanup. Drops the rest of the higher-level
ITensorNetworkandttn/mpsconstructor surface that wrapped the oldIndsNetwork-based code paths, plus thettn(::OpSum, ::IndsNetwork)andttn(::ITensor, ::IndsNetwork)dispatches (canonical name is nowTreeTensorNetwork;mpocontinues to dispatch through to it). Survivingconstruction surface:
ITensorNetwork(tensors),ITensorNetwork(tensors, graph), andTreeTensorNetwork(::OpSum / ::ITensor / ::ITensorNetwork, ...).Adds
factorize_edge!andGraphs.add_edge!onAbstractITensorNetwork.Internal callers that built
ITensorNetwork(::IndsNetwork)placeholders nowbuild
ITensorNetwork(tensors, graph)directly. Folds in two bug fixes(missing
trivial_spaceimport;_siteindsreturningTupleinstead ofVector{Index}).test/utils.jlsubstantially simplified (~261 → ~75 effective lines):surviving helpers are
random_tensornetwork,productstate, andModelHamiltonians;Distributionsdep dropped. Docs updated to thecanonical construction.
Project.tomlbumped 0.21 → 0.22.0-DEV (breaking;accumulator pattern — a strip-suffix PR will release 0.22.0 once v0.22
cleanups are batched).