Skip to content

Commit 76eb1b3

Browse files
committed
Version Bump. Proper package extension for TensorOperations
1 parent 8f13426 commit 76eb1b3

File tree

6 files changed

+29
-16
lines changed

6 files changed

+29
-16
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ITensorNetworks"
22
uuid = "2919e153-833c-4bdc-8836-1ea460a35fc7"
33
authors = ["Matthew Fishman <[email protected]>, Joseph Tindall <[email protected]> and contributors"]
4-
version = "0.11.28"
4+
version = "0.12.0"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
@@ -49,6 +49,7 @@ ITensorNetworksEinExprsExt = "EinExprs"
4949
ITensorNetworksGraphsFlowsExt = "GraphsFlows"
5050
ITensorNetworksOMEinsumContractionOrdersExt = "OMEinsumContractionOrders"
5151
ITensorNetworksObserversExt = "Observers"
52+
ITensorNetworksTensorOperationsExt = "TensorOperations"
5253

5354
[compat]
5455
AbstractTrees = "0.4.4"
@@ -92,6 +93,7 @@ EinExprs = "b1794770-133b-4de1-afb4-526377e9f4c5"
9293
GraphsFlows = "06909019-6f44-4949-96fc-b9d9aaa02889"
9394
OMEinsumContractionOrders = "6f22d1fd-8eed-4bb7-9776-e7d684900715"
9495
Observers = "338f10d5-c7f1-4033-a7d1-f9dec39bcaa0"
96+
TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2"
9597
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
9698

9799
[targets]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module ITensorNetworksTensorOperationsExt
2+
3+
using ITensors: ITensors, ITensor, dim, inds
4+
using ITensorNetworks: ITensorNetworks
5+
using TensorOperations: optimaltree
6+
using NDTensors.AlgorithmSelection: @Algorithm_str
7+
8+
function ITensorNetworks.contraction_sequence(::Algorithm"optimal", tn::Vector{ITensor})
9+
return optimal_contraction_sequence(tn)
10+
end
11+
12+
function optimal_contraction_sequence(tensors::Vector{<:ITensor})
13+
network = collect.(inds.(tensors))
14+
inds_to_dims = Dict(i => dim(i) for i in unique(reduce(vcat, network)))
15+
seq, _ = optimaltree(network, inds_to_dims)
16+
return seq
17+
end
18+
19+
end

src/contract.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using ITensors: ITensor, scalar
2-
using ITensors.ContractionSequenceOptimization: deepmap
32
using ITensors.NDTensors: NDTensors, Algorithm, @Algorithm_str, contract
43
using LinearAlgebra: normalize!
54
using NamedGraphs: NamedGraphs

src/contraction_sequences.jl

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,21 @@
11
using Graphs: vertices
2-
using ITensors: ITensor, contract, inds, dim
3-
using ITensors.ContractionSequenceOptimization: deepmap
2+
using ITensors: ITensor
43
using ITensors.NDTensors: Algorithm, @Algorithm_str
54
using NamedGraphs.Keys: Key
65
using NamedGraphs.OrdinalIndexing: th
7-
using TensorOperations: optimaltree
86

97
function contraction_sequence(tn::Vector{ITensor}; alg="optimal", kwargs...)
108
return contraction_sequence(Algorithm(alg), tn; kwargs...)
119
end
1210

11+
function deepmap(f, tree; filter=(x -> x isa AbstractArray))
12+
return filter(tree) ? map(t -> deepmap(f, t; filter=filter), tree) : f(tree)
13+
end
14+
1315
function contraction_sequence(tn::AbstractITensorNetwork; kwargs...)
1416
# TODO: Use `token_vertex` and/or `token_vertices` here.
1517
ts = map(v -> tn[v], (1:nv(tn))th)
1618
seq_linear_index = contraction_sequence(ts; kwargs...)
1719
# TODO: Use `Functors.fmap` or `StructWalk`?
1820
return deepmap(n -> Key(vertices(tn)[n * th]), seq_linear_index)
1921
end
20-
21-
function contraction_sequence(::Algorithm"optimal", tn::Vector{ITensor})
22-
return optimal_contraction_sequence(tn)
23-
end
24-
25-
function ITensors.optimal_contraction_sequence(tensors::Vector{<:ITensor})
26-
network = collect.(inds.(tensors))
27-
inds_to_dims = Dict(i => dim(i) for i in unique(reduce(vcat, network)))
28-
seq, _ = optimaltree(network, inds_to_dims)
29-
return seq
30-
end

test/test_contraction_sequence.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ using ITensorNetworks:
55
using ITensors: ITensors, contract
66
using NamedGraphs.NamedGraphGenerators: named_grid
77
using OMEinsumContractionOrders: OMEinsumContractionOrders
8+
using TensorOperations
89
using StableRNGs: StableRNG
910
using Test: @test, @testset
1011
@testset "contraction_sequence" begin

test/test_expect.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ using ITensorNetworks:
1212
using SplitApplyCombine: group
1313
using StableRNGs: StableRNG
1414
using Test: @test, @testset
15+
using TensorOperations
1516
@testset "Test Expect" begin
1617
#Test on a tree
1718
L, χ = 4, 2

0 commit comments

Comments
 (0)