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
9 changes: 8 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ITensorNetworksNext"
uuid = "302f2e75-49f0-4526-aef7-d8ba550cb06c"
version = "0.9.3"
version = "0.9.4"
authors = ["ITensor developers <support@itensor.org> and contributors"]

[workspace]
Expand All @@ -23,6 +23,12 @@ SimpleTraits = "699a6c99-e7fa-54fc-8d76-47d257e15c1d"
SplitApplyCombine = "03a91e81-4c3e-53e1-a0a4-9c0c8f19dd66"
TensorAlgebra = "68bd88dc-f39d-4e12-b2ca-f046b68fcc6a"

[weakdeps]
OMEinsumContractionOrders = "6f22d1fd-8eed-4bb7-9776-e7d684900715"

[extensions]
ITensorNetworksNextOMEinsumContractionOrdersExt = "OMEinsumContractionOrders"

[compat]
Adapt = "4.3"
AlgorithmsInterface = "0.1"
Expand All @@ -35,6 +41,7 @@ LinearAlgebra = "1.10"
MacroTools = "0.5.16"
MatrixAlgebraKit = "0.6"
NamedGraphs = "0.11, 0.12"
OMEinsumContractionOrders = "1"
Random = "1.10"
SimpleTraits = "0.9.5"
SplitApplyCombine = "1.2.3"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module ITensorNetworksNextOMEinsumContractionOrdersExt

using ITensorNetworksNext: ITensorNetworksNext
using OMEinsumContractionOrders: CodeOptimizer

function ITensorNetworksNext.contraction_order(alg::CodeOptimizer, tn)
return ITensorNetworksNext._contraction_order(alg, tn)
end

end
6 changes: 5 additions & 1 deletion src/contract_network.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ struct LeftAssociative end
function contraction_order(alg::LeftAssociative, tn)
return prod(i -> symnameddims(i, Tuple(axes(tn[i]))), keys(tn))
end
function contraction_order(alg::EvaluationOrderAlgorithm, tn)
# Internal implementation shared with the OMEinsumContractionOrders extension.
function _contraction_order(alg, tn)
s = contraction_order(Flat(), tn)
return optimize_evaluation_order(s; alg)
end
function contraction_order(alg::EvaluationOrderAlgorithm, tn)
return _contraction_order(alg, tn)
end
2 changes: 2 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ITensorPkgSkeleton = "3d388ab1-018a-49f4-ae50-18094d5f71ea"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MatrixAlgebraKit = "6c742aac-3347-4629-af66-fc926824e5e4"
NamedGraphs = "678767b0-92e7-4007-89e4-4527a8725b19"
OMEinsumContractionOrders = "6f22d1fd-8eed-4bb7-9776-e7d684900715"
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
Expand All @@ -36,6 +37,7 @@ ITensorNetworksNext = "0.9"
ITensorPkgSkeleton = "0.3.42"
MatrixAlgebraKit = "0.6"
NamedGraphs = "0.11, 0.12"
OMEinsumContractionOrders = "1"
QuadGK = "2.11.2"
Random = "1.10"
SafeTestsets = "0.1"
Expand Down
9 changes: 9 additions & 0 deletions test/test_contract_network.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using ITensorNetworksNext: Exact, ITensorNetwork, LeftAssociative, contract_netw
linkinds, siteinds, tensornetwork
using NamedGraphs.GraphsExtensions: arranged_edges, incident_edges
using NamedGraphs.NamedGraphGenerators: named_grid
using OMEinsumContractionOrders: GreedyMethod, TreeSA
using TensorOperations: TensorOperations
using Test: @test, @testset

Expand All @@ -20,7 +21,11 @@ using Test: @test, @testset
ABCD_1 = contract_network([A, B, C, D]; alg = orderalg(LeftAssociative()))
ABCD_2 = contract_network([A, B, C, D]; alg = orderalg(Greedy()))
ABCD_3 = contract_network([A, B, C, D]; alg = orderalg(Optimal()))
ABCD_4 = contract_network([A, B, C, D]; alg = orderalg(GreedyMethod()))
ABCD_5 = contract_network([A, B, C, D]; alg = orderalg(TreeSA()))
@test ABCD_1 == ABCD_2 == ABCD_3
@test ABCD_1 ≈ ABCD_4
@test ABCD_1 ≈ ABCD_5
end

@testset "Contract One Dimensional Network" begin
Expand All @@ -36,11 +41,15 @@ using Test: @test, @testset
z1 = contract_network(tn; alg = orderalg(LeftAssociative()))[]
z2 = contract_network(tn; alg = orderalg(Greedy()))[]
z3 = contract_network(tn; alg = orderalg(Optimal()))[]
z4 = contract_network(tn; alg = orderalg(GreedyMethod()))[]
z5 = contract_network(tn; alg = orderalg(TreeSA()))[]

@test abs(z1 - z2) / abs(z1) <= 1.0e3 * eps(Float64)
@test abs(z1 - z3) / abs(z1) <= 1.0e3 * eps(Float64)

@test z1 ≈ z2
@test z1 ≈ z3
@test z1 ≈ z4
@test z1 ≈ z5
end
end
Loading