Skip to content

Commit 5ade5c6

Browse files
mtfishmanclaude
andauthored
Make ITensorMPS a weak dependency (#35)
## Summary - Move `ITensorMPS` from `[deps]` to `[weakdeps]` so users who don't need MPS-aware visualization don't pay the cost of loading `ITensorMPS`. - Add a package extension `ITensorVisualizationBaseITensorMPSExt` (the first extension in this package) that defines the two `MPS`-specialized `visualize` / `visualize!` methods. The extension loads only when `ITensorMPS` is present. - Bump version to 0.1.19. --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 0350598 commit 5ade5c6

5 files changed

Lines changed: 19 additions & 7 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
.benchmarkci
77
.tmp
88
.vscode/
9+
.worktrees/
910
LocalPreferences.toml
1011
Manifest*.toml
1112
benchmark/*.json

Project.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ITensorVisualizationBase"
22
uuid = "cd2553d2-8bef-4d93-8a38-c62f17d5ad23"
3-
version = "0.1.18"
3+
version = "0.1.19"
44
authors = ["Matthew Fishman <mfishman@flatironinstitute.org> and contributors"]
55

66
[workspace]
@@ -11,14 +11,19 @@ AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
1111
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
1212
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
1313
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
14-
ITensorMPS = "0d1a4710-d33b-49a5-8f18-73bdf49b47e2"
1514
ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5"
1615
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1716
MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5"
1817
NetworkLayout = "46757867-2c16-5918-afeb-47bfcb05e46a"
1918
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
2019
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
2120

21+
[weakdeps]
22+
ITensorMPS = "0d1a4710-d33b-49a5-8f18-73bdf49b47e2"
23+
24+
[extensions]
25+
ITensorVisualizationBaseITensorMPSExt = "ITensorMPS"
26+
2227
[compat]
2328
AbstractTrees = "0.4"
2429
Compat = "3.40, 4"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module ITensorVisualizationBaseITensorMPSExt
2+
3+
import ITensors.ITensorVisualizationCore: visualize, visualize!
4+
using ITensorMPS: MPS
5+
using ITensors: data
6+
7+
visualize::MPS, args...; kwargs...) = visualize(data(ψ), args...; kwargs...)
8+
visualize!(fig, ψ::MPS, sequence = nothing; kwargs...) = visualize!(fig, data(ψ); kwargs...)
9+
10+
end

src/ITensorVisualizationBase.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ using Graphs: Graphs, AbstractEdge, AbstractGraph, SimpleDiGraph, SimpleGraph, a
99
add_vertex!, all_neighbors, dst, edges, ne, neighbors, nv, src, vertices
1010
using ITensors
1111
using ITensors.ITensorVisualizationCore
12-
using ITensors: QNIndex, data
12+
using ITensors: QNIndex
1313
using LinearAlgebra
1414
using MetaGraphs
1515
using NetworkLayout

src/visualize.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using ITensorMPS: MPS
2-
31
#
42
# Contraction sequence
53
#
@@ -115,7 +113,6 @@ end
115113
function visualize(tn::Tuple{Vector{ITensor}}, args...; kwargs...)
116114
return visualize(only(tn), args...; kwargs...)
117115
end
118-
visualize::MPS, args...; kwargs...) = visualize(data(ψ), args...; kwargs...)
119116
function visualize(tn::Tuple{ITensor, Vararg{ITensor}}, args...; kwargs...)
120117
return visualize(collect(tn), args...; kwargs...)
121118
end
@@ -142,7 +139,6 @@ end
142139
function visualize!(fig, tn::Vector{ITensor}, sequence = nothing; kwargs...)
143140
return visualize!(fig, MetaDiGraph(tn); kwargs...)
144141
end
145-
visualize!(fig, ψ::MPS, sequence = nothing; kwargs...) = visualize!(fig, data(ψ); kwargs...)
146142
function visualize!(fig, tn::Tuple{Vararg{ITensor}}, sequence = nothing; kwargs...)
147143
return visualize!(fig, collect(tn); kwargs...)
148144
end

0 commit comments

Comments
 (0)