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

CNOT decomposition method returns DecompositionUndefinedError #6039

Merged
merged 19 commits into from
Jul 26, 2024

Conversation

lillian542
Copy link
Contributor

@lillian542 lillian542 commented Jul 24, 2024

Context:
Before CNOT inherited from Controlled, its decomposition method returned a DecompositionUndefinedError. Now it uses the smart decomposition functions from Controlled, which in this case make it decompose to itself.

>>> op = qml.CNOT([0, 1])
>>> op.decomposition()
[CNOT(wires=[0, 1])]

The change in the decomposition method of CNOT was unintentional, and operators should not decompose to themselves.

Description of the Change:
We put it back how it was:

>>> op = qml.CNOT([0, 1])
>>> op.decomposition()
DecompositionUndefinedError

Related GitHub Issues:
#5711

@lillian542
Copy link
Contributor Author

[sc-63619]

Copy link
Contributor

@dwierichs dwierichs left a comment

Choose a reason for hiding this comment

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

Looks good to me overall, leaving a preliminary review :)
It might be good to add an explicit test of the CNOT decomposition, in case you were not planning to do that anyways. :)

pennylane/ops/functions/assert_valid.py Show resolved Hide resolved
pennylane/ops/functions/assert_valid.py Outdated Show resolved Hide resolved
pennylane/transforms/tape_expand.py Outdated Show resolved Hide resolved
pennylane/transforms/tape_expand.py Outdated Show resolved Hide resolved
tests/ops/functions/test_assert_valid.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jul 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.65%. Comparing base (b7675ca) to head (0744db6).
Report is 301 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6039      +/-   ##
==========================================
- Coverage   99.66%   99.65%   -0.01%     
==========================================
  Files         428      430       +2     
  Lines       41182    41169      -13     
==========================================
- Hits        41042    41028      -14     
- Misses        140      141       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lillian542 lillian542 marked this pull request as ready for review July 25, 2024 22:07
@lillian542 lillian542 linked an issue Jul 25, 2024 that may be closed by this pull request
1 task
Copy link
Contributor

@dwierichs dwierichs left a comment

Choose a reason for hiding this comment

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

Thanks @lillian542
Would be nice to update the comment regarding mapped_op.has_decomposition, otherwise LGTM! 🚀

@lillian542 lillian542 requested a review from albi3ro July 26, 2024 16:53
Copy link
Contributor

@albi3ro albi3ro left a comment

Choose a reason for hiding this comment

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

👍 minor, non-blocking suggestions.

@lillian542 lillian542 enabled auto-merge (squash) July 26, 2024 18:08
@lillian542 lillian542 merged commit c534c17 into master Jul 26, 2024
40 checks passed
@lillian542 lillian542 deleted the revert-cnot-decomp branch July 26, 2024 19:45
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.

[BUG] CNOT decomposes to CNOT
3 participants