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

Test transformations #217

merged 6 commits into from
Oct 15, 2024

Conversation

HerManNav
Copy link
Contributor

No description provided.

@HerManNav HerManNav added bug Something isn't working ci/cd Continuous Integration / Continuous Deployment labels Oct 8, 2024
@HerManNav HerManNav self-assigned this Oct 8, 2024
@mofeing mofeing changed the title Test/transformations Test transformations Oct 8, 2024
@mofeing
Copy link
Member

mofeing commented Oct 8, 2024

Did you find a bug?

@HerManNav
Copy link
Contributor Author

@mofeing I did, in tests. Jofre and I fix them in cf69d3b

Copy link
Member

@mofeing mofeing left a comment

Choose a reason for hiding this comment

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

Ah I see: the bug was in the tests.

@@ -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 max(rank.(tensors(reduced))...) <= max(rank.(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.

Would you mind deleting rank and replacing it for ndims?

Copy link
Member

Choose a reason for hiding this comment

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

Also it's better if you call maximum: the same as max but without variadic arguments and can use some map.

Suggested change
@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 length(tensors(reduced)) <= length(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.

Can you replace length(tensors(...)) for Tenet.ntensors?

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@test length(tensors(reduced)) <= length(tensors(tn))
@test Tenet.ntensors(reduced) <= Tenet.ntensors(tn)

Copy link
Member

Choose a reason for hiding this comment

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

Why is this better?

Copy link
Member

Choose a reason for hiding this comment

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

tensors needs to create a Vector where it copies all the Tensors while ntensors doesn't: it just queries the inner Dict

Copy link
Member

Choose a reason for hiding this comment

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

@jofrevalles it might be worth checking if that by @inlineing tensors and inds, it can optimize away the Vector creation.

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

Choose a reason for hiding this comment

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

Suggested change
@test length(tensors(tn)) > length(tensors(reduced_nonrecursive)) > length(tensors(reduced))
@test Tenet.ntensors(tn) > Tenet.ntensors(reduced_nonrecursive) > Tenent.ntensors(reduced)


# 2nd-stage simplification result in full simplification for this TN
reduced_full = transform(reduced_nonrecursive, ContractSimplification(:length, false))
@test length(tensors(reduced)) == length(tensors(reduced_full))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@test length(tensors(reduced)) == length(tensors(reduced_full))
@test Tenet.ntensors(reduced) == Tenet.ntensors(reduced_full)

# 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 max(rank.(tensors(reduced_byrank))...) <= max(rank.(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.

Suggested change
@test max(rank.(tensors(reduced_byrank))...) <= max(rank.(tensors(tn))...)
@test maximum(ndims, tensors(reduced_byrank)) <= maximum(ndims, tensors(tn))

@test max(rank.(tensors(reduced_byrank))...) <= max(rank.(tensors(tn))...)

# Test that the resulting number of tensors is bigger for a reduction by rank than for length
@test length(tensors(reduced_byrank)) > length(tensors(reduced))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@test length(tensors(reduced_byrank)) > length(tensors(reduced))
@test Tenet.ntensors(reduced_byrank) > Tenet.ntensors(reduced)

Comment on lines 154 to 155
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

@mofeing mofeing merged commit af54eba into master Oct 15, 2024
6 checks passed
@mofeing mofeing deleted the test/transformations branch October 15, 2024 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ci/cd Continuous Integration / Continuous Deployment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants