Skip to content

Commit

Permalink
Remove Bit.register and Bit.index (Qiskit#10996)
Browse files Browse the repository at this point in the history
* Remove Bit.register and Bit.index

* remove impor

* black

* reno

* Fixup release note

---------

Co-authored-by: Jake Lishman <[email protected]>
  • Loading branch information
1ucian0 and jakelishman authored Dec 19, 2023
1 parent f808fe5 commit 9439c8f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 60 deletions.
47 changes: 0 additions & 47 deletions qiskit/circuit/bit.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import copy

from qiskit.circuit.exceptions import CircuitError
from qiskit.utils.deprecation import deprecate_func


class Bit:
Expand Down Expand Up @@ -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):
Expand Down
9 changes: 9 additions & 0 deletions releasenotes/notes/fixes_10744-83e5f33f5db74a22.yaml
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 1 addition & 13 deletions test/python/circuit/test_bit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

0 comments on commit 9439c8f

Please sign in to comment.