diff --git a/releasenotes/notes/add_ControlledGate_class-010c5c90f8f95e78.yaml b/releasenotes/notes/add_ControlledGate_class-010c5c90f8f95e78.yaml new file mode 100644 index 000000000000..3096e29c3f1b --- /dev/null +++ b/releasenotes/notes/add_ControlledGate_class-010c5c90f8f95e78.yaml @@ -0,0 +1,29 @@ +--- +features: + - | + Add ``ControlledGate`` class for representing controlled + gates. Controlled gate instances are created with the + ``control(n)`` method of ``Gate`` objects where ``n`` represents + the number of controls. The control qubits come before the + controlled qubits in the new gate. For example:: + + from qiskit import QuantumCircuit + from qiskit.extensions import HGate + hgate = HGate() + circ = QuantumCircuit(4) + circ.append(hgate.control(3), [0, 1, 2, 3]) + print(circ) + + generates:: + + q_0: |0>──■── + │ + q_1: |0>──■── + │ + q_2: |0>──■── + ┌─┴─┐ + q_3: |0>┤ H ├ + └───┘ + + + diff --git a/test/python/circuit/test_controlled_gate.py b/test/python/circuit/test_controlled_gate.py index cfd692e45537..0a611c8b9cc5 100644 --- a/test/python/circuit/test_controlled_gate.py +++ b/test/python/circuit/test_controlled_gate.py @@ -15,9 +15,9 @@ """Test Qiskit's inverse gate operation.""" -from math import pi from inspect import signature import numpy as np +from numpy import pi from ddt import ddt, data from qiskit import QuantumRegister, QuantumCircuit, execute, BasicAer @@ -113,7 +113,7 @@ def test_multi_controlled_composite_gate(self): sub_q = QuantumRegister(2) cgate = QuantumCircuit(sub_q, name='cgate') cgate.h(sub_q[0]) - cgate.crz(np.pi/2, sub_q[0], sub_q[1]) + cgate.crz(pi/2, sub_q[0], sub_q[1]) cgate.swap(sub_q[0], sub_q[1]) cgate.u3(0.1, 0.2, 0.3, sub_q[1]) cgate.t(sub_q[0])