From 77155bceafd45783d365786bf6e0d4a9271741ed Mon Sep 17 00:00:00 2001 From: mtfishman Date: Wed, 27 Mar 2024 13:41:26 -0400 Subject: [PATCH] Fix more namespace issues --- README.md | 40 ++++++++++++++------------ examples/README.jl | 12 ++++++++ src/treetensornetworks/opsum_to_ttn.jl | 22 +++++++------- 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 6aec5bbb..d50f4377 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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)) @@ -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: @@ -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")) ``` @@ -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}} @@ -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: @@ -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; ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ diff --git a/examples/README.jl b/examples/README.jl index 755ca3ab..0157793e 100644 --- a/examples/README.jl +++ b/examples/README.jl @@ -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. diff --git a/src/treetensornetworks/opsum_to_ttn.jl b/src/treetensornetworks/opsum_to_ttn.jl index dc99ca5e..b2c2a1f0 100644 --- a/src/treetensornetworks/opsum_to_ttn.jl +++ b/src/treetensornetworks/opsum_to_ttn.jl @@ -1,3 +1,5 @@ +using ITensors.ITensorMPS: ITensorMPS + # convert ITensors.OpSum to TreeTensorNetwork # @@ -41,7 +43,7 @@ Hamiltonian, compressing shared interaction channels. """ function ttn_svd(os::OpSum, sites::IndsNetwork, root_vertex; kwargs...) # Function barrier to improve type stability - coefficient_type = ITensors.determineValType(terms(os)) + coefficient_type = ITensorMPS.determineValType(terms(os)) return ttn_svd(coefficient_type, os, sites, root_vertex; kwargs...) end @@ -100,7 +102,7 @@ function ttn_svd( end end inbond_coefs = Dict( - e => Dict{QN,Vector{ITensors.MatElem{coefficient_type}}}() for e in es + e => Dict{QN,Vector{ITensorMPS.MatElem{coefficient_type}}}() for e in es ) # bond coefficients for incoming edge channels site_coef_done = Prod{Op}[] # list of terms for which the coefficient has been added to a site factor # temporary symbolic representation of TTN Hamiltonian @@ -158,13 +160,13 @@ function ttn_svd( coutmap = get!(outmaps, edge_in => not_incoming_qn, Dict{Vector{Op},Int}()) cinmap = get!(inmaps, edge_in => -incoming_qn, Dict{Vector{Op},Int}()) - bond_row = ITensors.posInLink!(cinmap, incoming) - bond_col = ITensors.posInLink!(coutmap, not_incoming) # get incoming channel + bond_row = ITensorMPS.posInLink!(cinmap, incoming) + bond_col = ITensorMPS.posInLink!(coutmap, not_incoming) # get incoming channel bond_coef = convert(coefficient_type, ITensors.coefficient(term)) q_inbond_coefs = get!( - inbond_coefs[edge_in], incoming_qn, ITensors.MatElem{coefficient_type}[] + inbond_coefs[edge_in], incoming_qn, ITensorMPS.MatElem{coefficient_type}[] ) - push!(q_inbond_coefs, ITensors.MatElem(bond_row, bond_col, bond_coef)) + push!(q_inbond_coefs, ITensorMPS.MatElem(bond_row, bond_col, bond_coef)) T_inds[dim_in] = bond_col T_qns[dim_in] = -incoming_qn end @@ -172,7 +174,7 @@ function ttn_svd( coutmap = get!( outmaps, edges[dout] => outgoing_qns[edges[dout]], Dict{Vector{Op},Int}() ) - T_inds[dout] = ITensors.posInLink!(coutmap, outgoing[edges[dout]]) # add outgoing channel + T_inds[dout] = ITensorMPS.posInLink!(coutmap, outgoing[edges[dout]]) # add outgoing channel T_qns[dout] = outgoing_qns[edges[dout]] end # if term starts at this site, add its coefficient as a site factor @@ -197,11 +199,11 @@ function ttn_svd( push!(tempTTN[v], el) end - ITensors.remove_dups!(tempTTN[v]) + ITensorMPS.remove_dups!(tempTTN[v]) # manual truncation: isometry on incoming edge if !isnothing(dim_in) && !isempty(inbond_coefs[edges[dim_in]]) for (q, mat) in inbond_coefs[edges[dim_in]] - M = ITensors.toMatrix(mat) + M = ITensorMPS.toMatrix(mat) U, S, V = svd(M) P = S .^ 2 truncate!(P; maxdim, cutoff, mindim) @@ -489,7 +491,7 @@ function TTN( os = deepcopy(os) os = sorteachterm(os, sites, root_vertex) - os = ITensors.sortmergeterms(os) # not exported + os = ITensorMPS.sortmergeterms(os) # not exported if algorithm == "svd" T = ttn_svd(os, sites, root_vertex; kwargs...) else