Skip to content

Commit 611db6c

Browse files
authored
Update for most recent versions of NamedGraphs and DataGraphs
2 parents 4a85e5e + 3e79bc8 commit 611db6c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1154
-903
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
shell: julia --project=dev {0}
4040
run: |
4141
using Pkg;
42-
pkg"dev https://github.com/mtfishman/DataGraphs.jl.git ."
42+
pkg"dev ."
4343
- name: Run the tests
4444
shell: julia --project=dev {0}
4545
run: |

Project.toml

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

66
[deps]
7+
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
78
DataGraphs = "b5a273c3-7e6c-41f6-98bd-8d7f1525a36a"
89
Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4"
910
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
1011
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
1112
ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5"
1213
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
13-
MultiDimDictionaries = "87ff4268-a46e-478f-b30a-76b83dd64e3c"
1414
NamedGraphs = "678767b0-92e7-4007-89e4-4527a8725b19"
1515
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
16+
SimpleTraits = "699a6c99-e7fa-54fc-8d76-47d257e15c1d"
1617
SplitApplyCombine = "03a91e81-4c3e-53e1-a0a4-9c0c8f19dd66"
1718
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
1819

1920
[compat]
21+
Compat = "3, 4"
22+
DataGraphs = "0.1.1"
2023
Dictionaries = "0.3.15"
21-
Graphs = "1.6.0"
24+
DocStringExtensions = "0.8, 0.9"
25+
Graphs = "1.6"
2226
ITensors = "0.3"
23-
MultiDimDictionaries = "0.0.1"
24-
NamedGraphs = "0.0.1"
25-
Requires = "1.3.0"
26-
Suppressor = "0.2.1"
27-
julia = "1.6"
27+
NamedGraphs = "0.1.3"
28+
Requires = "1.3"
29+
SimpleTraits = "0.9"
30+
SplitApplyCombine = "1.2"
31+
Suppressor = "0.2"
32+
julia = "1.7"
2833

2934
[extras]
3035
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

README.md

Lines changed: 119 additions & 125 deletions
Large diffs are not rendered by default.

examples/README.jl

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,25 @@
44

55
#' ## Installation
66
#'
7-
#' This package relies on a few unregistered packages. To install, you will need to do:
8-
#'
7+
#' You can install this package through the Julia package manager:
98
#' ```julia
10-
#' julia> using Pkg
11-
#'
12-
#' julia> Pkg.add(url="https://github.com/mtfishman/MultiDimDictionaries.jl")
13-
#'
14-
#' julia> Pkg.add(url="https://github.com/mtfishman/NamedGraphs.jl")
15-
#'
16-
#' julia> Pkg.add(url="https://github.com/mtfishman/DataGraphs.jl")
17-
#'
18-
#' julia> Pkg.add(url="https://github.com/mtfishman/ITensorNetworks.jl")
9+
#' julia> ] add ITensorNetworks
1910
#' ```
2011

12+
#+ echo=false; term=false
13+
14+
using Random
15+
using ITensors
16+
Random.seed!(ITensors.index_id_rng(), 1234);
17+
2118
#' ## Examples
2219
#'
2320
#' Here are is an example of making a tensor network on a chain graph (a tensor train or matrix product state):
2421
#+ term=true
2522

2623
using ITensors
2724
using ITensorNetworks
28-
tn = ITensorNetwork(named_grid((4,)); link_space=2)
25+
tn = ITensorNetwork(named_grid(4); link_space=2)
2926
tn[1]
3027
tn[2]
3128
neighbors(tn, 1)
@@ -38,16 +35,16 @@ neighbors(tn, 4)
3835

3936
tn = ITensorNetwork(named_grid((2, 2)); link_space=2)
4037
tn[1, 1]
41-
neighbors(tn, 1, 1)
42-
neighbors(tn, 1, 2)
43-
tn_1 = tn[1, :]
44-
tn_2 = tn[2, :]
38+
neighbors(tn, (1, 1))
39+
neighbors(tn, (1, 2))
40+
tn_1 = subgraph(v -> v[1] == 1, tn)
41+
tn_2 = subgraph(v -> v[1] == 2, tn)
4542

4643
#' Networks can also be merged/unioned:
4744
#+ term=true
4845

4946
using ITensorUnicodePlots
50-
s = siteinds("S=1/2", named_grid((3,)))
47+
s = siteinds("S=1/2", named_grid(3))
5148
tn1 = ITensorNetwork(s; link_space=2)
5249
tn2 = ITensorNetwork(s; link_space=2)
5350
@visualize tn1;
@@ -59,9 +56,9 @@ Z̃ = contract(Z, (1, 1) => (2, 1));
5956
@visualize Z̃;
6057

6158
#' ## Generating this README
62-
#'
59+
6360
#' This file was generated with [weave.jl](https://github.com/JunoLab/Weave.jl) with the following commands:
64-
#' ```julia
65-
#' using ITensorNetworks, Weave
66-
#' weave(joinpath(pkgdir(ITensorNetworks), "examples", "README.jl"); doctype="github", out_path=pkgdir(ITensorNetworks))
67-
#' ```
61+
#+ eval=false
62+
63+
using ITensorNetworks, Weave
64+
weave(joinpath(pkgdir(ITensorNetworks), "examples", "README.jl"); doctype="github", out_path=pkgdir(ITensorNetworks))

examples/TTN/ttn_basics.jl

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,51 @@
1+
using Compat
12
using ITensors
3+
using Metis
24
using ITensorNetworks
5+
36
using ITensorNetworks:
4-
delta_network,
5-
formsubgraphs,
6-
partition,
7-
flatten_thicken_bonds,
8-
flattened_inner_network,
97
construct_initial_mts,
108
update_all_mts,
11-
get_single_site_expec,
12-
iterate_single_site_expec,
13-
contract_boundary_mps
14-
using KaHyPar
15-
using Compat
9+
get_single_site_expec
1610

17-
#nxn GRID
1811
n = 4
19-
g = named_grid((n, n))
12+
dims = (n, n)
13+
g = named_grid(dims)
14+
# g = named_comb_tree(dims)
2015
s = siteinds("S=1/2", g)
21-
chi = 3
16+
chi = 2
2217

23-
#Random Tensor Network, Flatten it too
24-
psi = randomITensorNetwork(s; link_space=chi)
25-
psiflat, combiners = flatten_thicken_bonds(deepcopy(psi))
18+
ψ = randomITensorNetwork(s; link_space=chi)
2619

27-
v = (1, 1)
20+
ψψ = norm_sqr_network(ψ; flatten=true, map_bra_linkinds=prime)
21+
combiners = linkinds_combiners(ψψ)
22+
ψψ = combine_linkinds(ψψ, combiners)
2823

29-
#Apply Sz to site v and flatten that
30-
psiflatO = flatten_thicken_bonds(psi; ops=["Sz"], vops=[v], s=s, combiners=combiners)
24+
# Apply Sz to site v
25+
v = one.(dims)
26+
= copy(ψ)
27+
Oψ[v] = apply(op("Sz", s[v]), ψ[v])
28+
ψOψ = inner_network(ψ, Oψ; flatten=true, map_bra_linkinds=prime)
29+
ψOψ = combine_linkinds(ψOψ, combiners)
3130

32-
#Get the value of sz on v via exact contraction
33-
actual_sz = ITensors.contract(psiflatO)[1] / ITensors.contract(psiflat)[1]
31+
# Get the value of sz on v via exact contraction
32+
contract_seq = contraction_sequence(ψψ)
33+
actual_sz = contract(ψOψ; sequence=contract_seq)[] / contract(ψψ; sequence=contract_seq)[]
3434

3535
println("Actual value of Sz on site " * string(v) * " is " * string(actual_sz))
3636

37-
nsites = 1
38-
println("First " * string(nsites) * " sites form a subgraph")
39-
dg_subgraphs = formsubgraphs(g, Int(n * n / nsites))
40-
mts = construct_initial_mts(psiflat, dg_subgraphs; init=(I...) -> allequal(I) ? 1 : 0)
41-
niters = 5
37+
niters = 20
4238

43-
iterate_single_site_expec(psiflat, psiflatO, mts, dg_subgraphs, niters, v)
39+
nsites = 1
40+
println("\nFirst " * string(nsites) * " sites form a subgraph")
41+
mts = construct_initial_mts(ψψ, nsites; init=(I...) -> @compat allequal(I) ? 1 : 0)
42+
@show get_single_site_expec(ψψ, mts, ψOψ, v)
43+
mts = update_all_mts(ψψ, mts, niters)
44+
@show get_single_site_expec(ψψ, mts, ψOψ, v)
4445

4546
nsites = 4
46-
println("Now " * string(nsites) * " sites form a subgraph")
47-
dg_subgraphs = formsubgraphs(g, Int(n * n / nsites))
48-
mts = construct_initial_mts(psiflat, dg_subgraphs; init=(I...) -> allequal(I) ? 1 : 0)
49-
50-
iterate_single_site_expec(psiflat, psiflatO, mts, dg_subgraphs, niters, v)
47+
println("\nNow " * string(nsites) * " sites form a subgraph")
48+
mts = construct_initial_mts(ψψ, nsites; init=(I...) -> @compat allequal(I) ? 1 : 0)
49+
@show get_single_site_expec(ψψ, mts, ψOψ, v)
50+
mts = update_all_mts(ψψ, mts, niters)
51+
@show get_single_site_expec(ψψ, mts, ψOψ, v)

examples/contraction_sequence/contraction_sequence.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using NamedGraphs
12
using ITensors
23
using ITensorNetworks
34
using Random
@@ -13,7 +14,7 @@ s = siteinds("S=1/2", g)
1314
χ = 10
1415
ψ = randomITensorNetwork(s; link_space=χ)
1516

16-
tn = norm_network(ψ)
17+
tn = norm_sqr_network(ψ)
1718

1819
# Contraction sequence for exactly computing expectation values
1920
# contract_edges = map(t -> (1, t...), collect(keys(cartesian_to_linear(dims))))
@@ -26,7 +27,7 @@ using OMEinsumContractionOrders
2627

2728
println("greedy")
2829
seq_greedy = @time contraction_sequence(tn; alg="greedy")
29-
res_greedy = @time contract(tn; alg=res_greedy)
30+
res_greedy = @time contract(tn; sequence=seq_greedy)
3031

3132
println("tree_sa")
3233
seq_tree_sa = @time contraction_sequence(tn; alg="tree_sa")

examples/examples.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
using ITensors
22
using ITensorNetworks
33
using ITensorUnicodePlots
4+
using NamedGraphs
45

56
χ, d = 5, 2
67
dims = (4, 4)
7-
vertices = vec([(i, j) for i in 1:dims[1], j in 1:dims[2]])
8-
g = NamedDimGraph(grid(dims), vertices)
8+
g = named_grid(dims)
99

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

examples/mps.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ e = edge_data(is)
2525

2626
@visualize ψ̃
2727

28-
ψψ = (ψ̃, ψ; new_dim_names=("bra", "ket"))
28+
ψψ = ("bra" => ψ̃) ("ket" => ψ)
2929

3030
@visualize ψψ
3131

@@ -38,6 +38,6 @@ inner_res = contract(ψψ; sequence)[]
3838

3939
@show inner_res
4040

41-
sub = ψψ[[("bra", 1), ("ket", 1), ("bra", 2), ("ket", 2)]]
41+
sub = subgraph(ψψ, [(1, "bra"), (1, "ket"), (2, "bra"), (2, "ket")])
4242

4343
@visualize sub
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
using Graphs
2-
using ITensorNetworks
32
using KaHyPar
43
using Metis
4+
using ITensorNetworks
55

66
g = grid((16,))
7-
npartitions = 2
7+
npartitions = 4
88

99
kahypar_partitions = partition(g, npartitions; backend="KaHyPar")
1010
metis_partitions = partition(g, npartitions; backend="Metis")
11-
@show kahypar_partitions
12-
@show metis_partitions
11+
@show kahypar_partitions, length(unique(kahypar_partitions))
12+
@show metis_partitions, length(unique(metis_partitions))

0 commit comments

Comments
 (0)