add ability to specify open controls.#3739
Conversation
|
can you make |
This PR adds the ability to control on '0' qubit states.
9b88df1 to
2209614
Compare
There was a problem hiding this comment.
There are no tests for a controlled Unitary gate (specified by a matrix). Can you add one please?
There are no modifications to the ControlledGate class as far as I can tell. It would be nice if the ctrl_state was also stored in instances of ControlledGate, so that e.g. it could be visualized with open controls. The conjugation with X gates should be done when decomposing that controlled gate.
|
|
||
| """ | ||
| import qiskit.extensions.standard as standard | ||
| if isinstance(operation, standard.RZGate) or operation.name == 'rz': |
There was a problem hiding this comment.
This is from before, but why is Rz a special case here, and all other gates are further down?
There was a problem hiding this comment.
This is due to the global phase issue. When num_ctrl_qubits=1 CrzGate is properly retrieved. However when num_ctrl_qubits > 1, the algorithm computes the control gate from the definition of the base gate. Since RzGate is defined by U1Gate, this leads to the wrong phase. By reducing the number of controls by 1 and using instead the definition from CrzGate, which is phase correct, the proper controlled version is generated.
There was a problem hiding this comment.
Ok, so maybe a comment here so someone reading the code would know why this is the way it is
|
@ajavadia Controlled unitaries are tested in the method |
ajavadia
left a comment
There was a problem hiding this comment.
The changes look good, thanks.
Were you going to test open control unitaries too?
Also I just saw the test for controlled unitaries and this is how random unitaries are made:
UnitaryGate(scipy.stats.unitary_group.rvs(num_target), but a simpler way is to just use qiskit.quantum_info.random.random_unitary()
* add ability specify open controls. This PR adds the ability to control on '0' qubit states. * add release notes * expected blank space * allow string control state specification. * linting * linting * remove f-string * add ctrl_state keyword to standard extensions * fix comments. add ctrl_state attribute to ControlledGate. * add ctrl_state and test of open controlled unitary matrix generation * minor bug fixes * linting * linting Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>
This PR adds the ability to control on '0' qubit states as described in issue #3726. Visualizations are not updated in this PR.
Summary
Details and comments
Add ability to specify control conditioned on a qubit being in the ground state. The state of the control qubits is represented by a decimal integer. For example:
Creates a four qubit gate where the fourth qubit gets flipped if the first qubit is in the ground state and the second and third qubits are in the excited state. If ctrl_state is None, the default, control is conditioned on all control qubits being excited.
Alternatively the ctrl_state may be specified as a bit string: