Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix legacy tests for contract #75

Merged
merged 4 commits into from
Jul 18, 2023
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
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ TenetQuacExt = "Quac"
[compat]
Bijections = "0.1"
Combinatorics = "1.0"
DeltaArrays = "0.1.0"
DeltaArrays = "0.1.1"
EinExprs = "0.2"
GraphMakie = "0.4,0.5"
Graphs = "1.7"
Expand All @@ -45,6 +45,6 @@ OMEinsum = "0.7"
Permutations = "0.4"
Quac = "0.2"
Requires = "1.3"
Tensors = "0.1.9"
Tensors = "0.1.11"
ValSplit = "0.1"
julia = "1.8"
31 changes: 8 additions & 23 deletions test/Transformations_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
)

# Test that the resulting contraction returns the same as the original
# @test contract(reduced) ≈ contract(tn)
@test contract(reduced) ≈ contract(tn)
end

@testset "openinds" begin
Expand Down Expand Up @@ -111,7 +111,7 @@
end

# Test that the resulting contraction returns the same as the original
# @test contract(reduced) ≈ contract(tn)
@test contract(reduced) ≈ contract(tn)
end
end

Expand All @@ -136,13 +136,7 @@
@test length(tensors(reduced)) ≤ length(tensors(tn))

# Test that the resulting contraction contains the same as the original
# TODO: the permutation will not be necessary if https://github.com/bsc-quantic/Tensors.jl/issues/27 is fixed
contracted_reduced = contract(reduced)
contracted_tn = contract(tn)

# Calculate the permutation for the `reduced` tensor labels to match `tn`
perm = sortperm(collect(labels(contracted_reduced)), by = x -> findfirst(==(x), collect(labels(contracted_tn))))
@test permutedims(contracted_reduced, perm) ≈ contracted_tn
@test contract(reduced) ≈ contract(tn)
end

@testset "AntiDiagonalGauging" begin
Expand Down Expand Up @@ -191,9 +185,7 @@
end

# Test that the resulting contraction is the same as the original
# TODO: Change for: @test contract(gauged) ≈ contract(tn), when is fixed
A_2, B_2, C_2 = tensors(gauged)
@test contract(A, contract(B, C)) ≈ contract(A_2, contract(B_2, C_2))
@test contract(gauged) ≈ contract(tn)
end

@testset "ColumnReduction" begin
Expand Down Expand Up @@ -222,9 +214,7 @@
@test length(tn.indices) > length(reduced.indices)

# Test that the resulting contraction is the same as the original
# TODO: Change for: @test contract(reduced) ≈ contract(tn), when is fixed
A_2, B_2, C_2 = tensors(reduced)
@test contract(A, contract(B, C, dims = [])) ≈ contract(A_2, contract(B_2, C_2, dims = []))
@test contract(reduced) ≈ contract(contract(A, B; dims=[]), C)
end

@testset "index size reduction" begin
Expand All @@ -243,15 +233,13 @@
# Test that all the tensors in reduced have no columns and they have smaller dimensions in the 2nd :j index
for tensor in tensors(reduced)
@test isempty(Tenet.find_zero_columns(parent(tensor)))
# @assert size(tensor, :j) == 2
@test size(tensor, :j) == 2
end

@test length(tn.indices) == length(reduced.indices)

# Test that the resulting contraction is the same as the original
# TODO: Change for: @test contract(reduced) ≈ contract(tn), when is fixed
A_2, B_2, C_2 = tensors(reduced)
@test contract(A, contract(B, C, dims = [])) ≈ contract(A_2, contract(B_2, C_2, dims = []))
@test contract(reduced) ≈ view(contract(tn), :j => 1:2:3)
end
end

Expand All @@ -278,9 +266,6 @@
@test smallest_deleted > largest_new

# Test that the resulting contraction is the same as the original
# TODO: Change for: @test contract(reduced) ≈ contract(tn), when is fixed
A_2, B_2, C_2, D_2, E_2 = tensors(reduced)
c_reduced = contract(contract(contract(contract(A_2, B_2), C_2), D_2), E_2)
@test contract(contract(tensors(tn)[1], tensors(tn)[2]), tensors(tn)[3]) ≈ c_reduced
@test contract(reduced) ≈ contract(tn)
end
end
Loading