Skip to content

Commit

Permalink
Test transformations (#217)
Browse files Browse the repository at this point in the history
* Fix previous ContractSimplification transformation tests

* Add tests for options (non-recursive and for rank heuristic)

* Improve some test and add comments

* Apply format for CI

* Add Sergio's suggested changes for PR

* Remove rank definition
  • Loading branch information
HerManNav authored Oct 15, 2024
1 parent b94af1c commit af54eba
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 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 @@ -153,14 +151,32 @@
reduced = transform(tn, ContractSimplification)

# 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))

# 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

0 comments on commit af54eba

Please sign in to comment.