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

Circuit cutting: Add input validation checks #2251

Merged
merged 9 commits into from
Mar 1, 2022

Conversation

trbromley
Copy link
Contributor

Context:

Adds input validation to the cut_circuit transform and supporting tests.

@trbromley
Copy link
Contributor Author

[sc-14724]

@codecov
Copy link

codecov bot commented Feb 28, 2022

Codecov Report

Merging #2251 (4a13302) into master (9c344f5) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2251   +/-   ##
=======================================
  Coverage   99.27%   99.27%           
=======================================
  Files         231      231           
  Lines       18381    18392   +11     
=======================================
+ Hits        18247    18258   +11     
  Misses        134      134           
Impacted Files Coverage Δ
pennylane/transforms/qcut.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9c344f5...4a13302. Read the comment docs.

Copy link
Contributor

@anthayes92 anthayes92 left a comment

Choose a reason for hiding this comment

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

Thanks @trbromley! Minor suggestions but good to go (looks like codecov isn't as happy as me though 🤔 )

@@ -941,6 +940,33 @@ def circuit(x):
>>> qml.grad(cut_circuit)(x)
-0.506395895364911
"""
if len(tape.measurements) != 1:
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to exclude tapes without measurements? Would be fairly simple to return fragment tapes. Though use cases for this is questionable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it makes sense to exclude the zero-measurements case:

  • It seems strange to go through the (potentially huge) process of cut placement and fragment execution, to contract a tensor network to nothing
  • I'm also not sure if it works in the current pipeline in practice
  • This is anyway quite an edge case because QNodes will always have at least one measurement. So only if a user applies the transform to a tape could they see this warning.
  • It's assumed in this PR

pennylane/transforms/qcut.py Outdated Show resolved Hide resolved
tests/transforms/test_qcut.py Outdated Show resolved Hide resolved
Copy link
Contributor Author

@trbromley trbromley left a comment

Choose a reason for hiding this comment

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

Thanks @anthayes92!

pennylane/transforms/qcut.py Outdated Show resolved Hide resolved
@@ -941,6 +940,33 @@ def circuit(x):
>>> qml.grad(cut_circuit)(x)
-0.506395895364911
"""
if len(tape.measurements) != 1:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it makes sense to exclude the zero-measurements case:

  • It seems strange to go through the (potentially huge) process of cut placement and fragment execution, to contract a tensor network to nothing
  • I'm also not sure if it works in the current pipeline in practice
  • This is anyway quite an edge case because QNodes will always have at least one measurement. So only if a user applies the transform to a tape could they see this warning.
  • It's assumed in this PR

@trbromley trbromley merged commit d4931e7 into master Mar 1, 2022
@trbromley trbromley deleted the qcut_integ_tests_4_validation branch March 1, 2022 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants