-
Notifications
You must be signed in to change notification settings - Fork 378
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 support for optimized multi-controlled gates #124
Conversation
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 looks good. Can you add a few tests? Not sure if you do your tests with manual Qobj or with Terra. If Terra, then we need to wait until Terra can generate these qobj instructions.
Edit: actually, you can already define any gate you want in terra.
Is it possible to have cswap
(Fredking Gate), as well as mcswap
? Not blocking for this PR.
// Calculate the permutation positions for the last qubit. | ||
const size_t N = qubits.size(); | ||
const size_t pos0 = MASKS[N - 1]; | ||
const size_t pos1 = MASKS[N]; | ||
// Lambda function for CNOT gate |
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.
// Lambda function for CNOT gate | |
// Lambda function for mcx gate |
const size_t pos0 = MASKS[N - 1]; | ||
const size_t pos1 = MASKS[N]; | ||
const complex_t I(0., 1.); | ||
// Lambda function for CNOT gate |
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.
// Lambda function for CNOT gate | |
// Lambda function for mcy gate |
const size_t N = qubits.size(); | ||
const size_t pos0 = MASKS[N - 1]; | ||
const size_t pos1 = MASKS[N]; | ||
// Lambda function for CNOT gate |
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.
// Lambda function for CNOT gate | |
// Lambda function for mcu gate |
@ajavadia shouldnt be too hard to add a cswap and mcswap, I'll do it in a follow up PR though |
fc8e6a0
to
25436af
Compare
4ea7132
to
397084a
Compare
@chriseclectic looks good to me! |
The application of these functions for regular cx, ccx, cz, swap are already covered in current tests, but I want to wait till terra has a stable way of adding custom gates before adding additional tests, (this is tracked in issue #132). |
9a9c088
to
f17f5a7
Compare
Any one know how to use this multiple controlled gates inside qiskit python? |
* add multi-controlled pauli gates * implement cx, cz as mcx, mcz * add multi controlled u1,u2,u3 gates * fixup indexes refs * update changelog
Summary
Adds support for multi-controller x,y,z,u1,u2,u3 gates to the statevector QasmSimulator, StatevectorSimulator and UnitarySimulator.
These gates have an optimized implementation making them faster to execute than the gate being unrolled into a basis of
cx
and single qubit gates.Closes #127
Details and comments
These gates are passed in as (N+1)-qubit qobj instructions such as:
where the first
N
qubits are the controls, and the last qubit is the target.For the controlled
u1,u2,u3
gates the instruction includes the same parameters as for the single qubit gates. Eg:TODO: