Skip to content

Commit b403745

Browse files
mtfishmanclaude
andauthored
[Backport] Move visualize overloads to package extension; bump to v0.21.2 (#369)
## Summary Backport of #367 onto the new `release-0.21` branch. Replaces the in-source `visualize(::AbstractITensorNetwork, ...)` method (in `src/abstractitensornetwork.jl`) and the two type-piracy methods on `AbstractNamedGraph` / `AbstractDataGraph` (in `src/visualize.jl`) with a single `ITensorNetworksITensorVisualizationBaseExt` package extension that overloads `visualize(::AbstractITensorNetwork, ...)` only. The type-piracy methods migrate upstream: - `NamedGraphs.jl` v0.11.1 ([#166](ITensor/NamedGraphs.jl#166)) adds the `AbstractNamedGraph` overload via its own `NamedGraphsITensorVisualizationBaseExt`. - `DataGraphs.jl` v0.4.1 ([#119](ITensor/DataGraphs.jl#119)) adds the `AbstractDataGraph` overload via `DataGraphsITensorVisualizationBaseExt`. ## Motivation for backporting Once NamedGraphs v0.11.1 and DataGraphs v0.4.1 register, any user on legacy ITensorNetworks v0.21.x alongside the new NamedGraphs/DataGraphs would hit method-overwrite warnings on the two type-pirated `visualize` methods. v0.22 may take a while to ship (its prerelease accumulator is still receiving changes), so we publish a v0.21.2 patch carrying the equivalent fix. ## Changes - Adds `ext/ITensorNetworksITensorVisualizationBaseExt/`. - Removes `src/visualize.jl` (and its `include` from `src/ITensorNetworks.jl`). - Removes the `visualize(::AbstractITensorNetwork, ...)` block from `src/abstractitensornetwork.jl`. - Adds `ITensorVisualizationBase` to `[weakdeps]` / `[extensions]` / `[compat]`. - Bumps `[compat]` floors: `NamedGraphs = "0.11.1"`, `DataGraphs = "0.4.1"`. - Bumps package version `0.21.1` → `0.21.2`. ## Release-branch workflow This is the first PR against the new `release-0.21` branch, modeled on Julia's `release-X.Y` convention (simplified — no `backports-release-X.Y` staging tier, since we expect only 1–2 backports before v0.22 ships). After merge, registration needs to be triggered manually via a `/register <merge-sha>` commit comment on the merge commit (the `Registrator.yml` workflow's `push` trigger only fires on `main`/`master` by default; the `issue_comment` path uses `force=true` and works regardless of branch). ## Status CI will be red until NamedGraphs v0.11.1 and DataGraphs v0.4.1 actually land in the registry. Opening the PR now mostly for tracking. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9a4c4a7 commit b403745

7 files changed

Lines changed: 44 additions & 52 deletions

File tree

Project.toml

Lines changed: 6 additions & 3 deletions
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.21.1"
3+
version = "0.21.2"
44
authors = ["Matthew Fishman <mfishman@flatironinstitute.org>, Joseph Tindall <jtindall@flatironinstitute.org> and contributors"]
55

66
[workspace]
@@ -38,10 +38,12 @@ TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
3838
TupleTools = "9d95972d-f1c8-5527-a6e0-b4b365fa01f6"
3939

4040
[weakdeps]
41+
ITensorVisualizationBase = "cd2553d2-8bef-4d93-8a38-c62f17d5ad23"
4142
OMEinsumContractionOrders = "6f22d1fd-8eed-4bb7-9776-e7d684900715"
4243
TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2"
4344

4445
[extensions]
46+
ITensorNetworksITensorVisualizationBaseExt = "ITensorVisualizationBase"
4547
ITensorNetworksOMEinsumContractionOrdersExt = "OMEinsumContractionOrders"
4648
ITensorNetworksTensorOperationsExt = "TensorOperations"
4749

@@ -52,18 +54,19 @@ Adapt = "4"
5254
Combinatorics = "1"
5355
Compat = "3, 4"
5456
ConstructionBase = "1.6"
55-
DataGraphs = "0.4"
57+
DataGraphs = "0.4.1"
5658
Dictionaries = "0.4"
5759
Distributions = "0.25.86"
5860
DocStringExtensions = "0.9"
5961
Graphs = "1.8"
62+
ITensorVisualizationBase = "0.1"
6063
ITensors = "0.7, 0.8, 0.9"
6164
IsApprox = "0.1, 1, 2"
6265
IterTools = "1.4"
6366
KrylovKit = "0.6, 0.7, 0.8, 0.9, 0.10"
6467
MacroTools = "0.5"
6568
NDTensors = "0.3, 0.4"
66-
NamedGraphs = "0.11"
69+
NamedGraphs = "0.11.1"
6770
OMEinsumContractionOrders = "0.8.3, 0.9, 1"
6871
SerializedElementArrays = "0.1"
6972
SimpleTraits = "0.9"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module ITensorNetworksITensorVisualizationBaseExt
2+
3+
using Graphs: vertices
4+
using ITensorNetworks: AbstractITensorNetwork
5+
using ITensorVisualizationBase: ITensorVisualizationBase
6+
7+
function ITensorVisualizationBase.visualize(
8+
tn::AbstractITensorNetwork,
9+
args...;
10+
vertex_labels_prefix = nothing,
11+
vertex_labels = nothing,
12+
kwargs...
13+
)
14+
if !isnothing(vertex_labels_prefix)
15+
vertex_labels = [vertex_labels_prefix * string(v) for v in vertices(tn)]
16+
end
17+
return ITensorVisualizationBase.visualize(
18+
[tn[v] for v in vertices(tn)], args...; vertex_labels, kwargs...
19+
)
20+
end
21+
22+
end

src/ITensorNetworks.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module ITensorNetworks
22

33
include("lib/BaseExtensions/src/BaseExtensions.jl")
44
include("lib/ITensorsExtensions/src/ITensorsExtensions.jl")
5-
include("visualize.jl")
65
include("abstractindsnetwork.jl")
76
include("indextags.jl")
87
include("indsnetwork.jl")

src/abstractitensornetwork.jl

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -791,24 +791,6 @@ end
791791

792792
Base.show(io::IO, graph::AbstractITensorNetwork) = show(io, MIME"text/plain"(), graph)
793793

794-
# TODO: Move to an `ITensorNetworksVisualizationInterfaceExt`
795-
# package extension (and define a `VisualizationInterface` package
796-
# based on `ITensorVisualizationCore`.).
797-
using ITensors.ITensorVisualizationCore: ITensorVisualizationCore, visualize
798-
function ITensorVisualizationCore.visualize(
799-
tn::AbstractITensorNetwork,
800-
args...;
801-
vertex_labels_prefix = nothing,
802-
vertex_labels = nothing,
803-
kwargs...
804-
)
805-
if !isnothing(vertex_labels_prefix)
806-
vertex_labels = [vertex_labels_prefix * string(v) for v in vertices(tn)]
807-
end
808-
# TODO: Use `tokenize_vertex`.
809-
return visualize([tn[v] for v in vertices(tn)], args...; vertex_labels, kwargs...)
810-
end
811-
812794
#
813795
# Link dimensions
814796
#

src/visualize.jl

Lines changed: 0 additions & 28 deletions
This file was deleted.

test/Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ GraphsFlows = "06909019-6f44-4949-96fc-b9d9aaa02889"
1212
ITensorMPS = "0d1a4710-d33b-49a5-8f18-73bdf49b47e2"
1313
ITensorNetworks = "2919e153-833c-4bdc-8836-1ea460a35fc7"
1414
ITensorPkgSkeleton = "3d388ab1-018a-49f4-ae50-18094d5f71ea"
15+
ITensorVisualizationBase = "cd2553d2-8bef-4d93-8a38-c62f17d5ad23"
1516
ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5"
1617
KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77"
1718
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -38,7 +39,7 @@ AbstractTrees = "0.4.5"
3839
Adapt = "4.3"
3940
Aqua = "0.8.11"
4041
Compat = "4.16"
41-
DataGraphs = "0.4"
42+
DataGraphs = "0.4.1"
4243
Dictionaries = "0.4.4"
4344
Distributions = "0.25.118"
4445
Glob = "1.3.1"
@@ -47,12 +48,13 @@ GraphsFlows = "0.1.1"
4748
ITensorMPS = "0.3.6, 0.4"
4849
ITensorNetworks = "0.21"
4950
ITensorPkgSkeleton = "0.3.42"
51+
ITensorVisualizationBase = "0.1"
5052
ITensors = "0.7, 0.8, 0.9"
5153
KrylovKit = "0.8, 0.9, 0.10"
5254
LinearAlgebra = "1.10"
5355
Metis = "1.5"
5456
NDTensors = "0.3, 0.4"
55-
NamedGraphs = "0.11"
57+
NamedGraphs = "0.11.1"
5658
OMEinsumContractionOrders = "0.9.5, 1"
5759
Pkg = "1.10"
5860
Random = "1.10"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using ITensorNetworks: AbstractITensorNetwork, ITensorNetwork
2+
using ITensorVisualizationBase: ITensorVisualizationBase
3+
using ITensors: ITensor, Index
4+
using Test: @test, @testset
5+
6+
@testset "ITensorNetworksITensorVisualizationBaseExt" begin
7+
i, j, k = Index(2, "i"), Index(2, "j"), Index(2, "k")
8+
tn = ITensorNetwork([ITensor(i, j), ITensor(j, k)])
9+
@test hasmethod(ITensorVisualizationBase.visualize, Tuple{AbstractITensorNetwork})
10+
@test isnothing(ITensorVisualizationBase.visualize(tn))
11+
@test isnothing(ITensorVisualizationBase.visualize(tn; vertex_labels_prefix = "v"))
12+
end

0 commit comments

Comments
 (0)