diff --git a/Project.toml b/Project.toml index 69fe3c7d..3f5cd526 100644 --- a/Project.toml +++ b/Project.toml @@ -29,6 +29,7 @@ SplitApplyCombine = "03a91e81-4c3e-53e1-a0a4-9c0c8f19dd66" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb" TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f" +TupleTools = "9d95972d-f1c8-5527-a6e0-b4b365fa01f6" [compat] AbstractTrees = "0.4.4" @@ -54,6 +55,7 @@ SplitApplyCombine = "1.2" StaticArrays = "1.5.12" Suppressor = "0.2" TimerOutputs = "0.5.22" +TupleTools = "1.4" julia = "1.7" [extras] diff --git a/README.md b/README.md index 872711a6..7c13ee59 100644 --- a/README.md +++ b/README.md @@ -36,18 +36,18 @@ and 3 edge(s): 3 => 4 with vertex data: -4-element Dictionaries.Dictionary{Int64, Any} - 1 │ ((dim=2|id=739|"1↔2"),) - 2 │ ((dim=2|id=739|"1↔2"), (dim=2|id=920|"2↔3")) - 3 │ ((dim=2|id=920|"2↔3"), (dim=2|id=761|"3↔4")) - 4 │ ((dim=2|id=761|"3↔4"),) +4-element Dictionary{Int64, Any} + 1 │ ((dim=2|id=739|"1,2"),) + 2 │ ((dim=2|id=739|"1,2"), (dim=2|id=920|"2,3")) + 3 │ ((dim=2|id=920|"2,3"), (dim=2|id=761|"3,4")) + 4 │ ((dim=2|id=761|"3,4"),) julia> tn[1] -ITensor ord=1 (dim=2|id=739|"1↔2") +ITensor ord=1 (dim=2|id=739|"1,2") NDTensors.EmptyStorage{NDTensors.EmptyNumber, NDTensors.Dense{NDTensors.EmptyNumber, Vector{NDTensors.EmptyNumber}}} julia> tn[2] -ITensor ord=2 (dim=2|id=739|"1↔2") (dim=2|id=920|"2↔3") +ITensor ord=2 (dim=2|id=739|"1,2") (dim=2|id=920|"2,3") NDTensors.EmptyStorage{NDTensors.EmptyNumber, NDTensors.Dense{NDTensors.EmptyNumber, Vector{NDTensors.EmptyNumber}}} julia> neighbors(tn, 1) @@ -88,14 +88,14 @@ and 4 edge(s): (1, 2) => (2, 2) with vertex data: -4-element Dictionaries.Dictionary{Tuple{Int64, Int64}, Any} - (1, 1) │ ((dim=2|id=74|"1×1↔2×1"), (dim=2|id=723|"1×1↔1×2")) - (2, 1) │ ((dim=2|id=74|"1×1↔2×1"), (dim=2|id=823|"2×1↔2×2")) - (1, 2) │ ((dim=2|id=723|"1×1↔1×2"), (dim=2|id=712|"1×2↔2×2")) - (2, 2) │ ((dim=2|id=823|"2×1↔2×2"), (dim=2|id=712|"1×2↔2×2")) +4-element Dictionary{Tuple{Int64, Int64}, Any} + (1, 1) │ ((dim=2|id=74|"1×1,2×1"), (dim=2|id=723|"1×1,1×2")) + (2, 1) │ ((dim=2|id=74|"1×1,2×1"), (dim=2|id=823|"2×1,2×2")) + (1, 2) │ ((dim=2|id=723|"1×1,1×2"), (dim=2|id=712|"1×2,2×2")) + (2, 2) │ ((dim=2|id=823|"2×1,2×2"), (dim=2|id=712|"1×2,2×2")) julia> tn[1, 1] -ITensor ord=2 (dim=2|id=74|"1×1↔2×1") (dim=2|id=723|"1×1↔1×2") +ITensor ord=2 (dim=2|id=74|"1×1,2×1") (dim=2|id=723|"1×1,1×2") NDTensors.EmptyStorage{NDTensors.EmptyNumber, NDTensors.Dense{NDTensors.EmptyNumber, Vector{NDTensors.EmptyNumber}}} julia> neighbors(tn, (1, 1)) @@ -118,9 +118,9 @@ and 1 edge(s): (1, 1) => (1, 2) with vertex data: -2-element Dictionaries.Dictionary{Tuple{Int64, Int64}, Any} - (1, 1) │ ((dim=2|id=74|"1×1↔2×1"), (dim=2|id=723|"1×1↔1×2")) - (1, 2) │ ((dim=2|id=723|"1×1↔1×2"), (dim=2|id=712|"1×2↔2×2")) +2-element Dictionary{Tuple{Int64, Int64}, Any} + (1, 1) │ ((dim=2|id=74|"1×1,2×1"), (dim=2|id=723|"1×1,1×2")) + (1, 2) │ ((dim=2|id=723|"1×1,1×2"), (dim=2|id=712|"1×2,2×2")) julia> tn_2 = subgraph(v -> v[1] == 2, tn) ITensorNetwork{Tuple{Int64, Int64}} with 2 vertices: @@ -132,9 +132,9 @@ and 1 edge(s): (2, 1) => (2, 2) with vertex data: -2-element Dictionaries.Dictionary{Tuple{Int64, Int64}, Any} - (2, 1) │ ((dim=2|id=74|"1×1↔2×1"), (dim=2|id=823|"2×1↔2×2")) - (2, 2) │ ((dim=2|id=823|"2×1↔2×2"), (dim=2|id=712|"1×2↔2×2")) +2-element Dictionary{Tuple{Int64, Int64}, Any} + (2, 1) │ ((dim=2|id=74|"1×1,2×1"), (dim=2|id=823|"2×1,2×2")) + (2, 2) │ ((dim=2|id=823|"2×1,2×2"), (dim=2|id=712|"1×2,2×2")) ``` @@ -155,13 +155,13 @@ and 2 edge(s): 2 => 3 with vertex data: -3-element Dictionaries.Dictionary{Int64, Vector{Index}} +3-element Dictionary{Int64, Vector{Index}} 1 │ Index[(dim=2|id=598|"S=1/2,Site,n=1")] 2 │ Index[(dim=2|id=457|"S=1/2,Site,n=2")] 3 │ Index[(dim=2|id=683|"S=1/2,Site,n=3")] and edge data: -0-element Dictionaries.Dictionary{NamedEdge{Int64}, Vector{Index}} +0-element Dictionary{NamedEdge{Int64}, Vector{Index}} julia> tn1 = ITensorNetwork(s; link_space=2) ITensorNetwork{Int64} with 3 vertices: @@ -175,10 +175,10 @@ and 2 edge(s): 2 => 3 with vertex data: -3-element Dictionaries.Dictionary{Int64, Any} - 1 │ ((dim=2|id=598|"S=1/2,Site,n=1"), (dim=2|id=123|"1↔2")) - 2 │ ((dim=2|id=457|"S=1/2,Site,n=2"), (dim=2|id=123|"1↔2"), (dim=2|id=656|"2↔3… - 3 │ ((dim=2|id=683|"S=1/2,Site,n=3"), (dim=2|id=656|"2↔3")) +3-element Dictionary{Int64, Any} + 1 │ ((dim=2|id=598|"S=1/2,Site,n=1"), (dim=2|id=123|"1,2")) + 2 │ ((dim=2|id=457|"S=1/2,Site,n=2"), (dim=2|id=123|"1,2"), (dim=2|id=656|"2,3… + 3 │ ((dim=2|id=683|"S=1/2,Site,n=3"), (dim=2|id=656|"2,3")) julia> tn2 = ITensorNetwork(s; link_space=2) ITensorNetwork{Int64} with 3 vertices: @@ -192,10 +192,10 @@ and 2 edge(s): 2 => 3 with vertex data: -3-element Dictionaries.Dictionary{Int64, Any} - 1 │ ((dim=2|id=598|"S=1/2,Site,n=1"), (dim=2|id=382|"1↔2")) - 2 │ ((dim=2|id=457|"S=1/2,Site,n=2"), (dim=2|id=382|"1↔2"), (dim=2|id=190|"2↔3… - 3 │ ((dim=2|id=683|"S=1/2,Site,n=3"), (dim=2|id=190|"2↔3")) +3-element Dictionary{Int64, Any} + 1 │ ((dim=2|id=598|"S=1/2,Site,n=1"), (dim=2|id=382|"1,2")) + 2 │ ((dim=2|id=457|"S=1/2,Site,n=2"), (dim=2|id=382|"1,2"), (dim=2|id=190|"2,3… + 3 │ ((dim=2|id=683|"S=1/2,Site,n=3"), (dim=2|id=190|"2,3")) julia> @visualize tn1; ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ diff --git a/src/treetensornetworks/abstracttreetensornetwork.jl b/src/treetensornetworks/abstracttreetensornetwork.jl index 0bb6668a..72642687 100644 --- a/src/treetensornetworks/abstracttreetensornetwork.jl +++ b/src/treetensornetworks/abstracttreetensornetwork.jl @@ -1,3 +1,5 @@ +using TupleTools: TupleTools + abstract type AbstractTreeTensorNetwork{V} <: AbstractITensorNetwork{V} end const AbstractTTN = AbstractTreeTensorNetwork @@ -334,7 +336,7 @@ function permute(ψ::AbstractTTN, ::Tuple{typeof(linkind),typeof(siteinds),typeo ψ̃ = copy(ψ) for v in vertices(ψ) ls = [only(linkinds(ψ, n => v)) for n in neighbors(ψ, v)] # TODO: won't work for multiple indices per link... - ss = sort(Tuple(siteinds(ψ, v)); by=plev) + ss = TupleTools.sort(Tuple(siteinds(ψ, v)); by=plev) setindex_preserve_graph!( ψ̃, permute(ψ[v], filter(!isnothing, (ls[1], ss..., ls[2:end]...))), v ) diff --git a/test/Project.toml b/test/Project.toml index 0d48cce5..ac355cb3 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -7,6 +7,7 @@ Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" Glob = "c27321d9-0574-5035-807b-f59d2c89b15c" Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" GraphsFlows = "06909019-6f44-4949-96fc-b9d9aaa02889" +ITensorNetworks = "2919e153-833c-4bdc-8836-1ea460a35fc7" ITensorUnicodePlots = "73163f41-4a9e-479f-8353-73bf94dbd758" ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5" KaHyPar = "2a6221f6-aa48-11e9-3542-2d9e0ef01880"