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: Remove circuit cuts that do not result in a disconnection #2260

Merged
merged 26 commits into from
Mar 3, 2022

Conversation

trbromley
Copy link
Contributor

Context:

Not all place WireCut operations lead to a disconnection between a pair of subgraphs. Sometimes a WireCut will live within a subgraph. For example, in this circuit:
image

This PR removes the MeasureNode and PrepareNode pairs resulting from WireCuts that do not lead to a disconnection.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 2022

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@codecov
Copy link

codecov bot commented Mar 1, 2022

Codecov Report

Merging #2260 (b3236fa) into master (3d36407) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2260   +/-   ##
=======================================
  Coverage   99.31%   99.31%           
=======================================
  Files         237      237           
  Lines       18899    18902    +3     
=======================================
+ Hits        18769    18772    +3     
  Misses        130      130           
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 3d36407...b3236fa. Read the comment docs.

Base automatically changed from qcut_remove_unneeded_subgraphs to master March 2, 2022 13:21
Copy link
Contributor

@angusjlowe angusjlowe left a comment

Choose a reason for hiding this comment

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

Hi Tom, had a quick look here and seems good to go! Thanks for dealing with all these edge cases. I just have a couple questions below.

Comment on lines 314 to 315
# to worry about adding back an edge between the predecessor to node1 and the successor
# to node2 because edge connectivity no longer matters in the subgraphs.
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, maybe this comment doesn't need to change but I'm personally not sure what "edge connectivity no longer matters" means here.

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 clarified the comment here: b358d1d
The idea is that after fragmenting we are happy to convert back to a tape for further processing. Going from graph to tape only requires looking at the nodes and the total order (which is a node attribute), so we don't care about edges in this conversion.

@@ -2095,7 +2112,7 @@ def circuit(x):
res = circuit(x)
assert np.allclose(res, np.cos(x))
assert len(spy.call_args[0][0]) == 1 # there should be 2 tensors for wire 0
assert spy.call_args[0][0][0].shape == (4, 4)
assert spy.call_args[0][0][0].shape == ()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did this have to change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The circuit in this test actually has a fully contained cut. Beforehand, we were going over all measurement and preparation configurations even though the cut didn't result in a disconnection. So we'd have a (4, 4) tensor with contraction equation a,a

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 @angusjlowe!

Comment on lines 314 to 315
# to worry about adding back an edge between the predecessor to node1 and the successor
# to node2 because edge connectivity no longer matters in the subgraphs.
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 clarified the comment here: b358d1d
The idea is that after fragmenting we are happy to convert back to a tape for further processing. Going from graph to tape only requires looking at the nodes and the total order (which is a node attribute), so we don't care about edges in this conversion.

@@ -2095,7 +2112,7 @@ def circuit(x):
res = circuit(x)
assert np.allclose(res, np.cos(x))
assert len(spy.call_args[0][0]) == 1 # there should be 2 tensors for wire 0
assert spy.call_args[0][0][0].shape == (4, 4)
assert spy.call_args[0][0][0].shape == ()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The circuit in this test actually has a fully contained cut. Beforehand, we were going over all measurement and preparation configurations even though the cut didn't result in a disconnection. So we'd have a (4, 4) tensor with contraction equation a,a

@trbromley trbromley merged commit e18cf53 into master Mar 3, 2022
@trbromley trbromley deleted the qcut_remove_contained_cuts branch March 3, 2022 13:47
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.

2 participants