Skip to content
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

Remove label argument from MCMTVChain and MCMT #9324

Merged
merged 5 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 3 additions & 55 deletions qiskit/circuit/library/generalized_gates/mcmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

"""Multiple-Control, Multiple-Target Gate."""

import warnings
from typing import Union, Callable, List, Tuple, Optional
from typing import Union, Callable, List, Tuple

from qiskit.circuit import ControlledGate, Gate, Instruction, Qubit, QuantumRegister, QuantumCircuit
from qiskit.exceptions import QiskitError
Expand Down Expand Up @@ -50,7 +49,6 @@ def __init__(
gate: Union[Gate, Callable[[QuantumCircuit, Qubit, Qubit], Instruction]],
num_ctrl_qubits: int,
num_target_qubits: int,
label: Optional[str] = None,
) -> None:
"""Create a new multi-control multi-target gate.

Expand All @@ -60,22 +58,11 @@ def __init__(
If it is a callable, it will be casted to a Gate.
num_ctrl_qubits: The number of control qubits.
num_target_qubits: The number of target qubits.
label: The name for the controlled circuit block. If None, set to `C-name` where
`name` is `gate.name`.

Raises:
AttributeError: If the gate cannot be casted to a controlled gate.
AttributeError: If the number of controls or targets is 0.
"""
if label is not None:
warnings.warn(
"The MCMT 'label' kwarg is deprecated as of qiskit-terra 0.19.0 and "
"will be removed no earlier than 3 months after the release date. "
"For details, see https://github.com/Qiskit/qiskit-terra/issues/6934.",
DeprecationWarning,
2,
)

if num_ctrl_qubits == 0 or num_target_qubits == 0:
raise AttributeError("Need at least one control and one target qubit.")

Expand All @@ -87,11 +74,7 @@ def __init__(

# initialize the circuit object
super().__init__(num_qubits, name="mcmt")

if label is None:
self._label = f"{num_target_qubits}-{self.gate.name.capitalize()}"
else:
self._label = label
self._label = f"{num_target_qubits}-{self.gate.name.capitalize()}"

# build the circuit
self._build()
Expand All @@ -110,30 +93,6 @@ def _build(self):
mcmt_gate = broadcasted_gate.control(self.num_ctrl_qubits)
self.append(mcmt_gate, self.qubits, [])

@property
def label(self):
"""Get label."""
warnings.warn(
"The MCMT 'label' property is deprecated as of qiskit-terra 0.19.0 and "
"will be removed no earlier than 3 months after the release date. "
"For details, see https://github.com/Qiskit/qiskit-terra/issues/6934.",
DeprecationWarning,
2,
)
return self._label

@label.setter
def label(self, label):
"""Set label."""
warnings.warn(
"The MCMT 'label' property is deprecated as of qiskit-terra 0.19.0 and "
"will be removed no earlier than 3 months after the release date. "
"For details, see https://github.com/Qiskit/qiskit-terra/issues/6934.",
DeprecationWarning,
2,
)
self._label = label

@property
def num_ancilla_qubits(self):
"""Return the number of ancillas."""
Expand Down Expand Up @@ -180,19 +139,8 @@ def _identify_gate(self, gate):

def control(self, num_ctrl_qubits=1, label=None, ctrl_state=None):
"""Return the controlled version of the MCMT circuit."""
if label is not None:
warnings.warn(
"The MCMT.control 'label' kwarg is deprecated as of qiskit-terra 0.19.0 and "
"will be removed no earlier than 3 months after the release date. "
"For details, see https://github.com/Qiskit/qiskit-terra/issues/6934.",
DeprecationWarning,
2,
)

if ctrl_state is None: # TODO add ctrl state implementation by adding X gates
return MCMT(
self.gate, self.num_ctrl_qubits + num_ctrl_qubits, self.num_target_qubits, label
)
return MCMT(self.gate, self.num_ctrl_qubits + num_ctrl_qubits, self.num_target_qubits)
return super().control(num_ctrl_qubits, label, ctrl_state)

def inverse(self):
Expand Down
4 changes: 4 additions & 0 deletions releasenotes/notes/remove_mcmt_label-cee8a11e0164f8e1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
upgrade:
- |
The classes :class:`~.MCMT` and :class:`~.MCMTVChain` deprecated the argument `label` in 0.19 and now is being removed.
1ucian0 marked this conversation as resolved.
Show resolved Hide resolved
27 changes: 0 additions & 27 deletions test/python/circuit/library/test_mcmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,6 @@
class TestMCMT(QiskitTestCase):
"""Test the multi-controlled multi-target circuit."""

@data(MCMT, MCMTVChain)
def test_mcmt_label(self, mcmt_class):
"""Test MCMT label remains functional but is deprecated."""
custom_label = "abc"
with self.subTest(msg="init with label and get"):
with self.assertWarns(DeprecationWarning):
mcmt = mcmt_class(
XGate(), num_ctrl_qubits=1, num_target_qubits=1, label=custom_label
)
with self.assertWarns(DeprecationWarning):
self.assertEqual(mcmt.label, custom_label)

with self.subTest(msg="label set and get"):
mcmt = mcmt_class(XGate(), num_ctrl_qubits=1, num_target_qubits=1)
with self.assertWarns(DeprecationWarning):
mcmt.label = custom_label
with self.assertWarns(DeprecationWarning):
self.assertEqual(mcmt.label, custom_label)

with self.subTest(msg="control gate label"):
mcmt = mcmt_class(XGate(), num_ctrl_qubits=1, num_target_qubits=1)
c_mcmt = mcmt.control()
with self.assertWarns(DeprecationWarning):
c_mcmt = mcmt.control(label=custom_label)
with self.assertWarns(DeprecationWarning):
self.assertEqual(c_mcmt.label, custom_label)

@data(MCMT, MCMTVChain)
def test_mcmt_as_normal_control(self, mcmt_class):
"""Test that the MCMT can act as normal control gate."""
Expand Down