Skip to content

Commit

Permalink
Gate's label in the control function
Browse files Browse the repository at this point in the history
  • Loading branch information
israelferrazaraujo committed Mar 5, 2023
1 parent 100a690 commit 7d3ea14
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions qiskit/circuit/library/standard_gates/multi_control_su2.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from qiskit.circuit.controlledgate import ControlledGate
from qiskit.circuit.library.standard_gates.x import MCXVChain
from qiskit.exceptions import QiskitError
from qiskit.circuit._utils import _ctrl_state_to_int


class MCSU2Gate(ControlledGate):
Expand Down Expand Up @@ -109,6 +110,34 @@ def inverse(self):
ctrl_state=self.ctrl_state,
)

def control(
self,
num_ctrl_qubits: int = 1,
label: Optional[str] = None,
ctrl_state: Optional[Union[str, int]] = None,
):
"""
Controlled version of this gate.
Args:
num_ctrl_qubits (int): number of control qubits.
label (str or None): An optional label for the gate [Default: None]
ctrl_state (int or str or None): control state expressed as integer,
string (e.g. '110'), or None. If None, use all 1s.
Returns:
ControlledGate: controlled version of this gate.
"""
ctrl_state = _ctrl_state_to_int(ctrl_state, num_ctrl_qubits)
new_ctrl_state = (self.ctrl_state << num_ctrl_qubits) | ctrl_state
gate = MCSU2Gate(
su2_matrix=self.su2_matrix,
num_ctrl_qubits=num_ctrl_qubits + self.num_ctrl_qubits,
ctrl_state=new_ctrl_state,
)

gate.label = label

return gate

@staticmethod
def _check_su2(matrix):
return isclose(np.linalg.det(matrix), 1.0)
Expand Down

0 comments on commit 7d3ea14

Please sign in to comment.