Skip to content

Commit 79396cb

Browse files
committed
add label for ccx
1 parent 005fe52 commit 79396cb

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

qiskit/circuit/quantumcircuit.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6284,6 +6284,7 @@ def ccx(
62846284
control_qubit1: QubitSpecifier,
62856285
control_qubit2: QubitSpecifier,
62866286
target_qubit: QubitSpecifier,
6287+
label: str | None = None,
62876288
ctrl_state: str | int | None = None,
62886289
) -> InstructionSet:
62896290
r"""Apply :class:`~qiskit.circuit.library.CCXGate`.
@@ -6294,6 +6295,7 @@ def ccx(
62946295
control_qubit1: The qubit(s) used as the first control.
62956296
control_qubit2: The qubit(s) used as the second control.
62966297
target_qubit: The qubit(s) targeted by the gate.
6298+
label: The string label of the gate in the circuit.
62976299
ctrl_state:
62986300
The control state in decimal, or as a bitstring (e.g. '1'). Defaults to controlling
62996301
on the '1' state.
@@ -6307,12 +6309,13 @@ def ccx(
63076309
StandardGate.CCX,
63086310
[control_qubit1, control_qubit2, target_qubit],
63096311
(),
6312+
label=label,
63106313
)
63116314

63126315
from .library.standard_gates.x import CCXGate
63136316

63146317
return self.append(
6315-
CCXGate(ctrl_state=ctrl_state),
6318+
CCXGate(label=label, ctrl_state=ctrl_state),
63166319
[control_qubit1, control_qubit2, target_qubit],
63176320
[],
63186321
copy=False,

test/python/circuit/test_controlled_gate.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,14 @@ def test_ccx_ctrl_state_consistency(self):
11141114
ref_circuit.append(ccx, [qreg[0], qreg[1], qreg[2]])
11151115
self.assertEqual(qc, ref_circuit)
11161116

1117+
def test_ccx_label_parameter(self):
1118+
"""To check that labels are forwarded to CCX gates."""
1119+
qreg = QuantumRegister(3)
1120+
qc = QuantumCircuit(qreg)
1121+
qc.ccx(qreg[0], qreg[1], qreg[2], label="my_ccx", ctrl_state=0)
1122+
1123+
self.assertEqual(qc.data[0].operation.label, "my_ccx")
1124+
11171125
@data((4, [0, 1, 2], 3, "010"), (4, [2, 1, 3], 0, 2))
11181126
@unpack
11191127
def test_multi_control_x_ctrl_state_parameter(

0 commit comments

Comments
 (0)