-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Port CRX/Y/Z gates to Rust #12648
Port CRX/Y/Z gates to Rust #12648
Conversation
One or more of the following people are relevant to this code:
|
Pull Request Test Coverage Report for Build 9650794209Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9659942591Details
💛 - Coveralls |
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.
Can you update the QuantumCircuit
methods to directly append the rust gate too? You can look at cx or h for an example of how to do this.
Pull Request Test Coverage Report for Build 9665498437Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
@@ -4776,6 +4776,12 @@ def crx( | |||
""" | |||
from .library.standard_gates.rx import CRXGate | |||
|
|||
# if the control state is |1> use the fast Rust version of the gate | |||
if ctrl_state is None or ctrl_state in ["1", 1]: |
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.
Hmm I get that you added the ["1", 1]
cases because it's the state set by default when ctrl_state
is None, but I wonder if we would be overseeing some edge case by adding this?? (If there is indeed no difference, I think we should do it in all controlled gate methods).
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.
If ctrl_state
is None
it is directly set to 1 in the constructor of any controlled gate, e.g.
>>> CRXGate(theta=0.5, ctrl_state=None).ctrl_state
1
so I think there should be no functional difference 🙂
But I agree we should generally cover all |1>
state definitions we can use the Rust implementation more generally.
Picking up the For example from qiskit.quantum_info import Operator
from qiskit.circuit import QuantumCircuit
qc = QuantumCircuit(2)
qc.crx(2, 0, 1)
print(Operator(qc)) # matrix with ctrl_state 1
# not very legal but not explicitly illegal?
qc.data[0].operation.ctrl_state = 0
# w/o Rust gates this prints the correct matrix with ctrl_state 0,
# with Rust gates it still shows the matrix for ctrl_state 1
print(Operator(qc)) This may be something we need to fix globally. |
Pull Request Test Coverage Report for Build 9692730727Details
💛 - Coveralls |
This sounds like a friend of:
I don't think we'll be able to mutate any gate element post-Rust migration using that syntax (reno) |
The other issue with |
Yes, I am trying to fix it as part of #12659. |
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 a lot, I added a path to handle custom control states in 9b47121, and I will also update the other circuit construction methods to add the ctrl_state in ["1", 1]
case once this PR is merged.
Pull Request Test Coverage Report for Build 9710882058Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9714453170Details
💛 - Coveralls |
* v0 of CR-Pauli gates * fix inevitable matrix typos * update multiply_param and prepare for U1/2/3 PR * fix num params/qubits * cct methods to append rust gates --------- Co-authored-by: Elena Peña Tapia <[email protected]>
Summary
Port the controlled Pauli rotations to Rust. Checks off parts of #12566.