From 9439c8fb188163985c1d5a8a3a57649d976ed172 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 19 Dec 2023 15:53:39 +0100 Subject: [PATCH] Remove Bit.register and Bit.index (#10996) * Remove Bit.register and Bit.index * remove impor * black * reno * Fixup release note --------- Co-authored-by: Jake Lishman --- qiskit/circuit/bit.py | 47 ------------------- .../notes/fixes_10744-83e5f33f5db74a22.yaml | 9 ++++ test/python/circuit/test_bit.py | 14 +----- 3 files changed, 10 insertions(+), 60 deletions(-) create mode 100644 releasenotes/notes/fixes_10744-83e5f33f5db74a22.yaml diff --git a/qiskit/circuit/bit.py b/qiskit/circuit/bit.py index d51e82c8462..fd5ce54cc46 100644 --- a/qiskit/circuit/bit.py +++ b/qiskit/circuit/bit.py @@ -16,7 +16,6 @@ import copy from qiskit.circuit.exceptions import CircuitError -from qiskit.utils.deprecation import deprecate_func class Bit: @@ -59,52 +58,6 @@ def __init__(self, register=None, index=None): self._hash = hash((self._register, self._index)) self._repr = f"{self.__class__.__name__}({self._register}, {self._index})" - @property - @deprecate_func( - is_property=True, - since="0.17", - package_name="qiskit-terra", - additional_msg=( - "Instead, use :meth:`~qiskit.circuit.quantumcircuit.QuantumCircuit.find_bit` to find " - "all the containing registers within a circuit and the index of the bit within the " - "circuit." - ), - ) - def register(self): # pylint: disable=bad-docstring-quotes - """Get the register of an old-style bit. - - In modern Qiskit Terra (version 0.17+), bits are the fundamental object and registers are - aliases to collections of bits. A bit can be in many registers depending on the circuit, so - a single containing register is no longer a property of a bit. It is an error to access - this attribute on bits that were not constructed as "owned" by a register.""" - if (self._register, self._index) == (None, None): - raise CircuitError("Attempt to query register of a new-style Bit.") - - return self._register - - @property - @deprecate_func( - is_property=True, - since="0.17", - package_name="qiskit-terra", - additional_msg=( - "Instead, use :meth:`~qiskit.circuit.quantumcircuit.QuantumCircuit.find_bit` to find " - "all the containing registers within a circuit and the index of the bit within the " - "circuit." - ), - ) - def index(self): # pylint: disable=bad-docstring-quotes - """Get the index of an old-style bit in the register that owns it. - - In modern Qiskit Terra (version 0.17+), bits are the fundamental object and registers are - aliases to collections of bits. A bit can be in many registers depending on the circuit, so - a single containing register is no longer a property of a bit. It is an error to access - this attribute on bits that were not constructed as "owned" by a register.""" - if (self._register, self._index) == (None, None): - raise CircuitError("Attempt to query index of a new-style Bit.") - - return self._index - def __repr__(self): """Return the official string representing the bit.""" if (self._register, self._index) == (None, None): diff --git a/releasenotes/notes/fixes_10744-83e5f33f5db74a22.yaml b/releasenotes/notes/fixes_10744-83e5f33f5db74a22.yaml new file mode 100644 index 00000000000..22af9ea1bac --- /dev/null +++ b/releasenotes/notes/fixes_10744-83e5f33f5db74a22.yaml @@ -0,0 +1,9 @@ +--- +upgrade: + - | + The properties ``Bit.register`` and ``Bit.index`` are removed. They were deprecated in + Qiskit 0.25 (released in April, 2021). The qubits and bits now live only in the context of + a :class:`.QuantumCircuit`. The alternative to the properties is + to use :meth:`.QuantumCircuit.find_bit` to find all the containing + registers within a circuit and the index of the bit within the + circuit. diff --git a/test/python/circuit/test_bit.py b/test/python/circuit/test_bit.py index a02e123ce20..cbacba159ab 100644 --- a/test/python/circuit/test_bit.py +++ b/test/python/circuit/test_bit.py @@ -17,7 +17,7 @@ from unittest import mock from qiskit.test import QiskitTestCase -from qiskit.circuit import bit, QuantumRegister +from qiskit.circuit import bit class TestBitClass(QiskitTestCase): @@ -106,15 +106,3 @@ def test_new_style_bit_equality(self): self.assertEqual(bit1, bit1) self.assertNotEqual(bit1, bit2) self.assertNotEqual(bit1, 3.14) - - def test_bit_register_backreferences_deprecated(self): - """Verify we raise a deprecation warning for register back-references.""" - - qr = QuantumRegister(3, "test_qr") - qubit = qr[0] - - with self.assertWarnsRegex(DeprecationWarning, "deprecated"): - _ = qubit.index - - with self.assertWarnsRegex(DeprecationWarning, "deprecated"): - _ = qubit.register