Skip to content

Commit c73d264

Browse files
committed
Working contract
1 parent 89d383d commit c73d264

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

src/contractnetwork.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using BackendSelection: @Algorithm_str, Algorithm
2-
using ITensorNetworksNext.LazyNamedDimsArrays: LazyNamedDimsArray, nested_array_to_lazy_multiply, substitute_lazy, materialize
2+
using ITensorNetworksNext.LazyNamedDimsArrays: nested_array_to_lazy_multiply, substitute_lazy, materialize, lazy,
3+
symnameddims
34

45
default_contract_alg = nothing
56

@@ -20,11 +21,8 @@ end
2021

2122
function contractnetwork(alg::Algorithm"exact", tn::Vector{<:AbstractArray})
2223
contract_sequence = isa(alg.sequence, String) ? contraction_sequence(tn; alg = alg.sequence) : sequence
23-
@show contract_sequence
24-
@show materialize(contract_sequence)
25-
contract_sequence = substitute_lazy(contract_sequence, Dict(i => lazy(tn[i]) for i in 1:length(tn)))
26-
@show contract_sequence
27-
#return materialize(substitute_lazy(contract_sequence, Dict(i => tn[i] for i in 1:length(tn))))
24+
contract_sequence = substitute_lazy(contract_sequence, Dict(symnameddims(i) => lazy(tn[i]) for i in 1:length(tn)))
25+
return materialize(contract_sequence)
2826
end
2927

3028
function contractnetwork(alg::Algorithm"exact", tn::AbstractTensorNetwork)

src/lazynameddimsarrays.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ TermInterface.operation(m::Mul) = *
294294
union::Union{A, Mul{LazyNamedDimsArray{T, A}}}
295295
end
296296
function LazyNamedDimsArray(a::AbstractNamedDimsArray)
297-
return LazyNamedDimsArray{eltype(a), typeof(a)}(a)
297+
return LazyNamedDimsArray{eltype(typeof(a)), typeof(a)}(a)
298298
end
299299
function LazyNamedDimsArray(a::Mul{LazyNamedDimsArray{T, A}}) where {T, A}
300300
return LazyNamedDimsArray{T, A}(a)

test/test_contractnetwork.jl

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ using NamedGraphs.GraphsExtensions: arranged_edges, incident_edges
33
using NamedGraphs.NamedGraphGenerators: named_grid
44
using ITensorBase: Index, ITensor
55
using ITensorNetworksNext:
6-
TensorNetwork, linkinds, siteinds, contractnetwork, contraction_sequence, symnameddims, lazy
6+
TensorNetwork, linkinds, siteinds, contractnetwork, contraction_sequence, symnameddims, lazy, substitute_lazy, materialize
77
using TensorOperations: TensorOperations
88
using Test: @test, @testset
99

@@ -15,14 +15,10 @@ using Test: @test, @testset
1515
C = ITensor([5.0, 1.0], j)
1616
D = ITensor([-2.0, 3.0, 4.0, 5.0, 1.0], k)
1717

18-
#@show s1 * s2
19-
#seq = contraction_sequence([A, B, C, D]; alg = "optimal")
20-
#@show seq
18+
ABCD_1 = contractnetwork([A, B, C, D]; alg = "exact", sequence = "leftassociative")
19+
ABCD_2 = contractnetwork([A, B, C, D]; alg = "exact", sequence = "optimal")
2120

22-
#ABCD_1 = contractnetwork([A, B, C, D]; alg = "exact", sequence = "leftassociative")
23-
# ABCD_2 = contractnetwork([A, B, C, D]; alg = "exact", sequence = "optimal")
24-
25-
# @test ABCD_1 == ABCD_2
21+
@test ABCD_1 == ABCD_2
2622
end
2723

2824
@testset "Contract One Dimensional Network" begin

0 commit comments

Comments
 (0)