Skip to content

Commit 7c98d32

Browse files
authored
More general ITensorNetwork constructors
2 parents 414d008 + 66a035d commit 7c98d32

17 files changed

+493
-216
lines changed

Project.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ITensorNetworks"
22
uuid = "2919e153-833c-4bdc-8836-1ea460a35fc7"
33
authors = ["Matthew Fishman <[email protected]> and contributors"]
4-
version = "0.2.1"
4+
version = "0.2.2"
55

66
[deps]
77
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
@@ -19,12 +19,12 @@ Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
1919

2020
[compat]
2121
Compat = "3, 4"
22-
DataGraphs = "0.1.1"
22+
DataGraphs = "0.1.7"
2323
Dictionaries = "0.3.15"
2424
DocStringExtensions = "0.8, 0.9"
2525
Graphs = "1.6"
26-
ITensors = "0.3"
27-
NamedGraphs = "0.1.3"
26+
ITensors = "0.3.23"
27+
NamedGraphs = "0.1.8"
2828
Requires = "1.3"
2929
SimpleTraits = "0.9"
3030
SplitApplyCombine = "1.2"

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ and 3 edge(s):
3636
3 => 4
3737

3838
with vertex data:
39-
4-element Dictionaries.Dictionary{Int64, Any}
39+
4-element Dictionary{Int64, Any}
4040
1 │ ((dim=2|id=739|"1↔2"),)
4141
2 │ ((dim=2|id=739|"1↔2"), (dim=2|id=920|"2↔3"))
4242
3 │ ((dim=2|id=920|"2↔3"), (dim=2|id=761|"3↔4"))
@@ -88,7 +88,7 @@ and 4 edge(s):
8888
(1, 2) => (2, 2)
8989

9090
with vertex data:
91-
4-element Dictionaries.Dictionary{Tuple{Int64, Int64}, Any}
91+
4-element Dictionary{Tuple{Int64, Int64}, Any}
9292
(1, 1) │ ((dim=2|id=74|"1×1↔2×1"), (dim=2|id=723|"1×1↔1×2"))
9393
(2, 1) │ ((dim=2|id=74|"1×1↔2×1"), (dim=2|id=823|"2×1↔2×2"))
9494
(1, 2) │ ((dim=2|id=723|"1×1↔1×2"), (dim=2|id=712|"1×2↔2×2"))
@@ -118,7 +118,7 @@ and 1 edge(s):
118118
(1, 1) => (1, 2)
119119

120120
with vertex data:
121-
2-element Dictionaries.Dictionary{Tuple{Int64, Int64}, Any}
121+
2-element Dictionary{Tuple{Int64, Int64}, Any}
122122
(1, 1) │ ((dim=2|id=74|"1×1↔2×1"), (dim=2|id=723|"1×1↔1×2"))
123123
(1, 2) │ ((dim=2|id=723|"1×1↔1×2"), (dim=2|id=712|"1×2↔2×2"))
124124

@@ -132,7 +132,7 @@ and 1 edge(s):
132132
(2, 1) => (2, 2)
133133

134134
with vertex data:
135-
2-element Dictionaries.Dictionary{Tuple{Int64, Int64}, Any}
135+
2-element Dictionary{Tuple{Int64, Int64}, Any}
136136
(2, 1) │ ((dim=2|id=74|"1×1↔2×1"), (dim=2|id=823|"2×1↔2×2"))
137137
(2, 2) │ ((dim=2|id=823|"2×1↔2×2"), (dim=2|id=712|"1×2↔2×2"))
138138
```
@@ -155,13 +155,13 @@ and 2 edge(s):
155155
2 => 3
156156

157157
with vertex data:
158-
3-element Dictionaries.Dictionary{Int64, Vector{Index}}
158+
3-element Dictionary{Int64, Vector{Index}}
159159
1 │ Index[(dim=2|id=598|"S=1/2,Site,n=1")]
160160
2 │ Index[(dim=2|id=457|"S=1/2,Site,n=2")]
161161
3 │ Index[(dim=2|id=683|"S=1/2,Site,n=3")]
162162

163163
and edge data:
164-
0-element Dictionaries.Dictionary{NamedGraphs.NamedEdge{Int64}, Vector{Index}}
164+
0-element Dictionary{NamedEdge{Int64}, Vector{Index}}
165165

166166
julia> tn1 = ITensorNetwork(s; link_space=2)
167167
ITensorNetwork{Int64} with 3 vertices:
@@ -175,7 +175,7 @@ and 2 edge(s):
175175
2 => 3
176176

177177
with vertex data:
178-
3-element Dictionaries.Dictionary{Int64, Any}
178+
3-element Dictionary{Int64, Any}
179179
1 │ ((dim=2|id=598|"S=1/2,Site,n=1"), (dim=2|id=123|"1↔2"))
180180
2 │ ((dim=2|id=457|"S=1/2,Site,n=2"), (dim=2|id=123|"1↔2"), (dim=2|id=656|"2↔3…
181181
3 │ ((dim=2|id=683|"S=1/2,Site,n=3"), (dim=2|id=656|"23"))
@@ -192,7 +192,7 @@ and 2 edge(s):
192192
2 => 3
193193
194194
with vertex data:
195-
3-element Dictionaries.Dictionary{Int64, Any}
195+
3-element Dictionary{Int64, Any}
196196
1 │ ((dim=2|id=598|"S=1/2,Site,n=1"), (dim=2|id=382|"12"))
197197
2 │ ((dim=2|id=457|"S=1/2,Site,n=2"), (dim=2|id=382|"12"), (dim=2|id=190|"23
198198
3 │ ((dim=2|id=683|"S=1/2,Site,n=3"), (dim=2|id=190|"2↔3"))
@@ -312,5 +312,9 @@ This file was generated with [weave.jl](https://github.com/JunoLab/Weave.jl) wit
312312
313313
```julia
314314
using ITensorNetworks, Weave
315-
weave(joinpath(pkgdir(ITensorNetworks), "examples", "README.jl"); doctype="github", out_path=pkgdir(ITensorNetworks))
315+
weave(
316+
joinpath(pkgdir(ITensorNetworks), "examples", "README.jl");
317+
doctype="github",
318+
out_path=pkgdir(ITensorNetworks),
319+
)
316320
```

examples/belief_propagation/bpexample.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ using ITensorNetworks
66
using ITensorNetworks: construct_initial_mts, update_all_mts, get_single_site_expec
77

88
n = 4
9-
dims = (n, n)
10-
g = named_grid(dims)
11-
# g = named_comb_tree(dims)
9+
system_dims = (n, n)
10+
g = named_grid(system_dims)
11+
# g = named_comb_tree(system_dims)
1212
s = siteinds("S=1/2", g)
1313
chi = 2
1414

@@ -19,7 +19,7 @@ combiners = linkinds_combiners(ψψ)
1919
ψψ = combine_linkinds(ψψ, combiners)
2020

2121
# Apply Sz to site v
22-
v = one.(dims)
22+
v = one.(system_dims)
2323
= copy(ψ)
2424
Oψ[v] = apply(op("Sz", s[v]), ψ[v])
2525
ψOψ = inner_network(ψ, Oψ; flatten=true, map_bra_linkinds=prime)

examples/contraction_sequence/contraction_sequence.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Random.seed!(1234)
77

88
ITensors.disable_warn_order()
99

10-
dims = (2, 3)
11-
g = named_grid(dims)
10+
system_dims = (2, 3)
11+
g = named_grid(system_dims)
1212
s = siteinds("S=1/2", g)
1313

1414
χ = 10
@@ -17,7 +17,7 @@ s = siteinds("S=1/2", g)
1717
tn = norm_sqr_network(ψ)
1818

1919
# Contraction sequence for exactly computing expectation values
20-
# contract_edges = map(t -> (1, t...), collect(keys(cartesian_to_linear(dims))))
20+
# contract_edges = map(t -> (1, t...), collect(keys(cartesian_to_linear(system_dims))))
2121
# inner_sequence = reduce((x, y) -> [x, y], contract_edges)
2222

2323
println("optimal")

examples/examples.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ using ITensorUnicodePlots
44
using NamedGraphs
55

66
χ, d = 5, 2
7-
dims = (4, 4)
8-
g = named_grid(dims)
7+
system_dims = (4, 4)
8+
g = named_grid(system_dims)
99

1010
# Network of indices
1111
is = IndsNetwork(g; link_space=χ, site_space=d)

examples/partition/partitioning.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ using ITensorUnicodePlots
55
using KaHyPar
66
using Suppressor
77

8-
dims = (4, 4)
9-
g = hypercubic_lattice_graph(dims)
8+
system_dims = (4, 4)
9+
g = hypercubic_lattice_graph(system_dims)
1010

1111
s = siteinds("S=1/2", g)
1212

examples/peps.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ function heisenberg(g::AbstractGraph)
1515
return os
1616
end
1717

18-
dims = (3, 3)
19-
g = named_grid(dims)
18+
system_dims = (3, 3)
19+
g = named_grid(system_dims)
2020
s = siteinds("S=1/2", g)
2121

2222
= heisenberg(g)

examples/peps/ising_tebd.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@ Random.seed!(1234)
88

99
ITensors.disable_warn_order()
1010

11-
dims = (6, 6)
12-
n = prod(dims)
13-
g = named_grid(dims)
11+
system_dims = (6, 6)
12+
n = prod(system_dims)
13+
g = named_grid(system_dims)
1414

1515
h = 2.0
1616

1717
@show h
18-
@show dims
18+
@show system_dims
1919

2020
s = siteinds("S=1/2", g)
2121

2222
#
2323
# DMRG comparison
2424
#
2525

26-
g_dmrg = rename_vertices(g, cartesian_to_linear(dims))
26+
g_dmrg = rename_vertices(g, cartesian_to_linear(system_dims))
2727
ℋ_dmrg = ising(g_dmrg; h)
2828
s_dmrg = [only(s[v]) for v in vertices(s)]
2929
H_dmrg = MPO(ℋ_dmrg, s_dmrg)
@@ -33,7 +33,7 @@ E_dmrg, ψ_dmrg = dmrg(
3333
H_dmrg, ψ_dmrg_init; nsweeps=20, maxdim=[fill(10, 10); 20], cutoff=1e-8
3434
)
3535
@show E_dmrg
36-
Z_dmrg = reshape(expect(ψ_dmrg, "Z"), dims)
36+
Z_dmrg = reshape(expect(ψ_dmrg, "Z"), system_dims)
3737

3838
display(Z_dmrg)
3939
display(heatmap(Z_dmrg))
@@ -59,7 +59,7 @@ println("maxdim = $χ")
5959
@show ortho
6060

6161
# Contraction sequence for exactly computing expectation values
62-
inner_sequence = reduce((x, y) -> [x, y], vec(Tuple.(CartesianIndices(dims))))
62+
inner_sequence = reduce((x, y) -> [x, y], vec(Tuple.(CartesianIndices(system_dims))))
6363

6464
println("\nFirst run TEBD without orthogonalization")
6565
ψ = @time tebd(
@@ -81,6 +81,6 @@ E = @time expect(ℋ, ψ; sequence=inner_sequence)
8181

8282
println("\nMeasure magnetization")
8383
Z_dict = @time expect("Z", ψ; sequence=inner_sequence)
84-
Z = [Z_dict[Tuple(I)] for I in CartesianIndices(dims)]
84+
Z = [Z_dict[Tuple(I)] for I in CartesianIndices(system_dims)]
8585
display(Z)
8686
display(heatmap(Z))

src/ITensorNetworks.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ using NamedGraphs:
2424
vertex_to_parent_vertex,
2525
parent_vertices_to_vertices,
2626
not_implemented
27-
using DataGraphs: edge_data_type, vertex_data_type
27+
using DataGraphs: IsUnderlyingGraph, edge_data_type, vertex_data_type
2828

2929
include("imports.jl")
3030

src/abstractitensornetwork.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ end
273273
# `Graphs.merge_vertices!` (https://github.com/mtfishman/ITensorNetworks.jl/issues/12)
274274
function contract(tn::AbstractITensorNetwork, edge::AbstractEdge; merged_vertex=dst(edge))
275275
V = promote_type(vertextype(tn), typeof(merged_vertex))
276-
tn = ITensorNetwork{V}(tn)
276+
# TODO: Check `ITensorNetwork{V}`, shouldn't need a copy here.
277+
tn = ITensorNetwork{V}(copy(tn))
277278
neighbors_src = setdiff(neighbors(tn, src(edge)), [dst(edge)])
278279
neighbors_dst = setdiff(neighbors(tn, dst(edge)), [src(edge)])
279280
new_itensor = tn[src(edge)] * tn[dst(edge)]
@@ -366,7 +367,9 @@ function factorize(
366367
)
367368
# Promote vertex type
368369
V = promote_type(vertextype(tn), typeof(X_vertex), typeof(Y_vertex))
369-
tn = ITensorNetwork{V}(tn)
370+
371+
# TODO: Check `ITensorNetwork{V}`, shouldn't need a copy here.
372+
tn = ITensorNetwork{V}(copy(tn))
370373

371374
neighbors_X = setdiff(neighbors(tn, src(edge)), [dst(edge)])
372375
left_inds = uniqueinds(tn, edge)
@@ -391,6 +394,14 @@ function factorize(
391394
return tn
392395
end
393396

397+
function factorize(
398+
tn::AbstractITensorNetwork,
399+
edge::Pair;
400+
kwargs...,
401+
)
402+
return factorize(tn, edgetype(tn)(edge); kwargs...)
403+
end
404+
394405
# For ambiguity error
395406
function _orthogonalize_edge(tn::AbstractITensorNetwork, edge::AbstractEdge; kwargs...)
396407
tn = factorize(tn, edge; kwargs...)

0 commit comments

Comments
 (0)