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
16 changes: 0 additions & 16 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,25 @@ authors = ["Matthew Fishman <mfishman@flatironinstitute.org>, Joseph Tindall <jt
projects = ["benchmark", "dev", "docs", "examples", "test"]

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
DataGraphs = "b5a273c3-7e6c-41f6-98bd-8d7f1525a36a"
Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5"
IsApprox = "28f27b66-4bd8-47e7-9110-e2746eb8bed7"
IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
NDTensors = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf"
NamedGraphs = "678767b0-92e7-4007-89e4-4527a8725b19"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SerializedElementArrays = "d3ce8812-9567-47e9-a7b5-65a6d70a3065"
SimpleTraits = "699a6c99-e7fa-54fc-8d76-47d257e15c1d"
SplitApplyCombine = "03a91e81-4c3e-53e1-a0a4-9c0c8f19dd66"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StructWalk = "31cdf514-beb7-4750-89db-dda9d2eb8d3d"
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
TupleTools = "9d95972d-f1c8-5527-a6e0-b4b365fa01f6"

[weakdeps]
Expand All @@ -45,31 +37,23 @@ ITensorNetworksOMEinsumContractionOrdersExt = "OMEinsumContractionOrders"
ITensorNetworksTensorOperationsExt = "TensorOperations"

[compat]
AbstractTrees = "0.4.4"
Accessors = "0.1.42"
Adapt = "4"
Combinatorics = "1"
Compat = "3, 4"
ConstructionBase = "1.6"
DataGraphs = "0.4"
Dictionaries = "0.4"
DocStringExtensions = "0.9"
Graphs = "1.8"
ITensors = "0.7, 0.8, 0.9"
IsApprox = "0.1, 1, 2"
IterTools = "1.4"
KrylovKit = "0.6, 0.7, 0.8, 0.9, 0.10"
MacroTools = "0.5"
NDTensors = "0.3, 0.4"
NamedGraphs = "0.11"
OMEinsumContractionOrders = "0.8.3, 0.9, 1"
SerializedElementArrays = "0.1"
SimpleTraits = "0.9"
SplitApplyCombine = "1.2"
StaticArrays = "1.5.12"
StructWalk = "0.2"
Suppressor = "0.2"
TensorOperations = "5.2"
TimerOutputs = "0.5.22"
TupleTools = "1.4"
julia = "1.10"
12 changes: 0 additions & 12 deletions docs/src/deprecated_methods.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
# Deprecated Methods

Suggestions of methods which could be deleted.

## Global Operations on ITensorNetworks


## Miscellaneous Methods

* Methods in `partitioneditensornetwork.jl`.
```julia
linkinds(pitn::PartitionedGraph, edge::QuotientEdge)
```
Likely removable once the BP `default_message` chain is cleaned up.

7 changes: 0 additions & 7 deletions docs/src/experimental_methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,6 @@ Methods which still need to be discussed, modified, or deprecated.
rename_vertices(f::Function, tn::AbstractIndsNetwork)
```

* Promoted index type across all site and link indices in the network (`abstractindsnetwork.jl`):
```julia
promote_indtypeof(is::AbstractIndsNetwork)
```

* Build an `IndsNetwork` whose site/link indices at each vertex/edge are the union
of the corresponding indices from each input network (graphs must match) (`abstractindsnetwork.jl`):
```julia
Expand All @@ -219,8 +214,6 @@ Methods which still need to be discussed, modified, or deprecated.

* Type-parameter accessors and graph-type metadata (`indsnetwork.jl`):
```julia
indtype(inds_network::IndsNetwork)
indtype(::Type{<:IndsNetwork{V, I}}) where {V, I}
data_graph(is::IndsNetwork)
underlying_graph(is::IndsNetwork)
vertextype(::Type{<:IndsNetwork{V}}) where {V}
Expand Down
9 changes: 3 additions & 6 deletions docs/src/interface_methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,10 @@ These ITensorNetwork constructor interfaces are foundational to other constructo
)
```

* Apply a set of gates to an ITensorNetwork (`apply.jl`):
* Apply a gate (or a sequence of gates) to an ITensorNetwork (`apply.jl`):
```julia
ITensors.apply(o::Union{NamedEdge, ITensor},ψ::AbstractITensorNetwork; kws...)
ITensors.apply(o⃗::Union{Vector{NamedEdge}, Vector{ITensor}}, ψ::AbstractITensorNetwork; kws...)
ITensors.apply(o⃗::Scaled,ψ::AbstractITensorNetwork; kws...)
ITensors.apply(o⃗::Prod, ψ::AbstractITensorNetwork; kws...)
ITensors.apply(o::Op, ψ::AbstractITensorNetwork; kws...)
ITensors.apply(o::ITensor, ψ::AbstractITensorNetwork; kws...)
ITensors.apply(o⃗::Vector{ITensor}, ψ::AbstractITensorNetwork; kws...)
```

## Visualization System
Expand Down
3 changes: 0 additions & 3 deletions src/ITensorNetworks.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module ITensorNetworks

include("lib/BaseExtensions/src/BaseExtensions.jl")
include("lib/ITensorsExtensions/src/ITensorsExtensions.jl")
include("visualize.jl")
include("abstractindsnetwork.jl")
include("indextags.jl")
Expand All @@ -13,7 +11,6 @@ include("contraction_sequences.jl")
include("tebd.jl")
include("itensornetwork.jl")
include("contract.jl")
include("partitioneditensornetwork.jl")
include("edge_sequences.jl")
include("caches/abstractbeliefpropagationcache.jl")
include("caches/beliefpropagationcache.jl")
Expand Down
15 changes: 1 addition & 14 deletions src/abstractindsnetwork.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using .ITensorsExtensions: ITensorsExtensions, promote_indtype, trivial_space
using DataGraphs: DataGraphs, AbstractDataGraph, DataGraph, IsUnderlyingGraph, edge_data,
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, unioninds
using ITensors: ITensors, Index, unioninds
using NamedGraphs.GraphsExtensions:
GraphsExtensions, directed_graph, incident_edges, rename_vertices
using NamedGraphs: NamedGraphs
Expand Down Expand Up @@ -62,18 +61,6 @@ end
# Convenience functions
#

function ITensorsExtensions.promote_indtypeof(is::AbstractIndsNetwork)
sitetype = mapreduce(promote_indtype, vertices(is); init = Index{Int}) do v
# TODO: Replace with `is[v]` once `getindex(::IndsNetwork, ...)` is smarter.
return mapreduce(typeof, promote_indtype, get(is, v, Index[]); init = Index{Int})
end
linktype = mapreduce(promote_indtype, edges(is); init = Index{Int}) do e
# TODO: Replace with `is[e]` once `getindex(::IndsNetwork, ...)` is smarter.
return mapreduce(typeof, promote_indtype, get(is, e, Index[]); init = Index{Int})
end
return promote_indtype(sitetype, linktype)
end

function union_all_inds(is_in::AbstractIndsNetwork...)
@assert all(map(ug -> ug == underlying_graph(is_in[1]), underlying_graph.(is_in)))
is_out = IndsNetwork(underlying_graph(is_in[1]))
Expand Down
6 changes: 0 additions & 6 deletions src/abstractitensornetwork.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using .ITensorsExtensions: ITensorsExtensions, indtype, promote_indtype, trivial_space
using Adapt: Adapt, adapt, adapt_structure
using DataGraphs: DataGraphs, edge_data, get_vertex_data, is_vertex_assigned,
set_vertex_data!, underlying_graph, underlying_graph_type, vertex_data
Expand Down Expand Up @@ -65,7 +64,6 @@ function ITensors.datatype(tn::AbstractITensorNetwork)
return mapreduce(v -> datatype(tn[v]), promote_type, vertices(tn))
end

# TODO: Move to `BaseExtensions` module.
function is_setindex!_expr(expr::Expr)
return is_assignment_expr(expr) && is_getindex_expr(first(expr.args))
end
Expand Down Expand Up @@ -210,10 +208,6 @@ end
# Promotion and conversion
#

function ITensorsExtensions.promote_indtypeof(tn::AbstractITensorNetwork)
return mapreduce(v -> indtype(tn[v]), promote_indtype, vertices(tn))
end

function NDTensors.scalartype(tn::AbstractITensorNetwork)
return mapreduce(v -> eltype(tn[v]), promote_type, vertices(tn); init = Bool)
end
Expand Down
95 changes: 47 additions & 48 deletions src/apply.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
using .BaseExtensions: maybe_real
using Graphs: has_edge, ne
using ITensors.NDTensors: scalartype
using ITensors: ITensors, ITensor, Index, Ops, apply, commonind, commoninds, contract, dag,
denseblocks, factorize, factorize_svd, hascommoninds, hasqns, isdiag, noprime, prime,
replaceind, replaceinds, tags, unioninds, uniqueinds
using ITensors: ITensors, ITensor, Index, apply, commonind, commoninds, contract, dag,
denseblocks, factorize, factorize_svd, hascommoninds, hasqns, isdiag, map_diag,
noncommonind, noprime, prime, replaceind, replaceinds, tags, unioninds, uniqueinds
using LinearAlgebra: eigen, norm, qr, svd
using NamedGraphs: NamedEdge

#TODO: Make this work for non-hermitian A
function eigendecomp(A::ITensor, linds, rinds; ishermitian = false, kwargs...)
@assert ishermitian
D, U = eigen(A, linds, rinds; ishermitian, kwargs...)
ul, ur = noncommonind(D, U), commonind(D, U)
Ul = replaceinds(U, vcat(rinds, ur), vcat(linds, ul))
return Ul, D, dag(U)
end

# Apply `f` to the eigenvalues of `A` (assumed Hermitian along the
# `Linds | Rinds` bipartition) and rebuild the operator. Used by
# `simple_update_bp` to form `sqrt(env)` and `inv ∘ sqrt(env)` of each
# product-environment factor.
function map_eigvals(f::Function, A::ITensor, Linds, Rinds; kws...)
isdiag(A) && return map_diag(f, A)
Ul, D, Ur = eigendecomp(A, Linds, Rinds; kws...)
return Ul * map_diag(f, D) * Ur
end

# Reduced simple-update on a 2-site gate `o`. Assumes `envs` is a product
# environment: each `env` shares indices with exactly one of `ψ[v⃗[1]]` or
Expand All @@ -14,31 +31,41 @@ using NamedGraphs: NamedEdge
# each endpoint into a small bond tensor, applies the gate, factor-SVDs back,
# then unwinds the inverse sqrt envs.
function simple_update_bp(
o::Union{NamedEdge, ITensor}, ψ, v⃗; envs, callback = Returns(nothing), apply_kwargs...
o::ITensor, ψ, v⃗; envs, callback = Returns(nothing), apply_kwargs...
)
cutoff = 10 * eps(real(scalartype(ψ)))
envs_v1 = filter(env -> hascommoninds(env, ψ[v⃗[1]]), envs)
envs_v2 = filter(env -> hascommoninds(env, ψ[v⃗[2]]), envs)
@assert all(ndims(env) == 2 for env in vcat(envs_v1, envs_v2))
sqrt_envs_v1 = [
ITensorsExtensions.map_eigvals(
sqrt, env, inds(env)[1], inds(env)[2]; cutoff, ishermitian = true
) for env in envs_v1
map_eigvals(sqrt, env, inds(env)[1], inds(env)[2]; cutoff, ishermitian = true)
for env in envs_v1
]
sqrt_envs_v2 = [
ITensorsExtensions.map_eigvals(
sqrt, env, inds(env)[1], inds(env)[2]; cutoff, ishermitian = true
) for env in envs_v2
map_eigvals(sqrt, env, inds(env)[1], inds(env)[2]; cutoff, ishermitian = true)
for env in envs_v2
]
inv_sqrt_envs_v1 = [
ITensorsExtensions.map_eigvals(
inv ∘ sqrt, env, inds(env)[1], inds(env)[2]; cutoff, ishermitian = true
) for env in envs_v1
map_eigvals(
inv ∘ sqrt,
env,
inds(env)[1],
inds(env)[2];
cutoff,
ishermitian = true
)
for env in envs_v1
]
inv_sqrt_envs_v2 = [
ITensorsExtensions.map_eigvals(
inv ∘ sqrt, env, inds(env)[1], inds(env)[2]; cutoff, ishermitian = true
) for env in envs_v2
map_eigvals(
inv ∘ sqrt,
env,
inds(env)[1],
inds(env)[2];
cutoff,
ishermitian = true
)
for env in envs_v2
]
ψᵥ₁ = contract([ψ[v⃗[1]]; sqrt_envs_v1])
ψᵥ₂ = contract([ψ[v⃗[2]]; sqrt_envs_v2])
Expand Down Expand Up @@ -68,7 +95,7 @@ function simple_update_bp(
end

function ITensors.apply(
o::Union{NamedEdge, ITensor},
o::ITensor,
ψ::AbstractITensorNetwork;
envs = ITensor[],
normalize = false,
Expand Down Expand Up @@ -119,7 +146,7 @@ function ITensors.apply(
end

function ITensors.apply(
o⃗::Union{Vector{NamedEdge}, Vector{ITensor}},
o⃗::Vector{ITensor},
ψ::AbstractITensorNetwork;
normalize = false,
ortho = false,
Expand All @@ -131,31 +158,3 @@ function ITensors.apply(
end
return o⃗ψ
end

function ITensors.apply(
o⃗::Scaled,
ψ::AbstractITensorNetwork;
cutoff = nothing,
normalize = false,
ortho = false,
apply_kwargs...
)
return maybe_real(Ops.coefficient(o⃗)) *
apply(Ops.argument(o⃗), ψ; cutoff, maxdim, normalize, ortho, apply_kwargs...)
end

function ITensors.apply(
o⃗::Prod, ψ::AbstractITensorNetwork; normalize = false, ortho = false, apply_kwargs...
)
o⃗ψ = ψ
for oᵢ in o⃗
o⃗ψ = apply(oᵢ, o⃗ψ; normalize, ortho, apply_kwargs...)
end
return o⃗ψ
end

function ITensors.apply(
o::Op, ψ::AbstractITensorNetwork; normalize = false, ortho = false, apply_kwargs...
)
return apply(ITensor(o, siteinds(ψ)), ψ; normalize, ortho, apply_kwargs...)
end
13 changes: 8 additions & 5 deletions src/caches/abstractbeliefpropagationcache.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Adapt: Adapt, adapt, adapt_structure
using Graphs: Graphs, IsDirected
using ITensors: delta, dir
using Graphs: Graphs, IsDirected, dst, src
using ITensors: commoninds, delta, dir
using LinearAlgebra: diag, dot
using NDTensors: NDTensors
using NamedGraphs.PartitionedGraphs: PartitionedGraph, PartitionedGraphs, QuotientVertex,
boundary_quotientedges, quotientedges, quotientvertices, unpartitioned_graph
using NamedGraphs.GraphsExtensions: subgraph
using NamedGraphs.PartitionedGraphs: PartitionedGraph, PartitionedGraphs, QuotientEdge,
QuotientVertex, boundary_quotientedges, quotientedges, quotientvertices,
unpartitioned_graph
using NamedGraphs.SimilarType: SimilarType
using NamedGraphs: to_graph_index
using SimpleTraits: SimpleTraits, @traitfn, Not
Expand Down Expand Up @@ -161,7 +163,8 @@ function PartitionedGraphs.quotientedge(
end

function linkinds(bpc::AbstractBeliefPropagationCache, pe::QuotientEdge)
return linkinds(partitioned_tensornetwork(bpc), pe)
pitn = partitioned_tensornetwork(bpc)
return commoninds(subgraph(pitn, src(pe)), subgraph(pitn, dst(pe)))
end

NDTensors.scalartype(bpc::AbstractBeliefPropagationCache) = scalartype(tensornetwork(bpc))
Expand Down
Loading
Loading