-
Notifications
You must be signed in to change notification settings - Fork 575
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
Add controlled unitary gate #1069
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1069 +/- ##
=======================================
Coverage 97.72% 97.73%
=======================================
Files 154 154
Lines 11655 11679 +24
=======================================
+ Hits 11390 11414 +24
Misses 265 265
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @trbromley! I might be missing something about how this is supposed to work, but it seems like control/target wires chosen doesn't make a difference, causing the first wires to always be control with the remaining wires at the end targets. 🤔
Co-authored-by: Theodor <theodor@xanadu.ai>
Thanks @thisac for the review! Let me know if you're not persuaded regarding the wires question and we can discuss more. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation @trbromley! It looks great. 💯
tests/ops/test_qubit_ops.py
Outdated
# the 4-qubit representation of the unitary if the control wires were [0, 1] and the target | ||
# wires were [2, 3] | ||
U_matrix = np.eye(16, dtype=np.complex128) | ||
for i in range(4): | ||
for j in range(4): | ||
U_matrix[i + 12, j + 12] = U[i, j] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use block_diag(np.eye(12, dtype=np.complex128), U)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes good point, I wanted to do it in a way that's totally different from what's done in ControlledQubitUnitary
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood! Not sure if that's necessary though, since we're not really testing block_diag
here. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good @trbromley! 💯 Left some comments mostly related to testing, but nothing major
Co-authored-by: antalszava <antalszava@gmail.com>
There was a problem hiding this 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! 💯
This reverts commit a4060d6.
Context:
Adds a new gate,
ControlledQubitUnitary
, which allows users to specify the matrix of a unitary, the control wire(s) and the target wire(s).Description of the Change:
This gate has been added as an operation in
pennylane/ops/qubit.py
. It inherits fromQubitUnitary
and just performs some tweaks in the__init__
.Possible Drawbacks:
The underlying matrix could get quite large if the user specifies a lot of control wires. However this seems anyway expected if we are working in the matrix representation.