Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyT1994 committed Mar 28, 2024
2 parents 8efff49 + d12ed32 commit 5b1393f
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 937 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ITensorNetworks"
uuid = "2919e153-833c-4bdc-8836-1ea460a35fc7"
authors = ["Matthew Fishman <[email protected]> and contributors"]
version = "0.4.1"
version = "0.4.2"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down Expand Up @@ -51,7 +51,7 @@ DocStringExtensions = "0.8, 0.9"
EinExprs = "0.6.4"
Graphs = "1.8"
GraphsFlows = "0.1.1"
ITensors = "0.3.23"
ITensors = "0.3.58"
IsApprox = "0.1"
IterTools = "1.4.0"
KrylovKit = "0.6.0"
Expand Down
40 changes: 22 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
> In short, use this package with caution, and don't expect the interface to be stable
> or for us to clearly announce parts of the code we are changing.


# ITensorNetworks

A package to provide general network data structures and tools to use with ITensors.jl.



## Installation

You can install this package through the Julia package manager:
Expand Down Expand Up @@ -99,13 +103,13 @@ and 4 edge(s):

with vertex data:
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"))
(1, 1) │ ((dim=2|id=712|"1×1,2×1"), (dim=2|id=598|"1×1,1×2"))
(2, 1) │ ((dim=2|id=712|"1×1,2×1"), (dim=2|id=457|"2×1,2×2"))
(1, 2) │ ((dim=2|id=598|"1×1,1×2"), (dim=2|id=683|"1×2,2×2"))
(2, 2) │ ((dim=2|id=457|"2×1,2×2"), (dim=2|id=683|"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=712|"1×1,2×1") (dim=2|id=598|"1×1,1×2")
NDTensors.EmptyStorage{NDTensors.EmptyNumber, NDTensors.Dense{NDTensors.EmptyNumber, Vector{NDTensors.EmptyNumber}}}

julia> neighbors(tn, (1, 1))
Expand All @@ -129,8 +133,8 @@ and 1 edge(s):

with vertex data:
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"))
(1, 1) │ ((dim=2|id=712|"1×1,2×1"), (dim=2|id=598|"1×1,1×2"))
(1, 2) │ ((dim=2|id=598|"1×1,1×2"), (dim=2|id=683|"1×2,2×2"))

julia> tn_2 = subgraph(v -> v[1] == 2, tn)
ITensorNetwork{Tuple{Int64, Int64}} with 2 vertices:
Expand All @@ -143,8 +147,8 @@ and 1 edge(s):

with vertex data:
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"))
(2, 1) │ ((dim=2|id=712|"1×1,2×1"), (dim=2|id=457|"2×1,2×2"))
(2, 2) │ ((dim=2|id=457|"2×1,2×2"), (dim=2|id=683|"1×2,2×2"))
```


Expand All @@ -166,9 +170,9 @@ and 2 edge(s):

with vertex data:
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")]
1 │ Index[(dim=2|id=830|"S=1/2,Site,n=1")]
2 │ Index[(dim=2|id=369|"S=1/2,Site,n=2")]
3 │ Index[(dim=2|id=558|"S=1/2,Site,n=3")]

and edge data:
0-element Dictionary{NamedEdge{Int64}, Vector{Index}}
Expand All @@ -186,9 +190,9 @@ and 2 edge(s):

with vertex data:
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"))
1 │ ((dim=2|id=830|"S=1/2,Site,n=1"), (dim=2|id=186|"1,2"))
2 │ ((dim=2|id=369|"S=1/2,Site,n=2"), (dim=2|id=186|"1,2"), (dim=2|id=430|"2,3…
3 │ ((dim=2|id=558|"S=1/2,Site,n=3"), (dim=2|id=430|"2,3"))
julia> tn2 = ITensorNetwork(s; link_space=2)
ITensorNetwork{Int64} with 3 vertices:
Expand All @@ -203,9 +207,9 @@ and 2 edge(s):
with vertex data:
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"))
1 │ ((dim=2|id=830|"S=1/2,Site,n=1"), (dim=2|id=994|"1,2"))
2 │ ((dim=2|id=369|"S=1/2,Site,n=2"), (dim=2|id=994|"1,2"), (dim=2|id=978|"2,3
3 │ ((dim=2|id=558|"S=1/2,Site,n=3"), (dim=2|id=978|"2,3"))

julia> @visualize tn1;
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
Expand Down
12 changes: 12 additions & 0 deletions examples/README.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
#' > [!WARNING]
#' > This is a pre-release software. There are no guarantees that functionality won't break
#' > from version to version, though we will try our best to indicate breaking changes
#' > following [semantic versioning](https://semver.org/) (semver) by bumping the minor
#' > version of the package. We are biasing heavily towards "moving fast and breaking things"
#' > during this stage of development, which will allow us to more quickly develop the package
#' > and bring it to a point where we have enough features and are happy enough with the external
#' > interface to officially release it for general public use.
#' >
#' > In short, use this package with caution, and don't expect the interface to be stable
#' > or for us to clearly announce parts of the code we are changing.

#' # ITensorNetworks
#'
#' A package to provide general network data structures and tools to use with ITensors.jl.
Expand Down
9 changes: 9 additions & 0 deletions src/abstractitensornetwork.jl
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,15 @@ end
# Common index checking
#

function hascommoninds(
::typeof(siteinds), A::AbstractITensorNetwork{V}, B::AbstractITensorNetwork{V}
) where {V}
for v in vertices(A)
!hascommoninds(siteinds(A, v), siteinds(B, v)) && return false
end
return true
end

function hassameinds(
::typeof(siteinds), A::AbstractITensorNetwork{V}, B::AbstractITensorNetwork{V}
) where {V}
Expand Down
2 changes: 2 additions & 0 deletions src/imports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ import ITensors:
dag,
# permute
permute,
#commoninds
hascommoninds,
# linkdims
linkdim,
linkdims,
Expand Down
12 changes: 0 additions & 12 deletions src/solvers/alternating_update/alternating_update.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ function alternating_update(
end

function alternating_update(operator::AbstractTTN, init_state::AbstractTTN; kwargs...)
check_hascommoninds(siteinds, operator, init_state)
check_hascommoninds(siteinds, operator, init_state')
# Permute the indices to have a better memory layout
# and minimize permutations
operator = ITensors.permute(operator, (linkind, siteinds, linkind))
Expand All @@ -106,8 +104,6 @@ end
function alternating_update(
operator::AbstractTTN, init_state::AbstractTTN, sweep_plans; kwargs...
)
check_hascommoninds(siteinds, operator, init_state)
check_hascommoninds(siteinds, operator, init_state')
# Permute the indices to have a better memory layout
# and minimize permutations
operator = ITensors.permute(operator, (linkind, siteinds, linkind))
Expand Down Expand Up @@ -138,10 +134,6 @@ Returns:
function alternating_update(
operators::Vector{<:AbstractTTN}, init_state::AbstractTTN; kwargs...
)
for operator in operators
check_hascommoninds(siteinds, operator, init_state)
check_hascommoninds(siteinds, operator, init_state')
end
operators .= ITensors.permute.(operators, Ref((linkind, siteinds, linkind)))
projected_operators = ProjTTNSum(operators)
return alternating_update(projected_operators, init_state; kwargs...)
Expand All @@ -150,10 +142,6 @@ end
function alternating_update(
operators::Vector{<:AbstractTTN}, init_state::AbstractTTN, sweep_plans; kwargs...
)
for operator in operators
check_hascommoninds(siteinds, operator, init_state)
check_hascommoninds(siteinds, operator, init_state')
end
operators .= ITensors.permute.(operators, Ref((linkind, siteinds, linkind)))
projected_operators = ProjTTNSum(operators)
return alternating_update(projected_operators, init_state, sweep_plans; kwargs...)
Expand Down
2 changes: 0 additions & 2 deletions src/solvers/contract.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ function sum_contract(
return typeof(tn2)([res])
end

# check_hascommoninds(siteinds, tn1, tn2)

# In case `tn1` and `tn2` have the same internal indices
operator = ProjOuterProdTTN{vertextype(first(tn1s))}[]
for (tn1, tn2) in zip(tn1s, tn2s)
Expand Down
12 changes: 0 additions & 12 deletions src/treetensornetworks/abstracttreetensornetwork.jl
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ function loginner(
end
ψ1dag = sim(dag(ψ1); sites=[])
traversal_order = reverse(post_order_dfs_vertices(ψ1, root_vertex))
check_hascommoninds(siteinds, ψ1dag, ψ2)

O = ψ1dag[root_vertex] * ψ2[root_vertex]

Expand Down Expand Up @@ -370,8 +369,6 @@ function inner(
y::AbstractTTN, A::AbstractTTN, x::AbstractTTN; root_vertex=default_root_vertex(x, A, y)
)
traversal_order = reverse(post_order_dfs_vertices(x, root_vertex))
check_hascommoninds(siteinds, A, x)
check_hascommoninds(siteinds, A, y)
ydag = sim(dag(y); sites=[])
x = sim(x; sites=[])
O = ydag[root_vertex] * A[root_vertex] * x[root_vertex]
Expand All @@ -397,15 +394,6 @@ function inner(
),
)
end
check_hascommoninds(siteinds, A, x)
check_hascommoninds(siteinds, B, y)
for v in vertices(B)
!hascommoninds(
uniqueinds(siteinds(A, v), siteinds(x, v)), uniqueinds(siteinds(B, v), siteinds(y, v))
) && error(
"$(typeof(x)) Ax and $(typeof(y)) By must share site indices. On site $v, Ax has site indices $(uniqueinds(siteinds(A, v), (siteinds(x, v)))) while By has site indices $(uniqueinds(siteinds(B, v), siteinds(y, v))).",
)
end
ydag = sim(linkinds, dag(y))
Bdag = sim(linkinds, dag(B))
traversal_order = reverse(post_order_dfs_vertices(x, root_vertex))
Expand Down
Loading

0 comments on commit 5b1393f

Please sign in to comment.