Skip to content

Commit eb5958f

Browse files
mtfishmanclaude
andauthored
Move visualize overloads to ITensorVisualizationBase extension (#367)
## Summary - Adds `ITensorNetworksITensorVisualizationBaseExt`, a new package extension keyed on `ITensorVisualizationBase`, holding the `visualize(::AbstractITensorNetwork, ...)` overload that previously lived in `src/abstractitensornetwork.jl`. - Drops `src/visualize.jl` entirely. The two methods it held (overloads of `visualize` on `AbstractNamedGraph` and `AbstractDataGraph`, which were type piracy from here) move upstream into the packages that own those types: see [ITensor/NamedGraphs.jl#166](ITensor/NamedGraphs.jl#166) and [ITensor/DataGraphs.jl#119](ITensor/DataGraphs.jl#119). - Bumps `[compat]` floors to `NamedGraphs = "0.11.1"` and `DataGraphs = "0.4.1"` to ensure the upstream extensions are present. - The extensions are keyed on the registered standalone `ITensorVisualizationBase` package. The methods overload `ITensorVisualizationBase.visualize`, which shares a binding with `ITensors.ITensorVisualizationCore.visualize` (the in-tree submodule), so rendering backends pick them up. Adds `test/test_itensorvisualizationbase_ext.jl` covering the new method. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 0990ac7 commit eb5958f

7 files changed

Lines changed: 43 additions & 51 deletions

File tree

Project.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,29 @@ StructWalk = "31cdf514-beb7-4750-89db-dda9d2eb8d3d"
2929
TupleTools = "9d95972d-f1c8-5527-a6e0-b4b365fa01f6"
3030

3131
[weakdeps]
32+
ITensorVisualizationBase = "cd2553d2-8bef-4d93-8a38-c62f17d5ad23"
3233
OMEinsumContractionOrders = "6f22d1fd-8eed-4bb7-9776-e7d684900715"
3334
TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2"
3435

3536
[extensions]
37+
ITensorNetworksITensorVisualizationBaseExt = "ITensorVisualizationBase"
3638
ITensorNetworksOMEinsumContractionOrdersExt = "OMEinsumContractionOrders"
3739
ITensorNetworksTensorOperationsExt = "TensorOperations"
3840

3941
[compat]
4042
Accessors = "0.1.42"
4143
Adapt = "4"
42-
DataGraphs = "0.4"
44+
DataGraphs = "0.4.1"
4345
Dictionaries = "0.4"
4446
DocStringExtensions = "0.9"
4547
Graphs = "1.8"
48+
ITensorVisualizationBase = "0.1"
4649
ITensors = "0.7, 0.8, 0.9"
4750
IsApprox = "0.1, 1, 2"
4851
KrylovKit = "0.6, 0.7, 0.8, 0.9, 0.10"
4952
MacroTools = "0.5"
5053
NDTensors = "0.3, 0.4"
51-
NamedGraphs = "0.11"
54+
NamedGraphs = "0.11.1"
5255
OMEinsumContractionOrders = "0.8.3, 0.9, 1"
5356
SimpleTraits = "0.9"
5457
SplitApplyCombine = "1.2"
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
@@ -1,6 +1,5 @@
11
module ITensorNetworks
22

3-
include("visualize.jl")
43
include("abstractindsnetwork.jl")
54
include("indextags.jl")
65
include("indsnetwork.jl")

src/abstractitensornetwork.jl

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

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

543-
# TODO: Move to an `ITensorNetworksVisualizationInterfaceExt`
544-
# package extension (and define a `VisualizationInterface` package
545-
# based on `ITensorVisualizationCore`.).
546-
using ITensors.ITensorVisualizationCore: ITensorVisualizationCore, visualize
547-
function ITensorVisualizationCore.visualize(
548-
tn::AbstractITensorNetwork,
549-
args...;
550-
vertex_labels_prefix = nothing,
551-
vertex_labels = nothing,
552-
kwargs...
553-
)
554-
if !isnothing(vertex_labels_prefix)
555-
vertex_labels = [vertex_labels_prefix * string(v) for v in vertices(tn)]
556-
end
557-
# TODO: Use `tokenize_vertex`.
558-
return visualize([tn[v] for v in vertices(tn)], args...; vertex_labels, kwargs...)
559-
end
560-
561543
#
562544
# Link dimensions
563545
#

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
@@ -10,6 +10,7 @@ GraphsFlows = "06909019-6f44-4949-96fc-b9d9aaa02889"
1010
ITensorMPS = "0d1a4710-d33b-49a5-8f18-73bdf49b47e2"
1111
ITensorNetworks = "2919e153-833c-4bdc-8836-1ea460a35fc7"
1212
ITensorPkgSkeleton = "3d388ab1-018a-49f4-ae50-18094d5f71ea"
13+
ITensorVisualizationBase = "cd2553d2-8bef-4d93-8a38-c62f17d5ad23"
1314
ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5"
1415
KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77"
1516
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -35,20 +36,21 @@ path = ".."
3536
Adapt = "4.3"
3637
Aqua = "0.8.11"
3738
Compat = "4.16"
38-
DataGraphs = "0.4"
39+
DataGraphs = "0.4.1"
3940
Dictionaries = "0.4.4"
4041
Glob = "1.3.1"
4142
Graphs = "1.12"
4243
GraphsFlows = "0.1.1"
4344
ITensorMPS = "0.3.6, 0.4"
4445
ITensorNetworks = "0.22"
4546
ITensorPkgSkeleton = "0.3.42"
47+
ITensorVisualizationBase = "0.1"
4648
ITensors = "0.7, 0.8, 0.9"
4749
KrylovKit = "0.8, 0.9, 0.10"
4850
LinearAlgebra = "1.10"
4951
Metis = "1.5"
5052
NDTensors = "0.3, 0.4"
51-
NamedGraphs = "0.11"
53+
NamedGraphs = "0.11.1"
5254
OMEinsumContractionOrders = "0.9.5, 1"
5355
Pkg = "1.10"
5456
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)