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

Test transformations #217

Merged
merged 6 commits into from
Oct 15, 2024
Merged
Changes from 5 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
25 changes: 21 additions & 4 deletions test/Transformations_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@
end

@testset "ContractSimplification" begin
# TODO test `ContractSimplification` options

using Tenet: ContractSimplification

# create a tensor network where tensors B and D can be absorbed
Expand All @@ -154,13 +152,32 @@

# Test that the resulting tn contains no tensors with larger rank than the original
rank = length ∘ size ∘ parent
@test max(rank(tensors(reduced)) == max(rank(tensors(tn))))
@test maximum(ndims, tensors(reduced)) <= maximum(ndims, tensors(tn))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the rank definition and it should be done


# Test that the resulting tn contains <= tensors than the original
@test length(tensors(reduced)) == 1
@test Tenet.ntensors(reduced) <= Tenet.ntensors(tn)

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

# Options (for non-recursive)
# Test that a non-recursive contraction is an intermediate simplification
reduced_nonrecursive = transform(tn, ContractSimplification(:length, false))
@test Tenet.ntensors(tn) > Tenet.ntensors(reduced_nonrecursive) > Tenet.ntensors(reduced)

# 2nd-stage simplification result in full simplification for this TN
reduced_full = transform(reduced_nonrecursive, ContractSimplification(:length, false))
@test Tenet.ntensors(reduced) == Tenet.ntensors(reduced_full)

@test contract(reduced) ≈ contract(tn)

# Options (minimization by rank)
# Test that the resulting tn contains no tensors with larger rank than the original
reduced_byrank = transform(tn, ContractSimplification(:rank, true))
@test maximum(ndims, tensors(reduced_byrank)) <= maximum(ndims, tensors(tn))

# Test that the resulting number of tensors is bigger for a reduction by rank than for length
@test Tenet.ntensors(reduced_byrank) > Tenet.ntensors(reduced)
end

@testset "AntiDiagonalGauging" begin
Expand Down
Loading