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

Allow numbers.Integral instead of only built-in int for QuantumRegister index #4591

Merged
merged 25 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0e6a04f
fixed issue 3929
arunraja-hub Jun 18, 2020
7544283
release note for #4591
arunraja-hub Jun 20, 2020
e9e049e
Update qiskit/circuit/register.py
arunraja-hub Jun 22, 2020
efdb422
Update releasenotes/notes/allowIntegerforQuantumRegisterSize-2e9a6cc0…
arunraja-hub Jun 22, 2020
487b455
Update releasenotes/notes/allowIntegerforQuantumRegisterSize-2e9a6cc0…
arunraja-hub Jun 23, 2020
e42801e
test for passing different types of integer as register sizes
arunraja-hub Jun 23, 2020
f670cb5
Merge branch 'fixissue3929' of https://github.com/arunraja-hub/qiskit…
arunraja-hub Jun 23, 2020
c0bd2bb
fixed lint issues
arunraja-hub Jun 24, 2020
5589651
Merge branch 'master' into fixissue3929
Cryoris Jun 24, 2020
c1ad60e
add test for np.int32 and 64
Cryoris Jun 24, 2020
7542af2
added tests for int32 and int64
arunraja-hub Jun 24, 2020
5fb7eb7
Merge branch 'fixissue3929' of https://github.com/arunraja-hub/qiskit…
arunraja-hub Jun 24, 2020
49587bf
Merge branch 'master' into fixissue3929
Jun 27, 2020
568277e
Merge branch 'master' into fixissue3929
Cryoris Jun 30, 2020
69476af
Update releasenotes/notes/allowIntegerforQuantumRegisterSize-2e9a6cc0…
arunraja-hub Jun 30, 2020
38fb6e7
resolved issue 3929
arunraja-hub Jul 8, 2020
6375707
Update qiskit/circuit/register.py
arunraja-hub Jul 8, 2020
f8eb801
resolved 3929
arunraja-hub Jul 21, 2020
f29419a
resolved
arunraja-hub Jul 21, 2020
95f48dd
resolved
arunraja-hub Jul 21, 2020
916fd05
resolved
arunraja-hub Jul 21, 2020
7287f29
Update qiskit/circuit/register.py
arunraja-hub Jul 21, 2020
58b7bf0
numbers.Integral includes int
Cryoris Jul 21, 2020
1f9d67e
Merge branch 'master' into fixissue3929
Cryoris Jul 21, 2020
01673f6
Merge branch 'master' into fixissue3929
Cryoris Jul 22, 2020
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
5 changes: 3 additions & 2 deletions qiskit/circuit/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"""
import re
import itertools
import numbers

from qiskit.circuit.exceptions import CircuitError

Expand Down Expand Up @@ -117,7 +118,7 @@ def __getitem__(self, key):
CircuitError: if the `key` is not an integer.
QiskitIndexError: if the `key` is not in the range `(0, self.size)`.
"""
if not isinstance(key, (int, slice, list)):
if not isinstance(key, (numbers.Integral, int, slice, list)):
Cryoris marked this conversation as resolved.
Show resolved Hide resolved
raise CircuitError("expected integer or slice index into register")
if isinstance(key, slice):
return self._bits[key]
Expand Down Expand Up @@ -152,4 +153,4 @@ def __eq__(self, other):

def __hash__(self):
"""Make object hashable, based on the name and size to hash."""
return self._hash
return self._hash
arunraja-hub marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
Use numbers.Integral instead of Python's built-in ``int`` as
supported index to ``QuantumRegister`` and ``ClassicalRegister``.

12 changes: 12 additions & 0 deletions test/python/circuit/test_circuit_registers.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ def test_qarg_numpy_int_size(self):
self.assertEqual(qr1.size, 10)
self.assertEqual(type(qr1), QuantumRegister)

def test_register_int_types(self):
"""Test attempt to pass different types of integer as indices
of QuantumRegister and ClassicalRegister
"""
ints = [int(2), np.int(2), np.int32(2), np.int64(2)]
for index in ints:
with self.subTest(index=index):
qr = QuantumRegister(4)
cr = ClassicalRegister(4)
self.assertEqual(qr[index], qr[2])
self.assertEqual(cr[index], cr[2])

def test_numpy_array_of_registers(self):
"""Test numpy array of Registers .
See https://github.com/Qiskit/qiskit-terra/issues/1898
Expand Down