Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ITensorNetworks"
uuid = "2919e153-833c-4bdc-8836-1ea460a35fc7"
version = "0.20.0"
version = "0.21.0"
authors = ["Matthew Fishman <mfishman@flatironinstitute.org>, Joseph Tindall <jtindall@flatironinstitute.org> and contributors"]

[workspace]
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ path = ".."
Documenter = "1.10"
Graphs = "1"
ITensorFormatter = "0.2.27"
ITensorNetworks = "0.20"
ITensorNetworks = "0.21"
ITensors = "0.9"
Literate = "2.20.1"
NamedGraphs = "0.11"
Expand Down
28 changes: 0 additions & 28 deletions docs/src/deprecated_methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,9 @@ Suggestions of methods which could be deleted.
ITensorNetwork(is::IndsNetwork; kwargs...)
```

#### Local Operations on ITensorNetworks

* Indices on the source tensor of `edge` that are not shared with the destination tensor.
(`abstractitensornetwork.jl`):
```julia
uniqueinds(tn::AbstractITensorNetwork, edge::AbstractEdge)
uniqueinds(tn::AbstractITensorNetwork, edge::Pair)
```

* Indices common to the ITensors on the vertices connected by the edge (`abstractitensornetwork.jl`):
(Use a set function like `intersection` instead.)
```julia
commoninds(tn::AbstractITensorNetwork, edge)
linkinds(tn::AbstractITensorNetwork, edge)
```

## Global Operations on ITensorNetworks


## TreeTensorNetwork Constructors

* From `Op` and related types (`opsum_to_ttn.jl`):
```julia
ttn(o::Op, s::IndsNetwork; kws...)
ttn(o::Scaled{C, Op}, s::IndsNetwork; kws...)
ttn(o::Sum{Op}, s::IndsNetwork; kws...)
ttn(o::Prod{Op}, s::IndsNetwork; kws...)
ttn(o::Scaled{C, Prod{Op}}, s::IndsNetwork; kws...)
ttn(o::Sum{Scaled{C, Op}}, s::IndsNetwork; kws...)
```

## Miscellaneous Methods

* Methods in `partitioneditensornetwork.jl`.
Expand Down
7 changes: 0 additions & 7 deletions docs/src/experimental_methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,6 @@ Methods which still need to be discussed, modified, or deprecated.
edge_data_eltype(::Type{<:AbstractIndsNetwork{V, I}}) where {V, I}
```

* Indices "unique" to one side of an edge — for `edge`, returns the indices on
`src(edge)` together with all of its other incident-edge link indices (`abstractindsnetwork.jl`):
```julia
uniqueinds(is::AbstractIndsNetwork, edge::AbstractEdge)
uniqueinds(is::AbstractIndsNetwork, edge::Pair)
```

* Merge two `AbstractIndsNetwork`s, returning an `IndsNetwork` over the merged graph (`abstractindsnetwork.jl`):
```julia
union(is1::AbstractIndsNetwork, is2::AbstractIndsNetwork; kwargs...)
Expand Down
10 changes: 5 additions & 5 deletions docs/src/interface_methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ These ITensorNetwork constructor interfaces are foundational to other constructo

## Global Operations on ITensorNetworks

* Scale tensors at chosen vertices by per-vertex weights, either out-of-place or in-place (`abstractitensornetwork.jl`). Comment: should probably be renamed to `scale_tensors`.
* Scale tensors at chosen vertices by per-vertex weights, either out-of-place or in-place (`abstractitensornetwork.jl`).
```julia
scale(tn::AbstractITensorNetwork, vertices_weights::Dictionary; kwargs...)
scale(weight_function::Function, tn; kwargs...)
scale!(tn::AbstractITensorNetwork, vertices_weights::Dictionary)
scale!(weight_function::Function, tn::AbstractITensorNetwork; kwargs...)
scale_tensors(tn::AbstractITensorNetwork, vertices_weights::Dictionary; kwargs...)
scale_tensors(weight_function::Function, tn; kwargs...)
scale_tensors!(tn::AbstractITensorNetwork, vertices_weights::Dictionary)
scale_tensors!(weight_function::Function, tn::AbstractITensorNetwork; kwargs...)
```

* Tensor product (disjoint union) of two ITensorNetworks (`abstractitensornetwork.jl`):
Expand Down
2 changes: 1 addition & 1 deletion examples/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ ITensorNetworks = "2919e153-833c-4bdc-8836-1ea460a35fc7"
path = ".."

[compat]
ITensorNetworks = "0.20"
ITensorNetworks = "0.21"
16 changes: 1 addition & 15 deletions src/abstractindsnetwork.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using DataGraphs: DataGraphs, AbstractDataGraph, DataGraph, IsUnderlyingGraph, e
get_edge_data, get_vertex_data, is_edge_assigned, is_vertex_assigned, map_data,
set_edge_data!, set_vertex_data!, underlying_graph_type, vertex_data
using Graphs: Graphs, AbstractEdge
using ITensors: ITensors, IndexSet, unioninds, uniqueinds
using ITensors: ITensors, unioninds
using NamedGraphs.GraphsExtensions:
GraphsExtensions, directed_graph, incident_edges, rename_vertices
using NamedGraphs: NamedGraphs
Expand Down Expand Up @@ -50,20 +50,6 @@ end
# Index access
#

function ITensors.uniqueinds(is::AbstractIndsNetwork, edge::AbstractEdge)
# TODO: Replace with `is[v]` once `getindex(::IndsNetwork, ...)` is smarter.
inds = IndexSet(get(is, src(edge), Index[]))
for ei in setdiff(incident_edges(is, src(edge)), [edge])
# TODO: Replace with `is[v]` once `getindex(::IndsNetwork, ...)` is smarter.
inds = unioninds(inds, get(is, ei, Index[]))
end
return inds
end

function ITensors.uniqueinds(is::AbstractIndsNetwork, edge::Pair)
return uniqueinds(is, edgetype(is)(edge))
end

function Base.union(is1::AbstractIndsNetwork, is2::AbstractIndsNetwork; kwargs...)
return IndsNetwork(union(data_graph(is1), data_graph(is2); kwargs...))
end
Expand Down
64 changes: 22 additions & 42 deletions src/abstractitensornetwork.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ using Dictionaries: Dictionary
using Graphs: Graphs, Graph, add_edge!, add_vertex!, bfs_tree, center, dst, edges, edgetype,
ne, neighbors, rem_edge!, src, vertices
using ITensors: ITensors, @Algorithm_str, ITensor, addtags, combiner, commoninds,
commontags, contract, dag, hascommoninds, inds, noprime, onehot, prime, replaceprime,
replacetags, setprime, settags, sim, swaptags, tags, unioninds, uniqueinds
commontags, contract, dag, inds, noprime, onehot, prime, replaceprime, replacetags,
setprime, settags, sim, swaptags, tags
using LinearAlgebra: LinearAlgebra, factorize
using MacroTools: @capture
using NDTensors: NDTensors, Algorithm, dim, scalartype
Expand All @@ -31,7 +31,7 @@ function Graphs.weights(graph::AbstractITensorNetwork)
es = Tuple.(edges(graph))
ws = Dictionary{Tuple{V, V}, Float64}(es, undef)
for e in edges(graph)
w = log2(dim(commoninds(graph, e)))
w = log2(dim(linkinds(graph, e)))
ws[(src(e), dst(e))] = w
end
return ws
Expand Down Expand Up @@ -135,7 +135,7 @@ function fix_edges!(tn::AbstractITensorNetwork, v)
for vertex in vertices(tn)
if v ≠ vertex
edge = v => vertex
if hascommoninds(tn, edge)
if !isempty(linkinds(tn, edge))
add_edge!(tn, edge)
end
end
Expand Down Expand Up @@ -180,7 +180,7 @@ function Base.union(tn1::AbstractITensorNetwork, tn2::AbstractITensorNetwork; kw
# Add any new edges that are introduced during the union
for v1 in vertices(tn1)
for v2 in vertices(tn2)
if hascommoninds(tn, v1 => v2)
if !isempty(linkinds(tn, v1 => v2))
add_edge!(tn, v1 => v2)
end
end
Expand All @@ -198,14 +198,6 @@ end
# Data modification
#

function ITensors.hascommoninds(tn::AbstractITensorNetwork, edge::Pair)
return hascommoninds(tn, edgetype(tn)(edge))
end

function ITensors.hascommoninds(tn::AbstractITensorNetwork, edge::AbstractEdge)
return hascommoninds(tn[src(edge)], tn[dst(edge)])
end

#
# Promotion and conversion
#
Expand Down Expand Up @@ -254,7 +246,7 @@ function IndsNetwork(tn::AbstractITensorNetwork)
is[v] = siteinds(tn, v)
end
for e in edges(tn)
is[e] = commoninds(tn, e)
is[e] = linkinds(tn, e)
end
return is
end
Expand All @@ -272,7 +264,7 @@ end
function linkinds(tn::AbstractITensorNetwork)
is = IndsNetwork(underlying_graph(tn))
for e in edges(tn)
is[e] = commoninds(tn, e)
is[e] = linkinds(tn, e)
end
return is
end
Expand All @@ -292,21 +284,9 @@ siteinds(tn::AbstractITensorNetwork, vertex) = _siteinds(tn, vertex)
# Fix ambiguity with `siteinds(::Type, ::Int)` from `sitetype.jl`.
siteinds(tn::AbstractITensorNetwork, vertex::Int) = _siteinds(tn, vertex)

function ITensors.uniqueinds(tn::AbstractITensorNetwork, edge::AbstractEdge)
return uniqueinds(tn[src(edge)], tn[dst(edge)])
end

function ITensors.uniqueinds(tn::AbstractITensorNetwork, edge::Pair)
return uniqueinds(tn, edgetype(tn)(edge))
end

function ITensors.commoninds(tn::AbstractITensorNetwork, edge)
e = edgetype(tn)(edge)
return commoninds(tn[src(e)], tn[dst(e)])
end

function linkinds(tn::AbstractITensorNetwork, edge)
return commoninds(tn, edge)
e = edgetype(tn)(edge)
return intersect(inds(tn[src(e)]), inds(tn[dst(e)]))
end

# Priming and tagging (changing Index identifiers)
Expand Down Expand Up @@ -520,7 +500,7 @@ function LinearAlgebra.svd(
kwargs...
)
tn = copy(tn)
left_inds = uniqueinds(tn, edge)
left_inds = setdiff(inds(tn[src(edge)]), inds(tn[dst(edge)]))
U, S, V =
svd(tn[src(edge)], left_inds; lefttags = u_tags, righttags = v_tags, kwargs...)

Expand All @@ -546,7 +526,7 @@ function LinearAlgebra.qr(
kwargs...
)
tn = copy(tn)
left_inds = uniqueinds(tn, edge)
left_inds = setdiff(inds(tn[src(edge)]), inds(tn[dst(edge)]))
Q, R = factorize(tn[src(edge)], left_inds; tags, kwargs...)

rem_vertex!(tn, src(edge))
Expand Down Expand Up @@ -574,7 +554,7 @@ function LinearAlgebra.factorize(
tn = ITensorNetwork{V}(copy(tn))

neighbors_X = setdiff(neighbors(tn, src(edge)), [dst(edge)])
left_inds = uniqueinds(tn, edge)
left_inds = setdiff(inds(tn[src(edge)]), inds(tn[dst(edge)]))
X, Y = factorize(tn[src(edge)], left_inds; tags, kwargs...)

rem_vertex!(tn, src(edge))
Expand Down Expand Up @@ -605,7 +585,7 @@ function gauge_edge(
# return contract(tn, new_vertex => dst(edge))
!has_edge(tn, edge) && throw(ArgumentError("Edge not in graph."))
tn = copy(tn)
left_inds = uniqueinds(tn, edge)
left_inds = setdiff(inds(tn[src(edge)]), inds(tn[dst(edge)]))
ltags = tags(tn, edge)
X, Y = factorize(tn[src(edge)], left_inds; tags = ltags, ortho = "left", kwargs...)
@preserve_graph tn[src(edge)] = X
Expand Down Expand Up @@ -680,7 +660,7 @@ end
function _truncate_edge(tn::AbstractITensorNetwork, edge::AbstractEdge; kwargs...)
!has_edge(tn, edge) && throw(ArgumentError("Edge not in graph."))
tn = copy(tn)
left_inds = uniqueinds(tn, edge)
left_inds = setdiff(inds(tn[src(edge)]), inds(tn[dst(edge)]))
ltags = tags(tn, edge)
U, S, V = svd(tn[src(edge)], left_inds; lefttags = ltags, kwargs...)
@preserve_graph tn[src(edge)] = U
Expand Down Expand Up @@ -865,7 +845,7 @@ function insert_linkinds(
)
tn = copy(tn)
for e in edges
if !hascommoninds(tn, e)
if isempty(linkinds(tn, e))
iₑ = Index(link_space, edge_tag(e))
X = onehot(iₑ => 1)
tn[src(e)] *= X
Expand Down Expand Up @@ -962,7 +942,7 @@ function add(tn1::AbstractITensorNetwork, tn2::AbstractITensorNetwork)
end

# Scale each tensor of the network via a function vertex -> Number
function scale!(
function scale_tensors!(
weight_function::Function,
tn::AbstractITensorNetwork;
vertices = collect(Graphs.vertices(tn))
Expand All @@ -971,18 +951,18 @@ function scale!(
end

# Scale each tensor of the network by a scale factor for each vertex in the keys of the dictionary
function scale!(tn::AbstractITensorNetwork, vertices_weights::Dictionary)
return scale!(v -> vertices_weights[v], tn; vertices = keys(vertices_weights))
function scale_tensors!(tn::AbstractITensorNetwork, vertices_weights::Dictionary)
return scale_tensors!(v -> vertices_weights[v], tn; vertices = keys(vertices_weights))
end

function scale(weight_function::Function, tn; kwargs...)
function scale_tensors(weight_function::Function, tn; kwargs...)
tn = copy(tn)
return scale!(weight_function, tn; kwargs...)
return scale_tensors!(weight_function, tn; kwargs...)
end

function scale(tn::AbstractITensorNetwork, vertices_weights::Dictionary; kwargs...)
function scale_tensors(tn::AbstractITensorNetwork, vertices_weights::Dictionary; kwargs...)
tn = copy(tn)
return scale!(tn, vertices_weights; kwargs...)
return scale_tensors!(tn, vertices_weights; kwargs...)
end

Base.:+(tn1::AbstractITensorNetwork, tn2::AbstractITensorNetwork) = add(tn1, tn2)
Expand Down
4 changes: 2 additions & 2 deletions src/apply.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ using .BaseExtensions: maybe_real
using Graphs: has_edge
using ITensors.NDTensors: scalartype
using ITensors: ITensors, ITensor, Index, Ops, apply, commonind, commoninds, contract, dag,
denseblocks, factorize, factorize_svd, hasqns, isdiag, noncommoninds, noprime, prime,
replaceind, replaceinds, tags, unioninds, uniqueinds
denseblocks, factorize, factorize_svd, hascommoninds, hasqns, isdiag, noncommoninds,
noprime, prime, replaceind, replaceinds, tags, unioninds, uniqueinds
using KrylovKit: linsolve
using LinearAlgebra: eigen, norm, qr, svd
using NamedGraphs: NamedEdge, has_edge
Expand Down
4 changes: 2 additions & 2 deletions src/caches/abstractbeliefpropagationcache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ function rescale_partitions(
bpc = copy(bpc)
tn = tensornetwork(bpc)
norms = map(v -> inv(norm(tn[v])), verts)
scale!(bpc, Dictionary(verts, norms))
scale_tensors!(bpc, Dictionary(verts, norms))

vertices_weights = Dictionary()
for pv in partitions
Expand All @@ -385,7 +385,7 @@ function rescale_partitions(
end
end

scale!(bpc, vertices_weights)
scale_tensors!(bpc, vertices_weights)

return bpc
end
Expand Down
4 changes: 2 additions & 2 deletions src/normalize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function rescale(alg::Algorithm"exact", tn::AbstractITensorNetwork; kwargs...)
vs = collect(vertices(tn))
c = inv(exp(logn / length(vs)))
vertices_weights = Dictionary(vs, [c for v in vs])
return scale(tn, vertices_weights)
return scale_tensors(tn, vertices_weights)
end

function rescale(
Expand Down Expand Up @@ -61,7 +61,7 @@ function LinearAlgebra.normalize(
vs = collect(vertices(tn))
c = inv(exp(logn / (2 * length(vs))))
vertices_weights = Dictionary(vs, [c for v in vs])
return scale(tn, vertices_weights)
return scale_tensors(tn, vertices_weights)
end

function LinearAlgebra.normalize(
Expand Down
1 change: 1 addition & 0 deletions src/solvers/applyexp.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using ITensors: uniqueinds
using Printf: @printf

@kwdef mutable struct ApplyExpProblem{State} <: AbstractProblem
Expand Down
1 change: 1 addition & 0 deletions src/solvers/subspace/densitymatrix.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using ITensors: hascommoninds, uniqueinds
using NamedGraphs.GraphsExtensions: incident_edges
using Printf: @printf

Expand Down
25 changes: 0 additions & 25 deletions src/treetensornetworks/opsum_to_ttn/opsum_to_ttn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -661,31 +661,6 @@ function mpo(os::OpSum, s::IndsNetwork; kwargs...)
return ttn(os, s; kwargs...)
end

# Conversion from other formats
function ttn(o::Op, s::IndsNetwork; kwargs...)
return ttn(OpSum{Float64}() + o, s; kwargs...)
end

function ttn(o::Scaled{C, Op}, s::IndsNetwork; kwargs...) where {C}
return ttn(OpSum{C}() + o, s; kwargs...)
end

function ttn(o::Sum{Op}, s::IndsNetwork; kwargs...)
return ttn(OpSum{Float64}() + o, s; kwargs...)
end

function ttn(o::Prod{Op}, s::IndsNetwork; kwargs...)
return ttn(OpSum{Float64}() + o, s; kwargs...)
end

function ttn(o::Scaled{C, Prod{Op}}, s::IndsNetwork; kwargs...) where {C}
return ttn(OpSum{C}() + o, s; kwargs...)
end

function ttn(o::Sum{Scaled{C, Op}}, s::IndsNetwork; kwargs...) where {C}
return ttn(OpSum{C}() + o, s; kwargs...)
end

# Catch-all for leaf eltype specification
function ttn(eltype::Type{<:Number}, os, sites::IndsNetwork; kwargs...)
return NDTensors.convert_scalartype(eltype, ttn(os, sites; kwargs...))
Expand Down
Loading
Loading